From 2610f9b67e4a915859c029da9b17e9d262b6564e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20J=C3=B8rgensen?= Date: Sat, 25 May 2024 11:53:43 +0200 Subject: Add task ui and editing --- page.go | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'page.go') diff --git a/page.go b/page.go index b58436d..8e2074e 100644 --- a/page.go +++ b/page.go @@ -24,12 +24,18 @@ type RootPage struct { DateInfo DateInfo Entry *EntryPage Entries []*Entry + Task *TaskPage + Tasks []*Task } type TasksPage struct { Tasks []*Task } +type TaskPage struct { + Task *Task +} + func NewService(db Database) *Service { return &Service{ Db: db, @@ -45,6 +51,23 @@ func NewDateInfo(t time.Time) DateInfo { } } +func (srv *Service) GetTaskPage(id *int, task *Task) (*TaskPage, error) { + if task == nil { + tasks, err := srv.Db.QueryTask(id, nil, nil) + if err != nil { + return nil, err + } + if len(tasks) < 1 { + return nil, ErrNotFound + } + task = tasks[0] + } + + return &TaskPage{ + Task: task, + }, nil +} + func (srv *Service) GetTasksPage() (*TasksPage, error) { tasks, err := srv.Db.GetTasks() if err != nil { @@ -54,6 +77,7 @@ func (srv *Service) GetTasksPage() (*TasksPage, error) { Tasks: tasks, }, nil } + func (srv *Service) GetEntryPage(detached *Entry, dt DateInfo) (*EntryPage, error) { tracking, err := srv.Db.GetTracking() if err != nil { @@ -81,7 +105,7 @@ func (srv *Service) GetRootPage(date Date) (*RootPage, error) { // If not today detach entry = NewEntry(date) } - + entryPage, err := srv.GetEntryPage(entry, NewDateInfo(date.ToStd())) if err != nil { return nil, err @@ -91,9 +115,21 @@ func (srv *Service) GetRootPage(date Date) (*RootPage, error) { return nil, err } + tasks, err := srv.Db.GetTasks() + if err != nil { + return nil, err + } + + task, err := srv.GetTaskPage(nil, NewTask()) + if err != nil { + return nil, err + } + return &RootPage{ DateInfo: entryPage.DateInfo, Entry: entryPage, Entries: entries, + Task: task, + Tasks: tasks, }, nil } -- cgit v1.2.3