diff options
| author | Grant Ammons <gammons@gmail.com> | 2016-05-02 08:49:56 -0400 |
|---|---|---|
| committer | Grant Ammons <gammons@gmail.com> | 2016-05-02 08:49:56 -0400 |
| commit | 4808994bf548a384f5c4de99b3e5667382bed936 (patch) | |
| tree | 1a055ffdfeb5b00c64f2b4cf7c89240d1b9b4f9f /todolist/grouper.go | |
| parent | 471b93141074222bdef537f08b6443e91fa0ea2f (diff) | |
Get filtering by projects, contexts working
Diffstat (limited to 'todolist/grouper.go')
| -rw-r--r-- | todolist/grouper.go | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/todolist/grouper.go b/todolist/grouper.go index 25547bf..2d13391 100644 --- a/todolist/grouper.go +++ b/todolist/grouper.go @@ -12,13 +12,16 @@ func (g *Grouper) GroupByContext(todos []Todo) *GroupedTodos { allContexts := []string{} for _, todo := range todos { - allContexts = addIfNotThere(allContexts, todo.Contexts) + allContexts = AddIfNotThere(allContexts, todo.Contexts) } for _, todo := range todos { for _, context := range todo.Contexts { groups[context] = append(groups[context], todo) } + if len(todo.Contexts) == 0 { + groups["No contexts"] = append(groups["No contexts"], todo) + } } return &GroupedTodos{Groups: groups} @@ -30,13 +33,16 @@ func (g *Grouper) GroupByProject(todos []Todo) *GroupedTodos { allProjects := []string{} for _, todo := range todos { - allProjects = addIfNotThere(allProjects, todo.Projects) + allProjects = AddIfNotThere(allProjects, todo.Projects) } for _, todo := range todos { for _, project := range todo.Projects { groups[project] = append(groups[project], todo) } + if len(todo.Projects) == 0 { + groups["No projects"] = append(groups["No projects"], todo) + } } return &GroupedTodos{Groups: groups} } @@ -46,18 +52,3 @@ func (g *Grouper) GroupByNothing(todos []Todo) *GroupedTodos { groups["all"] = todos return &GroupedTodos{Groups: groups} } - -func addIfNotThere(arr []string, items []string) []string { - for _, item := range items { - there := false - for _, arrItem := range arr { - if item == arrItem { - there = true - } - } - if !there { - arr = append(arr, item) - } - } - return arr -} |
