create-pmos 0.397.0 → 0.398.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/package.json +13 -13
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/payload/state/log.md +1 -1
  7. package/workspace/briefing-premium-adddoc-test.js +101 -52
  8. package/workspace/briefing-premium-board-test.js +252 -128
  9. package/workspace/briefing-premium-calendar-2-test.js +135 -198
  10. package/workspace/briefing-premium-calendar-3-test.js +143 -418
  11. package/workspace/briefing-premium-calendar-test.js +86 -196
  12. package/workspace/briefing-premium-doc-edit-test.js +95 -83
  13. package/workspace/briefing-premium-initiative-test.js +159 -296
  14. package/workspace/briefing-premium-insights-test.js +337 -219
  15. package/workspace/briefing-premium-metrics-test.js +53 -97
  16. package/workspace/briefing-premium-products-test.js +40 -27
  17. package/workspace/briefing-premium-sources-test.js +66 -48
  18. package/workspace/briefing-premium-test.js +150 -647
  19. package/workspace/briefing-premium-work-test.js +88 -283
  20. package/workspace/changelog.json +12 -0
  21. package/workspace/fixtures/board-premium-trail.js +32 -0
  22. package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
  23. package/workspace/guide/briefing-premium.md +3 -1
  24. package/workspace/guide/home.md +47 -0
  25. package/workspace/guide/index.md +1 -0
  26. package/workspace/lib/agent-roles.js +71 -0
  27. package/workspace/lib/board-premium.js +85 -19
  28. package/workspace/lib/board-trail.js +223 -0
  29. package/workspace/lib/home-work-item.js +58 -0
  30. package/workspace/lib/insights-goals.js +196 -0
  31. package/workspace/lib/insights-premium.js +62 -14
  32. package/workspace/lib/insights-records.js +101 -0
  33. package/workspace/lib/jira-tickets.js +1 -1
  34. package/workspace/lib/route-modules.js +4 -0
  35. package/workspace/lib/routes-board-trail.js +33 -0
  36. package/workspace/lib/routes-home-desk.js +176 -0
  37. package/workspace/lib/routes-insights-premium.js +12 -3
  38. package/workspace/lib/routes-insights-records.js +129 -0
  39. package/workspace/lib/routes-notes.js +1 -0
  40. package/workspace/lib/routes-viewer.js +108 -0
  41. package/workspace/lib/transcript-steps.js +123 -0
  42. package/workspace/lib/viewer-meeting.js +205 -0
  43. package/workspace/lib/viewer-report.js +89 -0
  44. package/workspace/package-lock.json +2 -2
  45. package/workspace/package.json +1 -1
  46. package/workspace/premium-board-actions-test.js +85 -75
  47. package/workspace/premium-briefing-depth-test.js +66 -53
  48. package/workspace/premium-chat-attach-test.js +54 -63
  49. package/workspace/premium-chat-chart-tab-test.js +35 -37
  50. package/workspace/premium-chat-context-test.js +19 -18
  51. package/workspace/premium-chat-goal-view-test.js +23 -23
  52. package/workspace/premium-chat-notes-test.js +26 -31
  53. package/workspace/premium-chat-report-tab-test.js +32 -28
  54. package/workspace/premium-chat-term-test.js +16 -16
  55. package/workspace/premium-chat-viewer-test.js +60 -59
  56. package/workspace/premium-core-doc-issue-test.js +50 -43
  57. package/workspace/premium-html-viewer-test.js +14 -17
  58. package/workspace/premium-phone-card-test.js +7 -2
  59. package/workspace/premium-phone-room-test.js +41 -35
  60. package/workspace/premium-report-read-test.js +115 -197
  61. package/workspace/premium-viewer-download-test.js +19 -22
  62. package/workspace/premium-viewer-flicker-test.js +11 -16
  63. package/workspace/premium-viewer-share-test.js +6 -9
  64. package/workspace/premium-viewer-test.js +41 -60
  65. package/workspace/premium-vw-backlog-test.js +53 -33
  66. package/workspace/premium-vw-cal-test.js +82 -128
  67. package/workspace/premium-vw-copy-test.js +17 -33
  68. package/workspace/premium-vw-doc-test.js +11 -10
  69. package/workspace/premium-vw-item-test.js +50 -49
  70. package/workspace/premium-vw-jira-test.js +53 -27
  71. package/workspace/premium-vw-meet-test.js +118 -187
  72. package/workspace/premium-vw-notes-test.js +85 -108
  73. package/workspace/premium-vw-rec-test.js +72 -194
  74. package/workspace/premium-vw-slides-test.js +46 -50
  75. package/workspace/premium-welcome-test.js +3 -2
  76. package/workspace/premium-work-depth-test.js +61 -53
  77. package/workspace/public/pm/bd-acts.js +305 -0
  78. package/workspace/public/pm/bd-span.js +186 -82
  79. package/workspace/public/pm/bd-stages.js +25 -11
  80. package/workspace/public/pm/c3-doc-sheet.js +1 -1
  81. package/workspace/public/pm/c3-md.js +3 -395
  82. package/workspace/public/pm/c3-phone-detail.js +1 -1
  83. package/workspace/public/pm/c3-phone-model.js +3 -68
  84. package/workspace/public/pm/chat-term.js +3 -3
  85. package/workspace/public/pm/cozy-board.css +497 -230
  86. package/workspace/public/pm/cozy-home.css +570 -142
  87. package/workspace/public/pm/cozy-home.js +5 -3
  88. package/workspace/public/pm/cozy-insights.css +296 -167
  89. package/workspace/public/pm/cozy-md.js +396 -0
  90. package/workspace/public/pm/cozy-nav.js +17 -6
  91. package/workspace/public/pm/cozy-placeholder.js +26 -0
  92. package/workspace/public/pm/cozy-viewer.css +3 -3
  93. package/workspace/public/pm/cozy-viewer.js +144 -0
  94. package/workspace/public/pm/cozy-vw.css +485 -0
  95. package/workspace/public/pm/cozy.css +83 -1
  96. package/workspace/public/pm/home-adddoc.js +48 -0
  97. package/workspace/public/pm/home-app.js +905 -0
  98. package/workspace/public/pm/home-around.js +515 -0
  99. package/workspace/public/pm/home-chat.js +459 -0
  100. package/workspace/public/pm/home-data.js +312 -0
  101. package/workspace/public/pm/home-draft.js +68 -0
  102. package/workspace/public/pm/home-more.js +249 -0
  103. package/workspace/public/pm/home-phone-card.js +109 -0
  104. package/workspace/public/pm/home-work.js +519 -0
  105. package/workspace/public/pm/phone-moment.js +69 -0
  106. package/workspace/public/pm/pm-work-view.js +1 -1
  107. package/workspace/public/pm/premium-attach.js +4 -0
  108. package/workspace/public/pm/premium-board.js +423 -394
  109. package/workspace/public/pm/premium-chart-tab.js +110 -62
  110. package/workspace/public/pm/premium-deck.js +3 -3
  111. package/workspace/public/pm/premium-first.js +25 -21
  112. package/workspace/public/pm/premium-insights.js +792 -568
  113. package/workspace/public/pm/premium-meeting.js +61 -549
  114. package/workspace/public/pm/premium-notes.js +1 -1
  115. package/workspace/public/pm/premium-report-frame.css +20 -0
  116. package/workspace/public/pm/premium-report-read.js +509 -480
  117. package/workspace/public/pm/premium-report-tab.js +87 -63
  118. package/workspace/public/pm/premium-shell.js +72 -119
  119. package/workspace/public/pm/premium-viewer.js +22 -1
  120. package/workspace/public/pm/premium-vw-cal.js +187 -48
  121. package/workspace/public/pm/premium-vw-doc.css +6 -0
  122. package/workspace/public/pm/premium-vw-doc.js +40 -2
  123. package/workspace/public/pm/premium-vw-file.js +2 -2
  124. package/workspace/public/pm/premium-vw-meet.js +6 -83
  125. package/workspace/public/pm/premium-vw-mtg.js +731 -0
  126. package/workspace/public/pm/premium-vw-notes.js +56 -69
  127. package/workspace/public/pm/premium-vw-open.js +35 -0
  128. package/workspace/public/pm/premium-vw-page.js +16 -0
  129. package/workspace/public/pm/premium-vw-rec.js +11 -218
  130. package/workspace/public/pm/premium-vw-slides.css +5 -0
  131. package/workspace/public/pm/premium-vw-slides.js +44 -8
  132. package/workspace/public/pm/term-view.js +22 -0
  133. package/workspace/public/premium-board.html +28 -70
  134. package/workspace/public/premium-initiative.html +8 -48
  135. package/workspace/public/premium-insights.html +22 -60
  136. package/workspace/public/premium-viewer.html +20 -0
  137. package/workspace/public/premium.html +16 -107
  138. package/workspace/server.js +18 -3
  139. package/workspace/test-files.json +1 -0
  140. package/workspace/test-lists/home-libs.json +9 -0
  141. package/workspace/test-lists/premium-report-read.json +1 -1
  142. package/workspace/test-lists/premium-vw-agreed.json +9 -0
  143. package/workspace/test-lists/premium-vw-notes.json +1 -1
  144. package/workspace/public/pm/premium-work.js +0 -729
  145. package/workspace/public/pm/premium.js +0 -1146
@@ -1,50 +1,68 @@
1
- /* pm/premium-board.js — the premium Board in the Agreed design (initiative premium-agreed-design: B1 B2 B3 N1 N2; built on briefing-premium-board).
1
+ /* pm/premium-board.js — the premium Board in the Agreed design (initiative premium-agreed-design: the AgBoard* frames; built on briefing-premium-board).
2
2
  * Reads GET /api/board-premium and draws the model lib/board-premium.js builds from the routes the production Initiatives page reads.
3
- * · one toolbar, no page header: the product picker, the view toggle (By stage, Stage track, Timeline, List), Find, Filter, New initiative and the
4
- * shell's bell and ⋯ menu; under it the Initiatives and Documents tabs and the chips (Jira read time, sprint and fix version, new asks, late,
5
- * at risk, blocked, idle, This sprint).
6
- * · the stage track (default): each initiative is a row across the six stages and two milestones (◆), with progress toward the output that
7
- * finishes its current step; a row opens the initiative panel, a deliverable segment opens its Jira ticket.
8
- * · the timeline (pm/bd-span.js): PMOS plan dates against the Jira forecast over six spans.
3
+ * · one toolbar: the product picker, the view toggle, Find, Filter, the shell's bell, New initiative and the shell's ⋯ menu; under it the
4
+ * Initiatives and Documents tabs and the chips (Jira read time, sprint and release, new asks, late, at risk, blocked, idle, This sprint).
5
+ * · the stage track (default): each initiative is a row across the six stages and two milestones (◆), with the parts or tickets counted
6
+ * toward the output that finishes its current step. Monitor and Evaluate rows fold under the table after the first of each.
7
+ * · the timeline (pm/bd-span.js): Quarter, Year and 5 yr.
8
+ * · a row opens the initiative panel and a ticket opens the Jira ticket panel, in the side panel (a bottom sheet on a phone).
9
9
  * · the Board has no chat: "Ask about this" sends the question to Home (/premium.html?ask=<initiative>&q=<question>).
10
- * The presses are the ones the page had: Draft it and Issue it on a core document, Add a document, and the board's presses of pm/premium-acts.js
11
- * (new asks, New initiative, a row's ⋯ menu: move, hold, cancel, archive and their Undo). The sprint, release and Metrics cards open as popovers. */
12
- import { openWorkItem, recordPress } from './premium-vw-item.js';
10
+ * What the Agreed design has no frame for (List, By stage, Documents, the Sprint, Half and 2 yr spans, Find, Filter, New initiative, the new
11
+ * asks, the sprint and release, Metrics, cancelled and archived, the initiative actions) works as a plain version with a "Waiting for design"
12
+ * tag (pm/bd-acts.js), in the side panel, and no older UI.
13
+ * After the model, GET /api/board-trail (lib/board-trail.js) adds what the model does not carry: days in the step and the usual days, the
14
+ * skipped steps and why, the parts of the output, what waits on you, tickets drafted in PMOS, PRD drift, links, dependencies and themes.
15
+ * Where no record holds a value for an initiative, the element says so: nothing is invented. */
13
16
  import { pmPost } from './http.js';
14
- import { openBacklog } from './premium-vw-backlog.js';
15
- import { $, $$, esc, openDlg, toast, loadThread, wireRail, logHtml, turnA, ptx, pillOf, store, crumbHtml, wireCrumb, chatAbout, kv, H, openAddDoc, setPageGaps, openSources } from './premium-shell.js';
16
- import { mountDocSheet } from './premium-doc-sheet.js';
17
- import * as MT from './premium-metric-tiles.js';
18
- import { openSprint } from './premium-vw-jira.js';
19
- import { dotsBtn, openMenu, closeMenu, menuKey, asksHtml, onAsks, openIniForm } from './premium-acts.js';
17
+ import { $, $$, esc, store, crumbHtml, wireCrumb, chatAbout, setPageGaps } from './premium-shell.js';
20
18
  import { mountNav } from './cozy-nav.js';
21
- import { stepsHelpHtml } from './bd-stages.js';
22
- import { timelineHtml, SPANS } from './bd-span.js';
19
+ import { stepsHelpHtml, rulesHelpHtml } from './bd-stages.js';
20
+ import { timelineHtml, SPANS, GROUPS, md } from './bd-span.js';
21
+ import * as Acts from './bd-acts.js';
22
+ import { open as viewerOpen } from './cozy-viewer.js';
23
23
 
24
- const MODE_KEY = 'pmos.premium.openAs', VIEW_KEY = 'pmos.board.view', SPAN_KEY = 'pmos.board.span';
25
- let M = null; // the model
26
- const docSheet = mountDocSheet({ ws: () => M.board.ws, scope: () => M.docs.scope, rows: () => M.docs.rows, reload: () => load(), noteKey: (d) => 'doc:' + M.board.id + ':' + d.key, sub: () => M.board.name, again: true });
24
+ const VIEW_KEY = 'pmos.board.view', SPAN_KEY = 'pmos.board.span', GROUP_KEY = 'pmos.board.group';
25
+ let M = null; // the model
26
+ let TR = null; // the trail (GET /api/board-trail): { usual, themes, items: { [id]: item } }
27
+ let group = GROUPS.some(([k]) => k === store.get(GROUP_KEY)) ? store.get(GROUP_KEY) : 'theme';
27
28
  let view = ['track', 'stages', 'time', 'list'].includes(store.get(VIEW_KEY)) ? store.get(VIEW_KEY) : 'track';
28
29
  let span = SPANS.some(([k]) => k === store.get(SPAN_KEY)) ? store.get(SPAN_KEY) : 'quarter';
29
30
  let tab = 'ini';
30
- let shown = 25; // rows on screen in the track and the list
31
31
  let readTimer = null;
32
- let showGone = false; // the cancelled and archived rows under the list
33
- const F = { chips: new Set(), owners: new Set(), lanes: new Set(), q: '' }; // the filters: chips, owner and lane, and Find
34
- let peek = null; // the open panel: { kind: 'ini' | 'tk', key, tk }
35
- wireRail('init');
32
+ let foldOpen = false; // the Monitor and Evaluate rows under the table
33
+ let sprintSet = false; // "This sprint" starts on, once, when the board has a sprint
34
+ const F = { chips: new Set(), q: '', owners: new Set(), lanes: new Set() }; // the chip filters, Find and Filter
35
+ let peek = null; // the open panel: { kind: 'ini' | 'tk' | 'acts', key, tk, from: 'track' | 'time' }
36
36
  mountNav('board');
37
- /** The context of the board presses (pm/premium-acts.js). */
38
- const ctxOf = () => ({ ws: M.board.ws, board: M.board.id, boardName: M.board.name, self: M.board.self, first: (M.board.stages || [])[0] || '', reload: load });
39
- const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
40
37
  const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
41
- const DOCI = '<path d="M6 3h9l4 4v14H6z"/><path d="M14 3v5h5M9 13h6M9 17h4"/>';
42
- const STATE_ICO = { Linked: '<path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/>', Live: '<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>', 'Up to date': '<path d="M5 12.5l4.5 4.5L19 7.5"/>', Draft: '<path d="M4 20l4-1 11-11-3-3L5 16z"/>', 'Not started': '<circle cx="12" cy="12" r="9"/><path d="M12 8v5M12 16.5v.5"/>', Stale: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>', Due: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>' };
38
+ const I = {
39
+ x: 'M6 6l12 12M18 6L6 18', expand: 'M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7', more: 'M5 12h.01M12 12h.01M19 12h.01', go: 'M5 12h14M13 6l6 6-6 6', next: 'M9 6l6 6-6 6',
40
+ ext: 'M14 4h6v6M20 4l-9 9M10 6H5v13h13v-5', refresh: 'M20 11a8 8 0 1 0-2.3 5.7M20 4v7h-7', cal: 'M4 6h16v14H4zM4 10h16M9 3v4M15 3v4', jira: 'M12 3l9 9-9 9-9-9z',
41
+ flag: 'M5 21V4M5 4h11l-2 4 2 4H5', note: 'M4 5h16v11h-9l-5 4v-4H4z', spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z',
42
+ doc: 'M6 3h9l4 4v14H6zM14 3v5h5', link: 'M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1', chev: 'M7 10l5 5 5-5', chevUp: 'M7 14l5-5 5 5',
43
+ move: 'M4 12h12M12 6l6 6-6 6M20 5v14', hold: 'M9 5v14M15 5v14', archive: 'M4 5h16v4H4zM6 9v10h12V9M10 13h4', group: 'M3 5h18v4H3zM3 11h18v4H3zM3 17h12v3H3z',
44
+ track: 'M3 5h18v4H3zM3 11h18v4H3zM3 17h12v3H3z', time: 'M4 6h9M8 12h11M6 18h7',
45
+ };
43
46
  const plural = (n, a, b) => (n === 1 ? a : b);
44
- const ago = (iso) => { const t = Date.parse(iso || ''); if (!t) return ''; const m = Math.max(0, Math.round((Date.now() - t) / 60000)); return m < 1 ? 'just now' : m < 60 ? m + ' min ago' : m < 60 * 36 ? Math.round(m / 60) + ' h ago' : Math.round(m / 1440) + ' days ago'; };
45
- const wsQ = (k) => (M.board.ws ? k + 'ws=' + encodeURIComponent(M.board.ws) : '');
47
+ const ago = (iso, short) => { const t = Date.parse(iso || ''); if (!t) return ''; const m = Math.max(0, Math.round((Date.now() - t) / 60000)); return m < 1 ? 'just now' : m < 60 ? m + ' min' + (short ? '' : ' ago') : m < 60 * 36 ? Math.round(m / 60) + ' h' + (short ? '' : ' ago') : Math.round(m / 1440) + ' days' + (short ? '' : ' ago'); };
48
+ const isoDate = (iso) => { const x = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return x ? new Date(+x[1], +x[2] - 1, +x[3]) : null; };
49
+ const fmt = (iso) => { const d = isoDate(iso); return d ? md(d) : ''; };
50
+ const PHONE = matchMedia('(max-width: 720px)');
51
+ const rowOf = (key) => (M && M.rows || []).find((r) => r.key === key) || null;
52
+
53
+ /** A plain panel of pm/bd-acts.js: it goes in the side panel like the others. */
54
+ function actsPanel(html, from) { peek = { kind: 'acts', key: peek && peek.key }; showPeek(html, from); } // keeps the initiative, so Close goes back to its row
46
55
 
47
- /* ── the toolbar: picker, views, chips ──────────────────────────────────────────────────────────────────────────── */
56
+ /* ── the toast: the Agreed design's dark pill ─────────────────────────────────────────────────────────────────────────────── */
57
+ let toastT = null;
58
+ /** The toast; with `undo`, an Undo button that runs it once (the write's opposite, through the same route). */
59
+ function say(msg, undo) {
60
+ const t = $('#bdToast'); t.innerHTML = `<span>${esc(msg)}</span>${undo ? '<button type="button" class="bd-undo">Undo</button>' : ''}`; t.hidden = false;
61
+ const u = t.querySelector('.bd-undo'); if (u) u.onclick = () => { u.disabled = true; t.hidden = true; undo(); };
62
+ clearTimeout(toastT); toastT = setTimeout(() => { t.hidden = true; }, undo ? 10000 : 5000);
63
+ }
64
+
65
+ /* ── the toolbar: picker, chips ───────────────────────────────────────────────────────────────────────────────────── */
48
66
  let crumbed = false;
49
67
  function drawHead() {
50
68
  if (!crumbed) {
@@ -56,173 +74,203 @@ function drawHead() {
56
74
  chatAbout('board:this-board', M.board.name ? 'the ' + M.board.name + ' board' : 'this board');
57
75
  }
58
76
  $('#snap').textContent = M.header.text;
77
+ $('#newIni').hidden = !!M.board.self; // PMOS-self: new work starts at the pmos-router skill
59
78
  setPageGaps(((M.header && M.header.missing) || []).length);
60
- $('#snap').title = 'Every figure on this page comes from a record of the board. A date, owner or progress shows only when one was set.';
61
- $('#brief').textContent = '';
62
79
  }
63
80
  const CHIP_F = [['late', 'late', 'm-warn', (n) => n + ' late'], ['risk', 'risk', 'm-warn', (n) => n + ' at risk'], ['blocked', 'red', 'm-crit', (n) => n + ' blocked'], ['idle', 'q', '', (n) => n + ' idle 30+ days']];
81
+ const longSpan = () => view === 'time' && (span === 'year' || span === 'y5');
64
82
  function drawChips() {
65
- const J = M.jira || {}, C = M.chips || {}, sp = J.sprint, rel = J.release;
66
- const jira = J.readAt ? 'Jira · read ' + ago(J.readAt) : 'Jira · not read';
67
- const sprint = [sp ? sp.name : null, rel ? rel.name + ' ships ' + rel.at : null].filter(Boolean).join(' · ') || 'No sprint on record';
68
- const asks = M.board.self ? 'New asks' : C.asks == null ? 'New asks · not read' : null;
69
- $('#bdChipset').innerHTML = `<button type="button" class="cz-chip" id="chJira" title="When Jira was last read. Sources reads it again." aria-haspopup="dialog">${SV('M20 11a8 8 0 1 0-2.3 5.7M20 4v7h-7')}<span>${esc(jira)}</span></button>`
70
- + `<button type="button" class="cz-chip" id="chSprint" aria-haspopup="dialog" aria-expanded="false" aria-controls="popSpr">${SV('M4 6h16v14H4zM4 10h16M9 3v4M15 3v4')}<span>${esc(sprint)}</span></button>`
71
- + `<button type="button" class="cz-chip" id="chAsks" aria-haspopup="dialog" aria-expanded="false" aria-controls="popAsks">${asks ? esc(asks) : `<i class="cz-dot you${C.asks ? ' m-info' : ''}"></i><b>${C.asks}</b> new ${plural(C.asks, 'ask', 'asks')}`}</button>`
72
- + '<span class="cz-vr"></span>'
73
- + CHIP_F.map(([k, tone, mo, word]) => (C[k] ? `<button type="button" class="cz-chip gh${F.chips.has(k) ? ' on' : ''}" data-f="${k}" aria-pressed="${F.chips.has(k)}"><i class="cz-dot ${tone} ${mo}"></i>${esc(word(C[k]))}</button>` : '')).join('')
74
- + (sp ? `<span class="bd-sp"></span><button type="button" class="cz-chip${F.chips.has('sprint') ? ' on' : ''}" data-f="sprint" aria-pressed="${F.chips.has('sprint')}">This sprint</button>` : '');
83
+ const J = M.jira || {}, C = M.chips || {}, sp = J.sprint, rel = J.release, phone = PHONE.matches;
84
+ const jira = J.readAt ? (phone ? 'Jira ' + ago(J.readAt, true) : 'Jira · read ' + ago(J.readAt)) : phone ? 'Jira not read' : 'Jira · not read';
85
+ const sprint = [sp ? sp.name : null, rel ? rel.name + ' ships ' + rel.at.replace(/^(\d+) (\w+)$/, '$2 $1') : null].filter(Boolean).join(' · ') || 'No sprint on record';
86
+ const asks = C.asks == null ? 'New asks · not read' : null;
87
+ const flt = (keys) => CHIP_F.filter(([k]) => keys.includes(k)).map(([k, tone, mo, word]) => (C[k] ? `<button type="button" class="bd-chip gh${F.chips.has(k) ? ' on' : ''}" data-f="${k}" aria-pressed="${F.chips.has(k)}"><i class="cz-dot ${tone} ${mo}"></i>${esc(word(C[k]))}</button>` : '')).join('');
88
+ const thisSprint = sp && (view === 'track' || phone) ? `<button type="button" class="bd-chip${F.chips.has('sprint') ? ' on' : ''}" data-f="sprint" aria-pressed="${F.chips.has('sprint')}">This sprint</button>` : '';
89
+ if (longSpan()) {
90
+ const gn = (GROUPS.find(([k]) => k === group) || GROUPS[0])[1];
91
+ $('#bdChipset').innerHTML = `<span class="bd-grpw"><button type="button" class="bd-chip" id="chGroup" aria-haspopup="menu" aria-expanded="false">${SV(I.group)}<span>Group:</span><b>${esc(gn)}</b></button><span class="bd-grpm" id="grpMenu" role="menu" hidden>${GROUPS.map(([k, n]) => `<button type="button" role="menuitemradio" aria-checked="${k === group}" data-grp="${k}">${esc(n)}</button>`).join('')}</span></span><span class="bd-sp"></span>${flt(['late', 'risk', 'blocked'])}`;
92
+ return;
93
+ }
94
+ const jiraChip = `<button type="button" class="bd-chip" id="chJira" title="Read Jira again">${SV(I.refresh)}<span>${esc(jira)}</span></button>`;
95
+ const askChip = `<button type="button" class="bd-chip" id="chAsks" aria-haspopup="dialog">${asks ? esc(asks) : `<i class="cz-dot you${C.asks ? ' m-info' : ''}"></i><b>${C.asks}</b> new ${plural(C.asks, 'ask', 'asks')}`}</button>`;
96
+ if (phone) {
97
+ const docs = M.docs && M.docs.rows ? M.docs.rows.length : 0;
98
+ $('#bdChipset').innerHTML = thisSprint + jiraChip + askChip + flt(['late', 'risk', 'blocked', 'idle']) + `<button type="button" class="bd-chip" id="chDocs">Docs ${docs}</button>`;
99
+ return;
100
+ }
101
+ $('#bdChipset').innerHTML = jiraChip
102
+ + `<button type="button" class="bd-chip" id="chSprint" aria-haspopup="dialog">${SV(I.cal)}<span>${esc(sprint)}</span></button>`
103
+ + askChip + '<span class="bd-vr"></span>' + flt(['late', 'risk', 'blocked', 'idle'])
104
+ + (thisSprint ? '<span class="bd-sp"></span>' + thisSprint : '');
75
105
  }
76
106
  $('#bdChipset').addEventListener('click', (e) => {
77
107
  const f = e.target.closest('[data-f]');
78
- if (f) { const k = f.dataset.f; if (F.chips.has(k)) F.chips.delete(k); else F.chips.add(k); shown = 25; drawChips(); drawInit(); return; }
79
- if (e.target.closest('#chJira')) { openSources(); return; }
80
- if (e.target.closest('#chSprint')) { togglePop('popSpr', $('#chSprint')); return; }
81
- if (e.target.closest('#chAsks')) { togglePop('popAsks', $('#chAsks')); }
108
+ if (f) { const k = f.dataset.f; if (F.chips.has(k)) F.chips.delete(k); else F.chips.add(k); drawChips(); drawInit(); return; }
109
+ const g = e.target.closest('[data-grp]');
110
+ if (g) { group = g.dataset.grp; store.set(GROUP_KEY, group); drawChips(); drawInit(); const c = $('#chGroup'); if (c) c.focus(); return; }
111
+ const b = e.target.closest('button'); if (!b) return;
112
+ if (b.id === 'chJira') refreshJira(b);
113
+ else if (b.id === 'chSprint') Acts.open.sprint(b);
114
+ else if (b.id === 'chAsks') Acts.open.asks(b);
115
+ else if (b.id === 'chGroup') { const m = $('#grpMenu'), o = m.hidden; m.hidden = !o; b.setAttribute('aria-expanded', String(o)); if (o) m.querySelector('[aria-checked="true"]').focus(); }
116
+ else if (b.id === 'chDocs') setTab('docs');
82
117
  });
118
+ /** Read Jira again: the Jira source's own refresh (POST /api/sources/refresh), the one the Sources list runs. It starts a read and changes no record. */
119
+ async function refreshJira(btn) {
120
+ if (btn) btn.disabled = true;
121
+ const r = await pmPost('/api/sources/refresh', { ws: (M && M.board.ws) || '', source: 'jira' }).catch(() => null);
122
+ if (btn) btn.disabled = false;
123
+ say(r && r.ok ? 'Reading Jira again. The Board shows it when the read lands.' : 'Jira was not read again: ' + ((r && r.error) || 'the server did not answer') + '.');
124
+ if (r && r.ok) setTimeout(load, 4000);
125
+ }
83
126
 
84
- /* ── popovers under the toolbar (new asks, sprint and release, metrics, filter, what finishes each step) ─────────────────── */
127
+ /* ── the popovers: what finishes each step, and the timeline's spans ───────────────────────────────────────────────────── */
85
128
  let popBtn = null;
86
- function closePops(back) { $$('.bd-pop').forEach((p) => { p.hidden = true; }); if (popBtn) { popBtn.setAttribute('aria-expanded', 'false'); if (back) popBtn.focus(); } popBtn = null; }
87
- function togglePop(id, btn, anchorOnly) {
129
+ function closePops(back) { $$('.bd-pop').forEach((p) => { p.hidden = true; }); if (popBtn && back) popBtn.focus(); popBtn = null; }
130
+ function togglePop(id, btn) {
88
131
  const p = $('#' + id), open = p.hidden;
89
132
  closePops();
90
133
  if (!open) return;
91
- p.hidden = false; popBtn = anchorOnly ? null : btn || null; if (popBtn) popBtn.setAttribute('aria-expanded', 'true');
92
- if (btn && innerWidth > 720) { const r = btn.getBoundingClientRect(), host = $('#stage').getBoundingClientRect(); p.style.top = (r.bottom - host.top + 8) + 'px'; p.style.left = Math.max(16, Math.min(r.left - host.left, host.width - p.offsetWidth - 16)) + 'px'; }
93
- else { p.style.top = ''; p.style.left = ''; }
94
- const f = p.querySelector('button, input, a'); if (f) f.focus({ preventScroll: true });
134
+ p.hidden = false; popBtn = btn || null;
135
+ const f = p.querySelector('button'); if (f) f.focus({ preventScroll: true });
95
136
  }
137
+ $('#popSteps').innerHTML = stepsHelpHtml();
138
+ $('#popRules').innerHTML = rulesHelpHtml();
96
139
  document.addEventListener('click', (e) => {
97
140
  if (e.target.closest('[data-pop-close]')) { closePops(true); return; }
98
- if (!e.target.closest('.bd-pop, [aria-controls^="pop"], .crmenu, #moreMenu, .dlg, .bam2')) closePops();
141
+ if (!e.target.closest('.bd-pop, [data-steps], [data-rules]')) closePops();
142
+ if (!e.target.closest('.bd-grpw')) { const m = $('#grpMenu'); if (m && !m.hidden) { m.hidden = true; $('#chGroup').setAttribute('aria-expanded', 'false'); } }
99
143
  });
100
144
 
101
- /* ── the rows on screen: the filters, Find, the order ──────────────────────────────────────────────────────────────── */
145
+ /* ── the rows on screen: the chip filters ─────────────────────────────────────────────────────────────────────────── */
146
+ /** "This sprint": an initiative with Jira tickets shows when one of them is in the current sprint; one with plan dates shows when they
147
+ * overlap the sprint; one with neither (the early stages) always shows. */
148
+ function inSprint(r, sp) {
149
+ const t = r.track || {};
150
+ if ((t.tickets || []).length) return t.tickets.some((k) => k.sprint === sp.name);
151
+ if (r.start && r.end && sp.start && sp.end) return r.start.slice(0, 10) <= sp.end && r.end.slice(0, 10) >= sp.start;
152
+ return true;
153
+ }
102
154
  function visible() {
103
- const q = F.q.trim().toLowerCase(), sp = M.jira && M.jira.sprint;
155
+ const sp = M.jira && M.jira.sprint;
104
156
  return M.initiatives.list.rows.filter((r) => {
105
157
  const t = r.track || {};
106
158
  if (F.chips.has('late') && !r.late) return false;
107
159
  if (F.chips.has('risk') && r.status !== 'at risk') return false;
108
160
  if (F.chips.has('blocked') && !t.blocked) return false;
109
161
  if (F.chips.has('idle') && t.idle == null) return false;
110
- if (F.chips.has('sprint') && !(sp && (t.tickets || []).some((k) => k.sprint === sp.name))) return false;
111
- if (F.owners.size && !F.owners.has(r.owner || '')) return false;
112
- if (F.lanes.size && !F.lanes.has(r.lane || '')) return false;
113
- if (q && !(r.title + ' ' + (r.id || '') + ' ' + (t.tickets || []).map((k) => k.key + ' ' + k.title).join(' ')).toLowerCase().includes(q)) return false;
162
+ if (F.chips.has('sprint') && sp && (view === 'track' || PHONE.matches) && !inSprint(r, sp)) return false;
163
+ if (F.q && !String(r.title || '').toLowerCase().includes(F.q.toLowerCase())) return false;
164
+ if (F.owners.size && !F.owners.has(r.owner || 'No owner')) return false;
165
+ if (F.lanes.size && !F.lanes.has(r.lane)) return false;
114
166
  return true;
115
167
  });
116
168
  }
117
- const filtered = () => F.chips.size || F.owners.size || F.lanes.size || F.q.trim();
118
- /** The status line of a row: the most important of blocked, late, at risk, idle and on hold, with its dot and its motion level. */
169
+ const filtered = () => [...F.chips].some((k) => k !== 'sprint') || !!F.q || F.owners.size > 0 || F.lanes.size > 0;
170
+ const clearFilters = () => { F.chips.forEach((k) => { if (k !== 'sprint') F.chips.delete(k); }); F.q = ''; F.owners.clear(); F.lanes.clear(); };
171
+ /** The status line of a row: on hold, waiting on you, late, at risk, idle, shipping, on track. A blocked ticket stays on its ticket. */
119
172
  function statusOf(r) {
120
173
  const t = r.track || {};
121
174
  if (r.acts && r.acts.life === 'hold') return { tone: 'q', mo: '', text: 'On hold' + (r.acts.back ? ' · back ' + r.acts.back : '') };
122
- if (t.blocked) return { tone: 'red', mo: 'm-crit', text: t.blocked + ' blocked in Jira' + (r.late ? ' · late' : '') };
175
+ if (t.you) return { tone: 'you', mo: 'm-info', text: t.you };
123
176
  if (r.late) return { tone: 'late', mo: 'm-warn', text: r.overDays > 0 ? r.overDays + ' ' + plural(r.overDays, 'day', 'days') + ' over' : 'Late' };
124
177
  if (r.status === 'at risk') return { tone: 'risk', mo: 'm-warn', text: 'At risk' + (r.owner ? '' : ' · no owner') };
125
178
  if (t.idle != null) return { tone: 'q', mo: '', text: 'Idle ' + t.idle + ' days' };
126
- if (r.status === 'on track') return { tone: 'ok', mo: '', text: 'On track' + (r.owner ? ' · ' + r.owner : '') };
179
+ if (r.status === 'on track' && r.release && r.release.days != null && r.release.days >= 0 && t.key === 'deliver') {
180
+ const d = r.release.days; return { tone: 'ok', mo: '', text: d === 0 ? 'Ships today' : d === 1 ? 'Ships tomorrow' : 'Ships ' + fmt(r.release.iso) };
181
+ }
182
+ if (r.status === 'on track') return { tone: 'ok', mo: '', text: 'On track' };
127
183
  return { tone: 'q', mo: '', text: r.statusLabel || r.sub };
128
184
  }
129
- const progText = (p) => (!p ? 'Not counted yet' : p.unit === '%' ? p.done + '%' : p.done + ' of ' + p.total + ' ' + p.unit);
185
+ /** The Output bar: one segment per ticket (a ticket opens its panel) or per part; a progress the record holds fills it as one bar. */
130
186
  function segHtml(r, big) {
131
- const p = r.track && r.track.prog;
132
- if (p && p.parts) return `<div class="seg5${big ? ' big' : ''}">${r.track.tickets.map((t) => `<button type="button" class="bt-tk ${esc(t.cls || 'td')}" data-tk="${esc(t.key)}" data-ini="${esc(r.key)}" aria-label="${esc(t.key + ': ' + t.title + ', ' + (t.blocked ? 'blocked' : t.status))}" title="${esc(t.key + ' · ' + t.title)}"></button>`).join('')}</div>`;
133
- if (p) return `<div class="seg5 pc${big ? ' big' : ''}" role="img" aria-label="${p.done}%"><i><b style="width:${Math.max(0, Math.min(100, p.done))}%"></b></i></div>`;
134
- return `<div class="seg5 none${big ? ' big' : ''}" aria-hidden="true"><i></i></div>`;
135
- }
187
+ const t = r.track || {}, segs = t.segs || [], n = segs.length;
188
+ if (!n) return `<div class="seg5 none${big ? ' big' : ''}" aria-hidden="true"><i class="na"></i></div>`;
189
+ const fill = (i) => { if (t.pct == null) return ''; const f = Math.max(0, Math.min(1, (t.pct / 100) * n - i)) * 100; return f > 0 ? ` style="background:linear-gradient(90deg,var(--bd-done) ${f.toFixed(1)}%,var(--bd-rail) ${f.toFixed(1)}%)"` : ''; };
190
+ return `<div class="seg5${big ? ' big' : ''}"${t.pct != null ? ` role="img" aria-label="${t.pct}% on record"` : ''}>${segs.map((s, i) => (s.tk
191
+ ? `<button type="button" class="bt-tk ${esc(s.cls || 'td')}" data-tk="${esc(s.tk)}" data-ini="${esc(r.key)}" aria-label="${esc(s.tk + ': ' + ((t.tickets.find((k) => k.key === s.tk) || {}).title || '') + ', ' + ((t.tickets.find((k) => k.key === s.tk) || {}).blocked ? 'blocked' : (t.tickets.find((k) => k.key === s.tk) || {}).status))}" title="${esc(s.tk)}"></button>`
192
+ : `<i class="${esc(s.cls || '')}"${fill(i)}></i>`)).join('')}</div>`;
193
+ }
194
+ const lineHtml = (r) => ((r.track && r.track.line) || []).map((x) => (x.tone ? `<em class="s-${x.tone}">${esc(x.text)}</em>` : esc(x.text))).join(' · ');
136
195
 
137
- /* ── the stage track (B1) ─────────────────────────────────────────────────────────────────────────────────────── */
138
- const LEGEND = '<span class="lg" aria-hidden="true"><span><i class="dn"></i>Done</span><span><i class="rv"></i>Review</span><span><i class="ip"></i>Doing</span><span><i class="bl"></i>Blocked</span></span>';
196
+ /* ── the stage track (AgBoard, AgBoardPhone) ──────────────────────────────────────────────────────────────────────────── */
197
+ const LEGEND = '<span class="lg" aria-hidden="true"><span><i class="sk"></i>Skipped</span><span><i class="dn"></i>Done</span><span><i class="rv"></i>Review</span><span><i class="ip"></i>Doing</span><span><i class="yo"></i>You</span><span><i class="bl"></i>Blocked</span></span>';
198
+ const DAYS = (t) => (t.days != null ? t.days + 'd' : '—');
199
+ /** "usually N days": the median of past initiatives in that step (lib/board-trail.js), shown only from 3 samples on. */
200
+ const usualOf = (t) => { const u = TR && TR.usual && t && TR.usual[t.key]; return u && u.n >= 3 && u.days != null ? u : null; };
201
+ const usualText = (u) => (u.days === 0 ? 'usually under a day' : 'usually ' + u.days + ' ' + plural(u.days, 'day', 'days'));
202
+ const dayTitle = (t) => t.label + ' · ' + (t.days != null ? t.days + ' ' + plural(t.days, 'day', 'days') + ' in this step' : 'days in this step are not on record') + (usualOf(t) ? ' · ' + usualText(usualOf(t)) : '');
139
203
  function trackRow(r) {
140
- const t = r.track || { k: -1, label: r.stage || 'No stage', output: '', prog: null }, s = statusOf(r), k = t.k;
204
+ const t = r.track || { k: -1, label: r.stage || 'No stage', output: '', segs: [], skipped: [] }, s = statusOf(r), k = t.k, sk = new Set(t.skipped || []);
141
205
  const cells = M.steps.map((st, j) => {
142
- const cls = ['sc', j === 0 ? 'f0' : '', j === 7 ? 'l' : '', st.ms ? 'ms' : '', j < k ? 'p' : '', j === k ? 'c bg' : ''].filter(Boolean).join(' ');
143
- return `<div class="${cls}" role="cell"${j === k ? ` title="${esc(st.label)}"` : ''}>${j === k ? `<span class="cur"><u class="cz-dot ${s.tone} ${s.mo}"></u></span>` : '<i></i>'}</div>`;
206
+ const cls = ['sc', j === 0 ? 'f0' : '', j === 7 ? 'l' : '', st.ms ? 'ms' : '', j < k ? 'p' : '', sk.has(j) ? 'k' : '', j === k ? 'c bg' : ''].filter(Boolean).join(' ');
207
+ const why = sk.has(j) && (t.skipWhy || []).find((x) => x.stage === st.key);
208
+ const title = j === k ? dayTitle(t) : sk.has(j) ? st.label + ' skipped' + (why && why.why ? ': ' + why.why : '') : '';
209
+ return `<div class="${cls}" role="cell"${title ? ` title="${esc(title)}"` : ''}>${j === k ? `<span class="cur"><u class="cz-dot ${s.tone} ${s.mo}"></u><small>${DAYS(t)}</small></span>` : '<i></i>'}</div>`;
144
210
  }).join('');
145
- const nx = t.next ? `<span class="${t.next.tone === 'red' ? 's-red' : ''}">${esc(t.next.text)}</span>` : (t.prog && t.prog.unit === '%' ? 'Progress from the record' : '');
146
- return `<div class="bt-r bt-l${peek && peek.key === r.key ? ' sel' : ''}${r.acts && r.acts.life === 'hold' ? ' held' : ''}" role="row" data-row="${esc(r.key)}">`
147
- + `<button type="button" class="ini2 bt-nm" data-key="${esc(r.key)}" role="rowheader" aria-haspopup="dialog"><b>${esc(r.title)}</b><span class="cs s-${s.tone}"><i class="cz-dot ${s.tone}"></i>${esc(s.text)}</span><span class="bt-pst">${t.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(t.label)}</span></button>`
211
+ return `<div class="bt-r bt-l${peek && peek.key === r.key && peek.kind !== 'acts' ? ' sel' : ''}${r.acts && r.acts.life === 'hold' ? ' held' : ''}" role="row" data-row="${esc(r.key)}">`
212
+ + `<button type="button" class="ini2 bt-nm" data-key="${esc(r.key)}" role="rowheader" aria-haspopup="dialog"><b>${esc(r.title)}</b><span class="cs s-${s.tone}"><i class="cz-dot ${s.tone}"></i>${esc(s.text)}</span><span class="bt-pst">${t.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(t.label)} · ${DAYS(t)}</span></button>`
148
213
  + `<div class="bt-cells" role="presentation">${cells}</div>`
149
- + `<div class="bt-dl" role="cell"><div class="t1"><b>${esc(t.output)}</b><span>${esc(progText(t.prog))}</span></div>${segHtml(r)}<div class="t3">${nx}</div></div>`
150
- + `<div class="bt-act" role="cell">${r.acts ? dotsBtn(r) : ''}</div></div>`;
214
+ + `<div class="bt-dl" role="cell"><div class="t1"><b>${esc(t.output)}</b><span>${esc(t.count || '')}</span></div>${segHtml(r)}<div class="t3">${lineHtml(r)}</div></div></div>`;
151
215
  }
216
+ const isME = (r) => r.track && r.track.k >= 6;
152
217
  function drawTrack(L) {
153
218
  const S = M.steps || [];
154
219
  const sorted = L.slice().sort((a, b) => ((a.track ? a.track.k : -1) < 0 ? 99 : a.track.k) - ((b.track ? b.track.k : -1) < 0 ? 99 : b.track.k));
155
- const head = `<div class="bt-r bt-h" role="row"><div class="bt-nmh" role="columnheader">Initiative <span>${L.length}</span><button type="button" class="bd-info" id="stHelp" aria-label="What finishes each step" title="What finishes each step" aria-haspopup="dialog" aria-controls="popSteps"><i aria-hidden="true">i</i></button></div><div class="bt-cells" role="presentation">${S.map((s) => `<div role="columnheader" class="${s.ms ? 'msh' : ''}">${s.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(s.label)}<span>${s.count}</span></div>`).join('')}</div><div class="bt-oh" role="columnheader">Output ${LEGEND}</div><div role="presentation"></div></div>`;
156
- if (!L.length) return `<div class="bt" role="table" aria-label="Initiatives by stage">${head}<p class="empty3 plain bt-empty">${filtered() ? 'No initiative matches the filters. <button type="button" class="dlink" id="fClear">Clear the filters</button>' : 'No initiatives are on this board\'s now view.'}</p>${goneHtml()}</div>`;
157
- return `<div class="bt" role="table" aria-label="Initiatives by stage">${head}${sorted.slice(0, shown).map(trackRow).join('')}`
158
- + `<div class="bt-tf">${L.length > shown ? `<button type="button" class="dlink" id="more">${SV('M7 10l5 5 5-5')}Show ${Math.min(25, L.length - shown)} more of ${L.length - shown}</button>` : '<span></span>'}<span class="bt-srt">Sorted by stage</span></div>${goneHtml()}</div>`;
220
+ // Monitor and Evaluate fold away after the first row of each (AgBoard: "19 more in Monitor and Evaluate")
221
+ const seen = new Set(), shown = [], folded = [];
222
+ for (const r of sorted) { if (isME(r) && seen.has(r.track.k) && !foldOpen) folded.push(r); else { if (isME(r)) seen.add(r.track.k); shown.push(r); } }
223
+ const meTotal = (S[6] ? S[6].count : 0) + (S[7] ? S[7].count : 0), meShown = shown.filter(isME).length, more = Math.max(folded.length, meTotal - meShown);
224
+ const n = M.initiatives.open || M.initiatives.list.rows.length;
225
+ const head = `<div class="bt-r bt-h" role="row"><div class="bt-nmh" role="columnheader">Initiative <span>${n}</span></div><div class="bt-cells" role="presentation">${S.map((s) => `<div role="columnheader" class="${s.ms ? 'msh' : ''}" data-steps title="What finishes each step" aria-haspopup="dialog" tabindex="0"><span class="bt-hl">${s.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(s.label)}</span><span>${s.count}</span></div>`).join('')}</div><div class="bt-oh" role="columnheader">Output ${LEGEND}</div></div>`;
226
+ const tf = more > 0 && !foldOpen ? `<button type="button" class="dlink" id="fold" aria-expanded="false">${SV(I.chev)}${more} more in Monitor and Evaluate</button>`
227
+ : foldOpen && meTotal > 1 ? `<button type="button" class="dlink" id="fold" aria-expanded="true">${SV(I.chevUp)}Fold Monitor and Evaluate${meTotal > meShown ? ` · ${meTotal - meShown} more are not loaded` : ''}</button>` : '<span></span>';
228
+ if (!L.length) return `<div class="bt" role="table" aria-label="Initiatives by stage">${head}<p class="bt-empty">${filtered() ? 'No initiative matches the chips, Find or Filter. <button type="button" class="dlink" id="fClear">Clear them</button>' : 'No initiatives are on this board\'s now view.'}</p></div>`;
229
+ return `<div class="bt" role="table" aria-label="Initiatives by stage">${head}${shown.map(trackRow).join('')}<div class="bt-tf">${tf}<span class="bt-srt">Sorted by stage</span></div>${PHONE.matches ? `<div class="bd-whead bd-phx">${Acts.WTAG}<span class="bd-phb"><button type="button" class="bd-chip" data-steps aria-haspopup="dialog">What finishes each step</button><button type="button" class="bd-chip" data-open="metrics" aria-haspopup="dialog">Metrics</button><button type="button" class="bd-chip" data-open="gone" aria-haspopup="dialog">Cancelled and archived</button></span></div>` : ''}</div>`; // the phone has no step heads: a plain entry to the steps help
159
230
  }
160
231
 
161
- /* ── the list and By stage (the earlier views, kept) ──────────────────────────────────────────────────────────────── */
162
- const sub = (r) => `${esc(r.sub)}${r.statusLabel ? ` · <span class="${r.late ? 'bad' : 'warn'}">${esc(r.statusLabel)}</span>` : ''}`;
163
- function listBtn(r) {
164
- return `<button class="ini2 ibi${r.first ? ' first' : ''}" data-key="${esc(r.key)}"><span class="it"><b>${esc(r.title)}${r.first ? '<em class="tgf">Do this first</em>' : ''}</b><small>${sub(r)}</small></span><span class="wst"><span class="sg2" aria-hidden="true">${r.seg.map((c) => `<i class="${c}"></i>`).join('')}</span><em>${esc(r.stage || 'No stage')}${r.stageNote ? ' · ' + esc(r.stageNote) : ''}</em></span><span class="pg">${r.progress == null ? '' : `<i><b style="width:${r.progress}%"></b></i>`}</span><span class="rl${r.over ? ' over' : ''}">${esc(r.finish)}</span></button>`;
165
- }
166
- function drawList(L) {
167
- if (!L.length) return `<p class="empty3 plain">${filtered() ? 'No initiative matches the filters.' : 'No initiatives are on this board\'s now view.'}</p>` + goneHtml();
168
- return `<div class="inih"><span>Initiative</span><span>Where it is</span><span>Progress</span><span>Planned finish</span></div><div class="inil">` + L.slice(0, shown).map((r) => `<div class="inirw">${listBtn(r)}${r.acts ? dotsBtn(r) : ''}</div>`).join('') + '</div>'
169
- + (L.length > shown ? `<p class="note" style="margin-top:10px">${L.length - shown} more are loaded. <button class="fold alt" id="more" type="button">Show ${Math.min(25, L.length - shown)} more</button></p>` : '') + goneHtml();
170
- }
171
- /** The cancelled and archived rows, under a fold (initiative premium-board-actions). Their menu offers Reopen or Restore. */
172
- function goneHtml() {
173
- const G = M.initiatives.gone || { cancelled: [], archived: [] }, nc = G.cancelled.length, na = G.archived.length;
174
- if (!nc && !na) return '';
175
- return `<div class="bagone"><button class="dlink" type="button" id="goneT" aria-expanded="${showGone}">${[nc ? nc + ' cancelled' : '', na ? na + ' archived' : ''].filter(Boolean).join(' · ')}. ${showGone ? 'Hide them' : 'Show them'}</button>${showGone ? `<div class="inil">${G.cancelled.concat(G.archived).map((r) => `<div class="inirw gone">${listBtn(r)}${dotsBtn(r)}</div>`).join('')}</div>` : ''}</div>`;
176
- }
177
- function drawStages() {
178
- const S = M.initiatives.stages;
179
- if (!S.length) return '<p class="empty3 plain">This board has no workflow stages on record.</p>';
180
- const keep = new Set(visible().map((r) => r.key));
181
- return `<div class="istg">${S.map((s) => { const rows = s.rows.filter((r) => !filtered() || keep.has(r.key)); return `<div class="isc"><p class="label">${esc(s.stage)} <em>${s.count}</em></p>${rows.map((r) => `<button class="icd ibi" data-key="${esc(r.key)}"><b>${esc(r.title)}</b><small>${sub(r)}</small>${r.progress == null ? '' : `<span class="pg"><i><b style="width:${r.progress}%"></b></i></span>`}<small>${esc(r.finish)}</small></button>`).join('') || '<p class="mut">None</p>'}${s.more ? `<p class="mut">${s.more} more</p>` : ''}</div>`; }).join('')}</div>`;
182
- }
183
- /* ── the timeline (B2) ───────────────────────────────────────────────────────────────────────────────────────── */
232
+ /* ── the timeline (AgBoardTimeline, AgBoardTlYear, AgBoardTl5y, AgBoardTimelinePhone) ───────────────────────────────────────── */
233
+ /** The phone has no frame for the span rules, Year and 5 yr: a plain row under its timeline reaches them, with a "Waiting for design" tag. */
234
+ function phoneSpans(sp) {
235
+ return `<div class="bd-whead bd-phx">${Acts.WTAG}<span class="bd-phb">${[['quarter', 'Quarter'], ['year', 'Year'], ['y5', '5 yr']].map(([k, n]) => `<button type="button" class="bd-chip${sp === k ? ' on' : ''}" data-span-go="${k}" aria-pressed="${sp === k}">${n}</button>`).join('')}<button type="button" class="bd-chip" data-rules aria-haspopup="dialog">How the spans group</button></span></div>`;
236
+ }
184
237
  function drawTime(L) {
185
- const T = timelineHtml(L, M, span);
186
- const none = T.none.length ? `<div class="tg-none"><b>${T.none.length} ${plural(T.none.length, 'has', 'have')} no dates:</b> <span>${esc(T.none.slice(0, 4).map((r) => r.title).join(', '))}${T.none.length > 4 ? ' and ' + (T.none.length - 4) + ' more' : ''}</span><a class="cz-chip" id="askDates" href="${esc(askHref(null, 'Propose start and end dates for ' + T.none.map((r) => r.title).join(', ')))}">${SV('M4 5h16v11h-9l-5 4v-4H4z')}Ask to propose dates</a></div>` : '';
187
- return T.html + none;
238
+ const phone = PHONE.matches, long = span === 'year' || span === 'y5';
239
+ const S = M.steps || [], sp = phone && span !== 'sprint' && !long ? 'quarter' : span; // a phone draws Quarter and Sprint (AgBoardTimelinePhone); Year and 5 yr as the desktop frame, scrolled
240
+ const T = timelineHtml(L, M, sp, { phone: phone && !long, sel: peek && peek.kind !== 'acts' ? peek.key : null, status: statusOf, hiddenCount: (S[6] ? S[6].count : 0) + (S[7] ? S[7].count : 0), themes: (TR && TR.themes) || [], group,
241
+ askHref: (none) => askHref(null, 'Propose start and end dates for ' + none.map((r) => r.title).join(', ')) });
242
+ return phone ? (long ? `<div class="bd-phscroll">${T.html}</div>` : T.html) + phoneSpans(sp) : T.html;
188
243
  }
189
-
190
- const PHONE = matchMedia('(max-width: 720px)');
191
- PHONE.addEventListener('change', () => { if (M) drawInit(); });
192
244
  function drawInit() {
193
- const I = M.initiatives;
194
- $('#iniCap').innerHTML = I.cap ? `<b>${I.cap.on} of ${I.cap.open}</b> open on track · ${I.risk} at risk · ${I.late} late${I.hold ? ' · ' + I.hold + ' on hold' : ''}` : 'no open initiatives';
195
- const bar = $('#iniBar'); bar.hidden = !I.cap; if (I.cap) { bar.setAttribute('aria-valuemax', I.cap.open); bar.setAttribute('aria-valuenow', I.cap.on); $('b', bar).style.width = (I.cap.open ? I.cap.on / I.cap.open * 100 : 0) + '%'; }
196
- $('#nIni').textContent = String(I.open || I.list.rows.length);
197
- const L = visible();
198
- const v = (view === 'stages' || view === 'list') && PHONE.matches ? 'track' : view; // the phone offers Track and Timeline only (AgBoardPhone)
199
- $('#ibBody').dataset.view = v;
200
- $('#ibBody').innerHTML = v === 'track' ? drawTrack(L) : v === 'list' ? drawList(L) : v === 'stages' ? drawStages() : drawTime(L);
201
- $('#iniNote').textContent = I.note;
245
+ $('#nIni').textContent = String(M.initiatives.open || M.initiatives.list.rows.length);
246
+ const L = visible(), v = PHONE.matches && (view === 'stages' || view === 'list') ? 'track' : view;
247
+ const body = $('#ibBody');
248
+ body.dataset.view = v; body.dataset.span = v === 'time' ? span : '';
249
+ body.innerHTML = v === 'track' ? drawTrack(L) : v === 'time' ? drawTime(L) : v === 'list' ? Acts.listHtml(L) : Acts.stagesHtml(L);
202
250
  $$('#ibTabs [data-v]').forEach((b) => b.setAttribute('aria-pressed', String(b.dataset.v === v)));
203
- $('#bdSpans').hidden = v !== 'time';
251
+ $('#bdView').innerHTML = SV(v === 'time' ? I.time : I.track); $('#bdView').setAttribute('aria-label', 'Change view. Now: ' + (v === 'time' ? 'Timeline' : 'Stage track'));
252
+ $('#bdSpans').hidden = v !== 'time' || PHONE.matches;
204
253
  $$('#bdSpans [data-sp]').forEach((b) => b.setAttribute('aria-pressed', String(b.dataset.sp === span)));
254
+ document.body.dataset.bdView = v;
205
255
  }
206
- $('#ibTabs').addEventListener('click', (e) => { const b = e.target.closest('[data-v]'); if (!b || !M) return; view = b.dataset.v; store.set(VIEW_KEY, view); shown = 25; drawInit(); });
207
- $('#bdSpans').addEventListener('click', (e) => { const b = e.target.closest('[data-sp]'); if (!b || !M) return; span = b.dataset.sp; store.set(SPAN_KEY, span); drawInit(); });
256
+ PHONE.addEventListener('change', () => { if (M) { drawChips(); drawInit(); } });
257
+ function setView(v) { view = v; store.set(VIEW_KEY, view); closePeek(); drawChips(); drawInit(); }
258
+ $('#ibTabs').addEventListener('click', (e) => { const b = e.target.closest('[data-v]'); if (!b || !M) return; setTab('ini'); setView(b.dataset.v); });
259
+ $('#bdView').addEventListener('click', () => { if (M) setView(view === 'time' ? 'track' : 'time'); });
260
+ $('#bdSpans').addEventListener('click', (e) => { const b = e.target.closest('[data-sp]'); if (!b || !M) return; span = b.dataset.sp; store.set(SPAN_KEY, span); drawChips(); drawInit(); });
208
261
  $('#ibBody').addEventListener('click', (e) => {
209
- if (e.target.closest('#more')) { shown += 25; drawInit(); return; }
210
- if (e.target.closest('#fClear')) { F.chips.clear(); F.owners.clear(); F.lanes.clear(); F.q = ''; $('#bdQ').value = ''; drawChips(); drawFilter(); drawInit(); return; }
211
- if (e.target.closest('#stHelp')) { togglePop('popSteps', $('#stHelp')); return; }
212
- if (e.target.closest('#goneT')) { showGone = !showGone; drawInit(); const g = $('#goneT'); if (g) g.focus(); return; }
213
- const im = e.target.closest('[data-im]'); if (im) { const r = rowOf(im.dataset.im); if (r) openMenu(im, ctxOf(), r); return; }
262
+ if (e.target.closest('#fold')) { foldOpen = !foldOpen; drawInit(); const f = $('#fold'); if (f) f.focus(); return; }
263
+ if (e.target.closest('#fClear')) { clearFilters(); drawChips(); drawInit(); return; }
264
+ const op = e.target.closest('[data-open]'); if (op) { Acts.open[op.dataset.open](op); return; }
265
+ const st = e.target.closest('[data-steps]'); if (st) { togglePop('popSteps', st); return; }
266
+ const ru = e.target.closest('[data-rules]'); if (ru) { togglePop('popRules', ru); return; }
267
+ const go = e.target.closest('[data-span-go]'); if (go) { span = go.dataset.spanGo; store.set(SPAN_KEY, span); drawChips(); drawInit(); return; }
214
268
  const tk = e.target.closest('[data-tk]'); if (tk) { openTicket(tk.dataset.ini, tk.dataset.tk, tk); return; }
215
- const th = e.target.closest('[data-tgtheme]'); if (th) { span = 'year'; store.set(SPAN_KEY, span); drawInit(); return; }
216
- const b = e.target.closest('[data-key]'); if (b) openIni(rowOf(b.dataset.key), b);
269
+ const th = e.target.closest('[data-tgtheme]'); if (th) { span = 'year'; store.set(SPAN_KEY, span); drawChips(); drawInit(); return; }
270
+ if (e.target.closest('[data-act]')) return; // pm/bd-acts.js handles its own presses
271
+ const b = e.target.closest('[data-key]'); if (b) openIni(rowOf(b.dataset.key), b, view === 'time' ? 'time' : 'track');
217
272
  });
218
- /* Page / Popup (kept from the earlier Board, in the ⋯ menu): a row opens the initiative panel; the panel's expand icon opens the initiative page
219
- * (Page) or the record dialog (Popup). The choice is kept in this browser. */
220
- let openMode = store.get(MODE_KEY) === 'popup' ? 'popup' : 'page';
221
- function drawMode() { $$('#modeSeg button').forEach((b) => b.setAttribute('aria-pressed', b.dataset.m === openMode)); pillOf($('#modeSeg')); }
222
- $('#modeSeg').addEventListener('click', (e) => { const b = e.target.closest('[data-m]'); if (!b) return; openMode = b.dataset.m; store.set(MODE_KEY, openMode); drawMode(); toast('The panel\'s expand now opens the initiative as a ' + openMode + '.'); });
223
- const pageHref = (r) => '/premium-initiative.html?id=' + encodeURIComponent(r.id) + (M.board.ws ? '&ws=' + encodeURIComponent(M.board.ws) + '&board=' + encodeURIComponent(M.board.id) : '');
224
- function expandIni(r) { if (!r) return; if (openMode === 'popup' || !r.id) openRow(r); else location.assign(pageHref(r)); }
225
- const rowOf = (key) => (M && M.rows || []).find((r) => r.key === key) || null;
273
+ $('#ibBody').addEventListener('keydown', (e) => { if ((e.key === 'Enter' || e.key === ' ') && e.target.matches('[data-steps]')) { e.preventDefault(); togglePop('popSteps', e.target); } });
226
274
 
227
275
  /* ── "Ask about this": the Board has no chat; the question goes to Home as a quick ask in that initiative (B3) ───────────────── */
228
276
  function askHref(r, q) {
@@ -232,262 +280,291 @@ function askHref(r, q) {
232
280
  if (M.board.ws) p.set('ws', M.board.ws);
233
281
  return '/premium.html?' + p.toString();
234
282
  }
283
+ const pageHref = (r) => '/premium-initiative.html?id=' + encodeURIComponent(r.id) + (M.board.ws ? '&ws=' + encodeURIComponent(M.board.ws) + '&board=' + encodeURIComponent(M.board.id) : '');
235
284
 
236
- /* ── the initiative panel and the Jira ticket panel (AgBoardPanel, AgBoardTicket; a bottom sheet on a phone) ───────────────── */
285
+ /* ── the side panel: the initiative (AgBoardPanel), the Jira ticket (AgBoardTicket) and the initiative from the timeline (AgBoardTimelinePanel) ── */
237
286
  let peekBack = null;
238
287
  function ladderHtml(t) {
239
- const k = t ? t.k : -1;
240
- return `<div class="pk-lad" role="img" aria-label="${esc(k >= 0 ? 'Step ' + (k + 1) + ' of 8: ' + t.label : 'No step on record')}"><i class="ln"></i><i class="lp" style="width:${k > 0 ? (k / 7) * 87.5 : 0}%"></i>${M.steps.map((s, j) => `<span class="${[j < k ? 'p' : '', j === k ? 'c' : '', s.ms ? 'm' : ''].filter(Boolean).join(' ')}"><i></i>${esc(s.short)}</span>`).join('')}</div>`;
288
+ const k = t ? t.k : -1, sk = new Set((t && t.skipped) || []);
289
+ return `<div class="pk-lad" role="img" aria-label="${esc(k >= 0 ? 'Step ' + (k + 1) + ' of 8: ' + t.label : 'No step on record')}"><i class="ln"></i><i class="lp" style="width:${k > 0 ? (k / 7) * 87.5 : 0}%"></i>${M.steps.map((s, j) => `<span class="${[j < k ? 'p' : '', j === k ? 'c' : '', s.ms ? 'm' : '', sk.has(j) ? 'k' : ''].filter(Boolean).join(' ')}"><i></i>${esc(s.short)}</span>`).join('')}</div>`;
241
290
  }
242
- function askForm(r, label) {
291
+ function askForm(r, label, o = {}) {
243
292
  const J = M.jira || {};
244
- return `<form class="pk-ask" data-ask="${esc(r.key)}"><div class="in"><input type="text" name="q" maxlength="2000" autocomplete="off" placeholder="Ask about ${esc(label)}…" aria-label="Ask about ${esc(label)}"><button type="submit" class="cz-ib solid" aria-label="Ask in Home" title="Ask in Home">${SV('M5 12h14M13 6l6 6-6 6')}</button></div><div class="ft"><span>Answer lands in Home</span><span class="sp"></span><span>${SV('M12 3l9 9-9 9-9-9z')}Jira ${J.readAt ? esc(ago(J.readAt)) : 'not read'}</span></div></form>`;
293
+ const ft = o.inside ? `<span>The answer lands in Home, inside ${esc(r.title)}.</span>`
294
+ : `<span>Answer lands in Home</span><span class="sp"></span><span class="jr">${SV(I.jira)}Jira ${J.readAt ? esc(ago(J.readAt)) : 'not read'}</span><button type="button" class="bd-ib sm" data-pk="jira" aria-label="Read Jira again" title="Read Jira again">${SV(I.refresh)}</button>`;
295
+ return `<form class="pk-ask" data-ask="${esc(r.key)}"><div class="in"><input type="text" name="q" maxlength="2000" autocomplete="off" placeholder="Ask about ${esc(label)}…" aria-label="Ask about ${esc(label)}"><button type="submit" class="bd-ib solid" aria-label="Ask in Home" title="Ask in Home">${SV(I.go)}</button></div><div class="ft">${ft}</div></form>`;
296
+ }
297
+ const eyeOf = (r, lower) => [r.lane ? (lower ? r.lane : r.lane.charAt(0).toUpperCase() + r.lane.slice(1)) : '', r.kr, ...(lower ? [] : [r.owner ? 'owner ' + r.owner : 'no owner'])].filter(Boolean);
298
+ const tkState = (k) => (k.blocked ? 'blocked' + (k.reason ? ' by ' + k.reason.replace(/^Waiting on /i, '') : '') : k.status === 'In review' ? 'in review' : k.status === 'In progress' ? 'in progress' : k.status === 'Done' ? 'done' : 'to do');
299
+ /** The output box: the open tickets (blocked first) with their state and assignee, the done ones folded into one line, and Deliver's two
300
+ * parts that are not tickets; for the other steps, the parts of the output, each counted only where a record holds it. */
301
+ function outRows(r) {
302
+ const t = r.track || {};
303
+ if (t.tickets && t.tickets.length && (t.key === 'build' || t.key === 'deliver')) {
304
+ const open = t.tickets.filter((k) => k.status !== 'Done').sort((a, b) => (b.blocked ? 1 : 0) - (a.blocked ? 1 : 0)), done = t.tickets.filter((k) => k.status === 'Done');
305
+ const rows = open.slice(0, 10).map((k) => `<button type="button" class="gi" data-tk="${esc(k.key)}" data-ini="${esc(r.key)}"><i class="k ${esc(k.cls || 'td')}"></i><span class="n"><em>${esc(k.key)}</em>${esc(k.title)} · ${esc(tkState(k))}</span>${k.assignee || k.age != null ? `<span class="r">${esc([k.assignee, k.age != null ? k.age + 'd' : ''].filter(Boolean).join(' · '))}</span>` : ''}</button>`);
306
+ if (open.length > 10) rows.push(`<p class="gi gm"><i class="k"></i><span class="n">${open.length - 10} more open tickets</span></p>`);
307
+ if (done.length) rows.push(`<p class="gi gm"><i class="k dn"></i><span class="n">${done.length} ${plural(done.length, 'ticket', 'tickets')} done · ${esc(done.slice(0, 3).map((k) => k.title.toLowerCase()).join(', '))}${done.length > 3 ? ', …' : ''}</span></p>`);
308
+ if (t.key === 'deliver') rows.push('<p class="gi gm"><i class="k"></i><span class="n">Release notes</span><span class="r">not on record</span></p>', `<p class="gi gm"><i class="k${t.you ? ' yo' : ''}"></i><span class="n">Your sign-off</span><span class="r">${t.you ? 'waiting' : 'after the tickets'}</span></p>`);
309
+ return rows.join('');
310
+ }
311
+ if (t.key === 'build' || t.key === 'deliver') return '<p class="gi gm"><i class="k na"></i><span class="n">No Jira ticket has been read for it yet</span></p>';
312
+ return (t.segs || []).map((s) => `<p class="gi gm"><i class="k ${esc(s.cls || '')}"></i><span class="n">${esc(s.name || '')}</span><span class="r">${esc(s.st || '')}</span></p>`).join('');
313
+ }
314
+ const TI = (r) => (r && r.trail) || null;
315
+ /** The skipped steps, each with its reason: the lane's own ladder or the board move's why (lib/board-trail.js). */
316
+ function skipHtml(t) {
317
+ const sk = (t.skipped || []).map((j) => M.steps[j]).filter(Boolean);
318
+ if (!sk.length) return '';
319
+ const why = sk.map((s) => { const w = (t.skipWhy || []).find((x) => x.stage === s.key); return w && w.why ? s.label + ' skipped. ' + w.why : null; });
320
+ if (why.every(Boolean)) return `<p class="pk-skip">${esc(why.join(' '))}</p>`;
321
+ return `<p class="pk-skip">${esc(sk.map((s) => s.label).join(', '))} skipped: it was moved past ${sk.length === 1 ? 'that step' : 'those steps'}. No reason is on record.</p>`;
322
+ }
323
+ /** What waits on you: the release sign-off (the model), else the trail's next action (the Commit of drafted tickets, a PRD change, the verdict). */
324
+ function nextHtml(r) {
325
+ const t = r.track || {};
326
+ if (t.you && t.youKind) {
327
+ const go = t.youKind === 'drift' && TI(r) && TI(r).links.prd ? `<button type="button" class="bd-ib solid" data-doc="${esc(TI(r).links.prd)}" aria-label="Open the PRD" title="Open the PRD">${SV(I.next)}</button>`
328
+ : r.id ? `<a class="bd-ib solid" href="${esc(pageHref(r))}" aria-label="${esc(t.you)}: open the initiative page" title="Open the initiative page">${SV(I.next)}</a>` : '';
329
+ return `<div class="pk-nb"><div class="t"><b>${esc(t.you)}</b><div>${esc(t.youWhy || '')}</div></div>${go}</div>`;
330
+ }
331
+ if (t.you) return `<div class="pk-nb"><div class="t"><b>Sign off ${esc(r.release ? r.release.name : t.output)}</b><div>Every release ticket is done. Release notes are not on record in PMOS.</div></div>${r.id ? `<a class="bd-ib solid" href="${esc(pageHref(r))}" aria-label="Review the release" title="Review the release">${SV(I.next)}</a>` : ''}</div>`;
332
+ return ''; // nothing waits on you: AgBoardPanel draws the card only when something does
333
+ }
334
+ /** Tickets drafted in PMOS and not yet in Jira: they go to Jira only through your Commit. */
335
+ function draftedHtml(r) {
336
+ const it = TI(r); if (!it) return '';
337
+ const d = (it.drafted || []).filter((x) => !x.key); if (!d.length) return '';
338
+ const g = it.gate || {};
339
+ return `<div class="pk-sec"><p class="lbl">Drafted in PMOS · ${d.length}</p><div class="pk-tks">${d.slice(0, 8).map((x) => `<p class="gi gm"><i class="k${x.waiting ? ' yo' : ''}"></i><span class="n">${x.id ? `<em>${esc(x.id)}</em>` : ''}${esc(x.summary || '')}</span><span class="r">not in Jira</span></p>`).join('')}${d.length > 8 ? `<p class="gi gm"><i class="k"></i><span class="n">${d.length - 8} more drafted</span></p>` : ''}</div><p class="pk-mut">They go to Jira only through your Commit${g.open === false && g.why ? '. The Commit is closed: ' + esc(g.why) : ''}.</p></div>`;
340
+ }
341
+ /** The PRD against what was pushed: tickets whose text came from a PRD that changed after the push. AgBoardPanel and AgBoardTicket draw only the
342
+ * amber card, so nothing shows when Jira and the PRD agree (or nothing is pushed yet). Its button puts a question about the change in the ask box. */
343
+ function driftHtml(r, one) {
344
+ const it = TI(r);
345
+ const keys = ((it && it.drift) || []).filter((k) => !one || k === one);
346
+ if (!keys.length) return '';
347
+ const q = 'What changed in the PRD after ' + keys.join(', ') + ' ' + (keys.length === 1 ? 'was' : 'were') + ' pushed?';
348
+ const btn = `<button type="button" class="bd-ib sm" data-pk="drift" data-q="${esc(q)}" aria-label="Ask about the PRD change" title="Ask about the PRD change">${SV(one ? I.spark : I.note)}</button>`;
349
+ return one
350
+ ? `<div class="pk-wt">${SV(I.flag)}<span><b>The PRD changed after the push.</b> ${esc(keys[0])} was pushed from an older PRD. Review it before the next push.</span>${btn}</div>`
351
+ : `<div class="pk-wt">${SV(I.flag)}<span><b>Jira differs from the PRD</b> · ${esc(keys.join(', '))} ${keys.length === 1 ? 'was' : 'were'} pushed from an older PRD. Review ${keys.length === 1 ? 'it' : 'them'} before the next push.</span>${btn}</div>`;
352
+ }
353
+ const DEP_ST = (d) => (!d.known ? 'not on this repository' : d.done ? 'done' : d.stage || 'open');
354
+ function linkedHtml(r) {
355
+ const it = TI(r), L = (it && it.links) || {}, epic = L.epic || (r.epics || [])[0];
356
+ // AgBoardPanel: PRD v3 · Rubric · Release notes · Blocks <initiative> · Epic <key>. A chip shows only where something is linked.
357
+ const doc = (label, path) => (path ? `<button type="button" class="bd-chip" data-doc="${esc(path)}" title="${esc(path)}">${SV(I.doc)}${esc(label)}</button>` : '');
358
+ const D = (it && it.deps) || [];
359
+ const chips = doc(L.prdVersion ? 'PRD v' + String(L.prdVersion).replace(/^v/i, '') : 'PRD', L.prd) + doc('Rubric', L.rubric) + doc('Evaluation', L.evaluation) + doc('Release notes', L.notes)
360
+ + D.map((d) => `<span class="bd-chip" title="${esc((d.title || d.id) + ': ' + DEP_ST(d))}">${SV(I.link)}${esc('Waits on ' + (d.title || d.id))}</span>`).join('')
361
+ + (epic ? `<span class="bd-chip">${SV(I.jira)}${esc('Epic ' + epic)}</span>` : '');
362
+ return chips ? `<div class="pk-sec"><p class="lbl">Linked</p><div class="pk-lk">${chips}</div></div>` : '';
245
363
  }
246
364
  function iniPanel(r) {
247
- const t = r.track || {}, s = statusOf(r), p = t.prog;
248
- const eye = [r.lane ? r.lane.charAt(0).toUpperCase() + r.lane.slice(1) : '', r.anchor, r.owner ? 'owner ' + r.owner : 'no owner'].filter(Boolean).join(' · ');
249
- const tks = (t.tickets || []).slice(0, 12).map((k) => `<button type="button" class="gi" data-tk="${esc(k.key)}" data-ini="${esc(r.key)}"><i class="k ${esc(k.cls || 'td')}"></i><span class="n"><em>${esc(k.key)}</em>${esc(k.title)}${k.blocked ? ' · blocked' : ''}</span><span class="r">${esc(k.status)}</span></button>`).join('');
250
- const more = (t.tickets || []).length > 12 ? `<p class="pk-mut">${t.tickets.length - 12} more tickets</p>` : '';
251
- const dates = [['PMOS plan', r.start || r.end ? [r.start ? fmt(r.start) : '…', r.end ? fmt(r.end) : '…'].join(' → ') : 'No dates on record'], ['Jira forecast', t.forecastLabel ? t.forecastLabel + ' (the latest sprint with an open ticket)' : 'No open ticket in a dated sprint']];
252
- return `<div class="pk-h"><div class="pk-ht"><p class="pk-eye">${esc(eye)}</p><h2 id="pkTitle">${esc(r.title)}</h2><p class="pk-st"><span class="cs s-${s.tone}"><i class="cz-dot ${s.tone} ${s.mo}"></i>${esc(s.text)}</span><span>·</span><span>${t.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(t.label || r.stage || 'No stage')}</span>${r.end ? `<span>·</span><span>ends <b>${esc(r.finish)}</b></span>` : ''}</p></div>`
253
- + `<div class="pk-tools"><button type="button" class="cz-ib" data-pk="expand" aria-label="${openMode === 'popup' ? 'Open the record' : 'Open the initiative page'}" title="${openMode === 'popup' ? 'Open the record' : 'Open the initiative page'}">${SV('M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7')}</button>${r.acts ? dotsBtn(r).replace('class="inim"', 'class="inim cz-ib"') : ''}<button type="button" class="cz-ib" data-pk="close" aria-label="Close" title="Close">${SV('M6 6l12 12M18 6L6 18')}</button></div></div>`
254
- + `<div class="pk-b">${ladderHtml(t)}`
255
- + `<div class="pk-box"><div class="t1"><b>${esc(t.output || 'No step on record')}</b><span>${esc(progText(p))}</span></div>${segHtml(r, true)}${tks ? `<div class="pk-tks">${tks}</div>${more}` : `<p class="pk-mut">${p && p.unit === '%' ? 'Progress comes from the initiative record.' : t.key === 'build' || t.key === 'deliver' ? 'No Jira ticket of this initiative has been read yet.' : 'Nothing is counted toward it yet.'}</p>`}</div>`
256
- + (t.next && t.next.tone === 'red' ? `<div class="pk-warn red">${SV('M12 4v10M12 18v2')}<span>${esc(t.next.text)}</span></div>` : '')
257
- + `<div class="pk-sec"><p class="lbl">Dates</p><div class="pk-kv">${dates.map(([a, b]) => `<span>${esc(a)}</span><b>${esc(b)}</b>`).join('')}</div></div>`
258
- + `<div class="pk-sec"><p class="lbl">Linked</p><div class="pk-lk"><button type="button" class="cz-chip" data-pk="record">${SV('M6 3h9l4 4v14H6zM14 3v5h5')}Record</button>${r.id ? `<a class="cz-chip" href="${esc(pageHref(r))}">${SV('M14 4h6v6M20 4l-7 7M10 6H5v13h13v-5')}Initiative page</a>` : ''}${r.id ? `<button type="button" class="cz-chip" data-pk="item">${SV('M4 6h16M4 12h16M4 18h10')}Checks and tasks</button>` : ''}</div></div>`
365
+ const t = r.track || {}, s0 = statusOf(r);
366
+ const s = r.release && /^Ships /.test(s0.text) ? { ...s0, text: 'On track' } : s0; // the line already says when it ships
367
+ const when = r.release ? `<span>·</span><span>ships <b>${esc(fmt(r.release.iso))}</b> with ${esc(r.release.name)}</span>` : r.end ? `<span>·</span><span>plan ends <b>${esc(fmt(r.end))}</b></span>` : '';
368
+ // the status line is one line, as AgBoardPanel draws it; "usually N days" stays in the step's tooltip
369
+ return `<div class="pk-h"><div class="pk-ht"><p class="pk-eye">${esc(eyeOf(r).join(' · '))}</p><h2 id="pkTitle">${esc(r.title)}</h2><p class="pk-st"><span class="cs s-${s.tone}"><i class="cz-dot ${s.tone} ${s.mo}"></i>${esc(s.text)}</span><span>·</span><span title="${esc(dayTitle(t))}">${t.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}<b>${esc(t.label || r.stage || 'No stage')}</b>${t.days != null ? ' day ' + t.days : ''}</span>${when}</p></div>`
370
+ + `<div class="pk-tools">${r.id ? `<a class="bd-ib" data-pk="expand" href="${esc(pageHref(r))}" aria-label="Open the initiative page" title="Open the initiative page">${SV(I.expand)}</a>` : ''}<button type="button" class="bd-ib" data-pk="acts" aria-label="Initiative actions" title="Initiative actions">${SV(I.more)}</button><button type="button" class="bd-ib" data-pk="close" aria-label="Close" title="Close">${SV(I.x)}</button></div></div>`
371
+ + `<div class="pk-b">${ladderHtml(t)}${skipHtml(t)}`
372
+ + nextHtml(r)
373
+ + `<div class="pk-box"><div class="t1"><b>${esc(t.output || 'No step on record')}</b><span>${esc(t.count || '')}</span></div>${segHtml(r, true)}<div class="pk-tks">${outRows(r)}</div>${typeof t.next === 'string' && t.next && !(t.tickets || []).length ? `<p class="pk-nx">Next: <b>${esc(t.next)}</b></p>` : ''}</div>`
374
+ + draftedHtml(r) + driftHtml(r) + linkedHtml(r) // the dependencies are Linked chips, as AgBoardPanel draws them
259
375
  + `</div>${askForm(r, r.title)}`;
260
376
  }
261
- const fmt = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? +m[3] + ' ' + ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][+m[2] - 1] : ''; };
377
+ function timePanel(r) {
378
+ const t = r.track || {}, k = t.k, epic = (r.epics || [])[0];
379
+ const eye = eyeOf(r, true).concat(epic ? ['epic ' + epic] : ['no Jira epic yet']);
380
+ const lad = `<div class="pk-seg" aria-hidden="true">${M.steps.map((_, j) => `<i class="${j < k ? 'p' : j === k ? 'c' : ''}"></i>`).join('')}</div>`;
381
+ const need = t.you
382
+ ? `<div class="pk-need"><i class="cz-dot you m-info"></i><div class="t"><b>${esc(t.you)}</b><div>${esc(t.youKind ? t.youWhy || '' : 'Every release ticket is done.')}</div></div>${r.id ? `<a class="bd-ib" href="${esc(pageHref(r))}" aria-label="Open the initiative page" title="Open the initiative page">${SV(I.ext)}</a>` : ''}</div>`
383
+ : ''; // AgBoardTimelinePanel draws the card only when something waits on you
384
+ const tks = (t.tickets || []).slice(0, 8).map((x) => `<button type="button" class="wi" data-tk="${esc(x.key)}" data-ini="${esc(r.key)}"><span class="wk">${esc(x.key)}</span><span class="wt2">${esc(x.title)}</span><span class="st${x.blocked ? ' r' : x.status === 'Done' ? '' : ' y'}">${esc(x.blocked ? 'Blocked' : x.status)}</span></button>`).join('');
385
+ // AgBoardTimelinePanel: change the plan dates, move, hold, archive. Dates go through Home (no route writes plan dates from the Board).
386
+ const acts = `<a class="bd-ib" href="${esc(askHref(r, 'Propose new start and end dates for ' + r.title))}" aria-label="Change the plan dates" title="Change the plan dates">${SV(I.cal)}</a>`
387
+ + [['move', 'Move to another stage'], ['hold', 'Put on hold'], ['archive', 'Archive']].map(([i, n]) => `<button type="button" class="bd-ib" data-pk="acts" aria-label="${n}" title="${n}">${SV(I[i])}</button>`).join('');
388
+ const D = (TI(r) && TI(r).deps) || [], open = D.filter((d) => d.known && !d.done);
389
+ const dep = D.length ? `<div class="pk-dep">${SV(I.link)}<div><b>Waits on ${esc(D.map((d) => d.title || d.id).join(', '))}</b><div>${esc(D.map((d) => (d.title || d.id) + ': ' + DEP_ST(d)).join(' · '))}.${open.length ? ' Its own dates hold only once ' + (open.length === 1 ? 'that one is' : 'those are') + ' done.' : ''}</div></div></div>`
390
+ : ''; // no card when nothing is on record
391
+ return `<div class="pk-h"><div class="pk-ht"><p class="pk-eye">${esc(eye.join(' · '))}</p><h2 id="pkTitle">${esc(r.title)}</h2></div><div class="pk-tools">${r.id ? `<a class="bd-ib" data-pk="expand" href="${esc(pageHref(r))}" aria-label="Open the initiative page" title="Open the initiative page">${SV(I.ext)}</a>` : ''}<button type="button" class="bd-ib" data-pk="close" aria-label="Close" title="Close">${SV(I.x)}</button></div></div>`
392
+ + `<div class="pk-b"><div><p class="pk-stp"><b>${esc(t.label || 'No step')}</b>${k >= 0 ? ' · step ' + (k + 1) + ' of 8' : ''}</p>${lad}</div>${need}`
393
+ + `<div class="pk-sec"><p class="lbl">Dates</p><div class="pk-kv"><span>PMOS plan</span><b>${esc(r.start || r.end ? [r.start ? fmt(r.start) : '…', r.end ? fmt(r.end) : '…'].join(' → ') : 'No dates on record')}</b><span>Jira forecast</span><b>${esc(t.forecastLabel ? fmt(t.forecast) : 'No open ticket in a dated sprint')}</b></div></div>`
394
+ + dep
395
+ + `<div class="pk-sec"><p class="lbl">Tickets · ${(t.tickets || []).length} in Jira</p>${tks ? `<div class="pk-wis">${tks}</div>` : '<p class="pk-mut">No ticket of this initiative is in a Jira reading.</p>'}</div>`
396
+ + `<div class="pk-sec"><p class="lbl">Initiative</p><div class="pk-acts">${acts}</div></div></div>${askForm(r, r.title, { inside: true })}`;
397
+ }
398
+ /** The blocker's own summary, where its key (in the reason) is a ticket of a row on this board. */
399
+ function blockerTitle(reason) {
400
+ const m = /\b([A-Z][A-Z0-9]+-\d+)\b/.exec(String(reason || '')); if (!m) return '';
401
+ for (const r of (M && M.rows) || []) { const x = ((r.track && r.track.tickets) || []).find((y) => y.key === m[1]); if (x && x.title && x.title !== x.key) return x.title; }
402
+ return '';
403
+ }
262
404
  function tkPanel(r, k) {
263
- const t = r.track || {}, J = M.jira || {};
264
- const meta = [k.blocked ? '<span class="cs s-red"><i class="cz-dot red m-crit"></i>Blocked</span>' : '', k.blocked && /block/i.test(k.raw || '') ? '' : esc(k.raw || k.status), k.assignee ? `<span class="pk-av" aria-hidden="true">${esc(k.assignee.charAt(0))}</span>${esc(k.assignee)}` : 'No assignee in the Jira reading', k.points != null ? esc(k.points + ' pts') : '', k.sprint ? esc(k.sprint) : ''].filter(Boolean).join('<span>·</span>');
265
- return `<div class="pk-h"><div class="pk-ht"><button type="button" class="pk-back" data-pk="back">${SV('M14 6l-6 6 6 6')}${esc(r.title)} · ${esc(t.label || '')}</button><h2 id="pkTitle">${esc(k.key)} · ${esc(k.title)}</h2><p class="pk-st">${meta}</p></div>`
266
- + `<div class="pk-tools">${k.url ? `<a class="cz-ib" href="${esc(k.url)}" target="_blank" rel="noopener" aria-label="Open ${esc(k.key)} in Jira" title="Open in Jira">${SV('M14 4h6v6M20 4l-9 9M10 6H5v13h13v-5')}</a>` : ''}<button type="button" class="cz-ib" data-pk="close" aria-label="Close" title="Close">${SV('M6 6l12 12M18 6L6 18')}</button></div></div>`
267
- + `<div class="pk-b">${k.blocked ? `<div class="pk-warn red"><span><b>Blocked in Jira.</b> ${esc(k.reason || 'Jira flags it.')}</span></div>` : ''}`
268
- + `<div class="pk-sec"><p class="lbl">Counts toward</p><p class="pk-p">${esc(t.output || '')} · ${esc(progText(t.prog))}</p></div>`
269
- + `<div class="pk-sec"><p class="lbl">In Jira</p><div class="pk-kv"><span>Status</span><b>${esc(k.raw || k.status)}</b><span>Assignee</span><b>${esc(k.assignee || 'Not in the reading')}</b><span>Sprint</span><b>${esc(k.sprint || 'None')}</b><span>Read</span><b>${esc(J.readAt ? ago(J.readAt) : 'Not read')}</b></div></div>`
405
+ const t = r.track || {}, x = TI(r) && TI(r).tickets ? TI(r).tickets[k.key] : null, sub = x && x.subtasks;
406
+ // what a blocker delays: the sprint it sits in ends, and the release the initiative rides on
407
+ const slip = k.sprintEnd ? 'If it is not fixed by ' + fmt(k.sprintEnd) + ', the end of ' + (k.sprint || 'its sprint') + ', ' + (r.release ? r.release.name + ' on ' + fmt(r.release.iso) + ' slips.' : 'it carries into the next sprint.') : r.release ? 'It holds up ' + r.release.name + ' on ' + fmt(r.release.iso) + '.' : '';
408
+ // AgBoardTicket: Blocked 2 days · In review · (M) Mei · 5 pts · Sprint 24, each field only where the Jira reading holds it
409
+ const bd = k.blockedDays != null ? ' ' + k.blockedDays + ' ' + plural(k.blockedDays, 'day', 'days') : '';
410
+ const meta = [k.blocked ? `<span class="cs s-red"><i class="cz-dot red m-crit"></i>Blocked${esc(bd)}</span>` : '', esc(k.raw && !(k.blocked && /block/i.test(k.raw)) ? k.raw : k.blocked ? '' : k.status), k.assignee ? `<span class="pk-who"><span class="pk-av" aria-hidden="true">${esc(k.assignee.charAt(0))}</span>${esc(k.assignee)}</span>` : '', k.points != null ? esc(k.points + ' pts') : '', k.sprint ? esc(k.sprint) : ''].filter(Boolean).join('<span>·</span>');
411
+ const reason = k.reason || (x && x.reason) || 'Flagged as blocked in Jira', bt = blockerTitle(reason);
412
+ // the subtasks: one row each where the reading lists them; else the reading's two counts as rows (done, open)
413
+ const items = sub && Array.isArray(sub.items) ? sub.items : null;
414
+ const subRows = items && items.length ? items.map((y) => `<p class="gi gm"><i class="k${y.done ? ' dn' : ''}"></i><span class="n">${esc(y.name || y.summary || '')}</span><span class="r">${y.done ? 'done' : 'open'}</span></p>`).join('')
415
+ : sub && sub.total ? [[sub.done, 'done', ' dn'], [sub.total - sub.done, 'open', '']].filter(([n]) => n > 0).map(([n, w, c]) => `<p class="gi gm"><i class="k${c}"></i><span class="n">${n} ${plural(n, 'subtask', 'subtasks')}</span><span class="r">${w}</span></p>`).join('')
416
+ : '<p class="gi gm"><i class="k"></i><span class="n">No subtasks are in the Jira reading</span></p>';
417
+ return `<div class="pk-h"><div class="pk-ht"><button type="button" class="pk-back" data-pk="back">${SV(I.next)}${esc(r.title)} · ${esc(t.label || '')}</button><h2 id="pkTitle">${esc(k.key)} · ${esc(k.title)}</h2><p class="pk-st">${meta}</p></div>`
418
+ + `<div class="pk-tools">${k.url ? `<a class="bd-ib" href="${esc(k.url)}" target="_blank" rel="noopener" aria-label="Open ${esc(k.key)} in Jira" title="Open in Jira">${SV(I.ext)}</a>` : ''}<button type="button" class="bd-ib" data-pk="close" aria-label="Close" title="Close">${SV(I.x)}</button></div></div>`
419
+ + `<div class="pk-b">${k.blocked ? `<div class="pk-nb red"><div class="t"><b>${esc(reason)}</b>${bt ? `<span class="pk-bt"> · ${esc(bt)}</span>` : ''}${slip ? `<div>${esc(slip)}</div>` : ''}</div>${k.url ? `<a class="bd-ib" href="${esc(k.url)}" target="_blank" rel="noopener" aria-label="Comment in Jira" title="Comment in Jira">${SV(I.note)}</a>` : ''}</div>` : ''}`
420
+ + driftHtml(r, k.key)
421
+ + `<div class="pk-box"><div class="t1"><b>Subtasks</b><span>${sub && sub.total ? sub.done + ' of ' + sub.total : ''}</span></div><div class="pk-tks">${subRows}</div></div>`
422
+ + `<div class="pk-sec"><p class="lbl">Counts toward</p><p class="pk-p">${esc(t.output || '')} · ${esc(t.count || '')}</p></div>`
270
423
  + '<p class="pk-mut">PMOS owns the ticket text. Status, sprint and assignee change only in Jira.</p></div>'
271
424
  + askForm(r, k.key);
272
425
  }
273
426
  function showPeek(html, back) {
274
427
  const pk = $('#peek'); pk.innerHTML = html; pk.hidden = false; document.body.classList.add('pk-on');
275
- if (back) peekBack = back;
276
- $$('#ibBody .bt-l').forEach((x) => x.classList.toggle('sel', !!peek && x.dataset.row === peek.key));
428
+ pk.classList.toggle('pk-tl', !!peek && peek.kind === 'ini' && peek.from === 'time'); // AgBoardTimelinePanel is 420 px wide
429
+ if (back && !$('#peek').contains(back)) peekBack = back; // a press inside the panel keeps the row the panel was opened from
430
+ $$('#ibBody [data-row]').forEach((x) => x.classList.toggle('sel', !!peek && peek.kind !== 'acts' && x.dataset.row === peek.key));
431
+ $$('#ibBody .tgp-r').forEach((x) => x.classList.toggle('sel', !!peek && peek.kind !== 'acts' && x.dataset.key === peek.key));
277
432
  const h = $('#pkTitle'); if (h) { h.tabIndex = -1; h.focus({ preventScroll: true }); }
278
433
  }
279
434
  function closePeek() {
280
435
  if ($('#peek').hidden) return;
281
436
  const key = peek && peek.key;
282
- $('#peek').hidden = true; document.body.classList.remove('pk-on'); peek = null; closeMenu();
283
- $$('#ibBody .bt-l.sel').forEach((x) => x.classList.remove('sel'));
437
+ $('#peek').hidden = true; document.body.classList.remove('pk-on'); peek = null;
438
+ $$('#ibBody .sel').forEach((x) => x.classList.remove('sel'));
284
439
  // a read can draw the rows again while the panel is open: then the focus goes to the same row as drawn now
285
440
  const back = peekBack && document.contains(peekBack) ? peekBack : key ? $$('#ibBody [data-key]').find((x) => x.dataset.key === key) : null;
286
441
  if (back) back.focus(); peekBack = null;
287
442
  }
288
- function openIni(r, from) {
289
- if (!r) return;
290
- if (!r.track) { openRow(r); return; } // a sprint or release row of the dialog
291
- peek = { kind: 'ini', key: r.key }; showPeek(iniPanel(r), from);
443
+ function openIni(r, from, where) {
444
+ if (!r || !r.track) return;
445
+ peek = { kind: 'ini', key: r.key, from: where || 'track' }; showPeek(peek.from === 'time' ? timePanel(r) : iniPanel(r), from);
292
446
  }
293
447
  function openTicket(iniKey, key, from) {
294
448
  const r = rowOf(iniKey); if (!r || !r.track) return;
295
449
  const k = (r.track.tickets || []).find((x) => x.key === key); if (!k) return;
296
- peek = { kind: 'tk', key: r.key, tk: key }; showPeek(tkPanel(r, k), from);
450
+ peek = { kind: 'tk', key: r.key, tk: key, from: peek && peek.from }; showPeek(tkPanel(r, k), from);
297
451
  }
298
452
  $('#peek').addEventListener('click', (e) => {
299
453
  const r = peek && rowOf(peek.key);
300
- const im = e.target.closest('[data-im]'); if (im && r) { openMenu(im, ctxOf(), r); return; }
301
454
  const tk = e.target.closest('[data-tk]'); if (tk) { openTicket(tk.dataset.ini, tk.dataset.tk); return; }
302
455
  const b = e.target.closest('[data-pk]'); if (!b) return;
303
456
  const a = b.dataset.pk;
304
457
  if (a === 'close') closePeek();
305
- else if (a === 'back' && r) { peek = { kind: 'ini', key: r.key }; showPeek(iniPanel(r)); }
306
- else if (a === 'expand' && r) expandIni(r);
307
- else if (a === 'record' && r) openRow(r);
308
- else if (a === 'item' && r) openWorkItem({ kind: 'initiative', id: r.id, title: r.title, ws: M.board.ws, board: M.board.id });
458
+ else if (a === 'back' && r) { peek = { kind: 'ini', key: r.key, from: peek.from }; showPeek(peek.from === 'time' ? timePanel(r) : iniPanel(r)); }
459
+ else if (a === 'jira') refreshJira(b);
460
+ else if (a === 'drift') { const q = $('#peek form.pk-ask input[name="q"]'); if (q) { q.value = b.dataset.q || ''; q.focus(); } }
461
+ else if (a === 'acts' && r) Acts.open.row(r, b);
462
+ });
463
+ /** A linked document opens in the Viewer: GET /api/doc, shown as its text. */
464
+ document.addEventListener('click', (e) => {
465
+ const d = e.target.closest('[data-doc]'); if (!d || !M) return;
466
+ const path = d.dataset.doc, ws = M.board.ws || '';
467
+ viewerOpen({ kind: 'Document', title: path.split('/').pop(), icon: 'doc', id: 'doc:' + path, render: async (body) => {
468
+ body.innerHTML = '<p class="bd-amut">Reading the document…</p>';
469
+ let text = null; try { const res = await fetch('/api/doc?ws=' + encodeURIComponent(ws) + '&path=' + encodeURIComponent(path), { credentials: 'same-origin' }); text = res.ok ? await res.text() : null; } catch { text = null; }
470
+ body.innerHTML = text == null ? `<p class="bd-amut">${esc(path)} could not be read.</p>` : `<p class="bd-amut">${esc(path)}</p><pre class="bd-doc">${esc(text)}</pre>`;
471
+ } });
309
472
  });
310
473
  $('#peek').addEventListener('submit', (e) => {
311
- const f = e.target.closest('[data-ask]'); if (!f) return;
474
+ const f = e.target.closest('form.pk-ask[data-ask]'); if (!f) return;
312
475
  e.preventDefault();
313
476
  const r = rowOf(f.dataset.ask), q = f.q.value.trim();
314
477
  if (!q) { f.q.focus(); return; }
315
478
  location.assign(askHref(r, peek && peek.kind === 'tk' ? peek.tk + ': ' + q : q));
316
479
  });
317
480
 
318
- /* ── Find and Filter ───────────────────────────────────────────────────────────────────────────────────────────── */
319
- $('#bdFind').addEventListener('click', () => { const row = $('#bdFindRow'), open = row.hidden; row.hidden = !open; $('#bdFind').setAttribute('aria-expanded', String(open)); if (open) $('#bdQ').focus(); else if (F.q) { F.q = ''; $('#bdQ').value = ''; drawInit(); } });
320
- $('#bdQ').addEventListener('input', () => { F.q = $('#bdQ').value; shown = 25; if (M) drawInit(); });
321
- $('#bdQ').addEventListener('keydown', (e) => { if (e.key === 'Escape' && $('#bdQ').value) { e.stopPropagation(); $('#bdQ').value = ''; F.q = ''; drawInit(); } });
322
- function drawFilter() {
323
- if (!M) return;
324
- const rows = M.initiatives.list.rows, owners = [...new Set(rows.map((r) => r.owner || ''))].sort(), lanes = [...new Set(rows.map((r) => r.lane || ''))].filter(Boolean).sort();
325
- const chip = (kind, v, label, on) => `<button type="button" class="cz-chip${on ? ' on' : ''}" data-fk="${kind}" data-fv="${esc(v)}" aria-pressed="${on}">${esc(label)}</button>`;
326
- $('#popFilter').innerHTML = `<div class="bd-fl"><p class="lbl">Owner</p><div class="pk-lk">${owners.map((o) => chip('o', o, o || 'No owner', F.owners.has(o))).join('')}</div><p class="lbl">Lane</p><div class="pk-lk">${lanes.map((l) => chip('l', l, l.charAt(0).toUpperCase() + l.slice(1), F.lanes.has(l))).join('')}</div>${F.owners.size || F.lanes.size ? '<button type="button" class="dlink" data-fk="clear">Clear owner and lane</button>' : ''}</div>`;
327
- const d = $('#bdFilter .bd-fdot'); if (d) d.hidden = !(F.owners.size || F.lanes.size);
328
- }
329
- $('#bdFilter').addEventListener('click', (e) => { e.stopPropagation(); drawFilter(); togglePop('popFilter', $('#bdFilter')); });
330
- $('#popFilter').addEventListener('click', (e) => {
331
- const b = e.target.closest('[data-fk]'); if (!b) return;
332
- if (b.dataset.fk === 'clear') { F.owners.clear(); F.lanes.clear(); } else { const S = b.dataset.fk === 'o' ? F.owners : F.lanes, v = b.dataset.fv; if (S.has(v)) S.delete(v); else S.add(v); }
333
- shown = 25; drawFilter(); drawInit();
334
- });
481
+ /* ── the tools the Agreed design draws but has no frame for: plain versions with a "Waiting for design" tag (pm/bd-acts.js) ─────────── */
482
+ $('#bdFind').addEventListener('click', (e) => Acts.open.find(e.currentTarget));
483
+ $('#bdFilter').addEventListener('click', (e) => Acts.open.filter(e.currentTarget));
484
+ $('#newIni').addEventListener('click', (e) => Acts.open.new(e.currentTarget));
485
+ $('#bdBell').addEventListener('click', (e) => { if (M) Acts.open.bell(e.currentTarget); });
335
486
 
336
- /* ── tabs: Initiatives and Documents ─────────────────────────────────────────────────────────────────────────── */
487
+ /* ── tabs: Initiatives and Documents (Documents has no frame yet: a plain list) ──────────────────────────────────────────────────────── */
337
488
  function setTab(t) {
338
489
  tab = t;
339
490
  $('#tabIni').setAttribute('aria-selected', String(t === 'ini')); $('#tabDocs').setAttribute('aria-selected', String(t === 'docs'));
340
491
  $('#cIni').hidden = t !== 'ini'; $('#cDocs').hidden = t !== 'docs';
341
- $('.bd-tools .bd-views').classList.toggle('off', t !== 'ini');
342
- if (t === 'docs' && $('#dmF')) pillOf($('#dmF')); // the filter's pill is placed once the tab shows
492
+ if (t === 'docs') { closePeek(); $('#docBody').innerHTML = M ? Acts.docsHtml() : ''; }
343
493
  }
344
494
  $('#tabIni').onclick = () => setTab('ini');
345
495
  $('#tabDocs').onclick = () => setTab('docs');
346
- $('.cz-tabs').addEventListener('keydown', (e) => { if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft') return; const n = tab === 'ini' ? 'docs' : 'ini'; setTab(n); $(n === 'ini' ? '#tabIni' : '#tabDocs').focus(); });
347
-
348
- /* ── sprint, release, documents ─────────────────────────────────────────────────────────────────────────── */
349
- function drawSide() {
350
- const S = M.sprint, R = M.release;
351
- $('#hSpr').textContent = S.name || 'Sprint';
352
- $('#sprCap').textContent = S.cap || '';
353
- $('#sprBody').innerHTML = S.name
354
- ? `<button type="button" class="spr sprb" data-open="board:sprint" aria-haspopup="dialog" aria-label="${esc(S.name)}, ${esc(S.cap || '')}. Open the sprint"><span class="sbar" aria-hidden="true"><i class="d" style="width:${S.pct.done}%"></i><i class="g" style="width:${S.pct.doing}%"></i></span>`
355
- + `<span class="cnt"><span><b>${S.counts.done}</b> done</span><span><b>${S.counts.doing}</b> doing</span><span><b>${S.counts.todo}</b> to do</span></span>`
356
- + `${S.goal ? `<span class="goal2">Goal: ${esc(S.goal)}</span>` : ''}${S.review ? `<span class="sum3">${esc(S.review)}</span>` : ''}</button>`
357
- : `<p class="mut">${esc(S.why)}</p>`;
358
- $('#hRel').textContent = 'Next release';
359
- $('#relCap').textContent = R.at ? '' : R.cap || 'none';
360
- $('#relBody').innerHTML = R.rel && R.rel.length
361
- ? `${R.at ? '' : `<p class="empty3 plain">${esc(R.why)}</p>`}<div class="rels">${R.rel.map((r) => `<button type="button" class="rel" data-open="board:release" aria-haspopup="dialog"><span class="rh"><b>${esc(r.name)}</b><em class="rtag">${esc(r.tag)}</em><time>${esc(r.at)}${r.away ? ' · ' + esc(r.away) : ''}</time></span>${r.ini.map((i) => `<span class="ri"><i class="hd ${i.tone}"></i>${esc(i.title)}${i.status ? ' · ' + esc(i.status) : ''}</span>`).join('')}</button>`).join('')}</div>`
362
- : `<p class="empty3 plain">${esc(R.why)}</p>`;
363
- }
364
- $('#cSpr').addEventListener('click', (e) => { const b = e.target.closest('[data-open]'); if (b) { closePops(); openRow(rowOf(b.dataset.open)); } });
365
- $('#cSpr').addEventListener('click', (e) => { if (e.target.closest('[data-open="board:sprint"]')) backlogBtn(); }); // after openRow: the sprint dialog's own detail gets "Open the backlog" (premium-viewer R10)
366
- $('#cRel').addEventListener('click', (e) => { const b = e.target.closest('[data-open]'); if (b) { closePops(); openRow(rowOf(b.dataset.open)); } });
367
- function docRow(d) {
368
- const act = !d.act ? '' : d.act.kind === 'draft' ? `<button class="dmcta alt" data-draft="${esc(d.key)}"${d.running ? ' disabled' : ''}>${d.running ? '<span class="cz-dot m-info" aria-hidden="true"></span>' : ICO('<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>')}${esc(d.act.label)}</button>` : `<button class="dmcta alt" data-tab="${esc(d.act.tab)}">${esc(d.act.label)}</button>`;
369
- return `<div class="dmr ${esc(d.st || '')}" role="listitem">${d.path ? `<button class="dmo" data-doc="${esc(d.key)}" aria-haspopup="dialog">` : '<span class="dmo">'}<span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(d.title)}</b><small>${esc(d.what)}</small><span class="dmm"><span class="s ${esc(d.st || 'live')}">${ICO(STATE_ICO[d.state] || STATE_ICO['Not started'])}${esc(d.state)}</span>${d.added ? `<span>${ICO('<rect x="3" y="5" width="18" height="16" rx="3"/><path d="M3 10h18M8 3v4M16 3v4"/>')}added ${esc(d.added)}</span>` : ''}${d.cadence ? `<span>${ICO('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>')}${esc(d.cadence)}</span>` : ''}${d.by ? `<span>${ICO('<circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/>')}${esc(d.by)}</span>` : ''}</span></span>${d.path ? '</button>' : '</span>'}<span class="dmq">${act}</span></div>`;
370
- }
371
- let docFilter = 'all', docQuery = '';
372
- const draftable = () => (M.docs.rows || []).filter((d) => d.st === 'missing' && d.act && d.act.kind === 'draft' && !d.running);
373
- const docMatch = (d) => (docFilter === 'all' || (docFilter === 'none' ? d.st === 'missing' : docFilter === 'draft' ? d.st === 'draft' : d.st === 'ok')) && (!docQuery.trim() || (d.title + ' ' + d.what).toLowerCase().includes(docQuery.trim().toLowerCase()));
374
- function drawDocList() {
375
- const D = M.docs, L = D.rows.filter(docMatch);
376
- $('#docBody').innerHTML = L.length ? L.map(docRow).join('') : `<div class="dmem"><p>No document matches${docQuery.trim() ? ' “' + esc(docQuery.trim()) + '”' : ''}.</p></div>`;
377
- $$('#dmF button').forEach((b) => b.setAttribute('aria-pressed', b.dataset.dmf === docFilter)); if ($('#dmF')) pillOf($('#dmF'));
378
- }
379
- function drawDocs() {
380
- const D = M.docs, c = D.counts;
381
- $('#addDoc').hidden = !D.scope;
382
- $('#docCap').textContent = D.rows.length ? String(c.all) : '';
383
- if (!D.rows.length) { $('#docTop').innerHTML = ''; $('#docBody').innerHTML = `<p class="empty3 plain">${D.missing ? 'The core documents could not be read, so none is shown.' : 'No core documents are on record for this board.'}</p>`; $('#docNote').textContent = ''; return; }
384
- const dot = { ok: 'ok', draft: 'warn', missing: 'mut' };
385
- const hadQ = $('#dmQ') && document.activeElement === $('#dmQ');
386
- $('#docTop').innerHTML = `<p class="dsum"><span><b>${c.draft}</b> ${c.draft === 1 ? 'draft' : 'drafts'} to review</span><span><b>${c.none}</b> not started</span><span><b>${c.ok}</b> up to date</span>${c.linked ? `<span><b>${c.linked}</b> linked</span>` : ''}${draftable().length > 1 ? `<button class="dlink" data-draftall="1">${ICO('<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>')}Draft the ${draftable().length} not started</button>` : ''}</p>
387
- <div class="dprog" role="img" aria-label="${c.ok} of ${c.all} up to date">${D.rows.map((d) => `<i class="${dot[d.st] || (d.st === 'live' ? 'ok' : 'mut')}"></i>`).join('')}</div>
388
- <div class="dtool"><div class="seg" id="dmF" role="group" aria-label="Filter documents"><i class="pill"></i>${[['all', 'All', c.all], ['none', 'Not started', c.none], ['draft', 'Draft', c.draft], ['ok', 'Up to date', c.ok]].map(([k, l, n]) => `<button data-dmf="${k}" aria-pressed="${docFilter === k}">${l}<em>${n}</em></button>`).join('')}</div>
389
- <label class="dmsr">${ICO('<circle cx="11" cy="11" r="6.5"/><path d="m20 20-4-4"/>')}<input id="dmQ" type="search" placeholder="Find a document" aria-label="Find a document" value="${esc(docQuery)}"></label></div>`;
390
- drawDocList();
391
- if (hadQ) { const q = $('#dmQ'); q.focus(); q.setSelectionRange(q.value.length, q.value.length); }
392
- $('#docNote').textContent = 'Draft it starts a read-only agent run that writes a draft for you to read. Nothing is sent. Press a document to read it; a draft has Issue it, which marks it issued and sends nothing. Dropping a document is not built on this page.';
393
- }
394
- $('#docTop').addEventListener('click', async (e) => {
395
- const f = e.target.closest('[data-dmf]'); if (f) { docFilter = f.dataset.dmf; drawDocList(); return; }
396
- const all = e.target.closest('[data-draftall]'); if (!all || all.disabled) return;
397
- all.disabled = true; let n = 0;
398
- for (const d of draftable()) { const res = await pmPost('/api/core-docs/draft', { ws: M.board.ws, scope: M.docs.scope, key: d.key }); if (res && res.ok === true) n++; else { toast((res && res.error) || 'A draft could not be started.'); break; } }
399
- if (n) toast('The agent is drafting ' + n + ' ' + (n === 1 ? 'document' : 'documents') + '. They run in the background and send nothing.');
400
- await load();
401
- });
402
- $('#docTop').addEventListener('input', (e) => { if (e.target.id === 'dmQ') { docQuery = e.target.value; drawDocList(); } });
403
- /* A document's Open stays on the premium pages (premium-rows-stay-premium): the board's own views, the release dialog, Insights for a report, Home's Horizon scan. */
404
- const GOTAB = {
405
- rep: () => location.assign('/premium-insights.html' + wsQ('?')),
406
- init: () => { setTab('ini'); const f = $('#ibBody button'); if (f) f.focus(); },
407
- asks: () => { setTab('ini'); togglePop('popAsks', $('#chAsks')); },
408
- rel: () => { const r = rowOf('board:release'); if (r) openRow(r); else togglePop('popSpr', $('#chSprint')); },
409
- scan: () => location.assign('/premium.html?around=scan' + wsQ('&')),
410
- };
411
- $('#docBody').addEventListener('click', async (e) => {
412
- const o = e.target.closest('[data-doc]'); if (o) { docSheet.open(M.docs.rows.find((x) => x.key === o.dataset.doc)); return; }
413
- const t = e.target.closest('[data-tab]'); if (t) { (GOTAB[t.dataset.tab] || GOTAB.init)(); return; }
414
- const b = e.target.closest('[data-draft]'); if (!b || b.disabled) return;
415
- const key = b.dataset.draft, d = M.docs.rows.find((x) => x.key === key);
416
- b.disabled = true;
417
- const res = await pmPost('/api/core-docs/draft', { ws: M.board.ws, scope: M.docs.scope, key });
418
- if (!res || res.ok !== true) { b.disabled = false; toast((res && res.error) || 'The draft could not be started.'); return; }
419
- toast('The agent is drafting “' + (d ? d.title : key) + '”. It runs in the background and sends nothing.');
420
- await load();
421
- });
422
- $('#addDoc').onclick = () => openAddDoc({ ws: M.board.ws, scope: M.docs.scope, sub: M.board.name, onAdded: load });
423
-
424
- /* ── new asks and New initiative (initiative premium-board-actions) ───────────────────────────────────────── */
425
- function drawAsks() {
426
- $('#asksHost').innerHTML = asksHtml(ctxOf(), M.asks);
427
- $('#newIni').hidden = !!M.board.self || !M.board.id;
428
- }
429
- $('#asksHost').addEventListener('click', (e) => { if (!M) return; if (e.target.closest('[data-ask]')) closePops(); onAsks(e, ctxOf(), M.asks); });
430
- $('#newIni').onclick = () => { closeMenu(); closePops(); openIniForm(ctxOf(), null); };
496
+ $('.bd-tabs').addEventListener('keydown', (e) => { if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft') return; const n = tab === 'ini' ? 'docs' : 'ini'; setTab(n); $(n === 'ini' ? '#tabIni' : '#tabDocs').focus(); });
431
497
 
432
- /* ── the ⋯ menu's Board items: what finishes each step, the sprint and release, the metrics, the cancelled and archived ─────────── */
498
+ /* ── the shell's bell sits before New initiative, as the design orders the tools; Escape closes a popover, then the panel ──────── */
499
+ /* the ⋯ menu ("More: sources, archived, export" in AgBoard): the Board adds Metrics and Cancelled and archived, plain versions waiting for design */
433
500
  {
434
- const at = $('#settingsBtn');
435
- if (at) at.insertAdjacentHTML('beforebegin', '<button role="menuitem" id="miSteps" aria-haspopup="dialog">What finishes each step</button><button role="menuitem" id="miSpr" aria-haspopup="dialog">Sprint and release</button><button role="menuitem" id="miMet" aria-haspopup="dialog">Metrics</button><button role="menuitem" id="miGone">Cancelled and archived</button><button role="menuitem" id="theme2m">Switch light or dark</button>');
436
- const on = (id, fn) => { const b = $(id); if (b) b.addEventListener('click', (e) => { e.stopPropagation(); fn(); }); };
437
- on('#miSteps', () => togglePop('popSteps', $('#moreBtn'), true));
438
- on('#miSpr', () => togglePop('popSpr', $('#chSprint')));
439
- on('#miMet', () => togglePop('popMet', $('#moreBtn'), true));
440
- on('#miGone', () => { setTab('ini'); if (view === 'stages' || view === 'time') view = 'track'; showGone = true; drawInit(); const g = $('#goneT'); if (g) g.focus(); else toast('No initiative of this board is cancelled or archived.'); });
441
- on('#theme2m', () => $('#theme2').click());
442
- // the shell's bell sits before New initiative, as the design orders the tools
443
- const bell = $('#pvBell'); if (bell) $('#newIni').before(bell);
501
+ const st = $('#settingsBtn');
502
+ if (st) st.insertAdjacentHTML('beforebegin', ['metrics', 'gone'].map((k) => `<button role="menuitem" id="${k === 'metrics' ? 'bdMetrics' : 'bdGone'}" aria-haspopup="dialog" data-open="${k}">${k === 'metrics' ? 'Metrics' : 'Cancelled and archived'}<span class="bd-wtag">Waiting for design</span></button>`).join(''));
503
+ $$('#moreMenu [data-open]').forEach((b) => { b.onclick = () => { if (M) Acts.open[b.dataset.open]($('#moreBtn')); }; });
444
504
  }
445
- $('#popSteps').innerHTML = stepsHelpHtml();
446
- // the Escape that closes the record dialog must not also close the panel under it: the dialog can close before this listener runs, so a close later than the key press means this press closed it
447
- let dlgShut = 0, dlgOn = false;
448
- new MutationObserver(() => { const on = $('#dlg').classList.contains('on'); if (dlgOn && !on) dlgShut = performance.now(); dlgOn = on; }).observe($('#dlg'), { attributes: true, attributeFilter: ['class'] });
449
505
  window.addEventListener('keydown', (e) => {
450
- if (e.key !== 'Escape' || $('#dlg').classList.contains('on') || dlgShut >= e.timeStamp || document.querySelector('.bam2') || (e.target.id === 'bdQ' && e.target.value)) return;
506
+ if (e.key !== 'Escape' || document.querySelector('.pv-ov:not([hidden]), #moreMenu:not([hidden]), #crMenu:not([hidden]), #czMenu:not([hidden])')) return;
451
507
  if ($$('.bd-pop').some((p) => !p.hidden)) { closePops(true); return; }
452
508
  if (!$('#peek').hidden) closePeek();
453
509
  }, true);
454
510
 
455
- /* ── dock (hidden in the Agreed design; its counts stay for the read-only agent) ───────────────────────────────────── */
456
- function drawDock() { $('#dN').textContent = M.dock.needs; $('#dLab').textContent = M.dock.label; $('#dNext').innerHTML = (M.dock.next ? `First <b>${esc(M.dock.next)}</b>` : 'Nothing is late or at risk') + (M.dock.release ? ` · Next release <b>${esc(M.dock.release.at)}</b> ${esc(M.dock.release.name)}` : ''); }
457
-
458
- /* ── the record dialog: the initiative's record, no press, the read-only agent beside it ──────────────────────────── */
459
- function cardHtml(r) { return `<div class="acard" id="card"><p class="ct">What this page can do</p><p class="nodef" id="holdWhy">${esc(r.dialog.hold)}</p></div>`; }
460
- function paneHtml(r) {
461
- const p = r.dialog.pane;
462
- return `<article class="paper doc">${p.file ? `<p class="dpath">${esc(p.file)}</p>` : ''}${p.rows.length ? `<div class="kv2">${p.rows.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div>` : ''}<p class="xn">${esc(p.note || 'The initiative as the board holds it.')}</p>${r.id && r.dialog.eye === 'Initiative' ? recordPress() : ''}</article>`;
463
- }
464
- function openRow(r) {
465
- if (!r) return;
466
- const d = r.dialog;
467
- openDlg({ eye: d.eye + ' · real data', title: r.title, sub: r.sub + (r.statusLabel ? ' · ' + r.statusLabel : ''), say: d.say, stream: turnA(logHtml(d)) + turnA(ptx(d.say)) + cardHtml(r), noteKey: r.key, pane: paneHtml(r), label: d.pane.label });
468
- const vb = $('#oMain [data-vwopen]'); if (vb) vb.onclick = () => openWorkItem({ kind: 'initiative', id: r.id, title: r.title, ws: M.board.ws, board: M.board.id }); // its record, checks, tasks and links as a viewer tab (premium-viewer S7)
469
- loadThread(r.key);
470
- if (r.key === 'board:sprint') openSprint({ ws: M.board.ws, board: M.board.id, name: r.title }); // the sprint as a board by status, beside its facts (premium-viewer S5)
471
- setTimeout(() => { const b = $('#dBody'); b.scrollTop = b.scrollHeight; }, 120);
472
- }
473
- /* the sprint dialog opens the board's Jira backlog beside it, as a viewer tab (premium-viewer R10); the button is added to #oMain, never re-rendering it */
474
- function backlogBtn() {
475
- const at = $('#oMain .paper'); if (!at || !M.board.id) return;
476
- const w = document.createElement('div'); w.className = 'cact';
477
- const b = document.createElement('button'); b.type = 'button'; b.className = 'cta alt'; b.id = 'openBacklog'; b.textContent = 'Open the backlog';
478
- b.onclick = () => openBacklog({ ws: M.board.ws, board: M.board.id, title: 'Backlog' });
479
- w.append(b); at.append(w);
480
- }
481
- $('#dBody').addEventListener('click', (e) => { const lt = e.target.closest('#logT'); if (lt) { const c = $('#alog').classList.toggle('col'); lt.setAttribute('aria-expanded', !c); } });
482
-
483
511
  /* ── load: the routes derive the initiatives in the background, so the first answers are "reading" ───────────── */
512
+ /* ── the trail (GET /api/board-trail): merged into the rows each time the model or the trail lands ──────────────────────── */
513
+ /** Adds to each row what the trail holds: days in the step, the skipped steps and why, the parts of the output and the next one, and what
514
+ * waits on you. Tickets stay the output of Build and Deliver; the parts replace the record's single progress for the other steps. */
515
+ function mergeTrail() {
516
+ if (!M || !TR || !TR.items) return;
517
+ const G = M.initiatives.gone || {}, all = [...(M.rows || []), ...M.initiatives.list.rows, ...(G.cancelled || []), ...(G.archived || [])]; // separate copies after JSON
518
+ for (const r of all) {
519
+ const it = r.id ? TR.items[r.id] : null; r.trail = it || null;
520
+ const t = r.track; if (!it || !t || t.trailed) continue;
521
+ t.trailed = true;
522
+ if (t.days == null && it.days != null) t.days = it.days;
523
+ const sk = new Set(t.skipped || []);
524
+ for (const x of it.skipped || []) { const j = (M.steps || []).findIndex((s) => s.key === x.stage); if (j >= 0) sk.add(j); }
525
+ t.skipped = [...sk].sort((a, b) => a - b); t.skipWhy = it.skipped || [];
526
+ const ticketStep = (t.key === 'build' || t.key === 'deliver') && (t.tickets || []).length;
527
+ if (it.parts && it.parts.length && !ticketStep) {
528
+ const n = it.parts.length, d = it.parts.filter((x) => x.done).length;
529
+ t.segs = it.parts.map((x) => ({ cls: x.done ? 'dn' : x.you ? 'yo' : '', name: x.name.charAt(0).toUpperCase() + x.name.slice(1), st: x.done ? 'done' : x.you ? 'waiting on you' : 'not yet' }));
530
+ t.pct = null; t.count = d + ' of ' + n + ' parts'; t.next = it.next || null;
531
+ t.line = it.next ? [{ text: 'Next: ' + it.next }] : [{ text: 'Every part is done' }];
532
+ }
533
+ if (!t.you && it.you) { t.you = it.you.text; t.youWhy = it.you.why || ''; t.youKind = it.you.kind || 'you'; }
534
+ }
535
+ }
536
+ async function loadTrail() {
537
+ const ids = [...new Set((M.rows || []).filter((r) => r.id && r.track).map((r) => r.id))].slice(0, 150);
538
+ if (!ids.length) return;
539
+ const q = 'ws=' + encodeURIComponent(M.board.ws || '') + (M.board.id ? '&board=' + encodeURIComponent(M.board.id) : '') + '&ids=' + ids.map(encodeURIComponent).join(',');
540
+ let r = null; try { r = await (await fetch('/api/board-trail?' + q, { credentials: 'same-origin' })).json(); } catch { r = null; }
541
+ if (!r || !r.ok) { TR = TR || { usual: {}, themes: [], items: {}, failed: true }; return; }
542
+ TR = r; mergeTrail(); draw();
543
+ }
544
+
484
545
  function draw() {
485
- const mk = menuKey(); closeMenu();
486
- drawMode(); drawHead(); drawChips(); drawInit(); drawAsks(); drawSide(); drawDocs(); drawDock();
487
- // a read that lands while a row's menu is open draws the row again: open its menu again, with what the row holds now
488
- if (mk) { const b = $$('#ibBody [data-im]').find((x) => x.dataset.im === mk), r = rowOf(mk); if (b && r) openMenu(b, ctxOf(), r); }
489
- // an open panel follows the new read, but not under an open dialog: its close gives the focus back to the panel's own button
490
- if (peek && !$('#peek').contains(document.activeElement) && !$('#dlg').classList.contains('on')) { const r = rowOf(peek.key); if (!r) closePeek(); else if (peek.kind === 'ini') showPeek(iniPanel(r)); }
546
+ mergeTrail();
547
+ if (!sprintSet && M.jira && M.jira.sprint) { F.chips.add('sprint'); sprintSet = true; }
548
+ drawHead(); drawChips(); drawInit();
549
+ $('#docCap').textContent = M.docs && M.docs.rows ? String(M.docs.rows.length) : '';
550
+ { const g = $('#bdGone'), G = M.initiatives.gone || { cancelled: [], archived: [] }, n = [G.cancelled.length ? G.cancelled.length + ' cancelled' : '', G.archived.length ? G.archived.length + ' archived' : ''].filter(Boolean).join(' · ');
551
+ if (g) g.firstChild.textContent = 'Cancelled and archived' + (n ? ' · ' + n : ''); } // the ⋯ menu item counts them
552
+ if (tab === 'docs') $('#docBody').innerHTML = Acts.docsHtml();
553
+ // an open panel follows the new read
554
+ if (peek && peek.kind !== 'acts' && !$('#peek').contains(document.activeElement)) {
555
+ const r = rowOf(peek.key);
556
+ if (!r) closePeek(); else if (peek.kind === 'ini') showPeek(peek.from === 'time' ? timePanel(r) : iniPanel(r));
557
+ }
558
+ }
559
+ /** ?focus=<initiative id> (Insights links here): open that initiative's panel once, on the first read that has it. */
560
+ let focusDone = false;
561
+ function focusOnce() {
562
+ if (focusDone) return;
563
+ const id = new URLSearchParams(location.search).get('focus'); if (!id) { focusDone = true; return; }
564
+ const r = (M.rows || []).find((x) => x.id === id && x.track); if (!r) return;
565
+ focusDone = true;
566
+ const b = $$('#ibBody [data-key]').find((x) => x.dataset.key === r.key);
567
+ openIni(r, b || null, 'track');
491
568
  }
492
569
  async function load() {
493
570
  const p = new URLSearchParams(location.search), q = [p.get('ws') ? 'ws=' + encodeURIComponent(p.get('ws')) : '', p.get('board') ? 'board=' + encodeURIComponent(p.get('board')) : ''].filter(Boolean).join('&');
@@ -495,70 +572,22 @@ async function load() {
495
572
  try { const res = await fetch('/api/board-premium' + (q ? '?' + q : ''), { credentials: 'same-origin' }); status = res.status; r = await res.json(); } catch { r = null; }
496
573
  clearInterval(readTimer);
497
574
  if (r && r.state === 'reading') {
498
- const t0 = Date.now(), tick = () => { $('#snap').textContent = 'Reading the board · ' + Math.round((Date.now() - t0) / 1000) + ' s so far'; if (!M) $('#brief').textContent = $('#snap').textContent; };
575
+ const t0 = Date.now(), tick = () => { const s = 'Reading the board · ' + Math.round((Date.now() - t0) / 1000) + ' s so far'; $('#snap').textContent = s; if (!M) $('#ibBody').innerHTML = `<p class="bd-msg"><b>${esc(s)}</b> The board derives each initiative from its records. This page shows nothing until it has read, rather than guess.</p>`; };
499
576
  tick(); readTimer = setInterval(tick, 1000);
500
- if (!M) { $('#ibBody').innerHTML = '<p class="empty3 plain">The board derives each initiative from its records. This page shows nothing until it has read, rather than guess.</p>'; $('#docBody').innerHTML = ''; }
501
577
  setTimeout(load, 3000);
502
578
  return;
503
579
  }
504
580
  if (!r || !r.ok) {
505
581
  $('#snap').textContent = 'The board could not be read';
506
- $('#brief').textContent = 'The board could not be read, so this page shows nothing rather than guess.' + (r && r.error ? ' The reason: ' + r.error : status ? ' (the server answered ' + status + ')' : ' The server did not answer.');
582
+ if (!M) $('#ibBody').innerHTML = `<p class="bd-msg err" role="alert"><b>The board could not be read</b>, so this page shows nothing rather than guess.${r && r.error ? ' The reason: ' + esc(r.error) : status ? ' The server answered ' + status + '.' : ' The server did not answer.'}</p>`;
507
583
  setTimeout(load, 15000);
508
584
  return;
509
585
  }
510
- $('#brief').textContent = '';
511
- const first = !M; M = r.model; draw();
512
- if (first && M.board.ws) startMetrics(M.board.ws); // the Metrics of a tenant's board read apart from the board
513
- if (M.docs.rows.some((d) => d.running) || r.stale) setTimeout(load, r.stale ? 2000 : 5000); // a core-document run is going, or a press is still being derived: ask again
586
+ M = r.model; draw();
587
+ focusOnce();
588
+ if (r.stale) setTimeout(load, 2000); // a press is still being derived: ask again
589
+ else loadTrail();
514
590
  }
515
- $('#brief').textContent = 'Reading the board.';
591
+ Acts.init({ M: () => M, load, say, panel: actsPanel, close: closePeek, redraw: () => { drawChips(); drawInit(); }, F, rowOf, statusOf, openIni: (r) => openIni(r, $('#bdBell'), 'track') });
516
592
  setTab('ini');
517
593
  load();
518
-
519
- /* ── the Metrics of a tenant's board (initiative briefing-premium-metrics), in the ⋯ menu's Metrics popover ──────────────────
520
- * Reads GET /api/board-metrics-premium?ws= apart from the board's own answer and draws lib/board-metrics-premium.js's tiles: a number and a chart only
521
- * where a record counted one, "Not read" where it could not be. A tile opens the standard dialog. Nothing here writes. */
522
- let MM = null, metTimer = null; // the Metrics' model and its re-read timer
523
-
524
- function metDraw() {
525
- const card = $('#cMet'); if (!MM) { card.hidden = true; return; }
526
- card.hidden = false;
527
- $('#metCap').textContent = MM.header;
528
- const ins = '/premium-insights.html' + (M.board.ws ? '?ws=' + encodeURIComponent(M.board.ws) + (M.board.id ? '&board=' + encodeURIComponent(M.board.id) : '') : '');
529
- $('#metHint').innerHTML = (MM.lead ? `<b class="mflag">${esc(MM.lead)}</b> ` : '') + esc(MM.body || MM.hint) + ` To set a target, or for longer ranges, <a class="lk" id="metIns" href="${esc(ins)}">open Insights</a>.`;
530
- $('#metBody').style.gridTemplateColumns = 'repeat(' + Math.min(4, MM.tiles.length) + ',minmax(0,1fr))';
531
- $('#metBody').innerHTML = MM.tiles.map(MT.tileHtml).join('');
532
- $('#metNote').textContent = MM.note;
533
- $('#metLead').hidden = !MM.lead; $('#metLead').textContent = MM.lead || '';
534
- pillOf($('#perTabs'));
535
- }
536
-
537
- function metOpenTile(i) {
538
- const t = MM.tiles[i], r = MM.rows[i]; if (!t || !r) return;
539
- closePops();
540
- const d = r.dialog;
541
- const rows = MT.factRows(t, MM.repo, MM.weeks);
542
- const vals = t.ser ? H('Values') + `<div class="vtb">${t.ser.map((v, j) => `<div><span>${esc(t.wk[j])}</span><b>${v == null ? (t.since ? 'Not kept yet' : 'No runs') : esc(MT.fmt(t, v))}</b></div>`).join('')}</div>` : '';
543
- const pane = `<article class="paper doc"><p class="lede" style="margin:0 0 10px">${esc(t.def)}</p>${kv(rows)}${vals}<p class="note" style="margin-top:12px">${esc(MM.note)}</p></article>`;
544
- openDlg({ eye: 'Measure · real data', title: t.label, sub: MM.repo, say: d.say, stream: turnA(logHtml({ logTitle: 'Read from the repository', log: ['Read the repository\'s own records', 'Counted them by week', 'Changed nothing'] })) + turnA(ptx(d.say)), noteKey: r.key, pane, label: 'Measure' });
545
- loadThread(r.key);
546
- }
547
-
548
- function metWire() {
549
- MT.wireTiles($('#metBody'), () => MM.tiles, metOpenTile);
550
- $('#perTabs').addEventListener('click', (e) => { const b = e.target.closest('[aria-disabled="true"]'); if (b) toast('PMOS counts runs and merges by week only.'); });
551
- }
552
-
553
- async function startMetrics(ws) {
554
- clearTimeout(metTimer);
555
- let r = null;
556
- try { const res = await fetch('/api/board-metrics-premium?ws=' + encodeURIComponent(ws || ''), { credentials: 'same-origin' }); r = await res.json(); } catch { r = null; }
557
- if (!r || !r.ok || r.state !== 'ready') {
558
- MM = null; metDraw(); $('#cMet').hidden = false; $('#metCap').textContent = 'not read'; $('#metHint').textContent = 'The metrics could not be read, so none is shown.' + (r && r.error ? ' The reason: ' + r.error : ''); $('#metLead').hidden = false; $('#metLead').textContent = $('#metHint').textContent; $('#metBody').innerHTML = ''; $('#metNote').textContent = '';
559
- return;
560
- }
561
- MM = r.model; metDraw();
562
- if (MM.pending) metTimer = setTimeout(() => startMetrics(ws), 4000); // the workflow engine is still deriving the Blocked and Idle tiles
563
- }
564
- metWire();