support only looping

This commit is contained in:
Bel LaPointe
2021-08-17 11:47:10 -06:00
parent fc088ec240
commit 95b10fd9f6
3 changed files with 19 additions and 6 deletions

View File

@@ -20,16 +20,24 @@ type taskWithDelta struct {
func (a *Ajax) loadTasks(w http.ResponseWriter, r *http.Request) error {
listID, _, _ := a.Cur(r)
filterComplete := filterComplete(form.Get(r, "compl"))
filterLooping := filterLooping(form.Get(r, "looping"))
filterTags := filterTags(form.ToStrArr(form.Get(r, "t")))
filterSubstr := filterSubstr(form.Get(r, "s"))
// TODO filter loop
tasks, err := a.storageListTasks(listID, filterComplete, filterTags, filterSubstr)
tasks, err := a.storageListTasks(listID, filterComplete, filterTags, filterSubstr, filterLooping)
if err != nil {
return err
}
return json.NewEncoder(w).Encode(map[string]interface{}{"list": tasks})
}
func filterLooping(looping string) func(t *task.Task) bool {
return func(t *task.Task) bool {
hasLoop := t.Loop > 0 || t.Cron != ""
onlyLooping := looping == "1"
return !onlyLooping || hasLoop
}
}
func filterComplete(compl string) func(t *task.Task) bool {
return func(t *task.Task) bool {
return compl == "" || !t.Complete || (compl == "1" && t.Complete)