summaryrefslogtreecommitdiff
path: root/page.go
diff options
context:
space:
mode:
authorJulian Jørgensen <julian@jtle.dk>2024-05-25 11:53:43 +0200
committerJulian Jørgensen <julian@jtle.dk>2024-05-25 11:53:43 +0200
commit2610f9b67e4a915859c029da9b17e9d262b6564e (patch)
tree4504bf2d995703f583fff199b1ae7e54eef4e432 /page.go
parent6cdd02af0684500b5376d4d4a08feb796fdaf889 (diff)
Add task ui and editingold
Diffstat (limited to 'page.go')
-rw-r--r--page.go38
1 files changed, 37 insertions, 1 deletions
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
}