From afb0a04fe600575b00d551da7dce6a08679ef7b8 Mon Sep 17 00:00:00 2001 From: Julian T Date: Sun, 26 May 2024 22:20:40 +0200 Subject: Working task selection --- page.go | 61 ++++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 13 deletions(-) (limited to 'page.go') diff --git a/page.go b/page.go index 8e2074e..cae7ecb 100644 --- a/page.go +++ b/page.go @@ -1,6 +1,8 @@ package main -import "time" +import ( + "time" +) type Service struct { Db Database @@ -14,10 +16,12 @@ type DateInfo struct { } type EntryPage struct { - Entry *Entry - Detached bool - Tracking *Entry - DateInfo DateInfo + Entry *Entry + Detached bool + Tracking *Entry + DateInfo DateInfo + GroupToTasks map[string]([]*Task) + TaskCount int } type RootPage struct { @@ -25,11 +29,12 @@ type RootPage struct { Entry *EntryPage Entries []*Entry Task *TaskPage - Tasks []*Task + Tasks *TasksPage } type TasksPage struct { - Tasks []*Task + Tasks []*Task + GroupToTasks map[string]([]*Task) } type TaskPage struct { @@ -73,8 +78,26 @@ func (srv *Service) GetTasksPage() (*TasksPage, error) { if err != nil { return nil, err } + + mp := make(map[string]([]*Task)) + + for _, task := range tasks { + key := task.Group + if key == nil { + empty := "" + key = &empty + } + mparr, ok := mp[*key] + if !ok { + mparr = make([]*Task, 0) + } + mparr = append(mparr, task) + mp[*key] = mparr + } + return &TasksPage{ - Tasks: tasks, + Tasks: tasks, + GroupToTasks: mp, }, nil } @@ -83,11 +106,19 @@ func (srv *Service) GetEntryPage(detached *Entry, dt DateInfo) (*EntryPage, erro if err != nil { return nil, err } + + tasksPage, err := srv.GetTasksPage() + if err != nil { + return nil, err + } + page := &EntryPage{ - Entry: tracking, - Detached: false, - Tracking: tracking, - DateInfo: dt, + Entry: tracking, + Detached: false, + Tracking: tracking, + DateInfo: dt, + GroupToTasks: tasksPage.GroupToTasks, + TaskCount: 0, } if detached != nil { @@ -95,6 +126,10 @@ func (srv *Service) GetEntryPage(detached *Entry, dt DateInfo) (*EntryPage, erro page.Detached = true } + if page.Entry != nil { + page.TaskCount = len(page.Entry.Tasks) + } + return page, nil } @@ -115,7 +150,7 @@ func (srv *Service) GetRootPage(date Date) (*RootPage, error) { return nil, err } - tasks, err := srv.Db.GetTasks() + tasks, err := srv.GetTasksPage() if err != nil { return nil, err } -- cgit v1.2.3