From 4808994bf548a384f5c4de99b3e5667382bed936 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Mon, 2 May 2016 08:49:56 -0400 Subject: Get filtering by projects, contexts working --- todolist/grouper.go | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'todolist/grouper.go') 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 -} -- cgit v1.3