create-pmos 0.412.0 → 0.413.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.
- package/package.json +13 -13
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/scripts/pmos-log.sh +6 -3
- package/payload/state/discoveries.md +1 -1
- package/workspace/board-programs-test.js +2 -2
- package/workspace/changelog.json +12 -0
- package/workspace/core-docs-workflow-test.js +144 -0
- package/workspace/guide/workflows.md +8 -1
- package/workspace/lib/board-premium.js +7 -2
- package/workspace/lib/briefing-premium-agent.js +16 -4
- package/workspace/lib/core-docs.js +79 -14
- package/workspace/lib/engine/boards.js +20 -12
- package/workspace/lib/initiative-chat.js +49 -0
- package/workspace/lib/initiative-premium.js +17 -7
- package/workspace/lib/item-cli.js +7 -2
- package/workspace/lib/plan-items.js +1 -1
- package/workspace/lib/pmos-verbs.js +1 -1
- package/workspace/lib/program-chat.js +1 -1
- package/workspace/lib/programs.js +21 -5
- package/workspace/lib/routes-boards.js +75 -13
- package/workspace/lib/routes-briefing-premium.js +17 -1
- package/workspace/lib/routes-core-docs.js +3 -1
- package/workspace/lib/routes-programs.js +12 -1
- package/workspace/lib/workflow-chat.js +1 -0
- package/workspace/lib/workflow-cli.js +91 -6
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-chat-line-test.js +9 -0
- package/workspace/premium-vw-item-test.js +3 -3
- package/workspace/premium-vw-jira-test.js +2 -1
- package/workspace/program-order-test.js +180 -0
- package/workspace/public/pm/bd-prog.js +3 -3
- package/workspace/public/pm/cozy-viewer.js +8 -3
- package/workspace/public/pm/goal-chat.js +1 -1
- package/workspace/public/pm/home-app.js +22 -8
- package/workspace/public/pm/home-chat.js +6 -1
- package/workspace/public/pm/home-ini-model.js +42 -29
- package/workspace/public/pm/home-ini.css +1 -0
- package/workspace/public/pm/home-ini.js +26 -34
- package/workspace/public/pm/home-list.js +2 -1
- package/workspace/public/pm/home-stage-card.js +3 -1
- package/workspace/public/pm/home-task.js +41 -65
- package/workspace/public/pm/home-today.js +7 -5
- package/workspace/public/pm/premium-board.js +12 -6
- package/workspace/public/pm/premium-initiative-head.js +21 -11
- package/workspace/public/pm/premium-viewer.js +1 -0
- package/workspace/public/pm/premium-vw-item-model.js +13 -7
- package/workspace/public/pm/premium-vw-item.js +49 -5
- package/workspace/public/pm/prog-order.css +47 -0
- package/workspace/public/pm/prog-order.js +188 -0
- package/workspace/public/pm/program-model.js +75 -0
- package/workspace/public/pm/task-card.css +108 -0
- package/workspace/public/pm/task-card.js +271 -0
- package/workspace/skills/workflow-setup.skill +14 -5
- package/workspace/stage-card-test.js +11 -0
- package/workspace/task-card-test.js +248 -0
- package/workspace/test-lists/core-documents-backend.json +15 -3
- package/workspace/test-lists/program-order.json +6 -0
- package/workspace/test-lists/task-card.json +6 -0
- package/workspace/test-lists/workflow-stage.json +5 -0
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { STEPS } from './premium-initiative-head.js';
|
|
14
14
|
import { whenOf } from './home-list.js';
|
|
15
15
|
import { ringHtml } from './home-line.js';
|
|
16
|
+
import { gripHtml, sugHtml } from './prog-order.js'; // a program's order: the grip and ✦ (canvas RoADrag, RoAPhone)
|
|
16
17
|
|
|
17
18
|
export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
18
19
|
export const P = {
|
|
@@ -78,7 +79,7 @@ export function chatHeadHtml(h) {
|
|
|
78
79
|
}
|
|
79
80
|
/** An initiative row: its mark, its title, the count of what is yours while it is folded, the stage track, and a chevron when something
|
|
80
81
|
* sits under it. The title opens the initiative; the chevron shows or hides its sessions, next steps, tasks and meetings. */
|
|
81
|
-
function iniHtml(r, o) {
|
|
82
|
+
function iniHtml(r, o, po) {
|
|
82
83
|
const open = o.isOpen(r.id);
|
|
83
84
|
const all = o.tasksOpen ? o.tasksOpen(r.id) : false, hid = r.kids.filter((k) => k.extra).length;
|
|
84
85
|
const kids = all ? r.kids : r.kids.filter((k) => !k.extra);
|
|
@@ -86,7 +87,7 @@ function iniHtml(r, o) {
|
|
|
86
87
|
const nest = open ? `<div class="hm-nest" role="group" aria-label="In ${esc(r.name)}">${kids.map((k) => rowHtml(k, { ...o, kid: true })).join('')}${more}</div>` : '';
|
|
87
88
|
const badge = !open && r.yours ? `<span class="hv-c" role="img" aria-label="${r.yours === 1 ? '1 is yours' : r.yours + ' are yours'}">${r.yours}</span>` : '';
|
|
88
89
|
const chev = r.kids.length ? `<button type="button" class="hv-xc" data-hm-kids="${esc(r.id)}" aria-expanded="${open}" aria-label="${open ? 'Hide' : 'Show'} what is in ${esc(r.name)}">${svg(open ? P.chevD : P.chevR, 15)}</button>` : '<span class="hv-xc" aria-hidden="true"></span>';
|
|
89
|
-
return `<div class="hm-r hv-r ini st-${esc(r.state)}${o.sel === r.id ? ' sel' : ''}" data-id="${esc(r.id)}"
|
|
90
|
+
return `<div class="hm-r hv-r ini st-${esc(r.state)}${o.sel === r.id ? ' sel' : ''}" data-id="${esc(r.id)}"${po ? ` data-po-id="${esc(r.ini || r.id)}"` : ''}>${po ? gripHtml(r.name) : ''}<button type="button" class="hm-rm" data-hm-sel="${esc(r.id)}"${o.sel === r.id ? ' aria-current="true"' : ''} title="${esc(r.hint)}">${markHtml(r.yours && r.state !== 'blocked' ? { state: 'needs' } : r)}`
|
|
90
91
|
+ `<span class="hm-rt"><b>${esc(r.name)}</b></span>${badge}${track(r.at, r.stage, r.steps)}</button>${chev}</div>${nest}`;
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -117,18 +118,19 @@ function productHtml(g, o) {
|
|
|
117
118
|
/** A program's group (canvas PgHomePhone, PgHomeDesk): above the products. Its header: the program tile, the name, the next milestone's
|
|
118
119
|
* diamond with its date and one small diamond per initiative it waits on (filled when that initiative is past the Deliver milestone), a chevron.
|
|
119
120
|
* The title opens the program in Home's Viewer with its own chat (canvas HbCProg); the chevron folds the group. Inside: the program's own tasks first, then a sub-heading
|
|
120
|
-
* per product with that product's initiatives
|
|
121
|
+
* per product with that product's initiatives, in the program's order (option A): the grip moves a row, a phone holds it then drags, and ✦
|
|
122
|
+
* in the open header offers Claude's order from the dates (prog-order.js). The blue dot still marks your turn; the row no longer jumps up. */
|
|
121
123
|
function programHtml(g, o) {
|
|
122
124
|
const open = o.pOpen(g);
|
|
123
125
|
const nx = g.st && g.st.next;
|
|
124
126
|
const ms = nx ? `<span class="hv-msd${nx.late ? ' late' : ''}"><span class="hv-dm"></span>${esc(nx.day || nx.name)}${nx.n ? `<span class="hv-rd">${Array.from({ length: nx.n }, (_, i) => `<i${i < nx.ready ? ' class="on"' : ''}></i>`).join('')}</span>` : ''}</span>` : '';
|
|
125
127
|
const line = nx ? 'Next milestone ' + nx.name + (nx.day ? ', ' + nx.day : '') + (nx.late ? ', late' : '') + (nx.n ? ', ' + nx.ready + ' of ' + nx.n + (nx.n === 1 ? ' initiative' : ' initiatives') + ' ready' : '') : 'No open milestone';
|
|
126
128
|
const head = `<div class="hv-gh hv-prg${open ? '' : ' closed'}${o.selHead === g.key ? ' sel' : ''}"><button type="button" class="hv-pt" data-hm-prog="${esc(g.program.id)}" aria-label="Open ${esc(g.name)}, a program"${o.selHead === g.key ? ' aria-current="true"' : ''}>`
|
|
127
|
-
+ `<span class="hv-tl tp" aria-hidden="true" data-cz-rail-tile="${esc(g.key)}" data-cz-rail-name="${esc(g.name)}">${svg(P.layers, 16)}${open ? '' : nd(g)}</span><b>${esc(g.name)}</b></button
|
|
129
|
+
+ `<span class="hv-tl tp" aria-hidden="true" data-cz-rail-tile="${esc(g.key)}" data-cz-rail-name="${esc(g.name)}">${svg(P.layers, 16)}${open ? '' : nd(g)}</span><b>${esc(g.name)}</b></button>${open && g.st ? sugHtml(g.program, g.st) : ''}`
|
|
128
130
|
+ `<button type="button" class="hv-pf" data-hm-pg="${esc(g.key)}" aria-expanded="${open}" aria-label="${esc(g.name)}. ${esc(line)}${g.yours ? '. ' + yoursWords(g) : ''}. ${open ? 'Close' : 'Open'} the group">${ms}<span class="hv-cv">${svg(open ? P.chevD : P.chevR, 16)}</span></button></div>`;
|
|
129
131
|
if (!open) return `<section class="hm-pg hv-g prg" aria-label="${esc(g.name)}">${head}</section>`;
|
|
130
132
|
const body = g.tasks.map((t) => rowHtml(t, o)).join('')
|
|
131
|
-
+ g.subs.map((x) => `<div class="hv-psub" role="heading" aria-level="3"><span class="hv-st2 t${x.tone}" aria-hidden="true">${esc(x.initials)}</span>${esc(x.name)}</div>${x.inis.map((r) => iniHtml(r, o)).join('')}
|
|
133
|
+
+ g.subs.map((x) => `<div class="hv-psub" role="heading" aria-level="3"><span class="hv-st2 t${x.tone}" aria-hidden="true">${esc(x.initials)}</span>${esc(x.name)}</div><div class="po-list" data-po-list="${esc(g.program.id)}">${x.inis.map((r) => iniHtml(r, o, true)).join('')}</div>`).join('');
|
|
132
134
|
return `<section class="hm-pg hv-g prg" aria-label="${esc(g.name)}">${head}<div class="hv-card">${body || `<p class="hm-none">${(g.program.members || []).length ? 'No open initiatives' : 'No initiatives yet'}. Open the program to move some in.</p>`}</div></section>`;
|
|
133
135
|
}
|
|
134
136
|
/** "Not in an initiative" (HvAC .lh): a line under the groups. Folded it shows a blue dot when a row waits on you, an amber square when one
|
|
@@ -31,6 +31,7 @@ import { programOf } from './program-model.js';
|
|
|
31
31
|
import { open as viewerOpen } from './cozy-viewer.js';
|
|
32
32
|
import * as VW from './cozy-viewer.js';
|
|
33
33
|
import * as PP from './bd-prog-panel.js';
|
|
34
|
+
import * as PO from './prog-order.js'; // the order of a program's initiatives: the grip and Claude's order from the dates (canvas RoADrag, RoASuggest)
|
|
34
35
|
import * as BI from './bd-ini-panel.js';
|
|
35
36
|
import { initiativeRename } from './rename-press.js';
|
|
36
37
|
import { setSay } from './cozy-xv.js';
|
|
@@ -328,7 +329,7 @@ function bandsHtml(r, t) {
|
|
|
328
329
|
return `<span class="${cls}" title="${esc(title)}">${i === at ? `<em>${esc(x.name)} · ${DAYS(t)}</em>` : ''}</span>`;
|
|
329
330
|
}).join('')}</div>`).join('');
|
|
330
331
|
}
|
|
331
|
-
function trackRow(r, cls = '') {
|
|
332
|
+
function trackRow(r, cls = '', po = false) {
|
|
332
333
|
const t = r.track || { k: -1, label: r.stage || 'No stage', output: '', segs: [], skipped: [] }, s = statusOf(r), pf = TK.mode === 'pf';
|
|
333
334
|
const S = pf ? M.steps : TK.steps || [];
|
|
334
335
|
const own = !pf && TK.mode === 'wf' ? WF.stagesOfRow(r) : null, cur = own ? WF.stageOfRow(r) : null;
|
|
@@ -338,13 +339,13 @@ function trackRow(r, cls = '') {
|
|
|
338
339
|
const cells = TK.mode === 'cats' ? bandsHtml(r, t) : S.map((st, j) => {
|
|
339
340
|
const cls = ['sc', j === 0 ? 'f0' : '', j === S.length - 1 ? 'l' : '', st.ms ? 'ms' : '', j < k ? 'p' : '', sk.has(j) ? 'k' : '', j === k ? 'c bg' : ''].filter(Boolean).join(' ');
|
|
340
341
|
const why = sk.has(j) && (pf ? (t.skipWhy || []).find((x) => x.stage === st.key) : ((own || []).find((y) => y.key === st.key) || {}).skipped);
|
|
341
|
-
const title = j === k ? dayTitle(t) : sk.has(j) ? st.label + ' skipped' + (why && why.why ? ': ' + why.why : '') : '';
|
|
342
|
+
const title = j === k ? dayTitle(t) : sk.has(j) ? st.label + ' skipped' + (why && why.why ? ': ' + why.why : '') : st.label + (j < k ? ' · done' : ''); // every bar names its stage on hover
|
|
342
343
|
const eta = E && E.j === j ? E : null;
|
|
343
344
|
const etaH = eta ? `<small class="eta${eta.late ? ' late' : ''}" title="${esc(eta.what + (eta.late ? ', passed' : ''))}">${esc(eta.text)}</small>` : '';
|
|
344
345
|
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>`;
|
|
345
346
|
}).join('');
|
|
346
347
|
const many = TK.mode === 'cats'; // All: each row names its workflow with its icon (WfATrack)
|
|
347
|
-
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)}"
|
|
348
|
+
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)}"${po ? ` data-po-id="${esc(r.id)}"` : ''}>${po ? PO.gripHtml(r.title) : ''}`
|
|
348
349
|
+ `<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) : ''}${many ? WF.wfIcon(WF.wfOf(r), 18) : ''}${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>`
|
|
349
350
|
+ `<div class="${cellsCls()}" role="presentation"${cellsStyle()}>${cells}</div>`
|
|
350
351
|
+ `<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>`;
|
|
@@ -378,8 +379,10 @@ function drawTrack(L) {
|
|
|
378
379
|
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 }; };
|
|
379
380
|
const rows = G ? G.map((g) => {
|
|
380
381
|
if (g.kind === 'program') {
|
|
381
|
-
|
|
382
|
-
|
|
382
|
+
// a program's rows follow its order (option A): each product's rows are one list the grip reorders (RoADrag)
|
|
383
|
+
const kids = PG.folded(g.key) ? '' : g.products.map((sub) => (g.products.length > 1 ? PG.subHtml(sub.name) : '') + `<div role="presentation" class="po-list" data-po-list="${esc(g.program.id)}">${sub.rows.map((r) => trackRow(r, ' bt-kid' + (r === g.rows[g.rows.length - 1] ? ' last' : ''), true)).join('')}</div>`).join('');
|
|
384
|
+
const st = progState(g.program);
|
|
385
|
+
return PG.bandHtml(g, st, { steps: S, plain: TK.mode !== 'pf', sug: PO.sugHtml(g.program, st) }) + kids;
|
|
383
386
|
}
|
|
384
387
|
if (PG.folded(g.key)) return PG.prodHtml(g);
|
|
385
388
|
const f = meFold(g.rows); inGroups += f.off.length;
|
|
@@ -555,7 +558,7 @@ async function loadOthers() {
|
|
|
555
558
|
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; }
|
|
556
559
|
const m = a && a.ok && a.model; if (!m) continue; // still reading, or not read: the member stays "missing", never guessed
|
|
557
560
|
const st = m.steps || [];
|
|
558
|
-
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 })) };
|
|
561
|
+
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, start: x.start || null, end: x.end || null })) };
|
|
559
562
|
}
|
|
560
563
|
if (Object.keys(XR).length) drawInit();
|
|
561
564
|
}
|
|
@@ -814,6 +817,9 @@ function renameIni(r) { return r && r.id ? initiativeRename({ pmPost, ws: r.ws |
|
|
|
814
817
|
say('Renamed', async () => { const u = await o.undo(); if (!u.ok) { say(u.error); return; } renamedOn([r.id], u.title); VW.retitle(BI.vidOf(r), u.title); load(); });
|
|
815
818
|
} }) : null; }
|
|
816
819
|
setSay(say);
|
|
820
|
+
PO.mount({ programs: () => PGS, stateOf: (p) => progState(p), say,
|
|
821
|
+
saved: (p) => { const i = PGS.findIndex((x) => x.id === p.id); if (i >= 0) PGS[i] = { ...PGS[i], ...p }; if (M) drawInit(); },
|
|
822
|
+
openIni: (id, from) => { const r = (M.rows || []).find((x) => x.id === id && x.track); if (r) openIni(r, from); } });
|
|
817
823
|
PP.mount({ M: () => M, programs: () => PGS, openIni: (id, from) => openIni((M.rows || []).find((x) => x.id === id && x.track), from), close: closePanel, reload: loadPrograms, say }); // the program panel (PgProgram)
|
|
818
824
|
setTab('ini');
|
|
819
825
|
load();
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* lifecycle steps with Deliver and Evaluate as milestones (◆), the previous step, the current one and the one it reaches next, what
|
|
7
7
|
* finishes the current step (done, you, agent, Jira, a person), the payoff line ("Then: ..."), the time in the stage, and one CTA.
|
|
8
8
|
*
|
|
9
|
-
* THE RULE (as lib/initiative-premium.js): every item comes from a field of a record.
|
|
10
|
-
*
|
|
9
|
+
* THE RULE (as lib/initiative-premium.js): every item comes from a field of a record. On Product feature the workflow engine's checks give
|
|
10
|
+
* the done and waiting items; on another workflow (D99) the current stage's To finish list and its output give them (scripts/workflows.js
|
|
11
|
+
* STAGE.finish, STAGE.output), and the engine's lane checks never show; the board's Jira tickets give the build item ("N of M tickets Done in Jira"); the engineers build in Jira, so the card
|
|
11
12
|
* never names a PMOS builder agent, a pull request or CI as the build story. A time in the stage shows only when a record holds one;
|
|
12
13
|
* otherwise the line gives the planned finish, or says the time is not recorded. */
|
|
13
14
|
|
|
@@ -65,13 +66,22 @@ export function headModel(M, now = Date.now()) {
|
|
|
65
66
|
const key = own ? (m.wfStage && m.wfStage.key) || null : stageKey(head.stage || acts.stage), at = key ? LIST.findIndex((s) => s.key === key) : -1;
|
|
66
67
|
const cur = at >= 0 ? LIST[at] : null, next = at >= 0 ? LIST[at + 1] || null : null, prev = at > 0 ? LIST[at - 1] : null;
|
|
67
68
|
const items = [];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
69
|
+
if (own) {
|
|
70
|
+
// another workflow (D99): what finishes its current stage is that stage's own To finish list and its output, in the PM's words. The
|
|
71
|
+
// workflow engine's lane checks (spec, contract, Review Gate) belong to Product feature and never show here (bug 2026-10-25).
|
|
72
|
+
const st = (m.wfStages || []).find((s) => m.wfStage && s.key === m.wfStage.key) || {};
|
|
73
|
+
for (const f of Array.isArray(st.finish) ? st.finish : []) if (f) items.push({ kind: 'agent', label: cap1(f) });
|
|
74
|
+
const o = st.output || {};
|
|
75
|
+
if (o.name && !items.some((x) => x.label.toLowerCase() === String(o.name).toLowerCase())) items.push({ kind: o.kind === 'signoff' ? 'you' : 'agent', label: o.kind === 'signoff' ? 'Your sign-off: ' + o.name : cap1(o.name) });
|
|
76
|
+
} else {
|
|
77
|
+
// the workflow engine's checks: done and waiting; Build and Quality are the engineers' (Jira below), so they are not listed as PMOS work
|
|
78
|
+
for (const c of m.checks || []) {
|
|
79
|
+
if (c.k === 'build' || c.k === 'quality') continue;
|
|
80
|
+
const say = STEP_SAY[c.k] || cap1(c.label);
|
|
81
|
+
if (c.state === 'done') items.push({ kind: 'done', label: say });
|
|
82
|
+
else if (c.state === 'blocked') items.push({ kind: 'risk', label: say + ' is blocked', note: c.owed || '' });
|
|
83
|
+
else if (c.state === 'pending' || c.state === 'current') items.push({ kind: YOU_STEPS.test(c.k) ? 'you' : 'agent', label: say, note: c.owed || '' });
|
|
84
|
+
}
|
|
75
85
|
}
|
|
76
86
|
// the build story is Jira's: the board's tickets for this initiative
|
|
77
87
|
const jira = ((m.tasks && m.tasks.rows) || []).filter((t) => /^Jira/.test(t.src || ''));
|
|
@@ -81,8 +91,8 @@ export function headModel(M, now = Date.now()) {
|
|
|
81
91
|
}
|
|
82
92
|
// the waiting record says who; a step that waits on the PM and is not in the list yet is added
|
|
83
93
|
const youWait = ov.who === 'Waits on you';
|
|
84
|
-
const step = String(ov.h || '').replace(/^Next: /, '');
|
|
85
|
-
if (youWait && step && !items.some((x) => x.kind === 'you')) items.push({ kind: 'you', label: STEP_SAY[step] || cap1(step) });
|
|
94
|
+
const step = own ? '' : String(ov.h || '').replace(/^Next: /, ''); // the engine's next step is Product feature's
|
|
95
|
+
if (!own && youWait && step && !items.some((x) => x.kind === 'you')) items.push({ kind: 'you', label: STEP_SAY[step] || cap1(step) });
|
|
86
96
|
const done = items.filter((x) => x.kind === 'done'), rest = items.filter((x) => x.kind !== 'done');
|
|
87
97
|
const life = acts.life || null;
|
|
88
98
|
const turn = rest.some((x) => x.kind === 'you') ? 'you' : life === 'hold' || life === 'cancelled' || rest.some((x) => x.kind === 'risk') ? 'stalled'
|
|
@@ -88,6 +88,7 @@ export function vwReopen() { if (!czLast) return false; czVw(czLast); return tru
|
|
|
88
88
|
function czVw(it) {
|
|
89
89
|
let el = null; czLast = it;
|
|
90
90
|
czOpen({ id: 'vw:' + it.id, kind: it.kind || it.title || 'Item', title: it.name || it.title || 'Item', icon: CZ_ICON[it.icon] || 'doc', url: it.url || '', rename: it.rename || null,
|
|
91
|
+
check: it.check || null, onPress: it.onPress, more: it.more, // a task's check box and its ⋯ (canvas XetX1Rest)
|
|
91
92
|
render: (body) => {
|
|
92
93
|
el = document.createElement('div'); el.className = 'obody vw'; el.dataset.vw = it.id; el.setAttribute('role', 'region'); body.append(el);
|
|
93
94
|
if (it.render) it.render(el); else el.innerHTML = it.html || '';
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* or a task tab, so a node test loads it with import(). Every line is a field of that model; a part the model does not hold is left out,
|
|
4
4
|
* and an answer that is still reading or failed is said as such. Every value is escaped here. */
|
|
5
5
|
|
|
6
|
+
import { cardHtml, taskOf } from './task-card.js';
|
|
7
|
+
|
|
6
8
|
export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
|
7
9
|
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
8
10
|
export const when = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
|
|
@@ -45,14 +47,18 @@ export function iniHtml(m, pageHref) {
|
|
|
45
47
|
return `<article class="paper doc vwi">${top}${kv(facts)}${sec('Next', next)}${sec('Watch', watch.length ? `<ul class="vwi-w">${watch.map((w) => `<li>${esc(w)}</li>`).join('')}</ul>` : '')}${sec('Checks', checks)}${sec('Tasks', tasks)}${sec('Links', linkHtml)}${miss}<p class="vwi-foot"><a class="vwi-go" href="${esc(pageHref)}">Open the initiative page</a></p></article>`;
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
/** The task tab. A task
|
|
49
|
-
|
|
50
|
+
/** The task tab. A PMOS task or a Jira ticket is the one task editor (task-card.js; canvas XetX1Rest, XetX1Jira): this is its first drawing,
|
|
51
|
+
* and premium-vw-item.js mounts the same card to edit it. A PRD requirement is read from the PRD and has nothing to edit. A task the model
|
|
52
|
+
* no longer holds says so. o: { groups, inis, owners, now } for the card's pickers. */
|
|
53
|
+
export function taskHtml(m, key, o = {}) {
|
|
50
54
|
const t = findTask(m, key);
|
|
51
55
|
if (!t) return `<article class="paper doc vwi"><p class="vwi-wait" role="status">This task is no longer on ${esc(m.title)}. It may have moved to another initiative or been removed.</p>${iniLink(m)}</article>`;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return `<article class="paper doc vwi
|
|
56
|
+
if (t.src === 'PRD requirement') {
|
|
57
|
+
const note = 'Read from the initiative’s PRD' + (m.tasks && m.tasks.basis && m.tasks.basis.source ? ' (' + m.tasks.basis.source + ')' : '') + '. The repository records no result for one requirement.';
|
|
58
|
+
return `<article class="paper doc vwi"><div class="vwi-head"><b>${esc(t.title)}</b></div><p class="vwi-p">${esc(note)}</p>${iniLink(m)}</article>`;
|
|
59
|
+
}
|
|
60
|
+
return `<article class="paper doc vwi vwi-tk">${cardHtml(cardTask(m, t), o)}</article>`;
|
|
57
61
|
}
|
|
62
|
+
/** A task row of the model as the card's task (task-card.js taskOf). */
|
|
63
|
+
export const cardTask = (m, row, group = '') => taskOf(row, { ini: m.id, iniTitle: m.title, group, board: m.board && m.board.id });
|
|
58
64
|
const iniLink = (m) => `<section class="vwi-s"><p class="label">Initiative</p><ul class="vwi-l"><li><button type="button" class="vwi-r" data-vwini="${esc(m.id)}"><span class="vwi-t"><b>${esc(m.title)}</b><small>${esc([m.head && m.head.statusLabel, m.lane, m.board && m.board.name].filter(Boolean).join(' · '))}</small></span></button></li></ul></section>`;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/* pm/premium-vw-item.js — an initiative or one of its tasks as a tab of the premium dialog's viewer (initiative premium-viewer, S7; PRD R9).
|
|
2
2
|
* openWorkItem({ kind: 'initiative', id, ws?, board? }) the record, the next step, the checks, the tasks and the links
|
|
3
|
-
* openWorkItem({ kind: 'task', ini, key, ws?, board? }) one task (key 'task:<uid>' or 'req:<id>')
|
|
3
|
+
* openWorkItem({ kind: 'task', ini, key, ws?, board? }) one task (key 'task:<uid>' or 'req:<id>'), edited in place with the one
|
|
4
|
+
* task editor (task-card.js; third feedback batch item 7), or a PRD
|
|
5
|
+
* requirement read from the PRD
|
|
4
6
|
* Both read GET /api/initiative-premium, the route the initiative page reads; the HTML comes from premium-vw-item-model.js. The route answers
|
|
5
7
|
* 'reading' while the board derives, and the tab asks again. Inside a tab a task opens its own tab and the initiative link opens the initiative's. */
|
|
6
8
|
import { vwOpen, vwStyle } from './premium-viewer.js';
|
|
7
|
-
import { esc, iniId, taskId, stateOf, readingHtml, errorHtml, iniHtml, taskHtml, findTask } from './premium-vw-item-model.js';
|
|
9
|
+
import { esc, iniId, taskId, stateOf, readingHtml, errorHtml, iniHtml, taskHtml, findTask, cardTask } from './premium-vw-item-model.js';
|
|
10
|
+
import { mountCard, boardSaver, checkOf, cardStyle, toastUndo } from './task-card.js';
|
|
11
|
+
import { pmPost } from './http.js';
|
|
12
|
+
import { setCheck } from './cozy-viewer.js';
|
|
8
13
|
|
|
9
14
|
const TRIES = 20, WAIT = 1500, KEEP = 30000;
|
|
10
15
|
const cache = new Map(); // query → { at, p }: two tabs of one initiative read once
|
|
@@ -34,24 +39,32 @@ export function openWorkItem(o) {
|
|
|
34
39
|
vwStyle('item');
|
|
35
40
|
const ctx = { id: o.kind === 'task' ? o.ini : o.id, ws: o.ws || '', board: o.board || '' };
|
|
36
41
|
if (!ctx.id) return null;
|
|
37
|
-
const isTask = o.kind === 'task';
|
|
42
|
+
const isTask = o.kind === 'task', editable = isTask && /^task:/.test(o.key || '');
|
|
43
|
+
if (editable) cardStyle();
|
|
44
|
+
const vid = isTask ? taskId(ctx.id, o.key) : iniId(ctx.id);
|
|
45
|
+
let card = null, cardT = null;
|
|
38
46
|
return vwOpen({
|
|
39
|
-
id:
|
|
47
|
+
id: vid,
|
|
40
48
|
title: o.title || (isTask ? 'Task' : 'Initiative'),
|
|
41
49
|
icon: isTask ? 'tk' : 'list',
|
|
42
50
|
rename: o.rename || null, // the Viewer's rename option, from the page that knows how to write it (rename-press.js)
|
|
51
|
+
check: editable ? { state: 'todo', label: 'Mark done' } : null, // the quick Done (canvas XetX1Rest); it follows the task once read
|
|
52
|
+
onPress: (act) => { if (act === 'check' && card && cardT && !cardT.jira) card.setStatus(cardT.status === 'Done' ? 'To do' : 'Done'); },
|
|
43
53
|
render(el) {
|
|
44
54
|
el.innerHTML = readingHtml(isTask ? 'the task' : 'the initiative');
|
|
45
55
|
read(ctx).then((s) => {
|
|
46
56
|
if (!el.isConnected) return;
|
|
47
57
|
if (s.state === 'reading') { el.innerHTML = readingHtml(isTask ? 'the task' : 'the initiative'); return; }
|
|
48
58
|
if (s.state === 'error') { el.innerHTML = errorHtml(isTask ? 'The task' : 'The initiative', s.error); return; }
|
|
49
|
-
el.innerHTML = isTask ? taskHtml(s.model, o.key) : iniHtml(s.model, pageHref(ctx));
|
|
50
59
|
el._vwi = s.model;
|
|
60
|
+
const row = isTask ? findTask(s.model, o.key) : null;
|
|
61
|
+
if (editable && row) { mountTask(el, s.model, row); return; }
|
|
62
|
+
el.innerHTML = isTask ? taskHtml(s.model, o.key) : iniHtml(s.model, pageHref(ctx));
|
|
51
63
|
});
|
|
52
64
|
},
|
|
53
65
|
wire(el) {
|
|
54
66
|
el.onclick = (e) => { // delegated on the tab's own pane
|
|
67
|
+
if (card) return; // the task editor wires its own presses
|
|
55
68
|
const m = el._vwi; if (!m) return;
|
|
56
69
|
const t = e.target.closest('[data-vwtask]');
|
|
57
70
|
if (t) { const row = findTask(m, t.dataset.vwtask); openWorkItem({ kind: 'task', ini: ctx.id, key: t.dataset.vwtask, title: row ? row.title : '', ws: ctx.ws, board: ctx.board }); return; }
|
|
@@ -59,6 +72,37 @@ export function openWorkItem(o) {
|
|
|
59
72
|
};
|
|
60
73
|
},
|
|
61
74
|
});
|
|
75
|
+
/* the one task editor: a PMOS task edits in place; a Jira ticket keeps Jira's fields and takes the PM's notes */
|
|
76
|
+
function mountTask(el, m, row) {
|
|
77
|
+
const ws = ctx.ws || (m.board && m.board.ws) || '', board = ctx.board || (m.board && m.board.id) || '';
|
|
78
|
+
const t = cardT = cardTask(m, row);
|
|
79
|
+
const lists = { inis: null, owners: null, groups: null };
|
|
80
|
+
const host = document.createElement('article'); host.className = 'paper doc vwi vwi-tk'; el.innerHTML = ''; el.append(host);
|
|
81
|
+
const check = () => { try { setCheck('vw:' + vid, checkOf(t)); } catch { /* the old dialog has no header check */ } };
|
|
82
|
+
card = mountCard(host, t, {
|
|
83
|
+
save: boardSaver({ ws, board, t, post: (p, b) => pmPost(p, b) }),
|
|
84
|
+
toast: toastUndo,
|
|
85
|
+
changed: () => { cache.clear(); check(); }, // the next read of the initiative sees the change
|
|
86
|
+
openIni: (id) => openWorkItem({ kind: 'initiative', id, title: id === m.id ? m.title : '', ws: ctx.ws, board: ctx.board }),
|
|
87
|
+
openTicket: (x) => import('./premium-vw-jira.js').then((J) => J.openTicket({ ws, board, initiative: x.ini, ref: x.jira.key })).catch(() => toastUndo('The ticket could not open.')),
|
|
88
|
+
iniTitleOf: (id) => ((lists.inis || []).find((x) => x.id === id) || {}).title || id,
|
|
89
|
+
inis: () => lists.inis || [], owners: () => lists.owners || [], groups: () => lists.groups,
|
|
90
|
+
});
|
|
91
|
+
check();
|
|
92
|
+
if (t.jira) return;
|
|
93
|
+
// the pickers' lists: the board's initiatives and owners, the initiative's groups (read once, after the card shows)
|
|
94
|
+
const q = (p) => fetch(p, { credentials: 'same-origin' }).then((r) => r.json()).catch(() => null);
|
|
95
|
+
const wq = ws ? '&ws=' + encodeURIComponent(ws) : '';
|
|
96
|
+
Promise.all([board ? q('/api/boards/items?board=' + encodeURIComponent(board) + wq) : null, q('/api/initiative-layout?initiative=' + encodeURIComponent(t.ini) + wq)]).then(([items, L]) => {
|
|
97
|
+
if (!host.isConnected) return;
|
|
98
|
+
if (items && items.ok) {
|
|
99
|
+
lists.inis = (items.initiatives || []).map((x) => ({ id: x.id, title: x.title }));
|
|
100
|
+
lists.owners = [...new Set((items.items || []).filter((x) => x.src === 'pmos' && x.owner).map((x) => x.owner))];
|
|
101
|
+
}
|
|
102
|
+
if (L && L.ok) { lists.groups = L.names || []; t.group = (L.of || {})[t.key] || ''; }
|
|
103
|
+
card.draw();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
62
106
|
}
|
|
63
107
|
|
|
64
108
|
/** The press a dialog's pane carries to open the initiative's full record as a tab. */
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* pm/prog-order.css — the order of a program's initiatives (pm/prog-order.js; canvas RoADrag, RoASuggest, RoAApplied, RoAPhone). Loaded once by
|
|
2
|
+
* prog-order.js mount, on the Board and on Home. Token variables only (cozy.css). */
|
|
3
|
+
:root { --po-prog: var(--bd-prog, rgb(91,79,176)); }
|
|
4
|
+
.po-grip { position: absolute; left: 18px; top: 50%; margin-top: -12px; width: 22px; height: 24px; border-radius: 7px; border: 0; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--cz-ink3); background: var(--cz-card); opacity: 0; cursor: grab; z-index: 2; touch-action: none; }
|
|
5
|
+
.po-grip svg { width: 16px; height: 16px; }
|
|
6
|
+
[data-po-id]:hover .po-grip, [data-po-id]:focus-within .po-grip, .po-lift .po-grip { opacity: 1; }
|
|
7
|
+
.po-grip:focus-visible { opacity: 1; outline: 2px solid var(--cz-blue); outline-offset: 1px; }
|
|
8
|
+
.po-lift { position: relative; z-index: 5; background: var(--cz-card); box-shadow: 0 18px 40px -16px rgba(42,46,53,.35), 0 0 0 1px var(--cz-hair); border-radius: 14px; }
|
|
9
|
+
.po-lift .po-grip { background: var(--cz-well); color: var(--cz-ink); cursor: grabbing; }
|
|
10
|
+
body.po-dragging, body.po-dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
|
|
11
|
+
.po-slot { grid-column: 1 / -1; height: 10px; margin: 4px 14px; border-radius: 6px; border: 1.5px dashed var(--cz-blue); background: var(--cz-bluebg); }
|
|
12
|
+
.po-list { display: contents; }
|
|
13
|
+
/* ✦ in the program header */
|
|
14
|
+
.po-sug { position: relative; width: 32px; height: 32px; border-radius: 10px; border: 0; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--po-prog); background: transparent; flex: none; cursor: pointer; }
|
|
15
|
+
.po-sug:hover { background: var(--cz-well); }
|
|
16
|
+
.po-sug:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
|
|
17
|
+
.po-sug svg { width: 17px; height: 17px; }
|
|
18
|
+
.po-nd { position: absolute; right: 4px; top: 4px; width: 7px; height: 7px; border-radius: 50%; background: var(--cz-blue); box-shadow: 0 0 0 2px var(--cz-card); }
|
|
19
|
+
.po-nd::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit; animation: po-info 6s ease-out infinite; }
|
|
20
|
+
@keyframes po-info { 0% { transform: scale(1); opacity: .25; } 35%, 100% { transform: scale(1.9); opacity: 0; } }
|
|
21
|
+
/* the suggestion */
|
|
22
|
+
.po-pop { position: fixed; z-index: 80; background: var(--cz-card); color: var(--cz-ink); border-radius: 20px; box-shadow: 0 30px 70px -24px rgba(42,46,53,.38), 0 0 0 1px var(--cz-hair); padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 10px; box-sizing: border-box; font-family: var(--cz-sans, inherit); max-height: calc(100vh - 24px); overflow: auto; }
|
|
23
|
+
.po-pop h4 { margin: 0; font-size: 14.5px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
|
|
24
|
+
.po-sp { color: var(--po-prog); display: inline-flex; }
|
|
25
|
+
.po-sp svg { width: 17px; height: 17px; }
|
|
26
|
+
.po-why { font-size: 12.5px; color: var(--cz-ink2); line-height: 1.45; margin: 0; }
|
|
27
|
+
.po-so { display: grid; grid-template-columns: 22px 1fr auto; gap: 2px 10px; align-items: center; padding: 8px 10px; border-radius: 12px; background: var(--cz-well); }
|
|
28
|
+
.po-so .n { font-size: 12px; font-weight: 800; color: var(--cz-ink3); text-align: center; }
|
|
29
|
+
.po-so b { font-size: 13px; font-weight: 800; min-width: 0; }
|
|
30
|
+
.po-so .dt { font-size: 12px; color: var(--cz-ink3); font-weight: 600; white-space: nowrap; }
|
|
31
|
+
.po-so .r { grid-column: 2 / -1; font-size: 11.5px; color: var(--cz-ink3); line-height: 1.35; }
|
|
32
|
+
.po-so.mv .n { color: var(--cz-blueink); }
|
|
33
|
+
.po-so.mv b::after { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--cz-blue); margin-left: 6px; vertical-align: 2px; }
|
|
34
|
+
.po-so.nod { background: transparent; border: 1.5px dashed var(--cz-hair); }
|
|
35
|
+
.po-adb { width: 26px; height: 26px; border-radius: 8px; border: 0; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--cz-blueink); background: var(--cz-bluebg); cursor: pointer; }
|
|
36
|
+
.po-adb svg { width: 15px; height: 15px; }
|
|
37
|
+
.po-acts { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }
|
|
38
|
+
.po-ib { width: 36px; height: 36px; border-radius: 999px; border: 0; padding: 0; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--cz-ink2); background: var(--cz-well); }
|
|
39
|
+
.po-ib svg { width: 17px; height: 17px; }
|
|
40
|
+
.po-ib.ok { background: var(--cz-ink); color: var(--cz-card); }
|
|
41
|
+
.po-ib:focus-visible, .po-adb:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
|
|
42
|
+
/* Home: the grip sits on the row's mark */
|
|
43
|
+
.hv-card .po-grip { left: 4px; }
|
|
44
|
+
/* a phone: no grip; hold the row, then drag (RoAPhone) */
|
|
45
|
+
@media (hover: none) { .po-grip { display: none; } .po-lift .po-grip { display: inline-flex; left: auto; right: 8px; opacity: 1; } }
|
|
46
|
+
body.cz-home .hv-r.po-lift { background: var(--cz-card); box-shadow: 0 18px 40px -14px rgba(42,46,53,.38), 0 0 0 1px var(--cz-hair); z-index: 5; }
|
|
47
|
+
@media (prefers-reduced-motion: reduce) { .po-nd::after { animation: none; } }
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/* pm/prog-order.js — the order of a program's initiatives (feedback batch 3 item 5, option A agreed 2026-10-25; canvas RoADrag, RoASuggest,
|
|
2
|
+
* RoAApplied, RoAPhone). One order per program, saved on the program (POST /api/programs/order, lib/programs.js `order` line); the Board, the
|
|
3
|
+
* program page and Home all list the initiatives in it (program-model.js inOrder).
|
|
4
|
+
*
|
|
5
|
+
* gripHtml(title) the drag grip of one row (shows on hover; the row lifts while it moves)
|
|
6
|
+
* sugHtml(p, st) ✦ in the program header: Claude's order from the dates. '' when the dates agree with the order (zero is silence);
|
|
7
|
+
* a blue dot while the PM has not said "not now" to these dates
|
|
8
|
+
* mount(o) once per page. o: { programs() GET /api/programs' list, stateOf(p) programState, saved(program) after a write (the page
|
|
9
|
+
* puts the program in its list and draws again), say(msg, undo) the page's toast, openIni(id, from) for Add dates }
|
|
10
|
+
*
|
|
11
|
+
* THE PAGE'S MARKUP: a container [data-po-list="<program id>"] holds the rows [data-po-id="<initiative id>"] of that program shown here (a product
|
|
12
|
+
* sub-list on a multi-product Board is its own container). The ✦ button is [data-po-sug="<program id>"].
|
|
13
|
+
* Desktop: drag by the grip. Phone: hold the row, then drag. Keyboard: Alt + ↑ or ↓ moves the focused row. Escape puts a lifted row back.
|
|
14
|
+
* Only the PM changes the order: every write is a page press. Claude suggests; ✓ applies it, Undo is in the toast, ✕ is "not now" until a
|
|
15
|
+
* date changes (remembered in this browser, pmos.order.notnow). */
|
|
16
|
+
import { pmPost } from './http.js';
|
|
17
|
+
import { fullOrder, moveTo, suggestOrder } from './program-model.js';
|
|
18
|
+
|
|
19
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
20
|
+
const SV = (d, w = 2) => `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${w}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`;
|
|
21
|
+
const GRIP = 'M9 6h.01M9 12h.01M9 18h.01M15 6h.01M15 12h.01M15 18h.01';
|
|
22
|
+
const SPARK = 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8zM18 15l.7 1.8 1.8.7-1.8.7L18 20l-.7-1.8-1.8-.7 1.8-.7z';
|
|
23
|
+
const X = 'M6 6l12 12M18 6L6 18', OK = 'M5 12l5 5 9-10', CAL = 'M4 6h16v14H4zM4 10h16M8 3v4M16 3v4M12 13v5M9.5 15.5h5';
|
|
24
|
+
const CSS = '/pm/prog-order.css';
|
|
25
|
+
|
|
26
|
+
/* ── "not now", per program, until a date changes ── */
|
|
27
|
+
const NN_KEY = 'pmos.order.notnow';
|
|
28
|
+
const notNow = () => { try { return JSON.parse(localStorage.getItem(NN_KEY) || '{}') || {}; } catch { return {}; } };
|
|
29
|
+
const setNotNow = (id, sig) => { const m = notNow(); m[id] = sig; try { localStorage.setItem(NN_KEY, JSON.stringify(m)); } catch { /* no storage: the dot comes back on reload */ } };
|
|
30
|
+
|
|
31
|
+
export const gripHtml = (title) => `<button type="button" class="po-grip" data-po-grip aria-label="Move ${esc(title)}. Drag, or press Alt and an arrow key" title="Drag to move">${SV(GRIP, 2.6)}</button>`;
|
|
32
|
+
|
|
33
|
+
export function sugHtml(p, st) {
|
|
34
|
+
const S = suggestOrder(st, p);
|
|
35
|
+
if (!S.differs) return '';
|
|
36
|
+
const dot = notNow()[p.id] !== S.sig;
|
|
37
|
+
return `<button type="button" class="po-sug" data-po-sug="${esc(p.id)}" aria-haspopup="dialog" aria-label="Claude suggests an order from the dates${dot ? '. The dates disagree with the order' : ''}" title="Claude suggests an order from the dates">${SV(SPARK, 1.8)}${dot ? '<span class="po-nd" aria-hidden="true"></span>' : ''}</button>`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let O = null;
|
|
41
|
+
const progOf = (id) => ((O && O.programs()) || []).find((p) => p && p.id === id) || null;
|
|
42
|
+
const idsIn = (list) => [...list.querySelectorAll('[data-po-id]')].filter((r) => r.closest('[data-po-list]') === list).map((r) => r.dataset.poId);
|
|
43
|
+
|
|
44
|
+
/** Saves the order; o.saved draws it. Returns the answer ({ ok, was, program } or { ok: false, error }). */
|
|
45
|
+
async function save(p, order) {
|
|
46
|
+
const r = await pmPost('/api/programs/order', { program: p.id, order }).catch(() => null);
|
|
47
|
+
if (!r || !r.ok) { O.say((r && r.error) || 'The order was not saved.'); return r || { ok: false }; }
|
|
48
|
+
if (r.program) O.saved(r.program);
|
|
49
|
+
return r;
|
|
50
|
+
}
|
|
51
|
+
/** The whole order after one id moves before another of the ids shown in `list` (null: after the last one shown). */
|
|
52
|
+
function moved(p, list, id, before) {
|
|
53
|
+
const shown = idsIn(list), st = O.stateOf(p);
|
|
54
|
+
const all = fullOrder(p, [...new Set(((st && st.inis) || []).map((i) => i.id).concat(shown))], (x) => ((st && st.inis) || []).find((i) => i.id === x)?.title || x);
|
|
55
|
+
// "after the last one shown": before whatever follows it in the whole order, so a row not shown here keeps its place after it
|
|
56
|
+
const tgt = before != null ? before : (() => { const last = shown.filter((x) => x !== id).pop(); const k = all.indexOf(last); return k >= 0 && k + 1 < all.length ? all[k + 1] : null; })();
|
|
57
|
+
return { all, next: moveTo(all, id, tgt === id ? null : tgt) };
|
|
58
|
+
}
|
|
59
|
+
const same = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
60
|
+
|
|
61
|
+
/* ── drag ── */
|
|
62
|
+
let D = null; // { row, list, p, id, y0, slot }
|
|
63
|
+
function slotAt(y) {
|
|
64
|
+
const rows = [...D.list.querySelectorAll('[data-po-id]')].filter((r) => r !== D.row && r.closest('[data-po-list]') === D.list);
|
|
65
|
+
for (const r of rows) { const b = r.getBoundingClientRect(); if (y < b.top + b.height / 2) return r; }
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
function mark(y) {
|
|
69
|
+
const t = slotAt(y);
|
|
70
|
+
D.before = t ? t.dataset.poId : null;
|
|
71
|
+
if (!D.slot) { D.slot = document.createElement('div'); D.slot.className = 'po-slot'; D.slot.setAttribute('aria-hidden', 'true'); }
|
|
72
|
+
if (t) t.before(D.slot); else { const rows = [...D.list.querySelectorAll('[data-po-id]')].filter((r) => r.closest('[data-po-list]') === D.list); const last = rows[rows.length - 1]; let end = last; while (end && end.nextElementSibling && !end.nextElementSibling.matches('[data-po-id]') && end.nextElementSibling.closest('[data-po-list]') === D.list && end.nextElementSibling.parentElement === last.parentElement) end = end.nextElementSibling; (end || last).after(D.slot); }
|
|
73
|
+
D.row.style.transform = `translateY(${Math.round(y - D.y0) - 6}px)`;
|
|
74
|
+
}
|
|
75
|
+
function start(row, y) {
|
|
76
|
+
const list = row.closest('[data-po-list]'), p = list && progOf(list.dataset.poList);
|
|
77
|
+
if (!p) return false;
|
|
78
|
+
D = { row, list, p, id: row.dataset.poId, y0: y, before: undefined, slot: null };
|
|
79
|
+
row.classList.add('po-lift'); list.classList.add('po-on'); document.body.classList.add('po-dragging');
|
|
80
|
+
mark(y);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
async function finish(cancel) {
|
|
84
|
+
if (!D) return;
|
|
85
|
+
const d = D; D = null;
|
|
86
|
+
d.row.classList.remove('po-lift'); d.row.style.transform = ''; d.list.classList.remove('po-on'); document.body.classList.remove('po-dragging');
|
|
87
|
+
if (d.slot) d.slot.remove();
|
|
88
|
+
if (cancel || d.before === undefined) return;
|
|
89
|
+
const { all, next } = moved(d.p, d.list, d.id, d.before);
|
|
90
|
+
if (same(all, next)) return;
|
|
91
|
+
await save(d.p, next);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/* ── ✦: Claude's order from the dates ── */
|
|
95
|
+
let POP = null;
|
|
96
|
+
function closePop(focus) {
|
|
97
|
+
if (!POP) return;
|
|
98
|
+
const b = POP.btn; POP.el.remove(); POP = null;
|
|
99
|
+
if (focus && b && b.isConnected) b.focus();
|
|
100
|
+
}
|
|
101
|
+
function openPop(btn) {
|
|
102
|
+
const p = progOf(btn.dataset.poSug); if (!p) return;
|
|
103
|
+
closePop();
|
|
104
|
+
const st = O.stateOf(p), S = suggestOrder(st, p);
|
|
105
|
+
const el = document.createElement('div');
|
|
106
|
+
el.className = 'po-pop'; el.setAttribute('role', 'dialog'); el.setAttribute('aria-label', 'Suggested order');
|
|
107
|
+
el.innerHTML = `<h4><span class="po-sp">${SV(SPARK, 1.8)}</span>Order by dates</h4><p class="po-why">${esc(S.why)}</p>`
|
|
108
|
+
+ S.rows.map((r) => `<div class="po-so${r.moved ? ' mv' : ''}${r.none ? ' nod' : ''}"><span class="n">${r.n}</span><b>${esc(r.title)}</b>`
|
|
109
|
+
+ (r.none ? `<button type="button" class="po-adb" data-po-dates="${esc(r.id)}" aria-label="Add dates to ${esc(r.title)}" title="Add dates">${SV(CAL, 1.8)}</button>` : `<span class="dt">${esc(r.range)}</span>`)
|
|
110
|
+
+ `<span class="r">${esc(r.reason)}</span></div>`).join('')
|
|
111
|
+
+ `<div class="po-acts"><button type="button" class="po-ib soft" data-po-no aria-label="Not now. Claude asks again only when a date changes" title="Not now">${SV(X, 1.8)}</button>`
|
|
112
|
+
+ `<button type="button" class="po-ib ok" data-po-use aria-label="Use this order" title="Use this order">${SV(OK, 2)}</button></div>`;
|
|
113
|
+
document.body.appendChild(el);
|
|
114
|
+
const b = btn.getBoundingClientRect(), w = Math.min(420, window.innerWidth - 24);
|
|
115
|
+
el.style.width = w + 'px';
|
|
116
|
+
el.style.left = Math.max(12, Math.min(window.innerWidth - w - 12, b.right - w)) + 'px';
|
|
117
|
+
el.style.top = Math.min(b.bottom + 8, Math.max(12, window.innerHeight - el.offsetHeight - 12)) + 'px';
|
|
118
|
+
POP = { el, btn, p, S };
|
|
119
|
+
el.querySelector('[data-po-use]').focus();
|
|
120
|
+
el.addEventListener('click', async (e) => {
|
|
121
|
+
if (e.target.closest('[data-po-no]')) { setNotNow(p.id, S.sig); const id = p.id; closePop(); O.saved(progOf(id) || p); return; }
|
|
122
|
+
const ad = e.target.closest('[data-po-dates]');
|
|
123
|
+
if (ad) { closePop(); if (O.openIni) O.openIni(ad.dataset.poDates, btn); return; }
|
|
124
|
+
if (e.target.closest('[data-po-use]')) {
|
|
125
|
+
const st2 = O.stateOf(p);
|
|
126
|
+
const all = fullOrder(p, ((st2 && st2.inis) || []).map((i) => i.id));
|
|
127
|
+
// the suggested ids first, then any initiative not read here, where it was
|
|
128
|
+
const next = S.ids.concat(all.filter((id) => !S.ids.includes(id)));
|
|
129
|
+
closePop();
|
|
130
|
+
const r = await save(p, next);
|
|
131
|
+
if (r && r.ok) O.say('Ordered by dates · Board, program page and Home', async () => { const u = await save(progOf(p.id) || p, r.was || []); return u; });
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function mount(o) {
|
|
137
|
+
O = o;
|
|
138
|
+
if (!document.querySelector(`link[href="${CSS}"]`)) { const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = CSS; document.head.appendChild(l); }
|
|
139
|
+
if (mount.on) return;
|
|
140
|
+
mount.on = true;
|
|
141
|
+
let hold = null; // a phone's hold: { row, x, y, t }
|
|
142
|
+
document.addEventListener('pointerdown', (e) => {
|
|
143
|
+
if (e.button !== 0) return;
|
|
144
|
+
const g = e.target.closest('[data-po-grip]');
|
|
145
|
+
if (g && e.pointerType !== 'touch') { const row = g.closest('[data-po-id]'); if (row && start(row, e.clientY)) { e.preventDefault(); g.setPointerCapture && g.setPointerCapture(e.pointerId); } return; }
|
|
146
|
+
if (e.pointerType === 'touch') {
|
|
147
|
+
const row = e.target.closest('[data-po-id]');
|
|
148
|
+
if (!row || !row.closest('[data-po-list]')) return;
|
|
149
|
+
hold = { row, x: e.clientX, y: e.clientY, t: setTimeout(() => { if (hold && start(hold.row, hold.y)) { hold.on = true; if (navigator.vibrate) navigator.vibrate(10); } }, 420) };
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
document.addEventListener('pointermove', (e) => {
|
|
153
|
+
if (hold && !hold.on && Math.hypot(e.clientX - hold.x, e.clientY - hold.y) > 8) { clearTimeout(hold.t); hold = null; }
|
|
154
|
+
if (D) mark(e.clientY);
|
|
155
|
+
});
|
|
156
|
+
// a touch that lifted a row drags it, not the page
|
|
157
|
+
document.addEventListener('touchmove', (e) => { if (D) e.preventDefault(); }, { passive: false });
|
|
158
|
+
const up = () => {
|
|
159
|
+
if (hold) { if (hold.on) { document.body.dataset.poJust = '1'; setTimeout(() => { delete document.body.dataset.poJust; }, 400); } clearTimeout(hold.t); hold = null; }
|
|
160
|
+
if (D) finish(false);
|
|
161
|
+
};
|
|
162
|
+
document.addEventListener('pointerup', up);
|
|
163
|
+
document.addEventListener('pointercancel', () => { if (hold) { clearTimeout(hold.t); hold = null; } if (D) finish(true); });
|
|
164
|
+
// the press that ends a hold-drag is not a tap on the row
|
|
165
|
+
document.addEventListener('click', (e) => { if (document.body.dataset.poJust) { delete document.body.dataset.poJust; e.preventDefault(); e.stopPropagation(); } }, true);
|
|
166
|
+
document.addEventListener('contextmenu', (e) => { if (D || (hold && hold.on)) e.preventDefault(); });
|
|
167
|
+
document.addEventListener('keydown', async (e) => {
|
|
168
|
+
if (e.key === 'Escape') { if (D) { e.stopPropagation(); finish(true); return; } if (POP) { e.stopPropagation(); closePop(true); return; } }
|
|
169
|
+
if (!e.altKey || (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')) return;
|
|
170
|
+
const row = e.target.closest && e.target.closest('[data-po-id]'), list = row && row.closest('[data-po-list]'), p = list && progOf(list.dataset.poList);
|
|
171
|
+
if (!p) return;
|
|
172
|
+
e.preventDefault();
|
|
173
|
+
const shown = idsIn(list), k = shown.indexOf(row.dataset.poId), to = e.key === 'ArrowUp' ? k - 1 : k + 1;
|
|
174
|
+
if (k < 0 || to < 0 || to >= shown.length) return;
|
|
175
|
+
const { all, next } = moved(p, list, row.dataset.poId, e.key === 'ArrowUp' ? shown[to] : shown[to + 1] ?? null);
|
|
176
|
+
if (same(all, next)) return;
|
|
177
|
+
const id = row.dataset.poId, grip = !!e.target.closest('[data-po-grip]');
|
|
178
|
+
const r = await save(p, next);
|
|
179
|
+
// the focus stays on the row that moved, in its new place
|
|
180
|
+
if (r && r.ok) { const n = document.querySelector(`[data-po-list="${CSS_ESC(p.id)}"] [data-po-id="${CSS_ESC(id)}"]`); const f = n && (grip ? n.querySelector('[data-po-grip]') : n.querySelector('button:not([data-po-grip])')); if (f) f.focus(); }
|
|
181
|
+
});
|
|
182
|
+
document.addEventListener('click', (e) => {
|
|
183
|
+
const s = e.target.closest('[data-po-sug]');
|
|
184
|
+
if (s) { e.preventDefault(); e.stopPropagation(); if (POP && POP.btn === s) closePop(); else openPop(s); return; }
|
|
185
|
+
if (POP && !e.target.closest('.po-pop')) closePop();
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
const CSS_ESC = (s) => (window.CSS && window.CSS.escape ? window.CSS.escape(s) : String(s).replace(/"/g, '\\"'));
|