diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-08-07 10:39:28 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-08-07 10:39:28 +0000 |
| commit | eadd17df2946a1219fdf02f2ee0a0ac19734e56d (patch) | |
| tree | e0460d1cdd9c17fd47ce7cce2fe7845378d8011e /internal | |
| parent | 06450fe69ade2928deb9274bb67b7ba60d394b4f (diff) | |
Wire the Tasks tab into nav; fold in buckets/projects/labels and recurrence
The Tasks tab (/tabs/tasks) existed server-side and was tested, but
nothing in the nav linked to it -- it was pure dead weight in the other
direction. Wiring it up as the natural home for everything that was
either misplaced in Settings or missing a web UI entirely:
- Maintenance Buckets, Projects, and Labels moved out of Settings and
into the Tasks tab (restyled from Settings' opaque slate cards to the
glass/backdrop-blur look already used by the tab's chain/atom cards --
they're now embedded in index.html's page shell, not a standalone
page, so the shared bg-card/bg-input classes from that shell apply).
Settings keeps only what's actually settings: Passkeys, Trusted
Agents, Data Sources.
- Added a Recurrence section to the task-detail modal (freq/interval/
weekday form, posting to a new POST /tasks/recurrence -- the HTMX
counterpart to the widget API's HandleWidgetTaskRecurrence). Native
task recurrence previously had zero web UI at all, only reachable via
the Android widget's RecurrenceEditDialog.
Also fixed a real bug found while touching this code: HandleGetTaskDetail's
source switch only had a case for "trello" -- opening any native ("doot")
task's detail modal, which is most tasks in this tab, showed a blank
title and description. Factored both call sites (initial GET and the
re-render after a recurrence edit) through one loadTaskDetailData helper
and added the missing "doot" case. Also fixed task-detail.html's styling,
which was still using pre-dark-theme classes (text-gray-900 etc.) --
functionally invisible text on the modal's dark background.
Verified with a throwaway local server (real templates + real DB, not
the MockRenderer the unit tests use) seeded with a recurring task,
a bucket, a project, and a label -- confirmed all five touched routes
render 200 with the expected content, including the populated
Buckets/Projects/Labels sections and a real weekly-recurrence form
with the correct weekdays pre-checked. Caught and fixed a copy bug
this way too ("every 2 weeklys" -> "every 2 weeks"). Not committed;
deleted after use.
go build ./..., go vet ./..., and go test ./... all clean.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EZ7ikw2ukGJFTHE3bJS7zL
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/handlers/buckets_web_test.go | 24 | ||||
| -rw-r--r-- | internal/handlers/chains_web_test.go | 3 | ||||
| -rw-r--r-- | internal/handlers/handlers.go | 160 | ||||
| -rw-r--r-- | internal/handlers/handlers_test.go | 107 | ||||
| -rw-r--r-- | internal/handlers/settings.go | 9 |
5 files changed, 264 insertions, 39 deletions
diff --git a/internal/handlers/buckets_web_test.go b/internal/handlers/buckets_web_test.go index befdc01..b29e842 100644 --- a/internal/handlers/buckets_web_test.go +++ b/internal/handlers/buckets_web_test.go @@ -7,7 +7,6 @@ import ( "testing" "task-dashboard/internal/models" - "task-dashboard/internal/store" ) func TestHandleBucketsCreate_Web_CreatesBucket(t *testing.T) { @@ -143,7 +142,7 @@ func TestHandleBucketDelete_Web_RemovesBucket(t *testing.T) { } } -func TestHandleSettingsPage_IncludesBucketsProjectsLabels(t *testing.T) { +func TestHandleTabTasks_IncludesBucketsProjectsLabels(t *testing.T) { h, cleanup := setupTestHandler(t) defer cleanup() if _, err := h.store.CreateBucket("Gutters", 30, 1); err != nil { @@ -156,9 +155,9 @@ func TestHandleSettingsPage_IncludesBucketsProjectsLabels(t *testing.T) { t.Fatal(err) } - req := httptest.NewRequest("GET", "/settings", nil) + req := httptest.NewRequest("GET", "/tabs/tasks", nil) w := httptest.NewRecorder() - h.HandleSettingsPage(w, req) + h.HandleTabTasks(w, req) if w.Code != http.StatusOK { t.Fatalf("status = %d, want 200, body=%s", w.Code, w.Body.String()) @@ -167,15 +166,14 @@ func TestHandleSettingsPage_IncludesBucketsProjectsLabels(t *testing.T) { mock := h.renderer.(*MockRenderer) lastCall := mock.Calls[len(mock.Calls)-1] data, ok := lastCall.Data.(struct { - Configs map[string][]models.SourceConfig - Sources []string - SyncLog []store.SyncLogEntry - Agents []models.Agent - Buckets []models.BucketSummary - Projects []models.Project - Labels []models.LabelColor - CSRFToken string - WebAuthnEnabled bool + Atoms []models.Atom + FutureAtoms []models.Atom + Boards []models.Board + Chains []models.ChainSummary + Buckets []models.BucketSummary + Projects []models.Project + Labels []models.LabelColor + Today string }) if !ok { t.Fatalf("unexpected data type %T", lastCall.Data) diff --git a/internal/handlers/chains_web_test.go b/internal/handlers/chains_web_test.go index d27dab9..b297fb1 100644 --- a/internal/handlers/chains_web_test.go +++ b/internal/handlers/chains_web_test.go @@ -197,6 +197,9 @@ func TestHandleTabTasks_IncludesChainSummaries(t *testing.T) { FutureAtoms []models.Atom Boards []models.Board Chains []models.ChainSummary + Buckets []models.BucketSummary + Projects []models.Project + Labels []models.LabelColor Today string }) if !ok { diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index a5bc51a..ed15e89 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -10,6 +10,7 @@ import ( "net/http" "path/filepath" "sort" + "strconv" "strings" "sync" "time" @@ -68,6 +69,45 @@ func New(s *store.Store, trello api.TrelloAPI, planToEat api.PlanToEatAPI, googl return "" } }, + // hasInt reports whether n is present in a []int -- used to pre-check + // the weekday checkboxes on a recurring task's edit form. + "hasInt": func(list []int, n int) bool { + for _, v := range list { + if v == n { + return true + } + } + return false + }, + // recurrenceUnit maps a recurrence freq to its singular noun, so the + // task-detail template can say "every 2 weeks" instead of gluing an + // "s" onto the adjective "weekly" ("every 2 weeklys"). + "recurrenceUnit": func(freq string) string { + switch freq { + case "daily": + return "day" + case "weekly": + return "week" + case "monthly": + return "month" + case "yearly": + return "year" + default: + return freq + } + }, + // weekdayNames formats recurrence weekday indices (0=Sunday, matching + // time.Weekday, see models/recurrence.go) as "Mon, Wed, Fri". + "weekdayNames": func(weekdays []int) string { + names := [7]string{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"} + parts := make([]string, 0, len(weekdays)) + for _, d := range weekdays { + if d >= 0 && d < 7 { + parts = append(parts, names[d]) + } + } + return strings.Join(parts, ", ") + }, } // Parse templates including partials @@ -752,37 +792,102 @@ func (h *Handler) HandleGetListsOptions(w http.ResponseWriter, r *http.Request) HTMLResponse(w, h.renderer, "lists-options", lists) } -// HandleGetTaskDetail returns task details as HTML for modal -func (h *Handler) HandleGetTaskDetail(w http.ResponseWriter, r *http.Request) { - id := r.URL.Query().Get("id") - source := r.URL.Query().Get("source") - - if id == "" || source == "" { - JSONError(w, http.StatusBadRequest, "Missing id or source", nil) - return - } +// taskDetailData is what the "task-detail" template renders (the modal +// opened from any tab's task card). Recurrence fields are doot-native only. +type taskDetailData struct { + Title string + ID string + Source string + Description string + IsDoot bool + RecurrenceFreq string + RecurrenceInterval int + RecurrenceWeekdays []int +} - var title, description string +// loadTaskDetailData fetches a task's current fields for the detail modal, +// shared between the initial GET and re-rendering after a recurrence edit. +func (h *Handler) loadTaskDetailData(id, source string) taskDetailData { + data := taskDetailData{ID: id, Source: source} switch source { case "trello": if boards, err := h.store.GetBoards(); err == nil { for _, b := range boards { for _, c := range b.Cards { if c.ID == id { - title, description = c.Name, c.Description + data.Title, data.Description = c.Name, c.Description break } } } } + case "doot": + if task, err := h.store.GetNativeTaskByID(id); err == nil { + data.IsDoot = true + data.Title = task.Content + data.Description = task.Description + data.RecurrenceFreq = task.RecurrenceFreq + data.RecurrenceInterval = task.RecurrenceInterval + data.RecurrenceWeekdays = task.RecurrenceWeekdays + } } + return data +} - HTMLResponse(w, h.renderer, "task-detail", struct { - Title string - ID string - Source string - Description string - }{title, id, source, description}) +// HandleGetTaskDetail returns task details as HTML for modal. +func (h *Handler) HandleGetTaskDetail(w http.ResponseWriter, r *http.Request) { + id := r.URL.Query().Get("id") + source := r.URL.Query().Get("source") + + if id == "" || source == "" { + JSONError(w, http.StatusBadRequest, "Missing id or source", nil) + return + } + + HTMLResponse(w, h.renderer, "task-detail", h.loadTaskDetailData(id, source)) +} + +// HandleSetTaskRecurrence sets or clears a doot-native task's recurrence +// pattern from the web task-detail modal -- the HTMX counterpart to the +// widget API's HandleWidgetTaskRecurrence (internal/handlers/widget.go). +// freq == "" clears recurrence. Re-renders the detail modal so it reflects +// the new state without closing. +func (h *Handler) HandleSetTaskRecurrence(w http.ResponseWriter, r *http.Request) { + if err := r.ParseForm(); err != nil { + JSONError(w, http.StatusBadRequest, "Failed to parse form", err) + return + } + id := r.FormValue("id") + if id == "" { + JSONError(w, http.StatusBadRequest, "Missing id", nil) + return + } + freq := r.FormValue("freq") + if freq != "" && freq != "daily" && freq != "weekly" && freq != "monthly" && freq != "yearly" { + JSONError(w, http.StatusBadRequest, "Invalid freq", nil) + return + } + interval, _ := strconv.Atoi(r.FormValue("interval")) + if interval <= 0 { + interval = 1 + } + var weekdays []int + for _, d := range r.Form["weekdays"] { + if n, err := strconv.Atoi(d); err == nil { + weekdays = append(weekdays, n) + } + } + + if err := h.store.SetTaskRecurrence(id, freq, interval, weekdays); err != nil { + if errors.Is(err, store.ErrNativeTaskNotFound) { + JSONError(w, http.StatusNotFound, "task not found", err) + return + } + JSONError(w, http.StatusInternalServerError, "Failed to update recurrence", err) + return + } + + HTMLResponse(w, h.renderer, "task-detail", h.loadTaskDetailData(id, "doot")) } // HandleTaskDetailPage renders a standalone full-page task detail view (used by Android widget deep-links). @@ -889,6 +994,21 @@ func (h *Handler) HandleTabTasks(w http.ResponseWriter, r *http.Request) { log.Printf("Warning: failed to build chain summaries: %v", err) } + bucketSummaries, err := BuildBucketSummaries(h.store) + if err != nil { + log.Printf("Warning: failed to build bucket summaries: %v", err) + } + + projects, err := h.store.GetProjects() + if err != nil { + log.Printf("Warning: failed to load projects: %v", err) + } + + labels, err := h.store.GetLabelColors() + if err != nil { + log.Printf("Warning: failed to load label colors: %v", err) + } + SortAtomsByUrgency(atoms) currentAtoms, futureAtoms := PartitionAtomsByTime(atoms) @@ -897,12 +1017,18 @@ func (h *Handler) HandleTabTasks(w http.ResponseWriter, r *http.Request) { FutureAtoms []models.Atom Boards []models.Board Chains []models.ChainSummary + Buckets []models.BucketSummary + Projects []models.Project + Labels []models.LabelColor Today string }{ Atoms: currentAtoms, FutureAtoms: futureAtoms, Boards: boards, Chains: chainSummaries, + Buckets: bucketSummaries, + Projects: projects, + Labels: labels, Today: config.Now().Format("2006-01-02"), } diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 4c776b0..a43dec2 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -1869,6 +1869,113 @@ func TestHandleGetTaskDetail_RendersTemplate(t *testing.T) { } } +// TestHandleGetTaskDetail_DootSource_LoadsRealTaskFields guards against a +// regression where source=="doot" fell through the switch in +// loadTaskDetailData with no case, silently leaving Title/Description blank +// -- native tasks are the primary type the Tasks tab and its detail modal +// are built around, so this previously meant opening any native task's +// detail showed an empty modal. +func TestHandleGetTaskDetail_DootSource_LoadsRealTaskFields(t *testing.T) { + h, cleanup := setupTestHandler(t) + defer cleanup() + + if err := h.store.CreateNativeTask(models.Task{ + ID: "task-1", Content: "Clean gutters", Description: "Ladder's in the garage", Priority: 1, + }); err != nil { + t.Fatal(err) + } + + req := httptest.NewRequest("GET", "/tasks/detail?id=task-1&source=doot", nil) + w := httptest.NewRecorder() + h.HandleGetTaskDetail(w, req) + + if w.Code != http.StatusOK { + t.Fatalf("status = %d, want 200, body=%s", w.Code, w.Body.String()) + } + + mock := h.renderer.(*MockRenderer) + lastCall := mock.Calls[len(mock.Calls)-1] + data, ok := lastCall.Data.(taskDetailData) + if !ok { + t.Fatalf("unexpected data type %T", lastCall.Data) + } + if !data.IsDoot { + t.Error("IsDoot = false, want true") + } + if data.Title != "Clean gutters" { + t.Errorf("Title = %q, want %q", data.Title, "Clean gutters") + } + if data.Description != "Ladder's in the garage" { + t.Errorf("Description = %q, want %q", data.Description, "Ladder's in the garage") + } +} + +func TestHandleSetTaskRecurrence_SetsAndClears(t *testing.T) { + h, cleanup := setupTestHandler(t) + defer cleanup() + + if err := h.store.CreateNativeTask(models.Task{ID: "task-1", Content: "Water plants", Priority: 1}); err != nil { + t.Fatal(err) + } + + req := httptest.NewRequest("POST", "/tasks/recurrence", strings.NewReader("id=task-1&freq=weekly&interval=2&weekdays=1&weekdays=3")) + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + w := httptest.NewRecorder() + h.HandleSetTaskRecurrence(w, req) + + if w.Code != http.StatusOK { + t.Fatalf("status = %d, want 200, body=%s", w.Code, w.Body.String()) + } + task, err := h.store.GetNativeTaskByID("task-1") + if err != nil { + t.Fatal(err) + } + if task.RecurrenceFreq != "weekly" || task.RecurrenceInterval != 2 { + t.Errorf("recurrence = freq=%q interval=%d, want weekly/2", task.RecurrenceFreq, task.RecurrenceInterval) + } + if len(task.RecurrenceWeekdays) != 2 { + t.Errorf("weekdays = %v, want [1 3]", task.RecurrenceWeekdays) + } + if task.RecurrenceSeriesID == "" { + t.Error("RecurrenceSeriesID should be set once a recurrence pattern is active") + } + + // Clearing (freq="") should drop the pattern. + req2 := httptest.NewRequest("POST", "/tasks/recurrence", strings.NewReader("id=task-1&freq=&interval=1")) + req2.Header.Set("Content-Type", "application/x-www-form-urlencoded") + w2 := httptest.NewRecorder() + h.HandleSetTaskRecurrence(w2, req2) + + if w2.Code != http.StatusOK { + t.Fatalf("status = %d, want 200, body=%s", w2.Code, w2.Body.String()) + } + task, err = h.store.GetNativeTaskByID("task-1") + if err != nil { + t.Fatal(err) + } + if task.RecurrenceFreq != "" { + t.Errorf("RecurrenceFreq = %q after clear, want empty", task.RecurrenceFreq) + } +} + +func TestHandleSetTaskRecurrence_InvalidFreq_Returns400(t *testing.T) { + h, cleanup := setupTestHandler(t) + defer cleanup() + + if err := h.store.CreateNativeTask(models.Task{ID: "task-1", Content: "Water plants", Priority: 1}); err != nil { + t.Fatal(err) + } + + req := httptest.NewRequest("POST", "/tasks/recurrence", strings.NewReader("id=task-1&freq=fortnightly")) + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + w := httptest.NewRecorder() + h.HandleSetTaskRecurrence(w, req) + + if w.Code != http.StatusBadRequest { + t.Fatalf("status = %d, want 400", w.Code) + } +} + // ============================================================================= // HandleGetListsOptions template tests // ============================================================================= diff --git a/internal/handlers/settings.go b/internal/handlers/settings.go index 5ba3724..9ab832c 100644 --- a/internal/handlers/settings.go +++ b/internal/handlers/settings.go @@ -14,9 +14,6 @@ func (h *Handler) HandleSettingsPage(w http.ResponseWriter, r *http.Request) { configs, _ := h.store.GetSourceConfigs() syncLog, _ := h.store.GetRecentSyncLog(20) agents, _ := h.store.GetAllAgents() - buckets, _ := BuildBucketSummaries(h.store) - projects, _ := h.store.GetProjects() - labels, _ := h.store.GetLabelColors() // Group configs by source bySource := make(map[string][]models.SourceConfig) @@ -29,9 +26,6 @@ func (h *Handler) HandleSettingsPage(w http.ResponseWriter, r *http.Request) { Sources []string SyncLog []store.SyncLogEntry Agents []models.Agent - Buckets []models.BucketSummary - Projects []models.Project - Labels []models.LabelColor CSRFToken string WebAuthnEnabled bool }{ @@ -39,9 +33,6 @@ func (h *Handler) HandleSettingsPage(w http.ResponseWriter, r *http.Request) { Sources: []string{"trello", "gcal", "gtasks"}, SyncLog: syncLog, Agents: agents, - Buckets: buckets, - Projects: projects, - Labels: labels, CSRFToken: auth.GetCSRFTokenFromContext(r.Context()), WebAuthnEnabled: h.WebAuthnEnabled, } |
