diff options
author | Julian T <julian@jtle.dk> | 2024-05-26 22:20:40 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2024-05-29 22:25:47 +0200 |
commit | afb0a04fe600575b00d551da7dce6a08679ef7b8 (patch) | |
tree | 8f90720887cf49045d65a9d17dad984dae06275c /page.go | |
parent | 9b55b16f3b906958171b4f45002b58d5f77b9705 (diff) |
Diffstat (limited to 'page.go')
-rw-r--r-- | page.go | 61 |
1 files changed, 48 insertions, 13 deletions
@@ -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 } |