create-pmos 0.401.0 → 0.403.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 +25 -30
- package/payload/KIT-VERSION +2 -2
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/board-programs-test.js +227 -0
- package/workspace/board-shot.js +54 -0
- package/workspace/briefing-premium-adddoc-test.js +28 -22
- package/workspace/briefing-premium-board-test.js +107 -82
- package/workspace/briefing-premium-calendar-2-test.js +23 -10
- package/workspace/briefing-premium-calendar-3-test.js +23 -19
- package/workspace/briefing-premium-calendar-test.js +20 -15
- package/workspace/briefing-premium-initiative-test.js +25 -12
- package/workspace/briefing-premium-insights-test.js +31 -18
- package/workspace/briefing-premium-metrics-test.js +8 -8
- package/workspace/briefing-premium-sources-test.js +15 -10
- package/workspace/briefing-premium-test.js +39 -16
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/board-premium-facts.js +20 -3
- package/workspace/fixtures/briefing-premium-facts.js +18 -2
- package/workspace/fixtures/premium-viewer-fixtures.js +24 -2
- package/workspace/fixtures/program-ascent.js +101 -0
- package/workspace/guide/home.md +11 -7
- package/workspace/guide/index.md +1 -0
- package/workspace/guide/jira.md +38 -6
- package/workspace/guide/programs.md +37 -0
- package/workspace/home-rows-test.js +184 -0
- package/workspace/lib/briefing-premium-products.js +4 -4
- package/workspace/lib/briefing-premium.js +2 -2
- package/workspace/lib/calendar-layers.js +8 -4
- package/workspace/lib/initiative-layout.js +4 -3
- package/workspace/lib/jira-cli.js +17 -12
- package/workspace/lib/jira-status.js +1 -1
- package/workspace/lib/jira-tickets.js +126 -24
- package/workspace/lib/meeting-files.js +58 -0
- package/workspace/lib/meeting-learn.js +139 -0
- package/workspace/lib/meeting-material.js +12 -5
- package/workspace/lib/notes.js +3 -0
- package/workspace/lib/programs.js +129 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-brief-page.js +8 -1
- package/workspace/lib/routes-briefing-premium.js +1 -1
- package/workspace/lib/routes-calendar-views.js +24 -3
- package/workspace/lib/routes-meeting-material.js +38 -0
- package/workspace/lib/routes-meeting-points.js +23 -3
- package/workspace/lib/routes-programs.js +122 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +31 -25
- package/workspace/premium-chat-context-test.js +1 -1
- package/workspace/premium-chat-goal-view-test.js +1 -1
- package/workspace/premium-chat-viewer-test.js +1 -1
- package/workspace/premium-core-doc-issue-test.js +13 -7
- package/workspace/premium-discuss-landing-test.js +83 -0
- package/workspace/premium-link-suggest-test.js +103 -0
- package/workspace/premium-report-read-test.js +86 -82
- package/workspace/premium-vw-backlog-test.js +6 -5
- package/workspace/premium-vw-cal-test.js +45 -19
- package/workspace/premium-vw-item-test.js +8 -6
- package/workspace/premium-vw-jira-test.js +3 -2
- package/workspace/premium-vw-meet-test.js +122 -66
- package/workspace/premium-vw-notes-test.js +7 -6
- package/workspace/premium-vw-rec-test.js +14 -13
- package/workspace/premium-vw-slides-test.js +11 -5
- package/workspace/program-panel-test.js +152 -0
- package/workspace/public/pm/bd-acts.js +24 -15
- package/workspace/public/pm/bd-asks.js +111 -30
- package/workspace/public/pm/bd-ini-panel.js +229 -0
- package/workspace/public/pm/bd-pop.js +2 -2
- package/workspace/public/pm/bd-prog-panel.js +436 -0
- package/workspace/public/pm/bd-prog.js +191 -0
- package/workspace/public/pm/bd-span.js +98 -15
- package/workspace/public/pm/bd-views.js +93 -29
- package/workspace/public/pm/cozy-board.css +214 -20
- package/workspace/public/pm/cozy-evui.js +4 -2
- package/workspace/public/pm/cozy-home-rows.css +54 -0
- package/workspace/public/pm/cozy-home.css +35 -0
- package/workspace/public/pm/cozy-insights.css +1 -2
- package/workspace/public/pm/cozy-mtg-present.css +160 -0
- package/workspace/public/pm/cozy-panel.css +155 -0
- package/workspace/public/pm/cozy-rec-pill.css +12 -0
- package/workspace/public/pm/cozy-rec-pill.js +46 -0
- package/workspace/public/pm/cozy-today.css +189 -0
- package/workspace/public/pm/cozy-viewer.js +307 -43
- package/workspace/public/pm/cozy-vw-mtg.css +96 -94
- package/workspace/public/pm/cozy-vw-rp.css +40 -25
- package/workspace/public/pm/cozy-vw-shell.css +127 -0
- package/workspace/public/pm/cozy-xv.css +51 -0
- package/workspace/public/pm/cozy-xv.js +34 -0
- package/workspace/public/pm/home-app.js +192 -72
- package/workspace/public/pm/home-chat.js +17 -4
- package/workspace/public/pm/home-data.js +1 -1
- package/workspace/public/pm/home-day.js +64 -0
- package/workspace/public/pm/home-ini-model.js +1 -1
- package/workspace/public/pm/home-ini.js +197 -54
- package/workspace/public/pm/home-list.js +100 -27
- package/workspace/public/pm/home-mentions.js +187 -0
- package/workspace/public/pm/home-rec-row.js +67 -0
- package/workspace/public/pm/home-review.js +20 -10
- package/workspace/public/pm/home-task.js +19 -18
- package/workspace/public/pm/home-today.js +137 -59
- package/workspace/public/pm/premium-board.js +294 -288
- package/workspace/public/pm/premium-insights.js +118 -82
- package/workspace/public/pm/premium-mtg-present.js +408 -100
- package/workspace/public/pm/premium-mtg-replay.js +70 -10
- package/workspace/public/pm/premium-report-read.js +118 -63
- package/workspace/public/pm/premium-vw-cal.js +62 -34
- package/workspace/public/pm/premium-vw-mtg.js +348 -192
- package/workspace/public/pm/program-model.js +192 -0
- package/workspace/public/pm/rec-state.js +63 -0
- package/workspace/public/pm/rp-parts.js +33 -8
- package/workspace/public/pm/tk-draft.js +107 -0
- package/workspace/public/pm/tk-model.js +134 -0
- package/workspace/public/pm/tk-send.js +124 -0
- package/workspace/public/pm/tk-tasks.css +120 -0
- package/workspace/public/premium-board.html +4 -2
- package/workspace/server.js +4 -2
- package/workspace/skills/jira-push.skill +3 -3
- package/workspace/test-lists/board-programs.json +9 -0
- package/workspace/test-lists/prd-to-jira.json +6 -0
- package/workspace/test-lists/program-hierarchy.json +11 -0
- package/workspace/test-lists/program-panel.json +9 -0
- package/workspace/test-lists/viewer-home-rows.json +9 -0
- package/workspace/test-lists/viewer-meetings.json +9 -0
- package/workspace/test-lists/viewer-shell-a.json +15 -0
- package/workspace/tk-tasks-test.js +199 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/* pm/program-model.js — what a program shows, derived from its initiatives (initiative program-hierarchy, P2, P8, P9; canvas PgModel, PgBoard,
|
|
2
|
+
* PgBoardProduct, PgProgram, PgMilestones, PgTimeline, PgKanban, PgList, PgHomePhone). PURE: no page, no fetch; a node test imports it.
|
|
3
|
+
*
|
|
4
|
+
* programState(p, rowsOf, now) { state, spread, span, products, inis, missing, milestones, next, tasks, openTasks }
|
|
5
|
+
* programOf(programs, ws, ini) the program an initiative of a workspace is in, or null
|
|
6
|
+
* milestoneTrack(st, cap) { done, shown, more, next, doneN } the panel's track: a done cluster, `cap` shown, an "N more" cluster (PgProgram)
|
|
7
|
+
* milestoneGroups(st) [{ key, label, items }] Done / Next / Later, the Milestones tab (PgMilestones)
|
|
8
|
+
* mergeClose(milestones, days) [{ first, n, items, label, range }] milestones within `days` of the first merge into one counted diamond (PgTimeline)
|
|
9
|
+
* goalsByPeriod(st, krsOf, now) { current, periods, earlier } the program's goals from its initiatives' KR anchors, per year half (PgProgram)
|
|
10
|
+
* groupRows(rows, programs, o) [group] programs first, then one group per product (Home, Board, Kanban, Timeline, List)
|
|
11
|
+
*
|
|
12
|
+
* p is one program of GET /api/programs (lib/programs.js merge): { id, title, home, owner, goal, target, milestones, members: [{ ws, initiative }], tasks }.
|
|
13
|
+
* rowsOf(ws) answers { name, rows } for a product: its name and its initiatives' rows (the Board model's rows, each with id, title, stage).
|
|
14
|
+
* A program has no stage ladder of its own (PM, 2026-10-23). Everything below comes from its initiatives' stages:
|
|
15
|
+
* · state Shaping while no initiative is past Triage, Closing once every initiative is at Monitor or later, Running otherwise
|
|
16
|
+
* · spread the first and last stage its initiatives are at
|
|
17
|
+
* · products the products its initiatives are in, in the order they first appear
|
|
18
|
+
* · a milestone is ready when every initiative it waits on is past ◆ Deliver; "n of m ready" counts them
|
|
19
|
+
* · a milestone that waits on no initiative is a program check: it is done when the PM marked it done (lib/programs.js `check` lines)
|
|
20
|
+
* · span the program's own start and target ("Sep 2026 to Jun 2028"), which can be longer than any initiative
|
|
21
|
+
* A member whose initiative no read row holds is listed as `missing`, never guessed. */
|
|
22
|
+
import { STEPS, stageKey } from './premium-initiative-head.js';
|
|
23
|
+
|
|
24
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
25
|
+
const at = (stage) => { const k = stageKey(stage); return k ? STEPS.findIndex((s) => s.key === k) : -1; };
|
|
26
|
+
const DELIVER = STEPS.findIndex((s) => s.key === 'deliver');
|
|
27
|
+
const MONITOR = STEPS.findIndex((s) => s.key === 'monitor');
|
|
28
|
+
const dayOf = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
29
|
+
export const shortDay = (iso) => { const d = dayOf(iso); return d ? MON[d.getMonth()] + ' ' + d.getDate() : ''; };
|
|
30
|
+
|
|
31
|
+
export function programOf(programs, ws, ini) {
|
|
32
|
+
return (programs || []).find((p) => (p.members || []).some((m) => m.initiative === ini && (!m.ws || !ws || m.ws === ws))) || null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function programState(p, rowsOf, now = Date.now()) {
|
|
36
|
+
const inis = [], missing = [], products = [];
|
|
37
|
+
for (const m of (p && p.members) || []) {
|
|
38
|
+
const got = rowsOf ? rowsOf(m.ws) : null;
|
|
39
|
+
const row = got && (got.rows || []).find((r) => r && r.id === m.initiative);
|
|
40
|
+
if (!row) { missing.push(m); continue; }
|
|
41
|
+
const product = (got && got.name) || '';
|
|
42
|
+
if (product && !products.includes(product)) products.push(product);
|
|
43
|
+
inis.push({ ws: m.ws, id: row.id, title: row.title || row.id, stage: row.stage || '', at: at(row.stage), product, row });
|
|
44
|
+
}
|
|
45
|
+
const idx = inis.map((i) => i.at).filter((i) => i >= 0);
|
|
46
|
+
const lo = idx.length ? Math.min(...idx) : -1, hi = idx.length ? Math.max(...idx) : -1;
|
|
47
|
+
const state = !idx.length || hi <= 0 ? 'Shaping' : lo >= MONITOR ? 'Closing' : 'Running';
|
|
48
|
+
const spread = idx.length ? { from: STEPS[lo].label, to: STEPS[hi].label, lo, hi } : null;
|
|
49
|
+
const today = new Date(now); today.setHours(0, 0, 0, 0);
|
|
50
|
+
const milestones = ((p && p.milestones) || []).map((m) => {
|
|
51
|
+
const check = !(m.waits || []).length;
|
|
52
|
+
const waits = (m.waits || []).map((id) => inis.find((i) => i.id === id)).filter(Boolean);
|
|
53
|
+
const ready = waits.filter((i) => i.at > DELIVER).length;
|
|
54
|
+
// a milestone whose initiatives are all unread is neither a check nor done: it waits on what no row says
|
|
55
|
+
const done = check ? m.done === true : waits.length > 0 && ready === waits.length && waits.length === m.waits.length;
|
|
56
|
+
const d = dayOf(m.date);
|
|
57
|
+
return { id: m.id, name: m.name, date: m.date || '', day: shortDay(m.date), waits: waits.map((i) => i.id), titles: waits.map((i) => i.title), n: waits.length, ready,
|
|
58
|
+
check, done, late: !!(d && d < today && !done) };
|
|
59
|
+
});
|
|
60
|
+
const next = milestones.filter((m) => !m.done).sort((a, b) => String(a.date || '9999').localeCompare(String(b.date || '9999')))[0] || null;
|
|
61
|
+
const tasks = ((p && p.tasks) || []);
|
|
62
|
+
return { id: p && p.id, title: (p && p.title) || '', state, spread, span: spanOf(p), products, inis, missing, milestones, next, tasks, openTasks: tasks.filter((t) => !t.done) };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const monthYear = (iso) => { const d = dayOf(iso); return d ? MON[d.getMonth()] + ' ' + d.getFullYear() : ''; };
|
|
66
|
+
/** The program's span: { start, target, label } — "Sep 2026 to Jun 2028", "from Sep 2026", "to Jun 2028", or '' when neither is set. */
|
|
67
|
+
export function spanOf(p) {
|
|
68
|
+
const a = monthYear(p && p.start), b = monthYear(p && p.target);
|
|
69
|
+
return { start: (p && p.start) || '', target: (p && p.target) || '', label: a && b ? (a === b ? a : a + ' to ' + b) : a ? 'from ' + a : b ? 'to ' + b : '' };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* ── milestones (PgProgram, PgMilestones, PgTimeline, PgKanban) ── */
|
|
73
|
+
const byDate = (a, b) => String(a.date || '9999').localeCompare(String(b.date || '9999'));
|
|
74
|
+
/** The panel's track (PgProgram): the last done milestone stays in view as where the program is, then the open ones from the next, `cap` in
|
|
75
|
+
* all; the earlier done ones fold into the done cluster and the later open ones into "N more". Both clusters open the Milestones tab. */
|
|
76
|
+
export function milestoneTrack(st, cap = 3) {
|
|
77
|
+
const all = ((st && st.milestones) || []).slice().sort(byDate);
|
|
78
|
+
const done = all.filter((m) => m.done), open = all.filter((m) => !m.done);
|
|
79
|
+
// with open milestones the last done one is kept in view (cap 1 shows only the next); with none open, the last `cap` done ones
|
|
80
|
+
const keep = !done.length ? 0 : open.length ? (cap > 1 ? 1 : 0) : Math.min(cap, done.length);
|
|
81
|
+
const room = Math.max(0, cap - keep);
|
|
82
|
+
const shown = done.slice(done.length - keep).concat(open.slice(0, room));
|
|
83
|
+
return { done: done.slice(0, done.length - keep), shown, more: open.slice(room), next: open[0] || null, doneN: done.length };
|
|
84
|
+
}
|
|
85
|
+
/** Done / Next / Later (PgMilestones): done newest first, the next one, the rest by date. A group with nothing in it is left out. */
|
|
86
|
+
export function milestoneGroups(st) {
|
|
87
|
+
const all = ((st && st.milestones) || []).slice().sort(byDate);
|
|
88
|
+
const done = all.filter((m) => m.done).reverse(), open = all.filter((m) => !m.done);
|
|
89
|
+
return [['done', 'Done', done], ['next', 'Next', open.slice(0, 1)], ['later', 'Later', open.slice(1)]].filter(([, , L]) => L.length).map(([key, label, items]) => ({ key, label, items }));
|
|
90
|
+
}
|
|
91
|
+
const DAY = 86400000;
|
|
92
|
+
/** A cluster's dates: "Nov 18", "Nov 18–21", "Nov 28–Dec 2". Month and day only: the time axis says the year. */
|
|
93
|
+
function rangeOf(a, b) {
|
|
94
|
+
const x = dayOf(a), y = dayOf(b);
|
|
95
|
+
if (!x) return '';
|
|
96
|
+
if (!y || +x === +y) return shortDay(a);
|
|
97
|
+
return x.getMonth() === y.getMonth() && x.getFullYear() === y.getFullYear() ? shortDay(a) + '–' + y.getDate() : shortDay(a) + '–' + shortDay(b);
|
|
98
|
+
}
|
|
99
|
+
/** Milestones that sit within `days` of a cluster's first one merge into one diamond with a count (PgTimeline "Pilot live +2 · Nov 18–21").
|
|
100
|
+
* A milestone with no date is left out: it has no place on a time axis. Each cluster: { first, n, items, label, range, date, end, done, late }. */
|
|
101
|
+
export function mergeClose(milestones, days = 7) {
|
|
102
|
+
const L = (milestones || []).filter((m) => m && dayOf(m.date)).slice().sort(byDate);
|
|
103
|
+
const out = [];
|
|
104
|
+
for (const m of L) {
|
|
105
|
+
const c = out[out.length - 1];
|
|
106
|
+
if (c && Math.round((dayOf(m.date) - dayOf(c.first.date)) / DAY) <= days) c.items.push(m); else out.push({ first: m, items: [m] });
|
|
107
|
+
}
|
|
108
|
+
return out.map((c) => {
|
|
109
|
+
const n = c.items.length, end = c.items[n - 1].date;
|
|
110
|
+
return { first: c.first, n, items: c.items, label: c.first.name + (n > 1 ? ' +' + (n - 1) : ''), range: rangeOf(c.first.date, end), date: c.first.date, end,
|
|
111
|
+
done: c.items.every((m) => m.done), late: c.items.some((m) => m.late) };
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/* ── goals (PgProgram goal row) ── */
|
|
116
|
+
/** A KR anchor's period → its year half: q1/q2 → H1, q3/q4 → H2, h1/h2 as written, a bare year → H2 (it ends with the year). */
|
|
117
|
+
export function halfOf(period) {
|
|
118
|
+
const s = String(period || '').toLowerCase().trim();
|
|
119
|
+
let m = /^q([1-4])[-_ ]?(\d{4})$/.exec(s) || /^(\d{4})[-_ ]?q([1-4])$/.exec(s);
|
|
120
|
+
if (m) { const [q, y] = /^q/.test(s) ? [+m[1], +m[2]] : [+m[2], +m[1]]; return { key: y + '-h' + (q <= 2 ? 1 : 2), label: 'H' + (q <= 2 ? 1 : 2) + ' ' + y }; }
|
|
121
|
+
m = /^h([12])[-_ ]?(\d{4})$/.exec(s) || /^(\d{4})[-_ ]?h([12])$/.exec(s);
|
|
122
|
+
if (m) { const [h, y] = /^h/.test(s) ? [m[1], m[2]] : [m[2], m[1]]; return { key: y + '-h' + h, label: 'H' + h + ' ' + y }; }
|
|
123
|
+
m = /^(?:fy|y)?(\d{4})$/.exec(s);
|
|
124
|
+
if (m) return { key: m[1] + '-h2', label: 'H2 ' + m[1] };
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
/** "q3-2026:o2:kr1" → { period: 'q3-2026', kr: 'KR 2.1' }; any other anchor (health:<id>, a name) → null. */
|
|
128
|
+
export function krOf(anchor) {
|
|
129
|
+
const m = /^([a-z0-9-]+):([a-z0-9-]+):([a-z0-9-]+)$/i.exec(String(anchor || '').trim().split(/\s/)[0]);
|
|
130
|
+
if (!m || /^health$/i.test(m[1])) return null;
|
|
131
|
+
const o = /^o(\d+)$/i.exec(m[2]), k = /^kr-?(\w+)$/i.exec(m[3]);
|
|
132
|
+
return { period: m[1].toLowerCase(), anchor: m[1].toLowerCase() + ':' + m[2].toLowerCase() + ':' + m[3].toLowerCase(), kr: o && k ? 'KR ' + o[1] + '.' + k[1].toUpperCase() : m[3].toUpperCase() };
|
|
133
|
+
}
|
|
134
|
+
/** The program's goals: the KRs its initiatives anchor to, once each, with the products whose initiatives move them, grouped by year half.
|
|
135
|
+
* krsOf(anchor, ini) → { name?, kr?, period?, met? } | null is what the page knows of a KR (its name, and whether it is met); a KR it does not
|
|
136
|
+
* know is still listed by its id. The half holding `now` comes first, the later halves after it; the earlier halves fold into ONE chip
|
|
137
|
+
* { label (the latest earlier half), n, met, periods }. A health anchor is a budget, not a goal: it is left out. */
|
|
138
|
+
export function goalsByPeriod(st, krsOf, now = Date.now()) {
|
|
139
|
+
const by = new Map();
|
|
140
|
+
for (const i of (st && st.inis) || []) {
|
|
141
|
+
const a = i.row && (i.row.anchor || i.row.parent_kr);
|
|
142
|
+
const k = krOf(a); if (!k) continue;
|
|
143
|
+
const info = (krsOf && krsOf(k.anchor, i)) || {};
|
|
144
|
+
const half = halfOf(info.period || k.period); if (!half) continue;
|
|
145
|
+
const g = by.get(k.anchor) || { anchor: k.anchor, kr: info.kr || k.kr, name: info.name || '', met: info.met === true, products: [], inis: [], half };
|
|
146
|
+
if (i.product && !g.products.includes(i.product)) g.products.push(i.product);
|
|
147
|
+
g.inis.push(i.id);
|
|
148
|
+
by.set(k.anchor, g);
|
|
149
|
+
}
|
|
150
|
+
const d = new Date(now), cur = d.getFullYear() + '-h' + (d.getMonth() < 6 ? 1 : 2);
|
|
151
|
+
const halves = new Map();
|
|
152
|
+
for (const g of by.values()) { const h = halves.get(g.half.key) || { key: g.half.key, label: g.half.label, goals: [] }; h.goals.push(g); halves.set(g.half.key, h); }
|
|
153
|
+
const list = [...halves.values()].sort((a, b) => a.key.localeCompare(b.key));
|
|
154
|
+
for (const h of list) h.goals.sort((a, b) => String(a.products[0] || '').localeCompare(String(b.products[0] || '')) || a.kr.localeCompare(b.kr, undefined, { numeric: true }));
|
|
155
|
+
const before = list.filter((h) => h.key < cur), periods = list.filter((h) => h.key >= cur);
|
|
156
|
+
const earlier = before.length ? { label: before[before.length - 1].label, n: before.reduce((s, h) => s + h.goals.length, 0), met: before.reduce((s, h) => s + h.goals.filter((g) => g.met).length, 0), periods: before } : null;
|
|
157
|
+
return { current: periods.length && periods[0].key === cur ? periods[0].label : '', periods, earlier };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* ── grouping (PgHomePhone, PgBoard, PgBoardProduct, PgKanban, PgTimeline, PgList) ── */
|
|
161
|
+
/** The shared grouping of initiative rows. Programs first, each with its products as sub-groups in the order their rows first appear, then one
|
|
162
|
+
* group per product with the rows no program holds. Each row appears once; there is no "Not in a program" group; a group with no row is left out.
|
|
163
|
+
* o.byProduct: product groups only, a program's row copied with { inProgram: id } (PgBoardProduct's layers icon).
|
|
164
|
+
* o.productOf(row) → the product's name (default row.product, else row.ws, else o.product); o.wsOf(row) → its workspace (default row.ws, else o.ws).
|
|
165
|
+
* Group: { kind: 'program', key: 'g:<id>', program, products: [{ name, rows }], rows } | { kind: 'product', key: 'p:<name>', name, rows }. */
|
|
166
|
+
export function groupRows(rows, programs, o = {}) {
|
|
167
|
+
const productOf = o.productOf || ((r) => r.product || r.ws || o.product || '');
|
|
168
|
+
const wsOf = o.wsOf || ((r) => r.ws || o.ws || '');
|
|
169
|
+
const live = (programs || []).filter((p) => p && !p.archived);
|
|
170
|
+
const progOf = (r) => programOf(live, wsOf(r), r.id);
|
|
171
|
+
const seen = new Set(), list = [];
|
|
172
|
+
for (const r of rows || []) { if (!r || seen.has(r)) continue; seen.add(r); list.push(r); }
|
|
173
|
+
const prods = [], prodRows = new Map();
|
|
174
|
+
const put = (name, r) => { if (!prodRows.has(name)) { prodRows.set(name, []); prods.push(name); } prodRows.get(name).push(r); };
|
|
175
|
+
if (o.byProduct) {
|
|
176
|
+
for (const r of list) { const p = progOf(r); put(productOf(r), p ? { ...r, inProgram: p.id } : r); }
|
|
177
|
+
return prods.map((name) => ({ kind: 'product', key: 'p:' + name, name, rows: prodRows.get(name) }));
|
|
178
|
+
}
|
|
179
|
+
const inProg = new Map();
|
|
180
|
+
for (const r of list) {
|
|
181
|
+
const p = progOf(r);
|
|
182
|
+
if (!p) { put(productOf(r), r); continue; }
|
|
183
|
+
const g = inProg.get(p.id) || { kind: 'program', key: 'g:' + p.id, program: p, products: [], rows: [] };
|
|
184
|
+
const name = productOf(r);
|
|
185
|
+
let sub = g.products.find((x) => x.name === name);
|
|
186
|
+
if (!sub) g.products.push((sub = { name, rows: [] }));
|
|
187
|
+
sub.rows.push(r); g.rows.push(r);
|
|
188
|
+
inProg.set(p.id, g);
|
|
189
|
+
}
|
|
190
|
+
const progs = live.map((p) => inProg.get(p.id)).filter(Boolean);
|
|
191
|
+
return progs.concat(prods.map((name) => ({ kind: 'product', key: 'p:' + name, name, rows: prodRows.get(name) })));
|
|
192
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* pm/rec-state.js — is a meeting recording now? One answer for every page (Viewer kit, meetings: the pinned row on Home, XvARecHome;
|
|
2
|
+
* the pill on Board and Insights, XvARecBoard).
|
|
3
|
+
*
|
|
4
|
+
* recState({ fresh }) → Promise<State> the recording now, read from GET /api/notes (kept 5 s unless fresh)
|
|
5
|
+
* onRecording(fn) → unsubscribe fn(State) now and on each change; while someone listens the page reads again every 10 s
|
|
6
|
+
* announce() a page that just started, paused, resumed or stopped a recording asks for a fresh read
|
|
7
|
+
* EVENT = 'cz:recording' the same State, as a CustomEvent on document, on each change
|
|
8
|
+
* window.czRecording = { state: recState, on: onRecording }
|
|
9
|
+
*
|
|
10
|
+
* State = { on, paused, id, title, startedAt, elapsedMs, href, here }
|
|
11
|
+
* on a note is recording or paused (false: no recording; every other field is then empty)
|
|
12
|
+
* paused it is paused (nothing is kept until it resumes)
|
|
13
|
+
* startedAt ms when this stretch of the meeting clock started, so a page can tick it: elapsed = elapsedMs + (Date.now() - readAt)
|
|
14
|
+
* elapsedMs the meeting time heard so far, at readAt
|
|
15
|
+
* href where the recording is shown: Home with the meeting open (/premium.html?meeting=<note id>)
|
|
16
|
+
* here this page holds the recorder (premium-meeting.js sets window.__premiumHolding)
|
|
17
|
+
* The answer comes from the notes the server keeps, so a page that did not start the recording still knows of it. Nothing is written. */
|
|
18
|
+
import { pmGet } from './http.js';
|
|
19
|
+
|
|
20
|
+
export const EVENT = 'cz:recording';
|
|
21
|
+
const OFF = Object.freeze({ on: false, paused: false, id: '', title: '', startedAt: 0, elapsedMs: 0, readAt: 0, href: '', here: false });
|
|
22
|
+
let last = null, lastAt = 0, inflight = null, timer = null;
|
|
23
|
+
const subs = new Set();
|
|
24
|
+
const same = (a, b) => !!a && !!b && a.on === b.on && a.paused === b.paused && a.id === b.id && a.title === b.title;
|
|
25
|
+
|
|
26
|
+
/** The State of the note list (pure). rows: GET /api/notes .notes */
|
|
27
|
+
export function stateOf(rows, now = Date.now(), holding = null) {
|
|
28
|
+
const live = (Array.isArray(rows) ? rows : []).filter((n) => n && (n.state === 'recording' || n.state === 'paused'));
|
|
29
|
+
if (!live.length) return { ...OFF, readAt: now };
|
|
30
|
+
const n = live.find((x) => x.state === 'recording') || live[0];
|
|
31
|
+
const el = Math.max(0, Number(n.meeting_ms) || 0);
|
|
32
|
+
return { on: true, paused: n.state === 'paused', id: String(n.id), title: String((n.meeting && n.meeting.title) || n.title || 'Meeting'), startedAt: n.state === 'recording' ? now - el : 0,
|
|
33
|
+
elapsedMs: el, readAt: now, href: '/premium.html?meeting=' + encodeURIComponent(n.id), here: !!(holding && holding.id === n.id) };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function recState({ fresh = false } = {}) {
|
|
37
|
+
if (!fresh && last && Date.now() - lastAt < 5000) return last;
|
|
38
|
+
if (!inflight) inflight = pmGet('/api/notes').then((r) => {
|
|
39
|
+
const s = stateOf(r && r.ok ? r.notes : [], Date.now(), typeof window !== 'undefined' ? window.__premiumHolding : null);
|
|
40
|
+
const changed = !same(s, last);
|
|
41
|
+
last = s; lastAt = Date.now();
|
|
42
|
+
if (changed) emit(s);
|
|
43
|
+
return s;
|
|
44
|
+
}).catch(() => last || { ...OFF }).finally(() => { inflight = null; });
|
|
45
|
+
return inflight;
|
|
46
|
+
}
|
|
47
|
+
function emit(s) {
|
|
48
|
+
for (const fn of subs) { try { fn(s); } catch { /* one listener does not stop the rest */ } }
|
|
49
|
+
try { document.dispatchEvent(new CustomEvent(EVENT, { detail: s })); } catch { /* no document */ }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function onRecording(fn) {
|
|
53
|
+
if (typeof fn !== 'function') return () => {};
|
|
54
|
+
subs.add(fn);
|
|
55
|
+
recState().then((s) => { if (subs.has(fn)) { try { fn(s); } catch { /* the listener's own */ } } });
|
|
56
|
+
if (!timer && typeof setInterval === 'function') timer = setInterval(() => { if (typeof document === 'undefined' || !document.hidden) recState({ fresh: true }); }, 10000);
|
|
57
|
+
return () => { subs.delete(fn); if (!subs.size && timer) { clearInterval(timer); timer = null; } };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A recording was started, paused, resumed or stopped on this page: read again now. */
|
|
61
|
+
export function announce() { return recState({ fresh: true }); }
|
|
62
|
+
|
|
63
|
+
if (typeof window !== 'undefined') window.czRecording = { state: recState, on: onRecording, EVENT };
|
|
@@ -9,6 +9,9 @@
|
|
|
9
9
|
* paperModel(W, o) · paperHtml(P) the report as a paper document, cut into pages (RpDoc)
|
|
10
10
|
* liveModel(m, o) · liveHtml(L, s) the report as a live page, from GET /api/insights-premium (RpLive)
|
|
11
11
|
* presentHtml(o) the full-screen presenting view (RpPhone Present, MtPresent's strip)
|
|
12
|
+
* reportSummary(o) the summary card on top of a report in Viewer shell A (XvAReport, XvAReportDoc): one line, the
|
|
13
|
+
* words, the meta and the one primary (Issue a draft, Share an issued cycle, Bring back an archived one);
|
|
14
|
+
* cozy-viewer.js czSummary draws it
|
|
12
15
|
*
|
|
13
16
|
* THE RULE (as the premium models): every number, date and chip comes from a field of a record. Where a record is silent the part says so or
|
|
14
17
|
* is left out; nothing is filled with a guess. */
|
|
@@ -166,18 +169,40 @@ export function paperModel(W, o = {}) {
|
|
|
166
169
|
});
|
|
167
170
|
return { eye, title: (W && W.title) || o.name || 'Report', minute, pages, foot, n: pages.length };
|
|
168
171
|
}
|
|
169
|
-
/** The paper as html: one sheet per page
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return `<div class="rp-paperwell"
|
|
173
|
-
+ `<button type="button" class="rp-linkbtn" data-r="dlm" aria-haspopup="menu">Download as PDF or Word</button></div>`
|
|
174
|
-
+ P.pages.map((pg, i) => `<article class="rp-pg" data-pg="${i + 1}" aria-label="Page ${i + 1} of ${P.n}">`
|
|
172
|
+
/** The paper as html: one sheet per page, then "Page n of N" said once under the sheets (Viewer shell A, XvAReportDoc). The summary card
|
|
173
|
+
* over it says the state, and Download is under ⋯, so there is no bar over the sheets. */
|
|
174
|
+
export function paperHtml(P) {
|
|
175
|
+
return `<div class="rp-paperwell">` + P.pages.map((pg, i) => `<article class="rp-pg" data-pg="${i + 1}" aria-label="Page ${i + 1} of ${P.n}">`
|
|
175
176
|
+ (i === 0 ? `<p class="rp-eye">${esc(P.eye)}</p><h1>${esc(P.title)}</h1>${P.minute ? `<div class="rp-minute"><p class="rp-mh">In one minute</p>${P.minute}</div>` : ''}` : '')
|
|
176
177
|
+ pg.map((b) => b.html).join('')
|
|
177
|
-
+ (i === P.n - 1 && P.foot ? `<div class="rp-fn">${P.foot}</div>` : '')
|
|
178
|
-
|
|
178
|
+
+ (i === P.n - 1 && P.foot ? `<div class="rp-fn">${P.foot}</div>` : '') + '</article>').join('')
|
|
179
|
+
+ `</div><p class="rp-count" data-rp-page aria-live="polite">Page 1 of ${P.n}</p>`;
|
|
179
180
|
}
|
|
180
181
|
|
|
182
|
+
/* ── the summary card (Viewer shell A: XvAReport, XvAReportDoc) ── */
|
|
183
|
+
/**
|
|
184
|
+
* The summary on top of a report: { line, tone, text, meta, primary: { r, label } }. Every part comes from the records the reader read;
|
|
185
|
+
* a part with no source is left out (zero is silence). o = {
|
|
186
|
+
* state 'draft'|'issued'|'archived' · slot 'YYYY-MM-DD' · purpose (the template's) · sub (the file's subtitle) · schedule (schedLabel, or '')
|
|
187
|
+
* dataFrom ('19 Oct', the headline figure's as-of) · shares ({ links, views } of the open links, or null when not read) · nextDraft ('YYYY-MM-DD')
|
|
188
|
+
* view 'deck'|'doc'|'live' · slides (count) · pages (count) · foot (true when the sources are footnotes) · path (for Bring back) }
|
|
189
|
+
* draft "Draft · Oct 21 cycle" in the warn tone, the purpose, "Every Mon 09:00 · data from 19 Oct", Issue
|
|
190
|
+
* issued "Issued 19 Oct", "Not shared yet." (or the open links) and the next cycle's day, the form it is read in, Share
|
|
191
|
+
* archived "Archived · issued 19 Oct", "It stays as sent.", Bring back
|
|
192
|
+
*/
|
|
193
|
+
export function reportSummary(o = {}) {
|
|
194
|
+
const m = slotOf(o.slot), short = m ? MONS[+m[2] - 1] + ' ' + +m[3] : String(o.slot || ''), on = dayMon(o.slot);
|
|
195
|
+
const form = o.view === 'doc' && o.pages ? 'Document · ' + o.pages + (o.pages === 1 ? ' page' : ' pages') + (o.foot ? ' · sources as footnotes' : '')
|
|
196
|
+
: o.view === 'live' ? 'Live page' : o.slides ? o.slides + (o.slides === 1 ? ' slide' : ' slides') : '';
|
|
197
|
+
const data = o.dataFrom ? 'data from ' + o.dataFrom : '';
|
|
198
|
+
if (o.state === 'archived') return { line: 'Archived' + (on ? ' · issued ' + on : ''), tone: '', text: 'It stays as sent.', meta: [form].filter(Boolean).join(' · '), primary: { r: 'unarch|' + (o.path || ''), label: 'Bring back' } };
|
|
199
|
+
if (o.state === 'issued') {
|
|
200
|
+
const S = o.shares, shared = !S ? '' : S.links ? 'Shared: ' + S.links + (S.links === 1 ? ' link' : ' links') + ' open, ' + (S.views ? S.views + (S.views === 1 ? ' view.' : ' views.') : 'not opened yet.') : 'Not shared yet.';
|
|
201
|
+
const next = o.nextDraft && dayMon(o.nextDraft) ? 'The next cycle starts ' + dayMon(o.nextDraft) + '.' : '';
|
|
202
|
+
return { line: 'Issued' + (on ? ' ' + on : ''), tone: '', text: [shared, next].filter(Boolean).join(' '), meta: [form, data].filter(Boolean).join(' · '), primary: { r: 'share', label: 'Share' } };
|
|
203
|
+
}
|
|
204
|
+
return { line: 'Draft' + (short ? ' · ' + short + ' cycle' : ''), tone: 'warn', text: String(o.purpose || o.sub || '').trim(), meta: [o.schedule, data].filter(Boolean).join(' · '), primary: { r: 'issue', label: 'Issue' } };
|
|
205
|
+
}
|
|
181
206
|
/* ── the live page (RpLive) ── */
|
|
182
207
|
const DAY = 86400000;
|
|
183
208
|
const ms = (d) => Date.parse(String(d).slice(0, 10) + 'T00:00:00Z');
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/* pm/tk-draft.js — one task as its drafted Jira ticket, in the team's template (canvas PgTkDraft; kit 2, T2).
|
|
2
|
+
*
|
|
3
|
+
* openDraft({ VW, ws, initiative, id, view?, ui: { menu, ask }, toast?, onChange?(), onSend?(id) })
|
|
4
|
+
*
|
|
5
|
+
* A drill-in of the initiative's Tasks (back: true, so ← returns to them). Type, Priority, Estimate and Depends on are four fields; the
|
|
6
|
+
* User story and the Acceptance criteria are shown; Additional context, User flow, Functional requirements, Terminal states and Refs are
|
|
7
|
+
* folded rows with a count. Every field and section is editable in place (POST /api/jira/edit, a page press: it writes the draft file,
|
|
8
|
+
* never Jira). The one send icon opens the Send sheet with this ticket ticked (tk-send.js). A ticket in Jira and unchanged has no send
|
|
9
|
+
* icon: there is nothing to send. ⋯ holds Edit the title and Edit with Claude. The model is tk-model.js draftModel. */
|
|
10
|
+
import { pmGet, pmPost } from './http.js';
|
|
11
|
+
import { draftModel, SECTION_NAMES } from './tk-model.js';
|
|
12
|
+
import { ensureCss } from './tk-send.js';
|
|
13
|
+
|
|
14
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
15
|
+
const SVG = (d, w = 16, sw = 1.8) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
|
|
16
|
+
const I = { send: 'M4 12l16-8-6 16-3-7z', edit: 'M4 20h4L19 9l-4-4L4 16zM13.5 6.5l4 4', right: 'M10 7l5 5-5 5', down: 'M7 10l5 5 5-5' };
|
|
17
|
+
const viewUrl = (ws, id) => '/api/jira/tickets?initiative=' + encodeURIComponent(id) + (ws ? '&ws=' + encodeURIComponent(ws) : '');
|
|
18
|
+
/** A section's text as paragraphs and lists, every character escaped: the draft is the PM's text, never markup. */
|
|
19
|
+
function textHtml(s) {
|
|
20
|
+
const out = []; let list = null;
|
|
21
|
+
for (const raw of String(s || '').split('\n')) {
|
|
22
|
+
const l = raw.trim();
|
|
23
|
+
const m = /^([-*]|\d+[.)])\s+(.*)$/.exec(l);
|
|
24
|
+
if (m) { const tag = /\d/.test(m[1]) ? 'ol' : 'ul'; if (!list || list.tag !== tag) { list = { tag, items: [] }; out.push(list); } list.items.push(m[2]); continue; }
|
|
25
|
+
list = null;
|
|
26
|
+
if (l && !/^[—–-]$/.test(l)) out.push(l.replace(/^#{1,6}\s+/, ''));
|
|
27
|
+
}
|
|
28
|
+
return out.map((x) => (typeof x === 'string' ? `<p>${esc(x)}</p>` : `<${x.tag}>${x.items.map((i) => `<li>${esc(i)}</li>`).join('')}</${x.tag}>`)).join('');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function draftHtml(D, st = {}) {
|
|
32
|
+
if (!D) return '<p class="tk-note">This ticket is not in the draft any more.</p>';
|
|
33
|
+
const field = (f) => `<button type="button" class="tk-f" data-tk-field="${esc(f.k)}" aria-haspopup="menu" aria-label="${esc(f.label)}: ${esc(f.value || f.none || '')}. Change"><span class="tk-fl">${esc(f.label)}</span><span class="tk-fv${f.value ? '' : ' mut'}">${esc(f.value || f.none || '')}</span></button>`;
|
|
34
|
+
const editor = (s) => `<div class="tk-ed"><label class="tk-vh" for="tkEd">${esc(s.name)}</label><textarea id="tkEd" rows="6" maxlength="20000">${esc(s.text)}</textarea><div class="tk-eda"><button type="button" class="tk-go sm" data-tk-save="${esc(s.key)}">Save</button><button type="button" class="tk-c sm" data-tk-noedit>Cancel</button></div></div>`;
|
|
35
|
+
const editBtn = (s) => `<button type="button" class="tk-ib" data-tk-edit="${esc(s.key)}" aria-label="Edit ${esc(s.name)}" title="Edit">${SVG(I.edit, 15)}</button>`;
|
|
36
|
+
const missing = (s) => (s.missing ? `<p class="tk-miss"><span class="tk-mk warn" aria-hidden="true"></span>Missing. A ticket needs it before it can be sent.</p>` : '');
|
|
37
|
+
const shown = D.shown.map((s) => {
|
|
38
|
+
const body = st.edit === s.key ? editor(s)
|
|
39
|
+
: s.entries && s.entries.length ? s.entries.map((e, i) => `<div class="tk-ac"><em>${i + 1}</em><span>${esc(e)}</span></div>`).join('') : s.text ? textHtml(s.text) : missing(s);
|
|
40
|
+
return `<section class="tk-card tk-sec2"><div class="tk-sh"><h3>${esc(s.name)}</h3>${st.edit === s.key ? '' : editBtn(s)}</div>${body}</section>`;
|
|
41
|
+
}).join('');
|
|
42
|
+
const folded = D.folded.map((s) => {
|
|
43
|
+
const open = st.open && st.open.has(s.key);
|
|
44
|
+
return `<div class="tk-coll${open ? ' on' : ''}"><button type="button" class="tk-cr" data-tk-fold="${esc(s.key)}" aria-expanded="${!!open}"><b>${esc(s.name)}</b><span class="tk-cn">${esc(s.count === 'empty' ? (s.missing ? 'missing' : '') : s.count)}</span>${SVG(open ? I.down : I.right, 15, 2)}</button>`
|
|
45
|
+
+ (open ? `<div class="tk-cb2">${st.edit === s.key ? editor(s) : (s.text ? textHtml(s.text) : missing(s) || '<p class="tk-mut">Empty.</p>') + `<div class="tk-cba">${editBtn(s)}</div>`}</div>` : '') + '</div>';
|
|
46
|
+
}).join('');
|
|
47
|
+
const mark = D.mark ? `<p class="tk-flag ${esc(D.mark[0])}"><span class="tk-mk ${esc(D.mark[0])}" aria-hidden="true"></span>${esc(D.mark[1])}</p>` : '';
|
|
48
|
+
return `<div class="tk-v tk-draft">${D.group ? `<p class="tk-crumb">${esc(D.group)}</p>` : ''}${D.inJira ? `<p class="tk-crumb">${esc(D.key)} · in Jira</p>` : ''}${mark}`
|
|
49
|
+
+ `<div class="tk-fields">${D.fields.map(field).join('')}</div>${shown}<div class="tk-card tk-folds">${folded}</div>`
|
|
50
|
+
+ `<p class="tk-msg" role="status" id="tkMsg">${esc(st.msg || '')}</p>`
|
|
51
|
+
+ (D.selectable ? `<button type="button" class="tk-fab" data-tk-send aria-label="Send to Jira" title="Send to Jira">${SVG(I.send, 20)}</button>` : '')
|
|
52
|
+
+ '</div>';
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function openDraft(o) {
|
|
56
|
+
ensureCss();
|
|
57
|
+
const st = { v: o.view || null, open: new Set(), edit: null, msg: '' };
|
|
58
|
+
const D = () => draftModel(st.v, o.id);
|
|
59
|
+
let body = null;
|
|
60
|
+
const read = async () => { const v = await pmGet(viewUrl(o.ws, o.initiative)); if (v && v.ok === true) st.v = v; return !!(v && v.ok); };
|
|
61
|
+
const draw = () => { if (body && body.isConnected) { const sc = body.scrollTop; body.innerHTML = draftHtml(D(), st); body.scrollTop = sc; } };
|
|
62
|
+
const save = async (patch, ok) => {
|
|
63
|
+
const r = await pmPost('/api/jira/edit', { ws: o.ws, initiative: o.initiative, id: o.id, patch });
|
|
64
|
+
if (!r || r.ok === false) { st.msg = (r && r.error) || 'Nothing was changed.'; draw(); return false; }
|
|
65
|
+
st.edit = null; st.msg = ''; await read(); draw();
|
|
66
|
+
if (o.toast && ok) o.toast(ok);
|
|
67
|
+
if (o.onChange) o.onChange();
|
|
68
|
+
return true;
|
|
69
|
+
};
|
|
70
|
+
if (!st.v) await read();
|
|
71
|
+
const d0 = D();
|
|
72
|
+
const more = [
|
|
73
|
+
{ label: 'Edit the title', on: (b) => o.ui.ask(b, 'Title', (D() || d0 || {}).title || '', (v) => save({ summary: v }, 'Title changed.'), { max: 250 }) },
|
|
74
|
+
{ label: 'Edit with Claude', on: () => {
|
|
75
|
+
const ta = document.getElementById('hmIn'); if (!ta) { if (o.toast) o.toast('The chat is not on this page.'); return; }
|
|
76
|
+
ta.value = `Edit the drafted Jira ticket ${o.id} of the initiative ${o.initiative} (pmos jira show ${o.initiative}). Change: `;
|
|
77
|
+
ta.dispatchEvent(new Event('input', { bubbles: true })); ta.focus(); ta.setSelectionRange(ta.value.length, ta.value.length);
|
|
78
|
+
} },
|
|
79
|
+
];
|
|
80
|
+
body = o.VW.open({ id: 'tk:' + o.initiative + ':' + o.id, kind: 'Jira ticket · drafted', title: (d0 && d0.title) || o.id, icon: 'jira', back: true, more,
|
|
81
|
+
render: (b) => { body = b; b.innerHTML = draftHtml(D(), st); wire(b); } });
|
|
82
|
+
function wire(b) {
|
|
83
|
+
b.onclick = async (e) => {
|
|
84
|
+
const t = e.target.closest('button'); if (!t || t.disabled) return;
|
|
85
|
+
const d = t.dataset, M = D(); if (!M) return;
|
|
86
|
+
if (d.tkFold) { if (st.open.has(d.tkFold)) st.open.delete(d.tkFold); else st.open.add(d.tkFold); draw(); return; }
|
|
87
|
+
if (d.tkEdit) { st.edit = d.tkEdit; st.open.add(d.tkEdit); draw(); const ta = b.querySelector('#tkEd'); if (ta) ta.focus(); return; }
|
|
88
|
+
if ('tkNoedit' in d) { st.edit = null; draw(); return; }
|
|
89
|
+
if (d.tkSave) { const ta = b.querySelector('#tkEd'); await save({ sections: { [d.tkSave]: ta ? ta.value : '' } }, SECTION_NAMES[d.tkSave] + ' saved.'); return; }
|
|
90
|
+
if ('tkSend' in d) { if (o.onSend) o.onSend(o.id); return; }
|
|
91
|
+
if (d.tkField) {
|
|
92
|
+
const f = M.fields.find((x) => x.k === d.tkField); if (!f) return;
|
|
93
|
+
if (f.k === 'depends') {
|
|
94
|
+
if (!M.others.length) { st.msg = 'This is the only ticket, so it depends on nothing here.'; draw(); return; }
|
|
95
|
+
const on = new Set(f.ids);
|
|
96
|
+
o.ui.menu(t, [{ head: 'Depends on' }, ...M.others.map((x) => ({ label: x.title, sub: x.id, radio: true, on: on.has(x.id), go: () => { if (on.has(x.id)) on.delete(x.id); else on.add(x.id); save({ depends: [...on] }, 'Depends on changed.'); } })),
|
|
97
|
+
...(on.size ? [{ hr: true }, { label: 'Depends on nothing', go: () => save({ depends: [] }, 'Depends on changed.') }] : [])], 'Depends on');
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
o.ui.menu(t, [{ head: f.label }, ...f.options.map((v) => ({ label: v, radio: true, on: f.value === v, go: () => save({ [f.k]: v }, f.label + ' changed.') })),
|
|
101
|
+
...(f.k === 'estimate' ? [{ label: 'Not set', radio: true, on: !f.value, go: () => save({ estimate: null }, 'Estimate cleared.') }] : [])], f.label);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
b.onkeydown = (e) => { if (e.key === 'Escape' && st.edit) { e.stopPropagation(); st.edit = null; draw(); } };
|
|
105
|
+
}
|
|
106
|
+
return body;
|
|
107
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/* pm/tk-model.js — the pure half of the initiative's PRD-to-Jira tasks (canvas PgTkList, PgTkDraft, PgTkSend, PgTkSent; kit 2, T1 to T3).
|
|
2
|
+
* No DOM, no request: it turns the answer of GET /api/jira/tickets (lib/jira-tickets.js view) into what the Tasks view, the drafted
|
|
3
|
+
* ticket and the Send sheet draw, so a node test loads it with import().
|
|
4
|
+
*
|
|
5
|
+
* ticketGroups(v) T1: the tasks grouped by the Jira epic they go into, with the send icon's count
|
|
6
|
+
* readLine(iso, now) T1: "Jira read at 9:02", said once under the groups
|
|
7
|
+
* draftModel(v, id) T2: the four fields, the two sections shown and the folded ones with their counts
|
|
8
|
+
* sendModel(v, { group, ticket, projects }) T3: the project, each epic with its Change, the tickets with their ticks, Send N
|
|
9
|
+
*
|
|
10
|
+
* Every task is a PRD story whose Jira ticket PMOS drafted. PMOS owns the text and Jira owns the status (D88): after the send a task shows
|
|
11
|
+
* its key, a status square for its Jira status category and its assignee when the Jira read holds one, never a guess.
|
|
12
|
+
* Several epics: a ticket names its epic group (v.groups); a ticket with no group goes under the initiative's one epic (v.epic). */
|
|
13
|
+
|
|
14
|
+
const str = (s) => (typeof s === 'string' ? s.trim() : '');
|
|
15
|
+
const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
|
|
16
|
+
const initials = (name) => { const w = str(name).split(/\s+/).filter(Boolean); return !w.length ? '' : w.length > 1 ? (w[0][0] + w[1][0]).toUpperCase() : w[0].slice(0, 2).replace(/^./, (c) => c.toUpperCase()); };
|
|
17
|
+
export const projectOf = (key) => (/^[A-Z][A-Z0-9_]*-\d+$/.test(str(key)) ? str(key).replace(/-\d+$/, '') : null);
|
|
18
|
+
|
|
19
|
+
/** One marker per task, the most urgent first (the view decides the flag): [tone, words]. Zero is silence: no flag, no marker. */
|
|
20
|
+
export function markOf(t) {
|
|
21
|
+
if (!t || !t.flag) return null;
|
|
22
|
+
if (t.flag === 'incomplete') return ['warn', 'Missing ' + (t.missing || []).join(', ')];
|
|
23
|
+
if (t.flag === 'prd-changed') return ['warn', 'The PRD changed this story'];
|
|
24
|
+
if (t.flag === 'removed') return ['warn', 'No longer in the PRD'];
|
|
25
|
+
if (t.flag === 'blocked') return ['warn', 'Blocked in Jira' + (t.jira && t.jira.reason ? ': ' + t.jira.reason : '')];
|
|
26
|
+
if (t.flag === 'pushing') return ['info', 'Sending to Jira'];
|
|
27
|
+
if (t.flag === 'edited') return ['info', 'Edited, not in Jira yet'];
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const CAT = { todo: 'To do', doing: 'In progress', done: 'Done' };
|
|
31
|
+
function rowOf(t) {
|
|
32
|
+
const j = t.jira || null;
|
|
33
|
+
const cat = t.inJira ? (j && CAT[j.category] ? j.category : 'todo') : null;
|
|
34
|
+
const who = j && str(j.assignee) ? str(j.assignee) : '';
|
|
35
|
+
return {
|
|
36
|
+
id: t.id, title: str(t.summary) || t.id, inJira: !!t.inJira, key: t.key || null, cat, status: t.inJira ? (j && str(j.status)) || CAT[cat] : '',
|
|
37
|
+
who, av: initials(who), sub: t.inJira ? t.key : [t.type, t.estimate].filter(Boolean).join(' · '), mark: markOf(t), selectable: !!t.selectable,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** T1. The groups: each epic group in the order the PRD gives them, then the tickets in no group. A group's `send` counts the tasks the
|
|
42
|
+
* Send sheet can tick; the header shows its send icon only when it is more than zero. */
|
|
43
|
+
export function ticketGroups(v) {
|
|
44
|
+
if (!v || v.ok !== true || !v.drafted) return [];
|
|
45
|
+
const groups = Array.isArray(v.groups) ? v.groups : [];
|
|
46
|
+
const by = new Map(groups.map((g) => [g.id, { id: g.id, name: g.name, key: g.key || null, locked: !!g.locked, rows: [] }]));
|
|
47
|
+
const ep = v.epic || {};
|
|
48
|
+
const loose = { id: '', name: groups.length ? 'Other tickets' : 'Tickets', key: ep.key || null, locked: !!ep.locked, rows: [], loose: true };
|
|
49
|
+
for (const t of v.tickets || []) (by.get(t.epic) || loose).rows.push(rowOf(t));
|
|
50
|
+
return [...by.values(), loose].filter((g) => g.rows.length).map((g) => ({ ...g, n: g.rows.length, send: g.rows.filter((r) => r.selectable).length, inJira: g.rows.filter((r) => r.inJira).length }));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
54
|
+
/** "Jira read at 9:02" today, "Jira read 23 Oct, 9:02" before; '' when Jira was never read. */
|
|
55
|
+
export function readLine(iso, now = Date.now()) {
|
|
56
|
+
const t = Date.parse(iso || '');
|
|
57
|
+
if (!Number.isFinite(t)) return '';
|
|
58
|
+
const d = new Date(t), n = new Date(now);
|
|
59
|
+
const hm = d.getHours() + ':' + String(d.getMinutes()).padStart(2, '0');
|
|
60
|
+
return d.toDateString() === n.toDateString() ? 'Jira read at ' + hm : 'Jira read ' + d.getDate() + ' ' + MON[d.getMonth()] + ', ' + hm;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* ── T2 · one drafted ticket ── */
|
|
64
|
+
const lines = (s) => String(s || '').split('\n').map((l) => l.trim()).filter((l) => l && !/^[—–-]$/.test(l));
|
|
65
|
+
const listItems = (s) => lines(s).filter((l) => /^([-*]|\d+[.)])\s+/.test(l));
|
|
66
|
+
/** The entries of a list section, without their bullets; a section with no list reads as its lines. */
|
|
67
|
+
export const entriesOf = (s) => { const L = listItems(s); return (L.length ? L : lines(s)).map((l) => l.replace(/^([-*]|\d+[.)])\s+/, '')); };
|
|
68
|
+
function countOf(key, text) {
|
|
69
|
+
const L = listItems(text);
|
|
70
|
+
if (!lines(text).length) return 'empty';
|
|
71
|
+
if (key === 'refs') return /PRD/.test(text) && L.length <= 1 ? 'PRD' : String(L.length || lines(text).length);
|
|
72
|
+
if (key === 'flow') return plural(L.length || lines(text).length, 'step', 'steps');
|
|
73
|
+
if (L.length) return String(L.length);
|
|
74
|
+
return plural(lines(text).length, 'line', 'lines');
|
|
75
|
+
}
|
|
76
|
+
const SHOWN = ['story', 'acceptance'];
|
|
77
|
+
const FOLDED = ['context', 'flow', 'functional', 'terminal', 'refs'];
|
|
78
|
+
const NAMES = { story: 'User story', context: 'Additional context', flow: 'User flow', functional: 'Functional requirements', terminal: 'Terminal states', acceptance: 'Acceptance criteria', refs: 'Refs' };
|
|
79
|
+
export const SECTION_NAMES = NAMES;
|
|
80
|
+
/** The drafted ticket: { id, title, group, fields, shown, folded, missing, inJira, key, selectable, mark } or null. */
|
|
81
|
+
export function draftModel(v, id) {
|
|
82
|
+
const t = v && v.ok === true ? (v.tickets || []).find((x) => x.id === id) : null;
|
|
83
|
+
if (!t) return null;
|
|
84
|
+
const all = new Map((v.tickets || []).map((x) => [x.id, str(x.summary) || x.id]));
|
|
85
|
+
const g = (v.groups || []).find((x) => x.id === t.epic);
|
|
86
|
+
const miss = new Set((t.missing || []).map((m) => m.toLowerCase()));
|
|
87
|
+
const sec = (k) => ({ key: k, name: NAMES[k], text: (t.sections || {})[k] || '', missing: miss.has(String({ story: 'User Story', functional: 'Functional Requirements', acceptance: 'Acceptance Criteria' }[k] || '').toLowerCase()) });
|
|
88
|
+
return {
|
|
89
|
+
id: t.id, title: str(t.summary) || t.id, group: g ? g.name : (v.groups || []).length ? 'Other tickets' : '', inJira: !!t.inJira, key: t.key || null, selectable: !!t.selectable, mark: markOf(t),
|
|
90
|
+
fields: [
|
|
91
|
+
{ k: 'type', label: 'Type', value: t.type || 'Task', options: v.types || ['Task', 'Story', 'Bug'] },
|
|
92
|
+
{ k: 'priority', label: 'Priority', value: t.priority || 'Medium', options: v.priorities || ['Highest', 'High', 'Medium', 'Low'] },
|
|
93
|
+
{ k: 'estimate', label: 'Estimate', value: t.estimate || '', options: v.estimates || ['XS', 'S', 'M', 'L', 'XL'], none: 'Not set' },
|
|
94
|
+
{ k: 'depends', label: 'Depends on', value: (t.depends || []).map((d) => all.get(d) || d).join(', '), ids: t.depends || [], none: 'Nothing' },
|
|
95
|
+
],
|
|
96
|
+
shown: SHOWN.map((k) => ({ ...sec(k), entries: k === 'acceptance' ? entriesOf(sec(k).text) : null })),
|
|
97
|
+
folded: FOLDED.map((k) => ({ ...sec(k), count: countOf(k, sec(k).text) })),
|
|
98
|
+
others: (v.tickets || []).filter((x) => x.id !== t.id).map((x) => ({ id: x.id, title: str(x.summary) || x.id })),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* ── T3 · confirm and send ── */
|
|
103
|
+
/**
|
|
104
|
+
* The Send sheet. Opened from a group's send icon (group: its id, '' for the tickets in no group), from a ticket's send icon (ticket: its
|
|
105
|
+
* id) or from the Commit row (neither: every group). It lists the tickets that can go to Jira now, ticked; a ticket that lacks text is
|
|
106
|
+
* listed, not ticked and not tickable, with what it lacks. A ticket in Jira and unchanged is not listed: there is nothing to send.
|
|
107
|
+
* projects: the board's Jira projects (lib/routes-boards.js jiraProjects), for when no epic key names the project.
|
|
108
|
+
* → { project, sections: [{ id, name, epic: { label, key, mode, locked }, items: [{ id, title, on, can, why, update }] }], n, empty }
|
|
109
|
+
*/
|
|
110
|
+
export function sendModel(v, { group = null, ticket = null, projects = [] } = {}) {
|
|
111
|
+
const G = ticketGroups(v);
|
|
112
|
+
const one = ticket ? (v.tickets || []).find((t) => t.id === ticket) : null;
|
|
113
|
+
const scopeId = one ? (one.epic && G.some((g) => g.id === one.epic) ? one.epic : '') : group;
|
|
114
|
+
const pick = scopeId == null ? G : G.filter((g) => g.id === scopeId);
|
|
115
|
+
const byId = new Map((v && v.tickets ? v.tickets : []).map((t) => [t.id, t]));
|
|
116
|
+
const ep = (v && v.epic) || {};
|
|
117
|
+
const sections = pick.map((g) => {
|
|
118
|
+
const items = g.rows.filter((r) => !r.inJira || r.selectable).map((r) => {
|
|
119
|
+
const t = byId.get(r.id) || {};
|
|
120
|
+
const why = (t.missing || []).length ? 'Missing ' + t.missing.join(', ') : t.removed ? 'No longer in the PRD' : '';
|
|
121
|
+
return { id: r.id, title: r.title, can: r.selectable, on: r.selectable && (!one || r.id === one.id), why, update: r.inJira };
|
|
122
|
+
});
|
|
123
|
+
const name = g.loose ? str(ep.summary) || str(v.title) || 'this initiative' : g.name;
|
|
124
|
+
const label = g.key ? g.key : 'New: ' + name;
|
|
125
|
+
return { id: g.id, name: g.loose && !(v.groups || []).length ? '' : g.name, epic: { label, key: g.key, mode: g.key ? 'existing' : 'new', locked: g.locked, group: g.loose ? null : g.id }, items };
|
|
126
|
+
}).filter((s) => s.items.length);
|
|
127
|
+
const keys = sections.map((s) => s.epic.key).filter(Boolean);
|
|
128
|
+
const list = (Array.isArray(projects) ? projects : []).map(str).filter(Boolean);
|
|
129
|
+
const project = projectOf(keys[0]) || (list.length ? list[0] : '');
|
|
130
|
+
const n = sections.reduce((a, s) => a + s.items.filter((i) => i.on).length, 0);
|
|
131
|
+
return { project, projectFrom: projectOf(keys[0]) ? 'epic' : project ? 'board' : 'ask', sections, n, empty: !sections.length };
|
|
132
|
+
}
|
|
133
|
+
/** The label of the final press: it is the one labeled button, since a send cannot be undone. */
|
|
134
|
+
export const sendLabel = (n) => (n ? 'Send ' + n : 'Send');
|