1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
# Multi-View Dashboard Implementation Plan
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
**Goal:** Let the user switch between four dashboard views (list, focus, calendar, agenda) with a shared client-side panel and scorecard integration.
**Architecture:** Four server-rendered Roda routes share a Layout that renders a view switcher in the header and an empty panel shell. Clicking a task fetches `/series/:id/panel` via JS and slides it open. Each view is a Phlex class. See `docs/plans/2026-02-17-multi-view-dashboard-design.md` for the full design.
**Tech Stack:** Ruby, Roda, Phlex, Alpine.js, OverType (no new dependencies)
---
### Task 1: Add `/series/:id/panel` endpoint and SeriesPanel view
The panel fragment endpoint is the foundation — everything else depends on fetching panel content via JS.
**Files:**
- Create: `lib/ketchup/views/series_panel.rb`
- Modify: `lib/ketchup/web.rb:92-100`
- Test: `test/test_web.rb`
**Step 1: Write the failing test**
Add to `test/test_web.rb`:
```ruby
def test_get_series_panel_returns_fragment
create_series(note: "Call Mom", interval_unit: "week", interval_count: "2",
first_due_date: "2026-03-01")
series = DB[:series].first
get "/series/#{series[:id]}/panel", {}, auth_headers
assert last_response.ok?
assert_includes last_response.body, "Call Mom"
assert_includes last_response.body, "panel-inner"
# Fragment — no <html>, no Layout wrapper
refute_includes last_response.body, "<!DOCTYPE"
end
def test_get_series_panel_requires_own_series
create_series(
note: "Alice task", interval_unit: "day", interval_count: "1",
first_due_date: "2026-03-01",
headers: auth_headers(login: "alice@example.com")
)
series = DB[:series].first
get "/series/#{series[:id]}/panel", {}, auth_headers(login: "bob@example.com")
assert_equal 404, last_response.status
end
```
**Step 2: Run tests to verify they fail**
Run: `rake test`
Expected: 2 failures (404 for panel route)
**Step 3: Create `SeriesPanel` view**
Create `lib/ketchup/views/series_panel.rb`. This is the existing `SeriesDetail` content but rendered as a standalone fragment (no Layout wrapper). For now, delegate to `SeriesDetail`:
```ruby
# frozen_string_literal: true
require "phlex"
require_relative "series_detail"
module Views
class SeriesPanel < Phlex::HTML
def initialize(series:, csrf: nil)
@series = series
@csrf = csrf
end
def view_template
render SeriesDetail.new(series: @series, csrf: @csrf)
end
end
end
```
**Step 4: Add the route**
In `lib/ketchup/web.rb`, inside the `r.on Integer do |series_id|` block (after line 93), add a `panel` route before the `r.is` block:
```ruby
r.get "panel" do
Views::SeriesPanel.new(series: @series, csrf: method(:csrf_token)).call
end
```
Also add `require_relative "views/series_panel"` near the top (after line 8).
**Step 5: Run tests to verify they pass**
Run: `rake test`
Expected: all pass
**Step 6: Commit**
Message: `Add /series/:id/panel endpoint for fragment fetching`
---
### Task 2: Move panel shell into Layout, make it always present
The Layout currently has no panel markup. Dashboard renders the panel conditionally. Move the panel shell into Layout so every page gets it.
**Files:**
- Modify: `lib/ketchup/views/layout.rb:35-46`
- Modify: `lib/ketchup/views/dashboard.rb:21-64`
- Test: `test/test_web.rb`
**Step 1: Write the failing test**
Add to `test/test_web.rb`:
```ruby
def test_layout_includes_panel_shell
get "/", {}, auth_headers
assert_includes last_response.body, 'id="panel"'
assert_includes last_response.body, 'x-data="panel"'
end
```
**Step 2: Run test to verify it fails**
Run: `rake test`
Expected: 1 failure (panel div not in root page without series selected)
**Step 3: Add panel shell to Layout**
In `lib/ketchup/views/layout.rb`, after the `yield` (line 42) and before `render_footer`, add the panel shell:
```ruby
div(
id: "panel",
class: "panel",
"x-data": "panel",
"x-bind:class": "open && 'panel--open'"
) do
div(class: "panel-backdrop", "x-show": "open", "x-on:click": "close()")
div(class: "panel-content", "x-ref": "content")
end
```
Remove the `panel_open` parameter from `Layout#initialize` and the `has-panel` body class logic (lines 7, 35) — the panel is now always present and managed by Alpine.
**Step 4: Remove panel rendering from Dashboard**
In `lib/ketchup/views/dashboard.rb`:
- Remove `render_panel` method entirely (lines 47-64)
- Remove `render_panel if has_panel` from `view_template` (line 26)
- Remove `has_panel` local variable (line 22-23)
- Simplify `view_template` to just render Layout + dashboard div + main column
- Remove `panel_open: has_panel` from Layout constructor call
- Keep `@series` in the initializer for now — it's still used for `selected_series` in TaskList
The Dashboard becomes:
```ruby
def view_template
render Layout.new(current_user: @current_user) do
div(class: "dashboard") do
render_main_column
end
end
end
```
**Step 5: Update Layout to not accept panel_open**
Remove `panel_open` from `Layout#initialize` signature and the `@panel_open` instance variable. Remove the `has-panel` body class.
**Step 6: Fix existing tests**
The `test_get_series_shows_sidebar` test currently GETs `/series/:id` and expects panel content in the response. Since the panel is now client-side, this test needs updating. The `/series/:id` route should still render the dashboard page, but the panel content comes from a separate fetch. Update the route to pass a `data-open-series` attribute and update the test:
In `lib/ketchup/web.rb`, change the GET `/series/:id` handler to:
```ruby
r.get do
Views::Dashboard.new(current_user: @user, series: @series, csrf: method(:csrf_token)).call
end
```
This still passes `series:` to Dashboard — but now it's only used for `selected_series` (highlighting the card), not for rendering the panel. Add a `data-open-series` attribute to the dashboard div so Alpine can auto-open the panel on page load.
In `dashboard.rb`, update `view_template`:
```ruby
def view_template
render Layout.new(current_user: @current_user) do
div(
class: "dashboard",
**(@series ? { "data-open-series": @series.id.to_s } : {})
) do
render_main_column
end
end
end
```
Update `test_get_series_shows_sidebar` to test the new behavior:
```ruby
def test_get_series_shows_sidebar
create_series(note: "Call Mom", interval_unit: "week", interval_count: "2",
first_due_date: "2026-03-01")
series = DB[:series].first
get "/series/#{series[:id]}", {}, auth_headers
assert last_response.ok?
assert_includes last_response.body, "task-card--selected"
assert_includes last_response.body, "data-open-series=\"#{series[:id]}\""
end
```
Also update `test_series_sidebar_has_new_link` — the "New" link and `href="/"` are no longer in the server-rendered panel. Remove or replace this test:
```ruby
def test_get_series_page_has_data_attribute
create_series(note: "Call Mom", interval_unit: "week", interval_count: "2",
first_due_date: "2026-03-01")
series = DB[:series].first
get "/series/#{series[:id]}", {}, auth_headers
assert last_response.ok?
assert_includes last_response.body, "data-open-series"
end
```
Update `test_get_series_shows_completed_history` — history is now served by the panel endpoint, not the full page. Move the history assertion to a panel test:
```ruby
def test_get_series_panel_shows_completed_history
create_series(note: "Call Mom", interval_unit: "week", interval_count: "1",
first_due_date: "2026-03-01")
task = DB[:tasks].first
series = DB[:series].first
csrf_post "/series/#{series[:id]}/tasks/#{task[:id]}/complete", {}, auth_headers
completed_task = DB[:tasks].first(id: task[:id])
patch "/series/#{series[:id]}/tasks/#{completed_task[:id]}/note", { note: "Left a message" }, auth_headers
get "/series/#{series[:id]}/panel", {}, auth_headers
assert last_response.ok?
assert_includes last_response.body, "Left a message"
assert_includes last_response.body, "task-history"
end
```
**Step 7: Run tests to verify they pass**
Run: `rake test`
Expected: all pass
**Step 8: Commit**
Message: `Move panel shell into Layout, serve panel content via fragment fetch`
---
### Task 3: Client-side panel Alpine component
Update the Alpine `panel` component to fetch content from `/series/:id/panel` and extract OverType setup into a reusable `initPanelEditors()` function.
**Files:**
- Modify: `public/js/app.js:61-78` (panel component)
- Modify: `public/js/app.js:180-241` (OverType setup)
**Step 1: Update the Alpine panel component**
Replace the existing `panel` data component in `app.js` (lines 63-78) with:
```js
Alpine.data("panel", () => ({
open: false,
loading: false,
init() {
// Auto-open panel if server set data-open-series on the dashboard
const dashboard = document.querySelector("[data-open-series]")
if (dashboard) {
const seriesId = dashboard.dataset.openSeries
if (seriesId) this.show(seriesId)
}
},
async show(seriesId) {
this.loading = true
this.open = true
try {
const resp = await fetch(`/series/${seriesId}/panel`)
if (!resp.ok) return
this.$refs.content.innerHTML = await resp.text()
initPanelEditors(this.$refs.content)
} finally {
this.loading = false
}
},
close() {
this.open = false
setTimeout(() => {
if (this.$refs.content) this.$refs.content.innerHTML = ""
}, 250)
},
}))
```
**Step 2: Extract `initPanelEditors()`**
Move the imperative OverType setup for `#series-note-detail` (lines 181-225) into a function that takes a container element instead of searching the whole document. Place this before `alpine:init`:
```js
function initPanelEditors(container) {
const noteDetail = container.querySelector("#series-note-detail")
if (noteDetail) {
const seriesId = noteDetail.dataset.seriesId
const initialNote = noteDetail.dataset.value || ""
const [editor] = new OverType(noteDetail, {
value: initialNote,
placeholder: "Series note...",
autoResize: true,
minHeight: 14,
padding: "0 4px",
})
const resizeNote = compactOverType(noteDetail)
const ta = noteDetail.querySelector("textarea")
if (ta) {
ta.style.pointerEvents = "none"
ta.readOnly = true
ta.addEventListener("blur", () => {
const note = editor.getValue().trim()
if (note === (initialNote || "").trim()) return
saveSeriesField(seriesId, "note", note).then(() => location.reload())
})
container.addEventListener("start-editing", () => {
ta.style.pointerEvents = ""
ta.readOnly = false
ta.focus()
if (resizeNote) requestAnimationFrame(resizeNote)
})
container.addEventListener("stop-editing", () => {
const note = editor.getValue().trim()
if (note !== (initialNote || "").trim()) {
saveSeriesField(seriesId, "note", note).then(() => location.reload())
return
}
ta.style.pointerEvents = "none"
ta.readOnly = true
if (resizeNote) requestAnimationFrame(resizeNote)
})
}
}
}
```
Remove the old inline `#series-note-detail` setup block from inside `alpine:init` (lines 180-225).
Keep the `#series-note-editor` setup (new series form) as-is — that lives on a standalone page, not in the panel.
**Step 3: Update task card links to use panel**
In `lib/ketchup/views/task_card.rb`, change the task name from a navigation link to a JS click handler. Replace line 28:
```ruby
a(href: "/series/#{@task[:series_id]}", class: "task-name") { name }
```
with:
```ruby
a(
href: "/series/#{@task[:series_id]}",
class: "task-name",
"x-on:click.prevent": "document.querySelector('[x-data=\"panel\"]').__x.$data.show(#{@task[:series_id]})"
) { name }
```
Actually, a cleaner approach — dispatch a custom event that the panel listens for. Change the link to:
```ruby
a(
href: "/series/#{@task[:series_id]}",
class: "task-name",
"x-on:click.prevent": "$dispatch('open-panel', { seriesId: #{@task[:series_id]} })"
) { name }
```
And in the panel's `init()`, add a listener:
```js
window.addEventListener("open-panel", (e) => {
this.show(e.detail.seriesId)
})
```
The `href` remains as a fallback for middle-click/ctrl-click to open in a new tab.
**Step 4: Verify manually**
Run: `rake dev`
Navigate to `/`. Click a task name. The panel should slide open with the series detail fetched via JS. Click the backdrop to close.
**Step 5: Run tests**
Run: `rake test`
Expected: all pass (the task card test `test_task_card_links_to_series` still passes because the `href` attribute is preserved)
**Step 6: Commit**
Message: `Switch panel to client-side fetch, extract initPanelEditors`
---
### Task 4: Add view switcher to header nav
Add view navigation links to the Layout header. The active view is indicated by bold weight.
**Files:**
- Modify: `lib/ketchup/views/layout.rb:7,36-41`
- Modify: `lib/ketchup/views/dashboard.rb:23`
- Modify: `public/css/app.css`
- Test: `test/test_web.rb`
**Step 1: Write the failing test**
```ruby
def test_header_shows_view_nav
get "/", {}, auth_headers
assert_includes last_response.body, 'href="/"'
assert_includes last_response.body, 'href="/focus"'
assert_includes last_response.body, 'href="/calendar"'
assert_includes last_response.body, 'href="/agenda"'
end
def test_header_highlights_active_view
get "/", {}, auth_headers
assert_includes last_response.body, "view-link--active"
end
```
**Step 2: Run tests to verify they fail**
Run: `rake test`
Expected: 2 failures
**Step 3: Add `active_view` to Layout**
In `lib/ketchup/views/layout.rb`, add `active_view: :list` to `initialize`:
```ruby
def initialize(current_user:, title: "Ketchup", active_view: :list)
@current_user = current_user
@title = title
@active_view = active_view
end
```
Update the nav in `view_template` (lines 38-41) to include view links:
```ruby
nav(class: "site-nav") do
view_links.each do |path, label, view_key|
a(
href: path,
class: ["view-link", ("view-link--active" if @active_view == view_key)]
) { label }
end
a(href: "/series/new", class: "header-action") { "+ New" }
a(href: "/users/#{@current_user[:id]}", class: "header-user") { @current_user[:login] }
end
```
Add the private helper:
```ruby
def view_links
[
["/", "List", :list],
["/focus", "Focus", :focus],
["/calendar", "Calendar", :calendar],
["/agenda", "Agenda", :agenda],
]
end
```
**Step 4: Add CSS for view links**
In `public/css/app.css`, after the `.header-action` styles (around line 66):
```css
.view-link {
font-size: var(--step--1);
color: #999;
text-decoration: none;
}
.view-link:hover {
color: #555;
}
.view-link--active {
color: #1a1a1a;
font-weight: 600;
}
```
**Step 5: Run tests to verify they pass**
Run: `rake test`
Expected: all pass
**Step 6: Commit**
Message: `Add view switcher nav links to header`
---
### Task 5: Focus view and route
Add the focus view that shows one overdue task at a time.
**Files:**
- Create: `lib/ketchup/views/focus.rb`
- Modify: `lib/ketchup/web.rb`
- Modify: `lib/ketchup/web.rb:144-148` (complete redirect)
- Modify: `lib/ketchup/views/task_card.rb:16,19-21` (return_to field)
- Add CSS: `public/css/app.css`
- Test: `test/test_web.rb`
**Step 1: Write the failing tests**
```ruby
def test_focus_view_shows_overdue_task
create_series(note: "Call Mom", interval_unit: "week", interval_count: "2",
first_due_date: (Date.today - 3).to_s)
get "/focus", {}, auth_headers
assert last_response.ok?
assert_includes last_response.body, "Call Mom"
assert_includes last_response.body, "focus-task"
end
def test_focus_view_redirects_when_caught_up
get "/focus", {}, auth_headers
assert last_response.redirect?
assert_includes last_response["Location"], "/"
end
def test_focus_view_shows_most_urgent_first
create_series(note: "Low urgency", interval_unit: "month", interval_count: "1",
first_due_date: (Date.today - 1).to_s)
create_series(note: "High urgency", interval_unit: "day", interval_count: "1",
first_due_date: (Date.today - 10).to_s)
get "/focus", {}, auth_headers
assert_includes last_response.body, "High urgency"
end
def test_complete_from_focus_redirects_to_focus
create_series(note: "Call Mom", interval_unit: "week", interval_count: "2",
first_due_date: (Date.today - 3).to_s)
task = DB[:tasks].first
series = DB[:series].first
csrf_post "/series/#{series[:id]}/tasks/#{task[:id]}/complete",
{ "return_to" => "/focus" }, auth_headers
assert last_response.redirect?
assert_equal "/focus", last_response["Location"]
end
```
**Step 2: Run tests to verify they fail**
Run: `rake test`
Expected: 4 failures
**Step 3: Create the Focus view**
Create `lib/ketchup/views/focus.rb`:
```ruby
# frozen_string_literal: true
require "phlex"
require_relative "layout"
module Views
class Focus < Phlex::HTML
def initialize(current_user:, task:, csrf:, position:, total:)
@current_user = current_user
@task = task
@csrf = csrf
@position = position
@total = total
end
def view_template
render Layout.new(current_user: @current_user, active_view: :focus) do
div(class: "focus-view") do
render_progress
render_task
render_complete_button
end
end
end
private
def render_progress
div(class: "focus-progress") do
plain "#{@position} of #{@total} overdue"
end
end
def render_task
name = @task[:note].lines.first&.strip || @task[:note]
interval_count = @task[:interval_count] || @task.series.interval_count
interval_unit = @task[:interval_unit] || @task.series.interval_unit
interval = "#{interval_count} #{interval_count == 1 ? interval_unit : "#{interval_unit}s"}"
div(class: "focus-task") do
div(class: "focus-urgency") do
plain "#{format("%.1f", @task.urgency)}× overdue"
end
h1(class: "focus-name") { name }
p(class: "focus-interval") { "every #{interval}" }
end
end
def render_complete_button
complete_path = "/series/#{@task[:series_id]}/tasks/#{@task[:id]}/complete"
form(method: "post", action: complete_path, class: "focus-form") do
input(type: "hidden", name: "_csrf", value: @csrf.call(complete_path))
input(type: "hidden", name: "return_to", value: "/focus")
button(type: "submit", class: "focus-complete-btn") do
span { "✓" }
plain " Done"
end
end
end
end
end
```
**Step 4: Add the route**
In `lib/ketchup/web.rb`, add `require_relative "views/focus"` at the top.
Add the focus route after `r.root` (after line 42):
```ruby
r.get "focus" do
overdue = @user.overdue_tasks.all.sort_by { |t| -t.urgency }
if overdue.empty?
r.redirect "/"
else
Views::Focus.new(
current_user: @user,
task: overdue.first,
csrf: method(:csrf_token),
position: 1,
total: overdue.size
).call
end
end
```
**Step 5: Add `return_to` support to the complete handler**
In `lib/ketchup/web.rb`, update the complete handler (around line 144-148):
```ruby
r.post "complete" do
r.halt 422 unless @task[:completed_at].nil?
@task.complete!(today: Date.today)
return_to = r.params["return_to"]
if return_to && return_to.start_with?("/")
r.redirect return_to
else
r.redirect "/series/#{series_id}"
end
end
```
The `start_with?("/")` check prevents open redirect.
**Step 6: Add `return_to` hidden field to TaskCard**
In `lib/ketchup/views/task_card.rb`, add a `return_to:` parameter to `initialize`:
```ruby
def initialize(task:, csrf:, selected: false, overdue: false, return_to: nil)
@task = task
@csrf = csrf
@selected = selected
@overdue = overdue
@return_to = return_to
end
```
In the form (line 19-25), add after the CSRF hidden input:
```ruby
input(type: "hidden", name: "return_to", value: @return_to) if @return_to
```
**Step 7: Add focus view CSS**
In `public/css/app.css`:
```css
/* -------------------- */
/* Focus view */
/* -------------------- */
.focus-view {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
flex: 1;
padding: var(--space-xl) var(--space-m);
text-align: center;
}
.focus-progress {
font-size: var(--step--1);
color: #999;
margin-bottom: var(--space-l);
}
.focus-task {
margin-bottom: var(--space-l);
}
.focus-urgency {
font-size: var(--step--2);
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.06em;
color: #c0392b;
margin-bottom: var(--space-2xs);
}
.focus-name {
font-size: var(--step-3);
font-weight: 700;
line-height: 1.2;
margin-bottom: var(--space-3xs);
}
.focus-interval {
font-size: var(--step-0);
color: #888;
}
.focus-form {
display: inline-flex;
}
.focus-complete-btn {
all: unset;
cursor: pointer;
display: inline-flex;
align-items: center;
gap: var(--space-2xs);
padding: var(--space-xs) var(--space-xl);
background: #1a1a1a;
color: #fff;
border-radius: 99px;
font-size: var(--step-1);
font-weight: 600;
transition: background 0.15s;
}
.focus-complete-btn:hover {
background: #333;
}
```
**Step 8: Run tests to verify they pass**
Run: `rake test`
Expected: all pass
**Step 9: Commit**
Message: `Add focus view for processing overdue tasks one at a time`
---
### Task 6: Calendar view and route
**Files:**
- Create: `lib/ketchup/views/calendar.rb`
- Modify: `lib/ketchup/web.rb`
- Add CSS: `public/css/app.css`
- Test: `test/test_web.rb`
**Step 1: Write the failing tests**
```ruby
def test_calendar_view_renders
get "/calendar", {}, auth_headers
assert last_response.ok?
assert_includes last_response.body, "calendar-grid"
end
def test_calendar_shows_tasks_on_due_date
create_series(note: "Call Mom", interval_unit: "week", interval_count: "2",
first_due_date: Date.today.to_s)
get "/calendar", {}, auth_headers
assert_includes last_response.body, "Call Mom"
end
def test_calendar_view_highlights_active
get "/calendar", {}, auth_headers
assert_includes last_response.body, "view-link--active"
end
```
**Step 2: Run tests to verify they fail**
Run: `rake test`
Expected: 3 failures
**Step 3: Create the Calendar view**
Create `lib/ketchup/views/calendar.rb`:
```ruby
# frozen_string_literal: true
require "phlex"
require "date"
require_relative "layout"
module Views
class Calendar < Phlex::HTML
def initialize(current_user:, csrf:, date: Date.today)
@current_user = current_user
@csrf = csrf
@date = date
end
def view_template
first_of_month = Date.new(@date.year, @date.month, 1)
last_of_month = Date.new(@date.year, @date.month, -1)
prev_month = first_of_month << 1
next_month = first_of_month >> 1
overdue = @current_user.overdue_tasks.all
upcoming = @current_user.upcoming_tasks
.where { due_date <= last_of_month }
.all
tasks_by_date = {}
overdue.each { |t| (tasks_by_date[Date.today] ||= []) << [t, true] }
upcoming.each { |t| (tasks_by_date[t[:due_date]] ||= []) << [t, false] }
render Layout.new(current_user: @current_user, active_view: :calendar) do
div(class: "calendar-view") do
div(class: "calendar-header") do
a(href: "/calendar?date=#{prev_month}", class: "calendar-nav") { "←" }
h2(class: "calendar-month-title") { first_of_month.strftime("%B %Y") }
a(href: "/calendar?date=#{next_month}", class: "calendar-nav") { "→" }
end
div(class: "calendar-grid") do
%w[Mon Tue Wed Thu Fri Sat Sun].each do |day_name|
div(class: "calendar-day-name") { day_name }
end
start_dow = (first_of_month.wday - 1) % 7
start_dow.times { div(class: "calendar-day calendar-day--empty") }
(1..last_of_month.day).each do |day_num|
date = Date.new(@date.year, @date.month, day_num)
is_today = date == Date.today
day_tasks = tasks_by_date[date] || []
div(class: ["calendar-day", ("calendar-day--today" if is_today)]) do
span(class: "calendar-day-num") { day_num.to_s }
day_tasks.each do |task, is_overdue|
task_name = task[:note].lines.first&.strip || task[:note]
a(
href: "/series/#{task[:series_id]}",
class: ["calendar-pill", ("calendar-pill--overdue" if is_overdue)],
"x-on:click.prevent": "$dispatch('open-panel', { seriesId: #{task[:series_id]} })"
) { task_name }
end
end
end
end
end
end
end
end
end
```
**Step 4: Add the route**
In `lib/ketchup/web.rb`, add `require_relative "views/calendar"` at the top.
Add after the focus route:
```ruby
r.get "calendar" do
date = begin
Date.parse(r.params["date"].to_s)
rescue Date::Error
Date.today
end
Views::Calendar.new(current_user: @user, csrf: method(:csrf_token), date: date).call
end
```
**Step 5: Add calendar CSS**
In `public/css/app.css`:
```css
/* -------------------- */
/* Calendar view */
/* -------------------- */
.calendar-view {
padding: var(--space-m) var(--space-m);
max-width: 56rem;
margin: 0 auto;
}
.calendar-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: var(--space-s);
}
.calendar-month-title {
font-size: var(--step-1);
font-weight: 700;
}
.calendar-nav {
font-size: var(--step-0);
color: #555;
text-decoration: none;
padding: var(--space-3xs) var(--space-2xs);
border-radius: 4px;
}
.calendar-nav:hover {
background: #f5f5f5;
}
.calendar-grid {
display: grid;
grid-template-columns: repeat(7, 1fr);
gap: 2px;
}
.calendar-day-name {
text-align: center;
font-size: var(--step--2);
font-weight: 600;
color: #999;
padding: var(--space-3xs);
}
.calendar-day {
min-height: 5rem;
padding: var(--space-3xs);
border: 1px solid #eee;
border-radius: 4px;
overflow: hidden;
}
.calendar-day--empty {
background: #fafafa;
border-color: transparent;
}
.calendar-day--today {
background: #f0f7ff;
border-color: #4a90d9;
border-width: 2px;
}
.calendar-day-num {
font-size: var(--step--2);
font-weight: 400;
color: #555;
display: block;
margin-bottom: 2px;
}
.calendar-day--today .calendar-day-num {
font-weight: 700;
color: #4a90d9;
}
.calendar-pill {
display: block;
font-size: 10px;
padding: 1px 4px;
background: #e8f5e9;
color: #2e7d32;
border-radius: 3px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-top: 1px;
text-decoration: none;
cursor: pointer;
}
.calendar-pill--overdue {
background: #fde8e6;
color: #c0392b;
}
```
**Step 6: Run tests to verify they pass**
Run: `rake test`
Expected: all pass
**Step 7: Commit**
Message: `Add calendar month view`
---
### Task 7: Agenda view and route
**Files:**
- Create: `lib/ketchup/views/agenda.rb`
- Modify: `lib/ketchup/web.rb`
- Add CSS: `public/css/app.css`
- Test: `test/test_web.rb`
**Step 1: Write the failing tests**
```ruby
def test_agenda_view_renders
get "/agenda", {}, auth_headers
assert last_response.ok?
assert_includes last_response.body, "agenda-view"
end
def test_agenda_shows_overdue_column
create_series(note: "Call Mom", interval_unit: "week", interval_count: "2",
first_due_date: (Date.today - 3).to_s)
get "/agenda", {}, auth_headers
assert_includes last_response.body, "Call Mom"
assert_includes last_response.body, "agenda-overdue"
end
def test_agenda_shows_upcoming_on_day
create_series(note: "Haircut", interval_unit: "week", interval_count: "6",
first_due_date: Date.today.to_s)
get "/agenda", {}, auth_headers
assert_includes last_response.body, "Haircut"
end
```
**Step 2: Run tests to verify they fail**
Run: `rake test`
Expected: 3 failures
**Step 3: Create the Agenda view**
Create `lib/ketchup/views/agenda.rb`:
```ruby
# frozen_string_literal: true
require "phlex"
require_relative "layout"
module Views
class Agenda < Phlex::HTML
DAYS = 7
def initialize(current_user:, csrf:)
@current_user = current_user
@csrf = csrf
end
def view_template
today = Date.today
dates = (0...DAYS).map { |i| today + i }
end_date = dates.last
overdue = @current_user.overdue_tasks.all.sort_by { |t| -t.urgency }
upcoming = @current_user.upcoming_tasks
.where { due_date <= end_date }
.all
tasks_by_date = {}
upcoming.each { |t| (tasks_by_date[t[:due_date]] ||= []) << t }
render Layout.new(current_user: @current_user, active_view: :agenda) do
div(class: "agenda-view") do
div(class: "agenda-columns") do
render_overdue_column(overdue)
dates.each_with_index do |date, i|
render_day_column(date, tasks_by_date[date] || [], i == 0)
end
end
end
end
end
private
def render_overdue_column(tasks)
div(class: "agenda-column agenda-overdue") do
div(class: "agenda-column-header agenda-column-header--overdue") { "Overdue" }
if tasks.empty?
p(class: "empty") { "All clear" }
else
tasks.each { |t| render_task_pill(t, overdue: true) }
end
end
end
def render_day_column(date, tasks, is_today)
label = if is_today
"Today"
elsif date == Date.today + 1
"Tomorrow"
else
date.strftime("%a %-d")
end
div(class: ["agenda-column", ("agenda-column--today" if is_today)]) do
div(class: "agenda-column-header") { label }
tasks.each { |t| render_task_pill(t, overdue: false) }
end
end
def render_task_pill(task, overdue:)
name = task[:note].lines.first&.strip || task[:note]
a(
href: "/series/#{task[:series_id]}",
class: ["agenda-pill", ("agenda-pill--overdue" if overdue)],
"x-on:click.prevent": "$dispatch('open-panel', { seriesId: #{task[:series_id]} })"
) { name }
end
end
end
```
**Step 4: Add the route**
In `lib/ketchup/web.rb`, add `require_relative "views/agenda"` at the top.
Add after the calendar route:
```ruby
r.get "agenda" do
Views::Agenda.new(current_user: @user, csrf: method(:csrf_token)).call
end
```
**Step 5: Add agenda CSS**
In `public/css/app.css`:
```css
/* -------------------- */
/* Agenda view */
/* -------------------- */
.agenda-view {
padding: var(--space-m);
overflow-x: auto;
}
.agenda-columns {
display: grid;
grid-template-columns: 120px repeat(7, 1fr);
gap: 2px;
min-width: 640px;
}
.agenda-column {
background: #fff;
border: 1px solid #eee;
border-radius: 4px;
padding: var(--space-3xs);
min-height: 12rem;
}
.agenda-column--today {
background: #f0f7ff;
border-color: #4a90d9;
}
.agenda-overdue {
background: #fefafa;
border-color: #f0e0de;
}
.agenda-column-header {
font-size: var(--step--2);
font-weight: 600;
color: #888;
text-align: center;
padding: var(--space-3xs);
margin-bottom: var(--space-3xs);
}
.agenda-column-header--overdue {
color: #c0392b;
}
.agenda-pill {
display: block;
font-size: var(--step--2);
padding: 3px 6px;
background: #e8f5e9;
color: #2e7d32;
border-radius: 4px;
margin-bottom: 3px;
text-decoration: none;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
}
.agenda-pill--overdue {
background: #fde8e6;
color: #c0392b;
font-weight: 600;
}
```
**Step 6: Run tests to verify they pass**
Run: `rake test`
Expected: all pass
**Step 7: Commit**
Message: `Add agenda week view with overdue column`
---
### Task 8: Scorecard data in series panel
Add streak count and on-time percentage to the series detail panel.
**Files:**
- Modify: `lib/ketchup/models.rb` (add `Series#completion_stats`)
- Modify: `lib/ketchup/views/series_detail.rb:91-92`
- Test: `test/test_web.rb`
**Step 1: Write the failing test**
```ruby
def test_series_panel_shows_stats
create_series(note: "Call Mom", interval_unit: "week", interval_count: "1",
first_due_date: (Date.today - 7).to_s)
series = DB[:series].first
task = DB[:tasks].first
csrf_post "/series/#{series[:id]}/tasks/#{task[:id]}/complete", {}, auth_headers
get "/series/#{series[:id]}/panel", {}, auth_headers
assert_includes last_response.body, "panel-stats"
end
```
**Step 2: Run test to verify it fails**
Run: `rake test`
Expected: 1 failure
**Step 3: Add `completion_stats` to Series model**
In `lib/ketchup/models.rb`, add to the `Series` class:
```ruby
def completion_stats
completed = completed_tasks
return { streak: 0, on_time_pct: 100, total: 0 } if completed.empty?
streak = 0
on_time = 0
completed.each_with_index do |t, i|
on_time += 1 if t[:completed_at].to_date <= t[:due_date]
streak += 1 if i == streak && t[:completed_at].to_date <= t[:due_date]
end
{ streak: streak, on_time_pct: (on_time * 100.0 / completed.size).round, total: completed.size }
end
```
**Step 4: Render stats in SeriesDetail**
In `lib/ketchup/views/series_detail.rb`, before the history section (line 92, `unless @series.completed_tasks.empty?`), add:
```ruby
unless @series.completed_tasks.empty?
stats = @series.completion_stats
div(class: "panel-stats") do
dl(class: "detail-fields") do
dt { "Streak" }
dd { stats[:streak].to_s }
dt { "On-time" }
dd { "#{stats[:on_time_pct]}%" }
end
end
```
Merge this with the existing `unless @series.completed_tasks.empty?` block — compute stats at the top of the block, render the stats div before the history heading.
**Step 5: Run tests to verify they pass**
Run: `rake test`
Expected: all pass
**Step 6: Commit**
Message: `Add completion stats (streak, on-time rate) to series panel`
---
### Task 9: Clean up and remove old panel code paths
Remove the `panel:` parameter from Dashboard, simplify the `/users/:id` and `/series/:id` GET routes now that the panel is client-side.
**Files:**
- Modify: `lib/ketchup/views/dashboard.rb:14`
- Modify: `lib/ketchup/web.rb:47-49`
- Test: `test/test_web.rb`
**Step 1: Review what's left**
The `/users/:id` GET route currently passes `panel: :user` to Dashboard. Since the panel is now client-side, this route should render the dashboard with a `data-open-user` attribute instead, or simply redirect to `/?panel=user`, or serve the user form via the panel fetch pattern.
For consistency, add a `/users/:id/panel` endpoint (like series) and handle user settings the same way — click the username in the header, fetch the user panel via JS.
**Step 2: Add user panel endpoint**
Add to `test/test_web.rb`:
```ruby
def test_get_user_panel_returns_fragment
get "/", {}, auth_headers # create user
user_id = DB[:users].first(login: "alice@example.com")[:id]
get "/users/#{user_id}/panel", {}, auth_headers
assert last_response.ok?
assert_includes last_response.body, "alice@example.com"
refute_includes last_response.body, "<!DOCTYPE"
end
```
In `lib/ketchup/web.rb`, add a panel route inside the users block:
```ruby
r.get "panel" do
Views::UserForm.new(current_user: @user, csrf: method(:csrf_token)).call
end
```
Update the `/users/:id` GET to render Dashboard without `panel:` and with a `data-open-user` attribute (similar to `data-open-series`).
**Step 3: Remove `panel:` from Dashboard**
Remove the `panel` parameter from `Dashboard#initialize`. Remove any remaining references to `@panel`.
**Step 4: Update existing user tests**
Update `test_get_user_shows_email_form` to test the panel endpoint instead:
```ruby
def test_get_user_panel_shows_email_form
get "/", {}, auth_headers
user_id = DB[:users].first(login: "alice@example.com")[:id]
get "/users/#{user_id}/panel", {}, auth_headers
assert last_response.ok?
assert_includes last_response.body, "alice@example.com"
assert_includes last_response.body, 'name="email"'
end
```
**Step 5: Run tests to verify they pass**
Run: `rake test`
Expected: all pass
**Step 6: Commit**
Message: `Add user panel endpoint, remove server-rendered panel from Dashboard`