diff --git a/models/routine.nim b/models/routine.nim index f79cc97..4fdd74c 100644 --- a/models/routine.nim +++ b/models/routine.nim @@ -1,3 +1,8 @@ +#[Copyright 2023 ITwrx. +This file is part of EZ-Bkup. +EZ-Bkup is released under the General Public License 3.0. +See COPYING or for details.]# + import std/[tables, strutils, sugar, hashes, algorithm, os] from std/sequtils import toSeq import tiny_sqlite @@ -18,13 +23,12 @@ type Routine* = object id*: RoutineId name*: string selected*: bool - #selByDef == selected by default. + #selected by default. selByDef*: bool sources*: seq[string] destinations*: seq[string] proc stringToSeq(commaSepString: string):seq[string] = - #return toSeq(commaSepString.split(',')) var newSeq: seq[string] if hasCommas(commaSepString) == true: newSeq = toSeq(commaSepString.split(',')) @@ -34,7 +38,6 @@ proc stringToSeq(commaSepString: string):seq[string] = return newSeq proc seqToString(strSeq: seq[string]):string = - #return strSeq.join(",") var newStr: string if strSeq.len >= 1: newStr = strSeq.join(",") @@ -67,11 +70,6 @@ proc locationsExist*(routine: Routine): bool = else: return true -#[proc matches*(routine: Routine, filter: string): bool = - ## Checks if the routine matches the given filter. - ## This function is used to search the list of routines. - filter.toLowerAscii() in toLowerAscii(routine.name)]# - type RoutineModel* = ref object ## Model for storing all routines. We model this as a ref object, so that changes ## made by any widget are also known to all other widgets that use the model. @@ -83,7 +81,7 @@ proc cmpRoutines(a, b: Routine): int = cmp(a.name, b.name) -#this is our stand-in for the search proc. returns a seq so we can iterate in routine_list. +#returns a seq so we can iterate in routine_list. proc routineSeq*(model: RoutineModel): seq[Routine] = var routineSeq: seq[Routine] ## Returns a seq of all routines. "id" is necessary to loop through table. @@ -92,8 +90,6 @@ proc routineSeq*(model: RoutineModel): seq[Routine] = routineSeq.sort(cmpRoutines, Ascending) - #echo routineSeq - return routineSeq let homePath = expandTilde("~") @@ -141,9 +137,6 @@ proc newRoutineModel*(path: string = homePath & "/.ez-bkup/ez-bkup.sqlite"): Rou destinationsSeq = stringToSeq(destinations) routines[id] = Routine(id: id, name: name, selByDef: selByDef, sources: sourcesSeq, destinations: destinationsSeq) - - #echo "newRoutineModel:" - #echo routines result = RoutineModel(db: db, routines: routines) @@ -184,14 +177,6 @@ proc update*(model: RoutineModel, routine: Routine) = # Update RoutineModel.routines model.routines[routine.id] = routine -#[proc search*(model: UserModel, filter: string): seq[User] {.locks: 0.} = - ## Returns a seq of all users that match the given filter. - for id, user in model.users: - if user.matches(filter): - result.add(user) - - result.sort((a, b: User) => cmp(a.lastName, b.lastName))]# - proc delete*(model: RoutineModel, id: RoutineId) = ## Deletes the routine with the given ID @@ -199,22 +184,4 @@ proc delete*(model: RoutineModel, id: RoutineId) = model.db.exec("DELETE FROM Routine WHERE id = ?", id) # Update RoutineModel.routines - model.routines.del(id) - -proc clear*(model: RoutineModel) = - ## Deletes all routines - - # Delete all routines from database - model.db.exec("DELETE FROM Routine") - - # Update RoutineModel.routines - model.routines.clear() - -#preload the selected seq with routines that have selByDef == true. -proc selectedPreload*(): seq[RoutineId] = - var selected: seq[RoutineId] - let model = newRoutineModel(databasePath) - for routine in model.routineSeq(): - if routine.selByDef == true: - selected.add(routine.id) - return selected \ No newline at end of file + model.routines.del(id) \ No newline at end of file