create-pmos 0.401.0 → 0.402.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 (51) hide show
  1. package/package.json +13 -18
  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/board-programs-test.js +226 -0
  8. package/workspace/board-shot.js +54 -0
  9. package/workspace/briefing-premium-board-test.js +22 -15
  10. package/workspace/briefing-premium-calendar-test.js +6 -3
  11. package/workspace/briefing-premium-sources-test.js +15 -10
  12. package/workspace/briefing-premium-test.js +38 -16
  13. package/workspace/changelog.json +12 -0
  14. package/workspace/fixtures/board-premium-facts.js +20 -3
  15. package/workspace/fixtures/briefing-premium-facts.js +18 -2
  16. package/workspace/fixtures/program-ascent.js +101 -0
  17. package/workspace/guide/home.md +11 -7
  18. package/workspace/guide/index.md +1 -0
  19. package/workspace/guide/programs.md +37 -0
  20. package/workspace/lib/briefing-premium-products.js +4 -4
  21. package/workspace/lib/briefing-premium.js +2 -2
  22. package/workspace/lib/programs.js +129 -0
  23. package/workspace/lib/route-modules.js +1 -0
  24. package/workspace/lib/routes-briefing-premium.js +1 -1
  25. package/workspace/lib/routes-programs.js +122 -0
  26. package/workspace/package-lock.json +2 -2
  27. package/workspace/package.json +1 -1
  28. package/workspace/premium-board-actions-test.js +1 -1
  29. package/workspace/premium-vw-cal-test.js +6 -3
  30. package/workspace/program-panel-test.js +143 -0
  31. package/workspace/public/pm/bd-acts.js +23 -14
  32. package/workspace/public/pm/bd-asks.js +89 -23
  33. package/workspace/public/pm/bd-prog-panel.js +451 -0
  34. package/workspace/public/pm/bd-prog.js +191 -0
  35. package/workspace/public/pm/bd-span.js +98 -15
  36. package/workspace/public/pm/bd-views.js +93 -29
  37. package/workspace/public/pm/cozy-board.css +226 -9
  38. package/workspace/public/pm/cozy-home.css +26 -0
  39. package/workspace/public/pm/cozy-panel.css +178 -0
  40. package/workspace/public/pm/cozy-today.css +189 -0
  41. package/workspace/public/pm/home-app.js +75 -19
  42. package/workspace/public/pm/home-chat.js +8 -4
  43. package/workspace/public/pm/home-data.js +1 -1
  44. package/workspace/public/pm/home-list.js +98 -17
  45. package/workspace/public/pm/home-today.js +137 -59
  46. package/workspace/public/pm/premium-board.js +225 -57
  47. package/workspace/public/pm/program-model.js +192 -0
  48. package/workspace/public/premium-board.html +4 -1
  49. package/workspace/test-lists/board-programs.json +9 -0
  50. package/workspace/test-lists/program-hierarchy.json +11 -0
  51. package/workspace/test-lists/program-panel.json +9 -0
@@ -18,13 +18,16 @@ import { pmPost } from './http.js';
18
18
  import { $, $$, esc, store, crumbHtml, wireCrumb, chatAbout, setPageGaps } from './premium-shell.js';
19
19
  import { mountNav } from './cozy-nav.js';
20
20
  import { stepsHelpHtml, rulesHelpHtml } from './bd-stages.js';
21
- import { timelineHtml, SPANS, GROUPS, md } from './bd-span.js';
21
+ import { timelineHtml, legendHtml, SPANS, GROUPS, md } from './bd-span.js';
22
22
  import * as Acts from './bd-acts.js';
23
23
  import * as V from './bd-views.js';
24
24
  import * as Asks from './bd-asks.js';
25
+ import * as PG from './bd-prog.js';
26
+ import { programOf } from './program-model.js';
25
27
  import { open as viewerOpen } from './cozy-viewer.js';
28
+ import * as PP from './bd-prog-panel.js';
26
29
 
27
- const VIEW_KEY = 'pmos.board.view', PVIEW_KEY = 'pmos.board.pview', SPAN_KEY = 'pmos.board.span', GROUP_KEY = 'pmos.board.group';
30
+ const VIEW_KEY = 'pmos.board.view', PVIEW_KEY = 'pmos.board.pview', SPAN_KEY = 'pmos.board.span', GROUP_KEY = 'pmos.board.group', GROUPING_KEY = 'pmos.board.grouping';
28
31
  let M = null; // the model
29
32
  let TR = null; // the trail (GET /api/board-trail): { usual, themes, items: { [id]: item } }
30
33
  let group = GROUPS.some(([k]) => k === store.get(GROUP_KEY)) ? store.get(GROUP_KEY) : 'theme';
@@ -37,9 +40,15 @@ let foldOpen = false; // the Monitor and Evaluate rows under the tab
37
40
  let sprintSet = false; // "This sprint" starts on, once, when the board has a sprint
38
41
  const F = { chips: new Set(), q: '', owners: new Set(), lanes: new Set(), sprints: new Set() }; // the chip filters, Find and Filter
39
42
  let GR = {}; // the first questions still open per initiative (GET /api/board-grill?ids=): { [id]: { open, total, later } }
43
+ let PGS = []; // the programs (GET /api/programs): every view groups the rows a program holds under it (PgBoard)
44
+ let XR = {}; // the other products' rows a program here holds, read once (GET /api/board-premium?ws=): { [ws]: { name, rows } }
45
+ const ALL = new URLSearchParams(location.search).get('all') === '1'; // All products: every product's board on one page (PgBoard)
46
+ let byProduct = store.get(GROUPING_KEY) === 'product'; // the grouping: programs first (default) or By product (PgBoardProduct)
40
47
  let DM = {}; // the documents' history (GET /api/board-docs): { [path]: { changed, by, log } }
41
48
  let peek = null; // the open panel: { kind: 'ini' | 'tk' | 'acts', key, tk, from: 'track' | 'time' }
42
49
  mountNav('board');
50
+ // a product head's goal dots (PgBoard .gd) count that product's open initiatives, the way Home's product header does
51
+ PG.goalsFrom((name) => (M ? M.initiatives.list.rows.filter((r) => !M.board.all || r.product === name) : null));
43
52
  const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
44
53
  const I = {
45
54
  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',
@@ -56,6 +65,9 @@ const fmt = (iso) => { const d = isoDate(iso); return d ? md(d) : ''; };
56
65
  const PHONE = matchMedia('(max-width: 720px)');
57
66
  const goneRows = () => { const G = (M && M.initiatives && M.initiatives.gone) || {}; return [...(G.cancelled || []), ...(G.archived || [])]; };
58
67
  const rowOf = (key) => (M && M.rows || []).find((r) => r.key === key) || goneRows().find((r) => r.key === key) || null;
68
+ /** The rows on screen grouped (pm/bd-prog.js groupsOf): programs first, then the product; or By product. null when no program holds a row here. */
69
+ const groups = (L) => PG.groupsOf(PGS, L, M, byProduct);
70
+ const progState = (p) => PG.stateOf(p, M, XR);
59
71
 
60
72
  /** A panel of pm/bd-acts.js or pm/bd-asks.js: it goes in the side panel like the others; cls widens it (pk-new, pk-wide, pk-doc). */
61
73
  function actsPanel(html, from, cls) {
@@ -77,14 +89,16 @@ let crumbed = false;
77
89
  function drawHead() {
78
90
  if (!crumbed) {
79
91
  crumbed = true;
80
- const boards = M.board.switcher || [];
92
+ // the picker: All products first when there is more than one product, then each product's board
93
+ const list = M.board.switcher || [], boards = list.length > 1 ? [{ ws: '*', id: '*', name: 'All products' }, ...list] : list;
81
94
  $('#crumbHost').innerHTML = crumbHtml({ page: '', board: M.board.name || 'Board', boards });
82
- wireCrumb({ boards, board: M.board.id, goBoard: (ws, id) => location.assign('/premium-board.html?ws=' + encodeURIComponent(ws) + '&board=' + encodeURIComponent(id)) });
95
+ wireCrumb({ boards, board: ALL ? '*' : M.board.id, goBoard: (ws, id) => location.assign(id === '*' ? '/premium-board.html?all=1' : '/premium-board.html?ws=' + encodeURIComponent(ws) + '&board=' + encodeURIComponent(id)) });
83
96
  $('#crBoard').setAttribute('aria-label', 'Product: ' + (M.board.name || 'Board'));
84
- chatAbout('board:this-board', M.board.name ? 'the ' + M.board.name + ' board' : 'this board');
97
+ chatAbout('board:this-board', ALL ? 'all products' : M.board.name ? 'the ' + M.board.name + ' board' : 'this board');
85
98
  }
86
99
  $('#snap').textContent = M.header.text;
87
- $('#newIni').hidden = !!M.board.self; // PMOS-self: new work starts at the pmos-router skill
100
+ // PMOS-self: new work starts at the pmos-router skill. All products: New asks which product the initiative is for
101
+ $('#newIni').hidden = ALL ? (M.board.products || []).every((p) => p.self) : !!M.board.self;
88
102
  setPageGaps(((M.header && M.header.missing) || []).length);
89
103
  }
90
104
  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']];
@@ -101,17 +115,20 @@ function drawChips() {
101
115
  $('#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'])}`;
102
116
  return;
103
117
  }
104
- const jiraChip = `<button type="button" class="bd-chip" id="chJira" title="Read Jira again">${SV(I.refresh)}<span>${esc(jira)}</span></button>`;
118
+ // All products (PgBoard): one Jira chip with the oldest read of any product, and every product's new asks; the sprint stays per product
119
+ const jiraChip = `<button type="button" class="bd-chip" id="chJira" title="${ALL ? 'Read Jira again for every product' : 'Read Jira again'}">${SV(I.refresh)}<span>${esc(jira)}</span></button>`;
105
120
  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>`;
106
121
  if (phone) {
107
122
  const docs = M.docs && M.docs.rows ? M.docs.rows.length : 0;
108
123
  $('#bdChipset').innerHTML = thisSprint + jiraChip + askChip + flt(['late', 'risk', 'blocked', 'idle']) + `<button type="button" class="bd-chip" id="chDocs">Docs ${docs}</button>`;
109
124
  return;
110
125
  }
126
+ // the timeline's legend sits at the end of the chip row (PgTimeline), with a program milestone only where a program is drawn
127
+ const lgd = view === 'time' && span === 'quarter' ? '<span class="bd-sp"></span>' + legendHtml(!byProduct && !!groups(visible())) : '';
111
128
  $('#bdChipset').innerHTML = jiraChip
112
- + `<button type="button" class="bd-chip" id="chSprint" aria-haspopup="dialog">${SV(I.cal)}<span>${esc(sprint)}</span></button>`
129
+ + (ALL ? '' : `<button type="button" class="bd-chip" id="chSprint" aria-haspopup="dialog">${SV(I.cal)}<span>${esc(sprint)}</span></button>`)
113
130
  + askChip + '<span class="bd-vr"></span>' + flt(['late', 'risk', 'blocked', 'idle'])
114
- + (thisSprint ? '<span class="bd-sp"></span>' + thisSprint : '');
131
+ + (thisSprint ? '<span class="bd-sp"></span>' + thisSprint : '') + lgd;
115
132
  }
116
133
  $('#bdChipset').addEventListener('click', (e) => {
117
134
  const f = e.target.closest('[data-f]');
@@ -133,10 +150,14 @@ $('#bdChipset').addEventListener('click', (e) => {
133
150
  /** 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. */
134
151
  async function refreshJira(btn) {
135
152
  if (btn) btn.disabled = true;
136
- const r = await pmPost('/api/sources/refresh', { ws: (M && M.board.ws) || '', source: 'jira' }).catch(() => null);
153
+ // All products: each product's own Jira source, one after the other
154
+ const W = ALL ? (M.board.products || []).filter((p) => !p.self).map((p) => p.ws) : [(M && M.board.ws) || ''];
155
+ const R = [];
156
+ for (const ws of W) R.push(await pmPost('/api/sources/refresh', { ws, source: 'jira' }).catch(() => null));
137
157
  if (btn) btn.disabled = false;
138
- 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') + '.');
139
- if (r && r.ok) setTimeout(load, 4000);
158
+ const bad = R.filter((r) => !r || !r.ok), ok = R.length - bad.length;
159
+ say(!bad.length ? 'Reading Jira again. The Board shows it when the read lands.' : ok ? 'Reading Jira again for ' + ok + ' of ' + R.length + ' products. The others did not start: ' + ((bad[0] && bad[0].error) || 'the server did not answer') + '.' : 'Jira was not read again: ' + ((bad[0] && bad[0].error) || 'the server did not answer') + '.');
160
+ if (ok) setTimeout(load, 4000);
140
161
  }
141
162
 
142
163
  /* ── the popovers: what finishes each step, and the timeline's spans ───────────────────────────────────────────────────── */
@@ -217,7 +238,17 @@ function segHtml(r, big) {
217
238
  ? `<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>`
218
239
  : `<i class="${esc(s.cls || '')}"${fill(i)}></i>`)).join('')}</div>`;
219
240
  }
220
- 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(' · ');
241
+ // the next step leads (PgBoard, the nextfirst layer): "Next: <the part>" with the part in blue ink; an output is named by its noun ("BRD", not "BRD complete")
242
+ const lineHtml = (r) => ((r.track && r.track.line) || []).map((x) => (x.tone ? `<em class="s-${x.tone}">${esc(x.text)}</em>` : /^Next: /.test(x.text) ? `Next: <em class="nx">${esc(x.text.slice(6))}</em>` : esc(x.text))).join(' · ');
243
+ const outName = (s) => String(s || '').replace(/ complete$/, '');
244
+ /** The committed date under a milestone (PgBoard .eta): the planned end under ◆ Deliver until the initiative passes it, then under ◆ Evaluate;
245
+ * amber when it is past and the milestone is not reached. At the milestone itself the date replaces the days count. */
246
+ function etaOf(r, t) {
247
+ if (!r.end) return null;
248
+ const j = t.k <= 5 ? 5 : t.k <= 7 ? 7 : -1; if (j < 0) return null;
249
+ const d = isoDate(r.end), today = new Date(); today.setHours(0, 0, 0, 0);
250
+ return { j, text: fmt(r.end), late: !!(d && d < today), what: j === 5 ? 'Committed delivery date' : 'Committed evaluation date' };
251
+ }
221
252
 
222
253
  /* ── the stage track (AgBoard, AgBoardPhone) ──────────────────────────────────────────────────────────────────────────── */
223
254
  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>';
@@ -226,18 +257,20 @@ const DAYS = (t) => (t.days != null ? t.days + 'd' : '—');
226
257
  const usualOf = (t) => { const u = TR && TR.usual && t && TR.usual[t.key]; return u && u.n >= 3 && u.days != null ? u : null; };
227
258
  const usualText = (u) => (u.days === 0 ? 'usually under a day' : 'usually ' + u.days + ' ' + plural(u.days, 'day', 'days'));
228
259
  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)) : '');
229
- function trackRow(r) {
230
- 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 || []);
260
+ function trackRow(r, cls = '') {
261
+ 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 || []), E = k >= 0 ? etaOf(r, t) : null;
231
262
  const cells = M.steps.map((st, j) => {
232
263
  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(' ');
233
264
  const why = sk.has(j) && (t.skipWhy || []).find((x) => x.stage === st.key);
234
265
  const title = j === k ? dayTitle(t) : sk.has(j) ? st.label + ' skipped' + (why && why.why ? ': ' + why.why : '') : '';
235
- 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>`;
266
+ const eta = E && E.j === j ? E : null;
267
+ const etaH = eta ? `<small class="eta${eta.late ? ' late' : ''}" title="${esc(eta.what + (eta.late ? ', passed' : ''))}">${esc(eta.text)}</small>` : '';
268
+ return `<div class="${cls}" role="cell"${title ? ` title="${esc(title)}"` : ''}>${j === k ? `<span class="cur"><u class="cz-dot ${s.tone} ${s.mo}"></u>${eta ? etaH : `<small>${DAYS(t)}</small>`}</span>` : '<i></i>' + etaH}</div>`;
236
269
  }).join('');
237
- 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)}">`
238
- + `<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>`
270
+ return `<div class="bt-r bt-l${cls}${peek && peek.key === r.key && peek.kind !== 'acts' ? ' sel' : ''}${r.acts && r.acts.life === 'hold' ? ' held' : ''}" role="row" data-row="${esc(r.key)}">`
271
+ + `<button type="button" class="ini2 bt-nm" data-key="${esc(r.key)}" role="rowheader" aria-haspopup="dialog"><b>${r.inProgram ? PG.memberIcon(PGS, r.inProgram) : ''}${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>`
239
272
  + `<div class="bt-cells" role="presentation">${cells}</div>`
240
- + `<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>`;
273
+ + `<div class="bt-dl" role="cell"><div class="t1"><b>${esc(outName(t.output))}</b><span>${esc(t.count || '')}</span></div>${segHtml(r)}<div class="t3">${lineHtml(r)}</div></div></div>`;
241
274
  }
242
275
  const isME = (r) => r.track && r.track.k >= 6;
243
276
  function drawTrack(L) {
@@ -252,13 +285,31 @@ function drawTrack(L) {
252
285
  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>`
253
286
  : 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>';
254
287
  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>`;
255
- 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"><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
288
+ // programs first, then the product (PgBoard); "By product" draws the product only, a program's rows with its layers icon (PgBoardProduct).
289
+ // Grouped, each product folds its own Monitor and Evaluate rows after the first of each, under "N more" (PgBoard .tf); the foot keeps
290
+ // only the ones this page has not loaded
291
+ const G = groups(sorted);
292
+ let inGroups = 0;
293
+ const meFold = (rs) => { const seen2 = new Set(), on = [], off = []; for (const r of rs) { if (isME(r) && seen2.has(r.track.k) && !foldOpen) off.push(r); else { if (isME(r)) seen2.add(r.track.k); on.push(r); } } return { on, off }; };
294
+ const rows = G ? G.map((g) => {
295
+ if (g.kind === 'program') {
296
+ const kids = PG.folded(g.key) ? '' : g.products.map((sub) => (g.products.length > 1 ? PG.subHtml(sub.name) : '') + sub.rows.map((r) => trackRow(r, ' bt-kid' + (r === g.rows[g.rows.length - 1] ? ' last' : ''))).join('')).join('');
297
+ return PG.bandHtml(g, progState(g.program), { steps: S }) + kids;
298
+ }
299
+ if (PG.folded(g.key)) return PG.prodHtml(g);
300
+ const f = meFold(g.rows); inGroups += f.off.length;
301
+ return PG.prodHtml(g) + f.on.map((r) => trackRow(r, ' bt-gr')).join('') + (f.off.length ? `<button type="button" class="dlink bt-gmore" data-mefold aria-expanded="false">${SV(I.chev)}${f.off.length} more</button>` : '');
302
+ }).join('') : shown.map((r) => trackRow(r)).join('');
303
+ const rest = G ? Math.max(0, meTotal - sorted.filter(isME).length) : more; // grouped: the ones not loaded here
304
+ const tf2 = !G ? tf : rest > 0 && !foldOpen && !inGroups ? `<button type="button" class="dlink" id="fold" aria-expanded="false">${SV(I.chev)}${rest} more in Monitor and Evaluate</button>` : foldOpen && meTotal > 1 ? tf : '<span></span>';
305
+ return `<div class="bt" role="table" aria-label="Initiatives by stage">${head}${rows}<div class="bt-tf">${tf2}<span class="bt-srt">Sorted by stage</span></div>${PHONE.matches ? `<div class="bd-whead bd-phx"><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
256
306
  }
257
307
 
258
308
  /* ── the timeline (AgBoardTimeline, AgBoardTlYear, AgBoardTl5y, AgBoardTimelinePhone) ───────────────────────────────────────── */
259
309
  function drawTime(L) {
260
310
  const S = M.steps || [];
261
- const T = timelineHtml(L, M, span, { 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, avatar: (n) => V.avatar(n, 'sm'),
311
+ const T = timelineHtml(L, M, span, { groups: groups(L), progState, folded: PG.folded, prodHtml: (g) => PG.prodHtml(g, 'tg-prd'), subHtml: (n) => PG.subHtml(n, 'tg-psb'), progTile: () => PG.progTile(), productsOf: PG.productsOf,
312
+ foldBtn: (g) => PG.foldBtn(g.key, g.program.title), memberIcon: (id) => PG.memberIcon(PGS, id), 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, avatar: (n) => V.avatar(n, 'sm'),
262
313
  askHref: (none) => askHref(null, 'Propose start and end dates for ' + none.map((r) => r.title).join(', ')) });
263
314
  return T.html;
264
315
  }
@@ -279,8 +330,27 @@ function drawInit() {
279
330
  $('#bdSpans').hidden = v !== 'time' || phone;
280
331
  $$('#bdSpans [data-sp]').forEach((b) => b.setAttribute('aria-pressed', String(b.dataset.sp === span)));
281
332
  document.body.dataset.bdView = v;
333
+ drawGrouping();
282
334
  }
283
335
  PHONE.addEventListener('change', () => { if (M) { drawChips(); drawInit(); } });
336
+ /** The grouping (PgBoard, PgBoardProduct): programs first is the default and draws nothing in the toolbar (PgBoard); the choice is in Filter.
337
+ * "By product" shows as an on chip after the views (PgBoardProduct), whose menu switches back. Only when a program holds a row here. */
338
+ const groupingOn = () => !!(M && PGS.length && PG.groupsOf(PGS, M.initiatives.list.rows, M, false));
339
+ function setGrouping(bp) { byProduct = !!bp; store.set(GROUPING_KEY, byProduct ? 'product' : 'program'); const m = $('#bdGrpMenu'); if (m) m.hidden = true; drawChips(); drawInit(); }
340
+ function drawGrouping() {
341
+ const w = $('#bdGrpw'), on = groupingOn() && byProduct;
342
+ w.hidden = !on; if (!on) { w.innerHTML = ''; return; }
343
+ const open = !!$('#bdGrpMenu') && !$('#bdGrpMenu').hidden;
344
+ const btn = `<button type="button" class="bd-chip bd-grp on" id="bdGroup" aria-haspopup="menu" aria-expanded="${open}" aria-label="Grouped by product. Change grouping">By product${SV(I.chev)}</button>`;
345
+ w.innerHTML = btn + `<span class="bd-grpm" id="bdGrpMenu" role="menu"${open ? '' : ' hidden'}>${[['program', 'Programs first'], ['product', 'By product']].map(([k, n]) => `<button type="button" role="menuitemradio" aria-checked="${(k === 'product') === byProduct}" data-grping="${k}">${n}</button>`).join('')}</span>`;
346
+ }
347
+ $('#bdGrpw').addEventListener('click', (e) => {
348
+ const g = e.target.closest('[data-grping]');
349
+ if (g) { setGrouping(g.dataset.grping === 'product'); const b = $('#bdGroup') || $('#bdFilter'); b.focus(); return; }
350
+ if (e.target.closest('#bdGroup')) { const m = $('#bdGrpMenu'), o = m.hidden; m.hidden = !o; $('#bdGroup').setAttribute('aria-expanded', String(o)); if (o) m.querySelector('[aria-checked="true"]').focus(); }
351
+ });
352
+ document.addEventListener('click', (e) => { if (!e.target.closest('#bdGrpw')) { const m = $('#bdGrpMenu'); if (m && !m.hidden) { m.hidden = true; $('#bdGroup').setAttribute('aria-expanded', 'false'); } } });
353
+ $('#bdGrpw').addEventListener('keydown', (e) => { if (e.key === 'Escape') { const m = $('#bdGrpMenu'); if (m && !m.hidden) { e.stopPropagation(); m.hidden = true; $('#bdGroup').setAttribute('aria-expanded', 'false'); $('#bdGroup').focus(); } } });
284
354
  function setView(v) { if (PHONE.matches) { pview = v; store.set(PVIEW_KEY, v); } else { view = v; store.set(VIEW_KEY, view); } closePeek(); drawChips(); drawInit(); }
285
355
  $('#ibTabs').addEventListener('click', (e) => { const b = e.target.closest('[data-v]'); if (!b || !M) return; setTab('ini'); setView(b.dataset.v); });
286
356
  $('#bdView').addEventListener('click', () => { if (M) setView(PHONE.matches ? (pview === 'list' ? 'stages' : pview === 'stages' ? 'track' : 'list') : view === 'time' ? 'track' : 'time'); });
@@ -291,12 +361,13 @@ $('#bdShowing').addEventListener('click', (e) => {
291
361
  });
292
362
  $('#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(); });
293
363
  $('#ibBody').addEventListener('click', (e) => {
294
- if (e.target.closest('#fold')) { foldOpen = !foldOpen; drawInit(); const f = $('#fold'); if (f) f.focus(); return; }
364
+ if (e.target.closest('#fold, [data-mefold]')) { foldOpen = !foldOpen; drawInit(); const f = $('#fold') || $('#ibBody [data-mefold]'); if (f) f.focus(); return; }
365
+ const gf = e.target.closest('[data-fold]'); if (gf) { const k = gf.dataset.fold; PG.fold(k); drawInit(); const b = $$('#ibBody [data-fold]').find((x) => x.dataset.fold === k); if (b) b.focus(); return; }
366
+ const cf = e.target.closest('[data-colfold]'); if (cf) { const k = cf.dataset.colfold; V.toggleCol(k); drawInit(); const b = $$('#ibBody [data-colfold]').find((x) => x.dataset.colfold === k); if (b) b.focus(); return; }
295
367
  if (e.target.closest('#fClear')) { clearFilters(); drawChips(); drawInit(); return; }
296
368
  const pv = e.target.closest('[data-pv]'); if (pv) { setView(pv.dataset.pv); const b = $(`#ibBody [data-pv="${pv.dataset.pv}"]`); if (b) b.focus(); return; }
297
369
  const so = e.target.closest('[data-sort]'); if (so) { V.setSort(so.dataset.sort); drawInit(); const b = $(`#ibBody [data-sort="${so.dataset.sort}"]`); if (b) b.focus(); return; }
298
370
  if (e.target.closest('[data-me]')) { V.toggleME(); drawInit(); const b = $('#ibBody [data-me]'); if (b) b.focus(); return; }
299
- const sr = e.target.closest('[data-strip]'); if (sr) { V.toggleStrip(sr.dataset.strip); drawInit(); const b = $(`#ibBody [data-strip="${sr.dataset.strip}"]`); if (b) b.focus(); return; }
300
371
  const rm = e.target.closest('[data-rowmenu]'); if (rm) { const r = rowOf(rm.dataset.rowmenu); if (r) Acts.open.row(r, rm); return; }
301
372
  if (e.target.closest('[data-backlog]')) return; // pm/bd-acts.js opens the backlog
302
373
  const op = e.target.closest('[data-open]'); if (op) { Acts.open[op.dataset.open](op); return; }
@@ -306,6 +377,7 @@ $('#ibBody').addEventListener('click', (e) => {
306
377
  const tk = e.target.closest('[data-tk]'); if (tk) { openTicket(tk.dataset.ini, tk.dataset.tk, tk); return; }
307
378
  const th = e.target.closest('[data-tgtheme]'); if (th) { span = 'year'; store.set(SPAN_KEY, span); drawChips(); drawInit(); return; }
308
379
  if (e.target.closest('[data-act]')) return; // pm/bd-acts.js handles its own presses
380
+ const pg = e.target.closest('[data-prog]'); if (pg) { PG.openProgram(pg.dataset.prog, pg); return; }
309
381
  const b = e.target.closest('[data-key]'); if (b) openIni(rowOf(b.dataset.key), b, view === 'time' ? 'time' : 'track');
310
382
  });
311
383
  $('#ibBody').addEventListener('keydown', (e) => { if ((e.key === 'Enter' || e.key === ' ') && e.target.matches('[data-steps]')) { e.preventDefault(); togglePop('popSteps', e.target); } });
@@ -314,15 +386,15 @@ $('#ibBody').addEventListener('keydown', (e) => { if ((e.key === 'Enter' || e.ke
314
386
  let dragKey = null;
315
387
  $('#ibBody').addEventListener('dragstart', (e) => { const c = e.target.closest('.bd-bc[draggable]'); if (!c) return; dragKey = c.dataset.key; e.dataTransfer.effectAllowed = 'move'; try { e.dataTransfer.setData('text/plain', dragKey); } catch { /* some browsers refuse */ } c.classList.add('drag'); });
316
388
  $('#ibBody').addEventListener('dragend', () => { dragKey = null; $$('#ibBody .drag, #ibBody .drop').forEach((x) => x.classList.remove('drag', 'drop')); });
317
- $('#ibBody').addEventListener('dragover', (e) => { const col = dragKey && e.target.closest('.bd-scol[data-step]'); if (!col) return; e.preventDefault(); $$('#ibBody .bd-scol.drop').forEach((x) => { if (x !== col) x.classList.remove('drop'); }); col.classList.add('drop'); });
389
+ $('#ibBody').addEventListener('dragover', (e) => { const col = dragKey && e.target.closest('.bd-scol[data-step], .bd-kc[data-step]'); if (!col) return; e.preventDefault(); $$('#ibBody .drop').forEach((x) => { if (x !== col) x.classList.remove('drop'); }); col.classList.add('drop'); });
318
390
  $('#ibBody').addEventListener('drop', async (e) => {
319
- const col = e.target.closest('.bd-scol[data-step]'); if (!col || !dragKey) return;
391
+ const col = e.target.closest('.bd-scol[data-step], .bd-kc[data-step]'); if (!col || !dragKey) return;
320
392
  e.preventDefault();
321
393
  const r = rowOf(dragKey), j = +col.dataset.step; dragKey = null; col.classList.remove('drop');
322
394
  if (!r || !r.track || r.track.k === j || !r.acts) return;
323
395
  const step = M.steps[j], to = (r.acts.stages || []).find((n) => stepOfName(n) === step.key);
324
396
  if (!to) { say(step.label + ' is not one of this board\'s stages, so it did not move.'); return; }
325
- const from = r.acts.stage, body = { ws: M.board.ws, board: M.board.id, id: r.id };
397
+ const from = r.acts.stage, body = { ws: r.ws || M.board.ws, board: r.boardId || M.board.id, id: r.id };
326
398
  const res = await pmPost('/api/boards/move', { ...body, to }).catch(() => null);
327
399
  if (!res || !res.ok) { say((res && res.error) || 'It did not move. The server did not say why.'); return; }
328
400
  say('Moved to ' + to + ' · ' + r.title + '.', async () => { const u = await pmPost('/api/boards/move', { ...body, to: from, why: 'Undo' }).catch(() => null); say(u && u.ok ? 'Back in ' + from + '.' : (u && u.error) || 'The undo did not land.'); load(); });
@@ -337,16 +409,16 @@ function askHref(r, q) {
337
409
  const p = new URLSearchParams();
338
410
  if (r && r.id) p.set('ask', r.id); else p.set('ask', 'board:' + (M.board.id || ''));
339
411
  if (q) p.set('q', q);
340
- if (M.board.ws) p.set('ws', M.board.ws);
412
+ const ws = (r && r.ws) || M.board.ws; if (ws) p.set('ws', ws);
341
413
  return '/premium.html?' + p.toString();
342
414
  }
343
- const pageHref = (r) => '/premium-initiative.html?id=' + encodeURIComponent(r.id) + (M.board.ws ? '&ws=' + encodeURIComponent(M.board.ws) + '&board=' + encodeURIComponent(M.board.id) : '');
415
+ const pageHref = (r) => { const ws = r.ws || M.board.ws, b = r.boardId || M.board.id; return '/premium-initiative.html?id=' + encodeURIComponent(r.id) + (ws ? '&ws=' + encodeURIComponent(ws) + '&board=' + encodeURIComponent(b) : ''); };
344
416
 
345
417
  /* ── the side panel: the initiative (AgBoardPanel), the Jira ticket (AgBoardTicket) and the initiative from the timeline (AgBoardTimelinePanel) ── */
346
418
  let peekBack = null;
347
419
  function ladderHtml(t) {
348
420
  const k = t ? t.k : -1, sk = new Set((t && t.skipped) || []);
349
- 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>`;
421
+ 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(PHONE.matches ? s.short : s.label)}</span>`).join('')}</div>`; // 60 % wide on desktop (XnAgBoardPanel): the steps' full names
350
422
  }
351
423
  function askForm(r, label, o = {}) {
352
424
  const J = M.jira || {};
@@ -533,6 +605,49 @@ function closePeek() {
533
605
  const back = peekBack && document.contains(peekBack) ? peekBack : key ? $$('#ibBody [data-key]').find((x) => x.dataset.key === key) : null;
534
606
  if (back) back.focus(); peekBack = null;
535
607
  }
608
+ /** The programs (GET /api/programs), then the rows of their initiatives in this board's other products, read once each, so a program's
609
+ * readiness and its products count every product (its other products' initiatives are not drawn here: PRD decision 5). */
610
+ async function loadPrograms() {
611
+ let r = null; try { r = await (await fetch('/api/programs', { credentials: 'same-origin' })).json(); } catch { r = null; }
612
+ if (!r || !r.ok) return;
613
+ PGS = r.programs || [];
614
+ if (M) { drawChips(); drawInit(); programOnce(); loadOthers(); }
615
+ readMe();
616
+ }
617
+ /** The PM's first name (GET /api/brief-page `me`, as Home reads it), once, and only when a program holds tasks: the program row's blue count
618
+ * (PgBoard .yc) counts the program tasks that are the PM's. Without it, only the tasks with no owner or "pm" count. */
619
+ let meRead = false;
620
+ async function readMe() {
621
+ if (meRead || !PGS.some((p) => (p.tasks || []).length)) return;
622
+ meRead = true;
623
+ let r = null; try { r = await (await fetch('/api/brief-page' + (M && M.board.ws ? '?ws=' + encodeURIComponent(M.board.ws) : ''), { credentials: 'same-origin' })).json(); } catch { r = null; }
624
+ if (r && r.ok && r.me) { PG.setMe(r.me); if (M) drawInit(); }
625
+ }
626
+ let othersRead = false;
627
+ async function loadOthers() {
628
+ if (othersRead || !M || !PGS.length || ALL) return; // All products has every product's rows already
629
+ othersRead = true;
630
+ const here = M.board.ws || '', boards = M.board.switcher || [];
631
+ const want = [...new Set(PGS.filter((p) => !p.archived && (p.members || []).some((m) => m.ws === here)).flatMap((p) => (p.members || []).map((m) => m.ws)).filter((w) => w && w !== here))];
632
+ for (const w of want.slice(0, 6)) {
633
+ const b = boards.find((x) => x.ws === w); if (!b) continue;
634
+ let a = null; try { a = await (await fetch('/api/board-premium?ws=' + encodeURIComponent(w) + '&board=' + encodeURIComponent(b.id), { credentials: 'same-origin' })).json(); } catch { a = null; }
635
+ const m = a && a.ok && a.model; if (!m) continue; // still reading, or not read: the member stays "missing", never guessed
636
+ const st = m.steps || [];
637
+ XR[w] = { name: (m.board && (m.board.product || m.board.name)) || b.name, rows: (m.rows || []).filter((x) => x.id).map((x) => ({ id: x.id, title: x.title, stage: x.track && x.track.k >= 0 && st[x.track.k] ? st[x.track.k].key : x.stage })) };
638
+ }
639
+ if (Object.keys(XR).length) drawInit();
640
+ }
641
+ /** ?program=<id> (Home links here): open that program once, its group unfolded, when the programs and the board are both read. */
642
+ let programDone = false;
643
+ function programOnce() {
644
+ if (programDone || !M || !PGS.length) return;
645
+ programDone = true;
646
+ const id = new URLSearchParams(location.search).get('program'); if (!id || !PGS.some((p) => p.id === id)) return;
647
+ PG.fold('g:' + id, false); drawInit();
648
+ const b = $$('#ibBody [data-prog]').find((x) => x.dataset.prog === id); if (b) b.scrollIntoView({ block: 'center' });
649
+ PG.openProgram(id, b);
650
+ }
536
651
  function openIni(r, from, where) {
537
652
  if (!r || !r.track) return;
538
653
  peek = { kind: 'ini', key: r.key, from: where || 'track' }; showPeek(peek.from === 'time' ? timePanel(r) : iniPanel(r), from);
@@ -575,7 +690,9 @@ $('#peek').addEventListener('submit', (e) => {
575
690
  /* ── the tools the Agreed design draws but has no frame for: plain versions with a "Waiting for design" tag (pm/bd-acts.js) ─────────── */
576
691
  $('#bdFind').addEventListener('click', (e) => Acts.open.find(e.currentTarget));
577
692
  $('#bdFilter').addEventListener('click', (e) => Acts.open.filter(e.currentTarget));
578
- $('#newIni').addEventListener('click', (e) => Acts.open.new(e.currentTarget));
693
+ // New (PgBoard: "New program or initiative"): a menu of the two. The program panel's own "New initiative" presses this button from code,
694
+ // and that press opens New initiative at once.
695
+ $('#newIni').addEventListener('click', (e) => { if (e.isTrusted) Asks.openNewMenu(e.currentTarget); else Acts.open.new(e.currentTarget); });
579
696
  $('#bdBell').addEventListener('click', (e) => { if (M) Acts.open.bell(e.currentTarget); });
580
697
 
581
698
  /* ── tabs: Initiatives and Documents (Documents has no frame yet: a plain list) ──────────────────────────────────────────────────────── */
@@ -593,16 +710,22 @@ $('.bd-tabs').addEventListener('keydown', (e) => { if (e.key !== 'ArrowRight' &&
593
710
  function drawDocs() { if (M) $('#docBody').innerHTML = V.docsHtml(); }
594
711
  $('#docBody').addEventListener('click', (e) => { const k = e.target.closest('[data-dkind]'); if (k) { V.setDocKind(k.dataset.dkind); drawDocs(); const b = $(`#docBody [data-dkind="${k.dataset.dkind}"]`); if (b) b.focus(); } });
595
712
  /** The history of the documents on screen (GET /api/board-docs): when each last changed, by whom, its last commits. Read-only. */
596
- async function loadDocMeta(paths) {
713
+ async function loadDocMeta(list) {
597
714
  if (!M) return;
598
- const P = (paths || V.docRows().map((x) => x.path)).filter((p) => p && !DM[p]).slice(0, 40);
599
- if (!P.length) return;
600
- let r = null; try { r = await (await fetch('/api/board-docs?ws=' + encodeURIComponent(M.board.ws || '') + '&paths=' + P.map(encodeURIComponent).join(','), { credentials: 'same-origin' })).json(); } catch { r = null; }
601
- if (!r || !r.ok) return;
602
- for (const p of P) DM[p] = r.docs[p] || { none: true };
603
- if (tab === 'docs') drawDocs();
715
+ // each document is read from its own product's workspace (All products lists every product's documents)
716
+ const here = M.board.ws || '', want = (list || V.docRows()).map((x) => ({ path: x.path, ws: x.ws || here })).filter((x) => x.path && !DM[x.ws + ':' + x.path]).slice(0, 40);
717
+ if (!want.length) return;
718
+ const by = new Map(); for (const x of want) { if (!by.has(x.ws)) by.set(x.ws, []); by.get(x.ws).push(x.path); }
719
+ let got = false;
720
+ for (const [ws, P] of by) {
721
+ let r = null; try { r = await (await fetch('/api/board-docs?ws=' + encodeURIComponent(ws) + '&paths=' + P.map(encodeURIComponent).join(','), { credentials: 'same-origin' })).json(); } catch { r = null; }
722
+ if (!r || !r.ok) continue;
723
+ for (const p of P) DM[ws + ':' + p] = r.docs[p] || { none: true };
724
+ got = true;
725
+ }
726
+ if (got && tab === 'docs') drawDocs();
604
727
  }
605
- const docMeta = (p) => { const d = DM[p]; return d && !d.none ? d : null; };
728
+ const docMeta = (p, ws) => { const d = DM[(ws || (M && M.board.ws) || '') + ':' + p]; return d && !d.none ? d : null; };
606
729
 
607
730
  /* ── the shell's bell sits before New initiative, as the design orders the tools; Escape closes a popover, then the panel ──────── */
608
731
  /* the ⋯ menu ("More: sources, archived, export" in AgBoard and BdHead): the Board adds Metrics and Cancelled and archived */
@@ -613,7 +736,7 @@ const docMeta = (p) => { const d = DM[p]; return d && !d.none ? d : null; };
613
736
  $$('#moreMenu [data-open]').forEach((b) => { b.onclick = () => { if (M) Acts.open[b.dataset.open]($('#moreBtn')); }; });
614
737
  }
615
738
  window.addEventListener('keydown', (e) => {
616
- if (e.key !== 'Escape' || document.querySelector('.pv-ov:not([hidden]), #moreMenu:not([hidden]), #crMenu:not([hidden]), #czMenu:not([hidden]), #bdPop:not([hidden])')) return;
739
+ if (e.key !== 'Escape' || document.querySelector('.pv-ov:not([hidden]), #moreMenu:not([hidden]), #crMenu:not([hidden]), #czMenu:not([hidden]), #bdPop:not([hidden]), #bdGrpMenu:not([hidden])')) return;
617
740
  if ($$('.bd-pop').some((p) => !p.hidden)) { closePops(true); return; }
618
741
  if (!$('#peek').hidden) closePeek();
619
742
  }, true);
@@ -643,21 +766,41 @@ function mergeTrail() {
643
766
  if (!t.you && it.you) { t.you = it.you.text; t.youWhy = it.you.why || ''; t.youKind = it.you.kind || 'you'; }
644
767
  }
645
768
  }
769
+ /** The boards the rows on screen come from: this one, or with All products every product's board, each with its rows' ids. */
770
+ function boardsRead(keep) {
771
+ const by = new Map();
772
+ for (const r of M.rows || []) {
773
+ if (!r.id || !r.track || !keep(r)) continue;
774
+ const ws = r.ws || M.board.ws || '', b = by.get(ws) || { ws, id: r.boardId || M.board.id, ids: [] };
775
+ if (!b.ids.includes(r.id)) b.ids.push(r.id);
776
+ by.set(ws, b);
777
+ }
778
+ return [...by.values()].map((b) => ({ ...b, ids: b.ids.slice(0, 150) }));
779
+ }
646
780
  async function loadTrail() {
647
- const ids = [...new Set((M.rows || []).filter((r) => r.id && r.track).map((r) => r.id))].slice(0, 150);
648
- if (!ids.length) return;
649
- const q = 'ws=' + encodeURIComponent(M.board.ws || '') + (M.board.id ? '&board=' + encodeURIComponent(M.board.id) : '') + '&ids=' + ids.map(encodeURIComponent).join(',');
650
- let r = null; try { r = await (await fetch('/api/board-trail?' + q, { credentials: 'same-origin' })).json(); } catch { r = null; }
651
- if (!r || !r.ok) { TR = TR || { usual: {}, themes: [], items: {}, failed: true }; return; }
652
- TR = r; mergeTrail(); draw();
781
+ const B = boardsRead(() => true);
782
+ if (!B.length) return;
783
+ let T = null;
784
+ for (const b of B) {
785
+ const q = 'ws=' + encodeURIComponent(b.ws) + (b.id ? '&board=' + encodeURIComponent(b.id) : '') + '&ids=' + b.ids.map(encodeURIComponent).join(',');
786
+ let r = null; try { r = await (await fetch('/api/board-trail?' + q, { credentials: 'same-origin' })).json(); } catch { r = null; }
787
+ if (!r || !r.ok) continue;
788
+ T = T ? { ...T, items: { ...T.items, ...r.items } } : r; // the usual days come from the first board read
789
+ }
790
+ if (!T) { TR = TR || { usual: {}, themes: [], items: {}, failed: true }; return; }
791
+ TR = T; mergeTrail(); draw();
653
792
  }
654
793
  /** The first questions still open (GET /api/board-grill?ids=): an initiative started on the Board shows "N questions before the BRD". */
655
794
  async function loadGrill() {
656
- const ids = [...new Set((M.rows || []).filter((r) => r.id && r.track && r.track.k <= 1).map((r) => r.id))].slice(0, 150);
657
- if (!ids.length) return;
658
- let r = null; try { r = await (await fetch('/api/board-grill?ws=' + encodeURIComponent(M.board.ws || '') + '&ids=' + ids.map(encodeURIComponent).join(','), { credentials: 'same-origin' })).json(); } catch { r = null; }
659
- if (!r || !r.ok) return;
660
- GR = r.items || {}; draw();
795
+ const B = boardsRead((r) => r.track.k <= 1);
796
+ if (!B.length) return;
797
+ let items = null;
798
+ for (const b of B) {
799
+ let r = null; try { r = await (await fetch('/api/board-grill?ws=' + encodeURIComponent(b.ws) + '&ids=' + b.ids.map(encodeURIComponent).join(','), { credentials: 'same-origin' })).json(); } catch { r = null; }
800
+ if (r && r.ok) items = { ...(items || {}), ...(r.items || {}) };
801
+ }
802
+ if (!items) return;
803
+ GR = items; draw();
661
804
  }
662
805
 
663
806
  function draw() {
@@ -684,10 +827,30 @@ function focusOnce() {
684
827
  const b = $$('#ibBody [data-key]').find((x) => x.dataset.key === r.key);
685
828
  openIni(r, b || null, 'track');
686
829
  }
687
- async function load() {
688
- 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('&');
830
+ /** One board's model (GET /api/board-premium); { r, status }. */
831
+ async function readBoard(q) {
689
832
  let r = null, status = 0;
690
833
  try { const res = await fetch('/api/board-premium' + (q ? '?' + q : ''), { credentials: 'same-origin' }); status = res.status; r = await res.json(); } catch { r = null; }
834
+ return { r, status };
835
+ }
836
+ /** All products: this board first, then every other product's board, merged into one model (pm/bd-prog.js mergeBoards). While any board
837
+ * is still reading, the answer is "reading"; a board that cannot be read is left out and named in the header, never guessed. */
838
+ async function readAll(q) {
839
+ const h = await readBoard(q);
840
+ if (!h.r || !h.r.ok || h.r.state === 'reading') return h;
841
+ const home = h.r.model, list = (home.board.switcher || []).filter((b) => !(b.ws === home.board.ws && b.id === home.board.id));
842
+ const got = await Promise.all(list.map((b) => readBoard('ws=' + encodeURIComponent(b.ws) + '&board=' + encodeURIComponent(b.id))));
843
+ if (got.some((g) => g.r && g.r.state === 'reading')) return { r: { state: 'reading' }, status: 200 };
844
+ const B = [{ ws: home.board.ws || '', id: home.board.id, name: home.board.name, model: home }];
845
+ const lost = [];
846
+ got.forEach((g, i) => { if (g.r && g.r.ok && g.r.model) B.push({ ...list[i], model: g.r.model }); else lost.push(list[i].name + ' board'); });
847
+ const model = PG.mergeBoards(B);
848
+ if (lost.length) { model.header.missing = [...model.header.missing, ...lost]; model.header.text += (/not read: /.test(model.header.text) ? ', ' : ' · not read: ') + lost.join(', '); }
849
+ return { r: { ok: true, model, stale: got.some((g) => g.r && g.r.stale) || h.r.stale }, status: 200 };
850
+ }
851
+ async function load() {
852
+ 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('&');
853
+ const { r, status } = ALL ? await readAll(q) : await readBoard(q);
691
854
  clearInterval(readTimer);
692
855
  if (r && r.state === 'reading') {
693
856
  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>`; };
@@ -702,16 +865,21 @@ async function load() {
702
865
  return;
703
866
  }
704
867
  M = r.model; draw();
705
- focusOnce();
868
+ focusOnce(); programOnce(); loadOthers();
706
869
  if (r.stale) setTimeout(load, 2000); // a press is still being derived: ask again
707
870
  else { loadTrail(); loadGrill(); }
708
871
  }
709
872
  const viewDoc = (path) => { const a = document.createElement('button'); a.dataset.doc = path; a.hidden = true; document.body.appendChild(a); a.click(); a.remove(); };
710
- const anchors = async () => { try { const r = await (await fetch('/api/boards/anchors?ws=' + encodeURIComponent(M.board.ws || '') + '&board=' + encodeURIComponent(M.board.id || ''), { credentials: 'same-origin' })).json(); return r && r.ok ? r.anchors || [] : []; } catch { return []; } };
873
+ const anchors = async (ws, board) => { try { const r = await (await fetch('/api/boards/anchors?ws=' + encodeURIComponent(ws || M.board.ws || '') + '&board=' + encodeURIComponent(board || M.board.id || ''), { credentials: 'same-origin' })).json(); return r && r.ok ? r.anchors || [] : []; } catch { return []; } };
711
874
  const openIniAny = (r) => openIni(r, $('#bdBell'), 'track');
712
- V.init({ M: () => M, statusOf, usual: usualOf, trail: TI, docMeta, sel: () => (peek && peek.kind !== 'acts' ? peek.key : null), docSel: () => Acts.docSel() });
713
- Asks.init({ M: () => M, load, say, panel: actsPanel, close: closePeek, rowOf, openIni: openIniAny, openDoc: viewDoc, anchors });
875
+ V.init({ M: () => M, statusOf, usual: usualOf, trail: TI, docMeta, sel: () => (peek && peek.kind !== 'acts' ? peek.key : null), docSel: () => Acts.docSel(),
876
+ groups: (L) => groups(L), folded: PG.folded, laneHead: (g) => PG.laneHtml(g, g.kind === 'program' ? progState(g.program) : null), subTile: (n) => PG.tileHtml(n, 'bd-ti s'),
877
+ memberIcon: (id) => PG.memberIcon(PGS, id), product: () => (M.board.product || M.board.name || ''), programOf: (r) => programOf(PGS, r.ws || M.board.ws || '', r.id), tileHtml: PG.tileHtml, progTile: PG.progTile });
878
+ Asks.init({ M: () => M, load, say, panel: actsPanel, close: closePeek, rowOf, openIni: openIniAny, openDoc: viewDoc, anchors, programs: () => PGS, reloadPrograms: loadPrograms });
714
879
  Acts.init({ M: () => M, load, say, panel: actsPanel, close: closePeek, redraw: () => { drawChips(); drawInit(); if (tab === 'docs') drawDocs(); }, F, rowOf, statusOf, openIni: openIniAny,
715
- openTicket: (ini, tk) => openTicket(ini, tk, $('#bdFind')), askHref, pageHref, trail: TI, docMeta, loadDocMeta, viewDoc });
880
+ openTicket: (ini, tk) => openTicket(ini, tk, $('#bdFind')), askHref, pageHref, trail: TI, docMeta, loadDocMeta, viewDoc,
881
+ grouping: () => ({ on: groupingOn(), byProduct }), setGrouping });
882
+ PP.mount({ M: () => M, programs: () => PGS, openIni: (id, from) => openIni((M.rows || []).find((x) => x.id === id && x.track), from, 'track'), close: closePeek, reload: loadPrograms, say }); // the program panel (PgProgram)
716
883
  setTab('ini');
717
884
  load();
885
+ loadPrograms();