create-pmos 0.396.0 → 0.397.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/nine-stages.js +49 -20
- package/payload/state/discoveries.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +20 -40
- package/workspace/briefing-premium-board-test.js +145 -107
- package/workspace/briefing-premium-calendar-2-test.js +5 -2
- package/workspace/briefing-premium-calendar-3-test.js +13 -8
- package/workspace/briefing-premium-calendar-test.js +16 -5
- package/workspace/briefing-premium-initiative-test.js +50 -41
- package/workspace/briefing-premium-insights-test.js +104 -85
- package/workspace/briefing-premium-metrics-test.js +11 -32
- package/workspace/briefing-premium-sources-test.js +42 -21
- package/workspace/briefing-premium-test.js +112 -98
- package/workspace/briefing-premium-work-test.js +78 -64
- package/workspace/changelog.json +12 -0
- package/workspace/fixtures/board-premium-facts.js +2 -1
- package/workspace/fixtures/board-premium-jira.js +28 -0
- package/workspace/fixtures/initiative-premium-facts.js +2 -1
- package/workspace/fixtures/initiatives-api/list.json +30 -42
- package/workspace/fixtures/initiatives-api/roadmap.json +40 -56
- package/workspace/fixtures/initiatives-api/sheet.json +10 -14
- package/workspace/fixtures/insights-premium-facts.js +11 -2
- package/workspace/guide/index.md +1 -0
- package/workspace/guide/lifecycle.md +51 -0
- package/workspace/home-shot.js +38 -0
- package/workspace/lib/board-premium.js +92 -1
- package/workspace/lib/engine/boards.js +15 -14
- package/workspace/lib/engine/nine-stages.js +49 -20
- package/workspace/lib/engine/signals/detectors.js +13 -11
- package/workspace/lib/insights-premium.js +78 -1
- package/workspace/lib/routes-board-premium.js +3 -2
- package/workspace/lib/routes-initiatives.js +1 -1
- package/workspace/lib/routes-insights-premium.js +8 -1
- package/workspace/lib/vendor/scripts/nine-stages.js +49 -20
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-agreed-viewer-shots.js +76 -0
- package/workspace/premium-board-actions-test.js +2 -0
- package/workspace/premium-chat-chart-tab-test.js +6 -5
- package/workspace/premium-chat-context-test.js +8 -6
- package/workspace/premium-chat-goal-view-test.js +9 -7
- package/workspace/premium-chat-notes-test.js +3 -2
- package/workspace/premium-chat-report-tab-test.js +8 -2
- package/workspace/premium-chat-term-test.js +3 -1
- package/workspace/premium-chat-viewer-test.js +23 -17
- package/workspace/premium-core-doc-issue-test.js +2 -0
- package/workspace/premium-html-viewer-test.js +4 -2
- package/workspace/premium-phone-card-test.js +1 -0
- package/workspace/premium-phone-room-test.js +16 -11
- package/workspace/premium-report-read-test.js +1 -1
- package/workspace/premium-vw-backlog-test.js +2 -0
- package/workspace/premium-vw-cal-test.js +9 -4
- package/workspace/premium-vw-doc-test.js +1 -1
- package/workspace/premium-vw-item-test.js +1 -0
- package/workspace/premium-vw-jira-test.js +4 -1
- package/workspace/premium-vw-notes-test.js +2 -1
- package/workspace/premium-vw-rec-test.js +3 -2
- package/workspace/premium-vw-slides-test.js +2 -2
- package/workspace/premium-work-depth-test.js +7 -3
- package/workspace/public/pm/bd-span.js +120 -0
- package/workspace/public/pm/bd-stages.js +33 -0
- package/workspace/public/pm/cozy-board.css +373 -0
- package/workspace/public/pm/cozy-home.css +152 -0
- package/workspace/public/pm/cozy-home.js +170 -0
- package/workspace/public/pm/cozy-initiative.css +138 -0
- package/workspace/public/pm/cozy-insights.css +292 -0
- package/workspace/public/pm/cozy-nav.js +54 -0
- package/workspace/public/pm/cozy-viewer.css +143 -0
- package/workspace/public/pm/cozy.css +172 -0
- package/workspace/public/pm/lifecycle-lens-model.js +45 -27
- package/workspace/public/pm/lifecycle-lens.js +22 -11
- package/workspace/public/pm/premium-board.js +329 -67
- package/workspace/public/pm/premium-brief.js +1 -1
- package/workspace/public/pm/premium-chat.js +17 -10
- package/workspace/public/pm/premium-initiative-head.js +138 -0
- package/workspace/public/pm/premium-initiative.js +28 -4
- package/workspace/public/pm/premium-insights.js +530 -244
- package/workspace/public/pm/premium-shell.js +40 -10
- package/workspace/public/pm/premium-viewer.js +5 -0
- package/workspace/public/pm/premium-vw-jira-model.js +22 -5
- package/workspace/public/pm/premium-vw-jira.css +11 -0
- package/workspace/public/pm/premium-vw-jira.js +11 -4
- package/workspace/public/pm/premium-vw-rec.js +5 -2
- package/workspace/public/pm/premium-work.js +18 -8
- package/workspace/public/pm/premium.js +19 -6
- package/workspace/public/premium-board.html +82 -47
- package/workspace/public/premium-chat.html +7 -33
- package/workspace/public/premium-initiative.html +15 -8
- package/workspace/public/premium-insights.html +82 -43
- package/workspace/public/premium-work.html +6 -72
- package/workspace/public/premium.html +61 -15
- package/workspace/public/vendor/nunito-var.woff2 +0 -0
- package/workspace/server.js +7 -0
- package/workspace/test-lists/premium-agreed-viewer.json +9 -0
- package/workspace/third-party/README.md +1 -0
|
@@ -1,68 +1,300 @@
|
|
|
1
|
-
/* pm/premium-insights.js — the premium Insights page (initiative
|
|
2
|
-
* lib/insights-premium.js
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
|
|
1
|
+
/* pm/premium-insights.js — the premium Insights page in the Agreed design (initiative premium-agreed-design, G1 and G2, N1 and N2).
|
|
2
|
+
* Reads GET /api/insights-premium (lib/insights-premium.js: the KR metric records as goals, the board's initiatives that move them, the dashboards, the report
|
|
3
|
+
* files and setups) and GET /api/board-metrics-premium for the Delivery trends tiles. One bar: the product picker, the tabs Goals, Outcomes and Library, the
|
|
4
|
+
* view, the period and the icon tools; the floating place menu (pm/cozy-nav.js) replaces the rail.
|
|
5
|
+
*
|
|
6
|
+
* Every press of the pages before it stays (briefing-premium-insights, briefing-premium-reports, insights-one-list): a saved dashboard (POST
|
|
7
|
+
* /api/premium-dashboards/save), Pin (POST /api/premium-dashboards/pin), the report presses (POST /api/report-setups/ask | change | cancel | setup | dismiss |
|
|
8
|
+
* pause | resume | draft), the report reader (pm/premium-report-read.js), a Delivery trends target (POST /api/board-metric-targets/save), and Edit, New chart
|
|
9
|
+
* and Shape it, which open the chat with the item in the tab beside it. New here: New goal adds a KR metric record (POST /api/records/kr-metrics/add).
|
|
10
|
+
* Ask why and a verdict are made in Home: they open /premium.html with the question in the box. Nothing is sent outward. */
|
|
11
|
+
import { $, $$, esc, openDlg, popKey, closeDlg, toast, loadThread, wireRail, logHtml, turnA, ptx, pillOf, kv, setPageGaps, infoBtn } from './premium-shell.js';
|
|
10
12
|
import { pmPost } from './http.js';
|
|
11
13
|
import { openReport } from './premium-report-read.js';
|
|
12
14
|
import * as MT from './premium-metric-tiles.js';
|
|
13
15
|
import { W, P, X, Y, tileHtml } from './premium-chart-draw.js';
|
|
16
|
+
import { mountNav } from './cozy-nav.js';
|
|
14
17
|
|
|
15
18
|
let M = null; // the model
|
|
16
|
-
let dash = null; // the
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
+
let dash = null; // the view: a dashboard id; 'all' is every goal
|
|
20
|
+
let tab = 'goals';
|
|
21
|
+
let listF = 'all'; // the Library filter
|
|
22
|
+
let per = null; // the period { key, label, sub, from, to }
|
|
23
|
+
let find = '', filt = { obj: null, type: null };
|
|
24
|
+
let selecting = false; const picked = new Set();
|
|
25
|
+
let sugOpen = false;
|
|
19
26
|
wireRail('rep');
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const PINI = '
|
|
24
|
-
const
|
|
25
|
-
const AIC = '<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>';
|
|
27
|
+
mountNav('insights');
|
|
28
|
+
const SV = (d, sw) => `<svg viewBox="0 0 24 24" aria-hidden="true"${sw ? ` stroke-width="${sw}"` : ''}><path d="${d}"/></svg>`;
|
|
29
|
+
const DOCI = 'M6 3h9l4 4v14H6zM14 3v5h5M9 13h6M9 17h4';
|
|
30
|
+
const PINI = 'M9 3h6l-1 6 4 3v2H6v-2l4-3zM12 14v7';
|
|
31
|
+
const CHK = 'M5 12l5 5 9-10';
|
|
26
32
|
const byKey = (k) => (M && (M.charts || []).concat(M.mine || []) || []).find((c) => c.key === k) || null;
|
|
27
33
|
const savedDash = () => (M.dashboards || []).filter((d) => d.saved);
|
|
34
|
+
const wsQ = () => (M && M.board.ws ? 'ws=' + encodeURIComponent(M.board.ws) + '&' : '');
|
|
35
|
+
/** Home with a question in the box (PRD decision: Ask lands in Home). */
|
|
36
|
+
const homeAsk = (kind, q) => '/premium.html?' + wsQ() + 'ask=' + encodeURIComponent(kind) + '&q=' + encodeURIComponent(q);
|
|
28
37
|
|
|
29
|
-
/* ──
|
|
30
|
-
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
/* ── small menus: one open at a time, Escape and an outside press close it ─────────────────────────────────────────────────────────────── */
|
|
39
|
+
const MENUS = [['#prodPick', '#prodMenu'], ['#viewChip', '#viewMenu'], ['#perChip', '#perMenu'], ['#filtB', '#filtMenu'], ['#newB', '#newMenu'], ['#helpB', '#helpPop'], ['#listNew', '#listMenu'], ['#dashMore', '#dashBar']];
|
|
40
|
+
function menu(btn, box, open) { $(box).hidden = !open; $(btn).setAttribute('aria-expanded', String(open)); }
|
|
41
|
+
function closeMenus(except) { for (const [b, m] of MENUS) if (m !== except && !$(m).hidden) menu(b, m, false); }
|
|
42
|
+
for (const [b, m] of MENUS) {
|
|
43
|
+
$(b).addEventListener('click', (e) => {
|
|
44
|
+
e.stopPropagation(); const open = $(m).hidden; closeMenus(m); menu(b, m, open);
|
|
45
|
+
if (open) { const f = $(m).querySelector('button:not([disabled]), input, a'); if (f) f.focus(); }
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
document.addEventListener('click', (e) => { for (const [b, m] of MENUS) if (!$(m).hidden && !e.target.closest(m) && !e.target.closest(b)) menu(b, m, false); });
|
|
49
|
+
document.addEventListener('keydown', (e) => {
|
|
50
|
+
if (e.key !== 'Escape') return;
|
|
51
|
+
for (const [b, m] of MENUS) if (!$(m).hidden) { menu(b, m, false); $(b).focus(); return; }
|
|
52
|
+
if (!$('#side').hidden && !$('#dlg').classList.contains('on')) closeSide();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/* ── the bar: product, tabs, view, period, filter, find ────────────────────────────────────────────────────────────────────────────────── */
|
|
56
|
+
function drawBar() {
|
|
57
|
+
$('#prodName').textContent = M.board.name || 'Insights';
|
|
58
|
+
const boards = M.board.switcher || [];
|
|
59
|
+
$('#prodMenu').innerHTML = boards.length ? boards.map((b) => `<button type="button" role="menuitemradio" aria-checked="${b.id === M.board.id && b.ws === M.board.ws}" data-ws="${esc(b.ws)}" data-board="${esc(b.id)}">${esc(b.name)}</button>`).join('')
|
|
60
|
+
: '<p class="note">One product is registered.</p>';
|
|
61
|
+
$('#nGoals').textContent = String(goalsShown().length);
|
|
62
|
+
$('#nOutcomes').textContent = String((M.outcomes || []).length);
|
|
63
|
+
const D = curDash();
|
|
64
|
+
$('#viewName').textContent = D.id === 'all' ? 'All goals' : D.name;
|
|
65
|
+
$('#viewMenu').innerHTML = M.dashboards.map((d) => `<button type="button" role="menuitemradio" aria-checked="${d.id === D.id}" data-view="${esc(d.id)}">${esc(d.id === 'all' ? 'All goals' : d.name)}<small>${d.id === 'all' ? 'Every goal and budget' : d.saved ? 'Saved dashboard · ' + d.charts.length + ' goals' : 'Objective'}${M.pinned === d.id ? ' · pinned' : ''}</small></button>`).join('');
|
|
66
|
+
drawPeriod(); drawFilter();
|
|
67
|
+
}
|
|
68
|
+
$('#prodMenu').addEventListener('click', (e) => { const b = e.target.closest('[data-board]'); if (!b) return; location.assign('/premium-insights.html?ws=' + encodeURIComponent(b.dataset.ws) + '&board=' + encodeURIComponent(b.dataset.board)); });
|
|
69
|
+
$('#viewMenu').addEventListener('click', (e) => { const b = e.target.closest('[data-view]'); if (!b) return; closeMenus(); setView(b.dataset.view); });
|
|
70
|
+
function setTab(t) {
|
|
71
|
+
tab = t;
|
|
72
|
+
for (const b of $$('.ins-tabs [role="tab"]')) { const on = b.dataset.tab === t; b.setAttribute('aria-selected', String(on)); b.tabIndex = on ? 0 : -1; }
|
|
73
|
+
$('#pGoals').hidden = t !== 'goals'; $('#pOutcomes').hidden = t !== 'outcomes'; $('#pLibrary').hidden = t !== 'library';
|
|
74
|
+
for (const x of $$('.ins-vw')) x.hidden = t !== 'goals';
|
|
75
|
+
document.body.dataset.tab = t;
|
|
76
|
+
try { history.replaceState(null, '', setQ({ tab: t === 'goals' ? null : t })); } catch { /* no history */ }
|
|
77
|
+
}
|
|
78
|
+
const setQ = (o) => { const q = new URLSearchParams(location.search); for (const [k, v] of Object.entries(o)) { if (v == null) q.delete(k); else q.set(k, v); } const s = q.toString(); return location.pathname + (s ? '?' + s : ''); };
|
|
79
|
+
$('.ins-tabs').addEventListener('click', (e) => { const b = e.target.closest('[role="tab"]'); if (b) setTab(b.dataset.tab); });
|
|
80
|
+
$('.ins-tabs').addEventListener('keydown', (e) => {
|
|
81
|
+
if (!/^Arrow(Left|Right)$/.test(e.key)) return;
|
|
82
|
+
const T = $$('.ins-tabs [role="tab"]'), i = T.findIndex((x) => x.getAttribute('aria-selected') === 'true'), n = T[(i + (e.key === 'ArrowRight' ? 1 : T.length - 1)) % T.length];
|
|
83
|
+
setTab(n.dataset.tab); n.focus();
|
|
84
|
+
});
|
|
85
|
+
function setView(id) { dash = id; setTab('goals'); drawGoals(); drawDash(); drawBar(); drawList(); }
|
|
86
|
+
|
|
87
|
+
/* the period (AgInsPeriod): this quarter, last quarter, this half, this year, or custom dates. A goal shows when its period overlaps the one picked. */
|
|
88
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
89
|
+
const day = (s) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(s || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
90
|
+
const iso = (t) => new Date(t).toISOString().slice(0, 10);
|
|
91
|
+
const md = (t) => { const d = new Date(t); return MON[d.getUTCMonth()] + ' ' + d.getUTCDate(); };
|
|
92
|
+
function periods() {
|
|
93
|
+
const t = day(M.today) || Date.now(), d = new Date(t), y = d.getUTCFullYear(), q = Math.floor(d.getUTCMonth() / 3), h = d.getUTCMonth() < 6 ? 0 : 1;
|
|
94
|
+
const span = (y0, m0, y1, m1) => ({ from: Date.UTC(y0, m0, 1), to: Date.UTC(y1, m1, 0) });
|
|
95
|
+
const lq = q ? { y, q: q - 1 } : { y: y - 1, q: 3 };
|
|
96
|
+
return [
|
|
97
|
+
Object.assign({ key: 'q', label: 'Q' + (q + 1) + ' ' + y, name: 'This quarter' }, span(y, q * 3, y, q * 3 + 3)),
|
|
98
|
+
Object.assign({ key: 'lq', label: 'Q' + (lq.q + 1) + ' ' + lq.y, name: 'Last quarter' }, span(lq.y, lq.q * 3, lq.y, lq.q * 3 + 3)),
|
|
99
|
+
Object.assign({ key: 'h', label: 'H' + (h + 1) + ' ' + y, name: 'This half' }, span(y, h * 6, y, h * 6 + 6)),
|
|
100
|
+
Object.assign({ key: 'y', label: String(y), name: 'This year' }, span(y, 0, y + 1, 0)),
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
const inPer = (g) => {
|
|
104
|
+
if (!per) return true;
|
|
105
|
+
const a = day(g.fromAt) ?? day(g.byAt), b = day(g.byAt) ?? day(g.fromAt);
|
|
106
|
+
return a === null ? true : a <= per.to && b >= per.from;
|
|
107
|
+
};
|
|
108
|
+
function drawPeriod() {
|
|
109
|
+
const P = periods(); if (!per) per = P[0];
|
|
110
|
+
const t = day(M.today) || Date.now(), total = Math.round((per.to - per.from) / 864e5) + 1, gone = Math.max(0, Math.min(total, Math.round((t - per.from) / 864e5) + 1));
|
|
111
|
+
per.gone = gone; per.total = total;
|
|
112
|
+
$('#perName').textContent = per.label;
|
|
113
|
+
$('#perSub').textContent = tab === 'outcomes' ? 'shipped or judged' : md(per.from) + ' – ' + md(per.to) + (t >= per.from && t <= per.to ? ' · day ' + gone + ' of ' + total : '');
|
|
114
|
+
const n = (p) => M.goals.filter((g) => { const o = per; per = p; const r = inPer(g); per = o; return r; }).length;
|
|
115
|
+
$('#perMenu').innerHTML = P.map((p) => `<button type="button" role="menuitemradio" aria-checked="${per.key === p.key}" data-per="${p.key}">${per.key === p.key ? SV(CHK) : '<i class="ins-ck"></i>'}<span>${esc(p.name + ' · ' + p.label)}<small>${esc(md(p.from) + ' – ' + md(p.to) + ' · ' + n(p) + (n(p) === 1 ? ' goal' : ' goals'))}</small></span></button>`).join('')
|
|
116
|
+
+ `<button type="button" role="menuitemradio" aria-checked="${per.key === 'c'}" data-per="c">${per.key === 'c' ? SV(CHK) : '<i class="ins-ck"></i>'}<span>Custom<small>Pick a start and end date</small></span></button>`
|
|
117
|
+
+ `<div class="ins-cust" id="perCust" ${per.key === 'c' ? '' : 'hidden'}><label>From<input type="date" id="perFrom" value="${esc(iso(per.from))}"></label><label>To<input type="date" id="perTo" value="${esc(iso(per.to))}"></label><button type="button" class="cz-chip" id="perGo">Apply</button></div>`
|
|
118
|
+
+ '<p class="note ins-mnote">A goal shows here when its period overlaps the one you pick. A goal with no date always shows.</p>';
|
|
119
|
+
}
|
|
120
|
+
$('#perMenu').addEventListener('click', (e) => {
|
|
121
|
+
if (e.target.closest('#perGo')) {
|
|
122
|
+
const a = day($('#perFrom').value), b = day($('#perTo').value);
|
|
123
|
+
if (a === null || b === null || b < a) { toast('Pick a start date before the end date.'); return; }
|
|
124
|
+
per = { key: 'c', label: 'Custom', from: a, to: b }; closeMenus(); redraw(); return;
|
|
37
125
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
126
|
+
const b = e.target.closest('[data-per]'); if (!b) return;
|
|
127
|
+
if (b.dataset.per === 'c') { $('#perCust').hidden = false; $('#perFrom').focus(); return; }
|
|
128
|
+
per = periods().find((p) => p.key === b.dataset.per); closeMenus(); redraw();
|
|
129
|
+
});
|
|
130
|
+
function drawFilter() {
|
|
131
|
+
const objs = [...new Set(M.goals.map((g) => g.pillar || ''))], types = [...new Set(M.goals.map((g) => g.type))];
|
|
132
|
+
const row = (k, v, label) => `<button type="button" role="menuitemcheckbox" aria-checked="${filt[k] === v}" data-fk="${k}" data-fv="${esc(v)}">${filt[k] === v ? SV(CHK) : '<i class="ins-ck"></i>'}<span>${esc(label)}</span></button>`;
|
|
133
|
+
$('#filtMenu').innerHTML = '<p class="ins-mh">Objective</p>' + objs.map((o) => row('obj', o, o || 'No objective')).join('') + '<p class="ins-mh">Type</p>' + types.map((t) => row('type', t, t)).join('')
|
|
134
|
+
+ (filt.obj !== null || filt.type !== null ? '<button type="button" data-fclr>Clear the filter</button>' : '');
|
|
135
|
+
$('#filtDot').hidden = filt.obj === null && filt.type === null;
|
|
42
136
|
}
|
|
137
|
+
$('#filtMenu').addEventListener('click', (e) => {
|
|
138
|
+
if (e.target.closest('[data-fclr]')) { filt = { obj: null, type: null }; closeMenus(); redraw(); return; }
|
|
139
|
+
const b = e.target.closest('[data-fk]'); if (!b) return;
|
|
140
|
+
filt[b.dataset.fk] = filt[b.dataset.fk] === b.dataset.fv ? null : b.dataset.fv; redraw(); menu('#filtB', '#filtMenu', true);
|
|
141
|
+
});
|
|
142
|
+
$('#findB').addEventListener('click', () => { const open = $('#findRow').hidden; $('#findRow').hidden = !open; $('#findB').setAttribute('aria-expanded', String(open)); if (open) $('#findIn').focus(); });
|
|
143
|
+
$('#findIn').addEventListener('input', () => { find = $('#findIn').value.trim().toLowerCase(); redraw(); });
|
|
144
|
+
$('#findX').addEventListener('click', () => { $('#findIn').value = ''; find = ''; $('#findRow').hidden = true; $('#findB').setAttribute('aria-expanded', 'false'); redraw(); $('#findB').focus(); });
|
|
145
|
+
const hit = (...s) => !find || s.some((x) => String(x || '').toLowerCase().includes(find));
|
|
43
146
|
|
|
44
|
-
/* ── the
|
|
45
|
-
function
|
|
46
|
-
const I = M.insight;
|
|
47
|
-
|
|
147
|
+
/* ── the strip: the strongest finding, and Ask why (Home) ─────────────────────────────────────────────────────────────────────────────── */
|
|
148
|
+
function drawStrip() {
|
|
149
|
+
const I = M.insight, G = goalsShown();
|
|
150
|
+
const behind = G.filter((g) => g.tone === 'late' || g.tone === 'red').length;
|
|
151
|
+
$('#insEye').textContent = per && per.gone && per.label !== 'Custom' ? per.gone + ' of ' + per.total + ' days gone in ' + per.label + '.' : G.length + (G.length === 1 ? ' goal' : ' goals') + (behind ? ', ' + behind + ' behind.' : '.');
|
|
48
152
|
$('#brief').textContent = I.text;
|
|
49
|
-
$('#insWhy').textContent = I.why || '';
|
|
50
|
-
$('#
|
|
51
|
-
$('#
|
|
52
|
-
$('#
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
153
|
+
$('#insWhy').textContent = I.none ? '' : I.why || '';
|
|
154
|
+
$('#insMore').innerHTML = (I.more || []).map((x) => `<li><button type="button" class="lk" data-open="${esc(x.chart)}" aria-haspopup="dialog">${esc(x.text)}</button></li>`).join('');
|
|
155
|
+
$('#askWhy').href = homeAsk('insights', I.none ? 'Why is there no insight on my goals yet?' : 'Why? ' + I.text);
|
|
156
|
+
$('#askWhy').hidden = false;
|
|
157
|
+
}
|
|
158
|
+
$('#insHero').addEventListener('click', (e) => { const o = e.target.closest('[data-open]'); if (o) openChart(byKey(o.dataset.open)); });
|
|
159
|
+
|
|
160
|
+
/* ── Goals (G1): the table, grouped by objective ──────────────────────────────────────────────────────────────────────────────────────── */
|
|
161
|
+
const COLS = 'ins-cols';
|
|
162
|
+
const curDash = () => M.dashboards.find((d) => d.id === dash) || M.dashboards[0];
|
|
163
|
+
function goalsShown() {
|
|
164
|
+
const D = curDash(), ids = D.saved ? D.charts : D.id.startsWith('p:') ? null : null;
|
|
165
|
+
return M.goals.filter((g) => inPer(g) && (!ids || ids.includes(g.id)) && (!D.id.startsWith('p:') || g.pillar === D.name)
|
|
166
|
+
&& (filt.obj === null || (g.pillar || '') === filt.obj) && (filt.type === null || g.type === filt.type) && hit(g.title, g.pillar, ...g.moves.map((m) => m.title)));
|
|
167
|
+
}
|
|
168
|
+
const TRACK_TONE = { late: 'late', 'at risk': 'risk', done: 'ok', 'on track': 'ok' };
|
|
169
|
+
/** The lifecycle track: six stages and two milestones (◆); the current stage is the large dot in the initiative's status colour. */
|
|
170
|
+
function trackHtml(r) {
|
|
171
|
+
const tone = TRACK_TONE[r.status] || 'q';
|
|
172
|
+
return `<span class="ins-trk" title="${esc(r.stageLabel || 'No stage')}" aria-label="${esc((r.stageLabel ? 'Stage ' + r.stageLabel : 'No lifecycle stage') + (r.status ? ', ' + r.status : ''))}" role="img">`
|
|
173
|
+
+ [0, 1, 2, 3, 4, 5, 6, 7].map((i) => `<i class="${[i < r.idx ? 'p' : '', i === r.idx ? 'c ' + tone : '', i === 5 || i === 7 ? 'm' : ''].filter(Boolean).join(' ')}"></i>`).join('') + '</span>';
|
|
174
|
+
}
|
|
175
|
+
const ST_PILL = { late: ['late', 'Late'], 'at risk': ['risk', 'At risk'], 'on hold': ['q', 'On hold'], done: ['ok', 'Done'], cancelled: ['q', 'Cancelled'], 'on track': ['q', 'On track'] };
|
|
176
|
+
const initRow = (r) => { const p = ST_PILL[r.status]; return `<a class="ins-ini" href="/premium-initiative.html?${wsQ()}id=${encodeURIComponent(r.id)}">${trackHtml(r)}<span class="n">${esc(r.title)}</span>${p ? `<span class="cz-pill ${p[0]}">${esc(p[1])}</span>` : ''}</a>`; };
|
|
177
|
+
const TONE_BAR = { ok: 'var(--cz-dot-ok)', late: 'var(--cz-dot-late)', red: 'var(--cz-dot-red)', q: 'var(--cz-dot-q)', risk: 'var(--cz-dot-risk)' };
|
|
178
|
+
function barHtml(g) {
|
|
179
|
+
return `<div class="ins-bar1" role="img" aria-label="${g.done === null ? 'No progress to read' : Math.round(g.done * 100) + '% of the way to the target'}${g.timeGone === null ? '' : ', ' + Math.round(g.timeGone * 100) + '% of its time gone'}"><i style="width:${g.done === null ? 0 : Math.round(g.done * 100)}%;background:${TONE_BAR[g.tone]}"></i>${g.timeGone === null ? '' : `<span class="today" title="today" style="left:${Math.round(g.timeGone * 100)}%"></span>`}</div>`;
|
|
180
|
+
}
|
|
181
|
+
/** The so-far sparkline: the readings at their dates across the goal's span, the target as a dashed line, and the pace carried to the date, dashed. */
|
|
182
|
+
function sparkHtml(g, w = 210, h = 40) {
|
|
183
|
+
const c = g.key ? byKey(g.key) : null;
|
|
184
|
+
if (!c) return `<span class="note">${esc(g.readings ? 'One reading, no series yet' : 'No reading yet')}</span>`;
|
|
185
|
+
const t0 = day(c.pts[0].at), tl = day(c.pts[c.pts.length - 1].at), t1 = Math.max(tl, day(g.byAt) || tl);
|
|
186
|
+
const ys = c.pts.map((p) => p.v).concat(g.target !== null ? [g.target] : [], g.proj ? [g.proj.atDue] : []), lo = Math.min(...ys), hi = Math.max(...ys), rg = hi - lo || 1;
|
|
187
|
+
const x = (t) => 5 + (t1 > t0 ? (t - t0) / (t1 - t0) : 1) * (w - 10), y = (v) => 4 + (1 - (v - lo) / rg) * (h - 8);
|
|
188
|
+
const pts = c.pts.map((p) => x(day(p.at)).toFixed(1) + ',' + y(p.v).toFixed(1)), last = pts[pts.length - 1].split(',');
|
|
189
|
+
const fill = `${x(t0).toFixed(1)},${h} ${pts.join(' ')} ${last[0]},${h}`;
|
|
190
|
+
const proj = g.proj && day(g.byAt) > tl ? `<polyline points="${last.join(',')} ${x(day(g.byAt)).toFixed(1)},${y(g.proj.atDue).toFixed(1)}" class="pj"/>` : '';
|
|
191
|
+
return `<svg class="ins-spark" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}" role="img" aria-label="${esc(g.title + ': ' + c.pts.length + ' readings' + (g.targetTxt ? ', target ' + g.targetTxt : ''))}"><polygon points="${fill}" class="ar"/>${g.target !== null ? `<line x1="0" x2="${w}" y1="${y(g.target).toFixed(1)}" y2="${y(g.target).toFixed(1)}" class="tg"/>` : ''}${proj}<polyline points="${pts.join(' ')}" class="ln"/><circle cx="${last[0]}" cy="${last[1]}" r="3.6" class="dt" style="fill:${TONE_BAR[g.tone]}"/></svg>`;
|
|
192
|
+
}
|
|
193
|
+
const PACE_C = { ok: 'var(--cz-ok)', late: 'var(--cz-late)', q: 'var(--cz-ink3)' };
|
|
194
|
+
function goalRow(g) {
|
|
195
|
+
const sel = selecting && picked.has(g.id);
|
|
196
|
+
const sub = [g.dirTxt, g.baseTxt ? 'from ' + g.baseTxt + (g.from ? ' on ' + g.from : '') : ''].filter(Boolean).join(' · ');
|
|
197
|
+
return `<div class="ins-tr ins-row ${COLS}${sel ? ' sel' : ''}" role="row" data-goal="${esc(g.id)}"${g.key ? ` data-open="${esc(g.key)}"` : ''} tabindex="0" aria-label="${esc(g.title)}">`
|
|
198
|
+
+ `<div class="nm" role="cell">${selecting ? `<span class="ins-cb${sel ? ' on' : ''}" role="checkbox" aria-checked="${sel}" aria-label="Select ${esc(g.title)}">${sel ? SV(CHK, 3) : ''}</span>` : ''}<span><b>${esc(g.title)}</b><small><span class="cz-pill q ins-type">${esc(g.type)}</span>${esc(sub)}</small></span></div>`
|
|
199
|
+
+ `<div class="val" role="cell"><b>${esc(g.nowTxt || '—')}</b> <span class="note">${esc(g.targetTxt ? 'of ' + g.targetTxt : 'no target')}</span>${barHtml(g)}</div>`
|
|
200
|
+
+ `<div class="spk" role="cell">${sparkHtml(g)}</div>`
|
|
201
|
+
+ `<div class="pace" role="cell"><b style="color:${PACE_C[g.pace.tone]}">${esc(g.pace.head)}</b><div class="note">${esc(g.pace.sub)}</div></div>`
|
|
202
|
+
+ `<div class="mv" role="cell">${g.moves.length ? g.moves.slice(0, 3).map(initRow).join('') + (g.moves.length > 3 ? `<span class="note">and ${g.moves.length - 3} more</span>` : '') : `<span class="note">${M.initiativesRead ? 'No initiative anchors to it' : 'The initiatives are not read yet'}</span>`}</div>`
|
|
203
|
+
+ '</div>';
|
|
204
|
+
}
|
|
205
|
+
function drawGoals() {
|
|
206
|
+
const G = goalsShown(), T = $('#goalTbl');
|
|
207
|
+
if (!M.goals.length) { T.innerHTML = `<div class="ins-empty"><b>No goal is recorded for this workspace.</b> A goal is a KR metric with a target and a date. Press New, then New goal.</div>` + bmHtml(); bmDraw(); return; }
|
|
208
|
+
const head = `<div class="ins-tr ins-th ${COLS}" role="row"><div role="columnheader">Goal <span>${G.length} · in ${esc(per ? per.label : '')}</span></div><div role="columnheader">Now, of target <span class="ins-lg"><i class="ins-tdk"></i>today</span></div><div role="columnheader">So far</div><div role="columnheader">By its date</div><div role="columnheader" class="ins-mvh">Moved by <span class="ins-lg"><span><i class="ins-trk"><i class="p m"></i></i>Milestone</span></span></div></div>`;
|
|
209
|
+
const by = new Map(); for (const g of G) { const k = g.pillar || ''; if (!by.has(k)) by.set(k, []); by.get(k).push(g); }
|
|
210
|
+
let i = 0;
|
|
211
|
+
const groups = [...by.entries()].map(([k, L]) => {
|
|
212
|
+
const scored = L.filter((g) => g.tone !== 'q'), bad = scored.filter((g) => g.tone === 'late' || g.tone === 'red').length;
|
|
213
|
+
const pill = !scored.length ? '' : bad ? `<span class="cz-pill late">${bad} of ${L.length} behind</span>` : '<span class="cz-pill ok">on track</span>';
|
|
214
|
+
i++;
|
|
215
|
+
return `<div class="ins-grp" role="row"><span role="cell">${k ? 'Objective ' + i + ' · ' + esc(k) : 'No objective'}</span> <span class="q">${esc(per ? per.label : '')}</span>${pill}</div>` + L.map(goalRow).join('');
|
|
216
|
+
}).join('');
|
|
217
|
+
T.innerHTML = head + (G.length ? groups : `<div class="ins-empty">No goal matches${find ? ' “' + esc(find) + '”' : ''}${filt.obj !== null || filt.type !== null ? ' this filter' : ''} in ${esc(per.label)}. <button type="button" class="lk" id="goalsAll">Show every goal</button></div>`) + bmHtml();
|
|
218
|
+
bmDraw();
|
|
219
|
+
}
|
|
220
|
+
$('#goalTbl').addEventListener('click', (e) => {
|
|
221
|
+
if (e.target.closest('#goalsAll')) { find = ''; $('#findIn').value = ''; filt = { obj: null, type: null }; per = periods()[3]; redraw(); return; }
|
|
222
|
+
if (e.target.closest('a, #bmRange, #cBm')) return;
|
|
223
|
+
const r = e.target.closest('[data-goal]'); if (!r) return;
|
|
224
|
+
if (selecting) { const id = r.dataset.goal; if (picked.has(id)) picked.delete(id); else picked.add(id); drawGoals(); drawSel(); if (!$('#side').hidden && sideKind === 'dash') drawDashSide(); return; }
|
|
225
|
+
if (r.dataset.open) openChart(byKey(r.dataset.open)); else toast('This goal has fewer than two readings, so it has no chart yet.');
|
|
62
226
|
});
|
|
227
|
+
$('#goalTbl').addEventListener('keydown', (e) => { if (e.key !== 'Enter' && e.key !== ' ') return; const r = e.target.closest && e.target.closest('.ins-row'); if (!r || e.target !== r) return; e.preventDefault(); r.click(); });
|
|
63
228
|
|
|
64
|
-
/* ──
|
|
65
|
-
|
|
229
|
+
/* ── Delivery trends: the Board's measures, a tile press sets a target (initiative briefing-premium-metrics) ──────────────────────────────── */
|
|
230
|
+
let BM = null, bmWeeks = 8, bmTimer = null, bmErr = '';
|
|
231
|
+
const BM_KEY = 'pmos.premium.bmWeeks';
|
|
232
|
+
try { const w = Number(localStorage.getItem(BM_KEY)); if ([8, 26, 52].includes(w)) bmWeeks = w; } catch { /* a blocked store keeps 8 weeks */ }
|
|
233
|
+
const bmHtml = () => `<section class="ins-trends" id="cBm" aria-labelledby="hBm" hidden><div class="ins-grp" role="row"><h2 id="hBm" role="cell">Delivery trends</h2> <span class="q" id="bmCap"></span><span class="q ins-bmlead" id="bmLead" hidden></span><button type="button" class="infob" aria-controls="bmFold" aria-expanded="false" aria-label="About the Delivery trends" title="About the Delivery trends"><i aria-hidden="true">i</i></button>`
|
|
234
|
+
+ `<div class="cz-seg mper" id="bmRange" role="group" aria-label="Range"><button data-w="8" aria-pressed="true">8w</button><button data-w="26" aria-pressed="false">26w</button><button data-w="52" aria-pressed="false">52w</button></div></div>`
|
|
235
|
+
+ '<div class="ifold" id="bmFold" hidden><p class="mhint" id="bmHint"></p><p class="note" id="bmNote"></p></div><div class="bt2 ibt ins-tiles" id="bmBody"></div></section>';
|
|
236
|
+
function bmDraw() {
|
|
237
|
+
const card = $('#cBm'); if (!card) return;
|
|
238
|
+
card.hidden = !M || !M.board || !M.board.ws;
|
|
239
|
+
$$('#bmRange button').forEach((b) => b.setAttribute('aria-pressed', String(+b.dataset.w === bmWeeks)));
|
|
240
|
+
if (!BM) {
|
|
241
|
+
$('#bmCap').textContent = bmErr ? 'not read' : 'reading';
|
|
242
|
+
$('#bmHint').textContent = bmErr ? 'The Board measures could not be read, so none is shown.' + (bmErr !== '1' ? ' The reason: ' + bmErr : '') : '';
|
|
243
|
+
$('#bmLead').hidden = !bmErr; $('#bmLead').textContent = $('#bmHint').textContent; $('#bmBody').innerHTML = ''; $('#bmNote').textContent = '';
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
$('#bmCap').textContent = 'the Board shows today’s counts as chips · press a tile to set its target · ' + BM.header;
|
|
247
|
+
$('#bmHint').innerHTML = (BM.lead ? `<b class="mflag">${esc(BM.lead)}</b> ` : '') + esc(BM.body) + ' Press a measure to set its target. The Board draws the same target.';
|
|
248
|
+
$('#bmBody').style.gridTemplateColumns = 'repeat(' + Math.max(1, Math.min(6, BM.tiles.length)) + ',minmax(0,1fr))';
|
|
249
|
+
$('#bmBody').innerHTML = BM.tiles.map(MT.tileHtml).join('');
|
|
250
|
+
$('#bmNote').textContent = BM.note;
|
|
251
|
+
$('#bmLead').hidden = !BM.lead; $('#bmLead').textContent = BM.lead || '';
|
|
252
|
+
}
|
|
253
|
+
async function bmLoad() {
|
|
254
|
+
clearTimeout(bmTimer);
|
|
255
|
+
if (!M || !M.board || !M.board.ws) { bmDraw(); return; }
|
|
256
|
+
let r = null;
|
|
257
|
+
try { const res = await fetch('/api/board-metrics-premium?ws=' + encodeURIComponent(M.board.ws) + '&weeks=' + bmWeeks, { credentials: 'same-origin' }); r = await res.json(); } catch { r = null; }
|
|
258
|
+
if (!r || !r.ok || r.state !== 'ready') { BM = null; bmErr = (r && r.error) || '1'; bmDraw(); return; }
|
|
259
|
+
BM = r.model; bmErr = ''; bmDraw();
|
|
260
|
+
if (BM.pending) bmTimer = setTimeout(bmLoad, 4000); // the workflow engine is still deriving Blocked and Idle
|
|
261
|
+
}
|
|
262
|
+
function bmOpen(i) {
|
|
263
|
+
const t = BM && BM.tiles[i]; if (!t) return;
|
|
264
|
+
const vals = t.ser ? `<h3 class="sh">Values</h3><div class="vtb">${t.ser.map((v, j) => `<div><span>${esc(t.wk[j])}</span><b>${v == null ? (t.since ? 'Not kept yet' : 'No runs') : esc(MT.fmt(t, v))}</b></div>`).join('')}</div>` : '';
|
|
265
|
+
const form = t.absent ? '<p class="note" style="margin:12px 0 0">A target can be set once this measure is counted.</p>'
|
|
266
|
+
: `<div class="addf" style="margin-top:14px"><label>Target (${t.lowBetter ? 'at most' : 'at least'})<input id="bmT" inputmode="decimal" maxlength="12" value="${t.tg != null ? esc(String(t.tg)) : ''}" placeholder="For example: ${t.key === 'corrections' ? '10' : t.key === 'merges' ? '5' : '0'}"></label>
|
|
267
|
+
<p class="note" id="bmM" role="status" style="margin:0;min-height:1.2em"></p><div class="cact"><button class="cta" id="bmGo">Save target</button>${t.tg != null ? '<button class="cta alt" id="bmClr">Clear target</button>' : ''}</div></div>`;
|
|
268
|
+
const lt = (s) => { const d = new Date(s); return Number.isNaN(d.getTime()) ? '' : d.getDate() + ' ' + d.toLocaleString('en-GB', { month: 'short' }) + ' ' + String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0'); };
|
|
269
|
+
const fetched = t.trunk ? (t.trunk.fetched_at ? `${t.trunk.ref} was last fetched ${lt(t.trunk.fetched_at)}` : `${t.trunk.ref} has no fetch on record`) : '';
|
|
270
|
+
const tgt = t.tg != null ? ` The target is ${t.tg}; change it or clear it here.` : ' No target is set; type one and save it.';
|
|
271
|
+
const say = t.absent ? `${t.label} is not shown: ${t.why}`
|
|
272
|
+
: t.quiet ? `${t.label} was ${t.quiet.peak} in the week to ${t.quiet.week}, then 0 for the last two weeks. That is a quiet trunk or an old fetch: ${fetched || 'the fetch time is not known'}.${tgt}`
|
|
273
|
+
: `${t.label} is ${t.value}, ${t.text}.${t.change ? ' ' + t.change.txt + '.' : ''}${fetched ? ' ' + fetched + '.' : ''}${tgt}`;
|
|
274
|
+
const facts = MT.factRows(t, BM.repo, BM.weeks).concat(t.trunk ? [['Trunk read', t.trunk.ref + (t.trunk.fetched_at ? ', fetched ' + lt(t.trunk.fetched_at) : ', no fetch on record')]] : []);
|
|
275
|
+
const pane = `<article class="paper doc"><p class="lede" style="margin:0 0 10px">${esc(t.def)}</p>${kv(facts)}${form}${vals}<p class="note" style="margin-top:12px">${esc(BM.note)}</p></article>`;
|
|
276
|
+
openDlg({ eye: 'Board measure · real data', title: t.label, sub: BM.repo, say, stream: turnA(ptx(say)), noteKey: popKey('measure', BM.repo, t.key || t.label), facts, pane, label: 'Measure' });
|
|
277
|
+
$('#oMain').onchange = null;
|
|
278
|
+
$('#oMain').onclick = async (e) => {
|
|
279
|
+
const go = e.target.closest('#bmGo'), clr = e.target.closest('#bmClr'); if (!go && !clr) return;
|
|
280
|
+
const target = clr ? null : $('#bmT').value.trim();
|
|
281
|
+
if (go && target === '') { $('#bmM').textContent = 'Type a number first.'; return; }
|
|
282
|
+
(go || clr).disabled = true; $('#bmM').textContent = 'Saving.';
|
|
283
|
+
const res = await pmPost('/api/board-metric-targets/save', { ws: M.board.ws, key: t.key, target });
|
|
284
|
+
(go || clr).disabled = false;
|
|
285
|
+
if (!res || res.ok !== true) { $('#bmM').textContent = (res && res.error) || 'The target could not be saved.'; return; }
|
|
286
|
+
closeDlg(); toast(clr ? 'The target of ' + t.label + ' is cleared.' : 'The target of ' + t.label + ' is ' + target + '.');
|
|
287
|
+
bmLoad();
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/* the tiles are redrawn inside #goalTbl, so their presses are delegated from it */
|
|
291
|
+
MT.wireTiles($('#goalTbl'), () => (BM ? BM.tiles : []), bmOpen);
|
|
292
|
+
$('#goalTbl').addEventListener('click', (e) => {
|
|
293
|
+
const b = e.target.closest('#bmRange [data-w]'); if (!b || +b.dataset.w === bmWeeks) return;
|
|
294
|
+
bmWeeks = +b.dataset.w; try { localStorage.setItem(BM_KEY, String(bmWeeks)); } catch { /* not kept */ } bmDraw(); bmLoad();
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
/* ── the view's charts (charts live only on dashboards): the pinned one first, Pin, Edit and New chart in its ⋯ ─────────────────────────── */
|
|
66
298
|
function chartAt(t, j) {
|
|
67
299
|
const c = byKey(t.dataset.key); if (!c) return;
|
|
68
300
|
const n = c.pts.length; j = j == null ? n - 1 : Math.max(0, Math.min(n - 1, j));
|
|
@@ -74,99 +306,77 @@ function chartAt(t, j) {
|
|
|
74
306
|
$('.mval', t).textContent = val; $('.mwk', t).textContent = cap;
|
|
75
307
|
t.setAttribute('aria-label', c.title + ', ' + (last ? 'now ' : '') + val + ', ' + cap + '. Use the arrow keys to read each reading.');
|
|
76
308
|
}
|
|
77
|
-
|
|
78
|
-
/* ── the top card: the pinned dashboard (insights-one-list L4) ─────────────────────────────────────────────────── */
|
|
79
|
-
const curDash = () => M.dashboards.find((d) => d.id === dash) || M.dashboards[0];
|
|
80
309
|
const pinnable = (D) => !!M.board.id && (D.id === 'all' || D.saved);
|
|
81
|
-
/* The dashboard's insight band. The finding the page already leads with is skipped, so the band says what else is on this dashboard. */
|
|
82
310
|
function findingsHtml(D) {
|
|
83
311
|
const I = D.insight; if (!I || I.none) return '';
|
|
84
312
|
const all = I.finds, F = all.filter((f) => f.chart !== M.insight.chart), also = F.length < all.length;
|
|
85
313
|
const label = also ? 'Also on this dashboard' : 'Insight';
|
|
86
|
-
const rows = F.length ? F.map((f) => `<li class="${esc(f.kind)}"><button class="nfr" data-open="${esc(f.chart)}" aria-haspopup="dialog"><i class="nfdot" aria-hidden="true"></i><span class="nft"><b>${esc(f.text)}</b> ${esc(f.why)}</span
|
|
314
|
+
const rows = F.length ? F.map((f) => `<li class="${esc(f.kind)}"><button class="nfr" data-open="${esc(f.chart)}" aria-haspopup="dialog"><i class="nfdot" aria-hidden="true"></i><span class="nft"><b>${esc(f.text)}</b> ${esc(f.why)}</span></button></li>`).join('')
|
|
87
315
|
: `<li class="calm"><div class="nfr"><i class="nfdot" aria-hidden="true"></i><span class="nft">${esc(also ? 'Nothing else stands out here.' : I.calmText)}</span></div></li>`;
|
|
88
316
|
return `<div class="nfd" role="region" aria-label="${esc(label)}"><p class="label">${esc(label)}</p><ul>${rows}</ul></div>`;
|
|
89
317
|
}
|
|
90
318
|
function drawDash() {
|
|
91
319
|
const D = curDash(), L = D.keys.map(byKey).filter(Boolean), isPin = M.pinned === D.id;
|
|
92
|
-
$('#hDash').textContent = D.name;
|
|
320
|
+
$('#hDash').textContent = 'Charts on ' + (D.id === 'all' ? 'All goals' : D.name);
|
|
93
321
|
$('#dashTag').textContent = isPin ? 'Pinned' : 'Not pinned';
|
|
94
|
-
$('#dashTag').className = '
|
|
322
|
+
$('#dashTag').className = 'cz-pill ' + (isPin ? 'you' : 'q');
|
|
95
323
|
$('#dashCap').textContent = L.length ? (L.length - D.off) + ' of ' + L.length + ' on their line' : '';
|
|
96
324
|
drawDashBar(D, isPin);
|
|
97
|
-
$('#cDash').hidden = !D.saved && !M.charts.length;
|
|
325
|
+
$('#cDash').hidden = !D.saved && !M.charts.length;
|
|
98
326
|
if (D.saved) { drawSaved(D, L); return; }
|
|
99
|
-
if (!M.charts.length) {
|
|
100
|
-
$('#dashBody').innerHTML = `<div class="nempty" style="margin-top:14px"><p><b>${esc(M.counts.total ? 'No KR metric holds two readings yet.' : 'No KR metric is recorded for this workspace.')}</b> ${esc(M.counts.total ? 'A chart needs a series, so nothing is drawn.' : 'There is nothing to chart. Add one where the KR metrics are kept.')}</p></div>` + noSeriesHtml();
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
327
|
+
if (!M.charts.length) { $('#dashBody').innerHTML = ''; return; }
|
|
103
328
|
const off = D.off, tot = L.length;
|
|
104
|
-
$('#dashBody').innerHTML =
|
|
105
|
-
+
|
|
106
|
-
+ `<
|
|
107
|
-
+ `<div class="ngrid">${L.map((c) => tileWrap(c)).join('')}</div>` + (D.id === 'all' ? mineHtml() + noSeriesHtml() : '');
|
|
329
|
+
$('#dashBody').innerHTML = findingsHtml(D)
|
|
330
|
+
+ `<p class="mhint"><b>${tot - off} of ${tot}</b> on their line${off ? `. <b class="mflag">${off} ${off === 1 ? 'is' : 'are'} behind it.</b>` : '.'} ${infoBtn('dashFold', 'About these charts')}</p><div class="ifold" id="dashFold" hidden><p class="mhint">Each chart is one goal, drawn at the dates of its readings. A gap between readings is left as a gap. The dashed line is the target.</p></div>`
|
|
331
|
+
+ `<div class="ngrid">${L.map(tileWrap).join('')}</div>` + (D.id === 'all' ? mineHtml() + noSeriesHtml() : '');
|
|
108
332
|
}
|
|
109
|
-
/* The bar under the heading: Pin or Unpin, Back to the pinned one, a saved dashboard's purpose and Edit, and New chart. Hidden with no board to save on. */
|
|
110
333
|
function drawDashBar(D, isPin) {
|
|
111
|
-
const bar = $('#dashBar');
|
|
112
|
-
$('#dashPurpose').textContent = D.saved ? D.purpose : D.id === 'all' ? 'Every
|
|
334
|
+
const bar = $('#dashBar');
|
|
335
|
+
$('#dashPurpose').textContent = D.saved ? D.purpose : D.id === 'all' ? 'Every goal of this product. PMOS makes it, so it cannot be deleted.' : 'The goals of the ' + D.name + ' objective.';
|
|
113
336
|
$('#dashMore').hidden = !M.board.id;
|
|
114
337
|
if (!M.board.id) { bar.innerHTML = ''; return; }
|
|
115
|
-
const
|
|
116
|
-
bar.innerHTML = `<p class="note pdst">${isPin ? 'Pinned
|
|
117
|
-
+ (pinnable(D) ? `<button
|
|
118
|
-
+ (
|
|
119
|
-
+ (D.saved ? '<button
|
|
120
|
-
+ (M.charts.length ? '<button
|
|
338
|
+
const Pd = M.pinned ? M.dashboards.find((d) => d.id === M.pinned) : null;
|
|
339
|
+
bar.innerHTML = `<p class="note pdst">${isPin ? 'Pinned: it opens first on Goals' : 'Not pinned'}</p>`
|
|
340
|
+
+ (pinnable(D) ? `<button type="button" id="pdPin" data-pin="${esc(isPin ? '' : D.id)}" aria-pressed="${isPin}">${SV(PINI)}${isPin ? 'Unpin' : 'Pin'}</button>` : '')
|
|
341
|
+
+ (Pd && !isPin ? `<button type="button" id="pdBack">Back to ${esc(Pd.name)}</button>` : '')
|
|
342
|
+
+ (D.saved ? '<button type="button" id="pdEdit" aria-haspopup="dialog">Edit</button>' : '')
|
|
343
|
+
+ (M.charts.length ? '<button type="button" id="pcNew" aria-haspopup="dialog">New chart</button>' : '');
|
|
121
344
|
}
|
|
122
345
|
function drawSaved(D, L) {
|
|
123
346
|
const off = D.off, tot = L.length;
|
|
124
|
-
const gone = D.gone.length ? `<p class="label ngl">Not drawn · ${D.gone.length}</p><div class="dplist" role="list">${D.gone.map((g) => `<div class="nempty" role="listitem"
|
|
347
|
+
const gone = D.gone.length ? `<p class="label ngl">Not drawn · ${D.gone.length}</p><div class="dplist" role="list">${D.gone.map((g) => `<div class="nempty" role="listitem"><p><b>${esc(g.title)}</b><br>${esc(g.why)}</p></div>`).join('')}</div>` : '';
|
|
125
348
|
const checks = D.checks.length ? `<p class="note pdck">${D.checks.map(esc).join(' ')}</p>` : '';
|
|
126
|
-
$('#dashBody').innerHTML = (tot ?
|
|
127
|
-
+
|
|
128
|
-
+ `<
|
|
129
|
-
|
|
130
|
-
: `<div class="nempty" style="margin-top:14px"><p><b>This dashboard draws no chart yet.</b> Press Edit to add a measure with a series.</p></div>`) + checks + gone;
|
|
349
|
+
$('#dashBody').innerHTML = (tot ? findingsHtml(D)
|
|
350
|
+
+ `<p class="mhint"><b>${tot - off} of ${tot}</b> on their line${off ? `. <b class="mflag">${off} ${off === 1 ? 'is' : 'are'} behind it.</b>` : '.'} ${infoBtn('dashFold', 'About these charts')}</p><div class="ifold" id="dashFold" hidden><p class="mhint">The charts are drawn in the order you saved. The dashed line is the target.</p></div>`
|
|
351
|
+
+ `<div class="ngrid">${L.map(tileWrap).join('')}</div>`
|
|
352
|
+
: '<div class="nempty"><p><b>This dashboard draws no chart yet.</b> Press Edit to add a goal with a series.</p></div>') + checks + gone;
|
|
131
353
|
}
|
|
132
|
-
/* A tile with its footer: Details, and Edit for a chart the PM saved (premium-studio-chart C4). */
|
|
133
354
|
const tileWrap = (c) => `<div class="ntw">${tileHtml(c)}<div class="ntf"><button class="lk" data-open="${esc(c.key)}">Details</button>${c.mine ? `<button class="lk" data-ced="${esc(c.id)}" aria-haspopup="dialog">Edit</button>` : ''}</div></div>`;
|
|
134
|
-
/* The board's saved charts under All measures (premium-studio-chart C2). A saved chart whose measure has no series in its range is listed, not drawn. */
|
|
135
355
|
function mineHtml() {
|
|
136
356
|
const L = M.mine || [], G = M.mineGone || [];
|
|
137
357
|
if (!L.length && !G.length) return '';
|
|
138
358
|
return `<p class="label ngl">Your charts · ${L.length + G.length}</p>` + (L.length ? `<div class="ngrid">${L.map(tileWrap).join('')}</div>` : '')
|
|
139
|
-
+ G.map((g) => `<div class="nempty" role="listitem"
|
|
359
|
+
+ G.map((g) => `<div class="nempty" role="listitem"><p><b>${esc(g.title)}</b><br>${esc(g.why)} It is not drawn. <button class="lk" data-ced="${esc(g.id)}" aria-haspopup="dialog">Edit</button></p></div>`).join('');
|
|
140
360
|
}
|
|
141
361
|
function noSeriesHtml() {
|
|
142
362
|
const N = M.noSeries; if (!N.length) return '';
|
|
143
|
-
return `<p class="label ngl">No series recorded · ${N.length}</p><div class="dplist" role="list">${N.map((n) => `<div class="nempty" role="listitem"
|
|
363
|
+
return `<p class="label ngl">No series recorded · ${N.length}</p><div class="dplist" role="list">${N.map((n) => `<div class="nempty" role="listitem"><p><b>${esc(n.title)}</b>${n.pillar ? ' · ' + esc(n.pillar) : ''}<br>${esc(n.why)} It is not drawn.</p></div>`).join('')}</div>`;
|
|
144
364
|
}
|
|
145
|
-
|
|
146
|
-
async function pinDash(id, from) {
|
|
365
|
+
async function pinDash(id) {
|
|
147
366
|
const res = await pmPost('/api/premium-dashboards/pin', { ws: M.board.ws, board: M.board.id, id: id || null });
|
|
148
|
-
if (!res || res.ok !== true) { toast((res && res.error) || 'The pin could not be saved. Nothing changed.'); return; }
|
|
367
|
+
if (!res || res.ok !== true) { toast((res && res.error) || 'The pin could not be saved. Nothing changed.'); return false; }
|
|
149
368
|
const D = M.dashboards.find((d) => d.id === id);
|
|
150
369
|
dash = res.pinned || 'all';
|
|
151
|
-
toast(res.pinned ? 'Pinned ' + (D ? D.name : 'the dashboard') + '. It
|
|
370
|
+
toast(res.pinned ? 'Pinned ' + (D ? D.name : 'the dashboard') + '. It opens first on Goals.' : 'Unpinned. All goals opens first.');
|
|
152
371
|
await load();
|
|
153
|
-
|
|
372
|
+
return true;
|
|
154
373
|
}
|
|
155
|
-
/* the ⋯ of the top card: Pin or Unpin, Back, Edit and New chart (premium-calmer-first-screen) */
|
|
156
|
-
function dashMenu(open) { $('#dashBar').hidden = !open; $('#dashMore').setAttribute('aria-expanded', String(open)); }
|
|
157
|
-
$('#dashMore').addEventListener('click', () => { const open = $('#dashBar').hidden; dashMenu(open); if (open) { const f = $('#dashBar button'); if (f) f.focus(); } });
|
|
158
|
-
document.addEventListener('click', (e) => { if (!$('#dashBar').hidden && !e.target.closest('#dashBar, #dashMore')) dashMenu(false); });
|
|
159
|
-
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !$('#dashBar').hidden) { dashMenu(false); $('#dashMore').focus(); } });
|
|
160
374
|
$('#dashBar').addEventListener('click', (e) => {
|
|
161
|
-
const pin = e.target.closest('#pdPin'); if (pin) { pin.disabled = true; pinDash(pin.dataset.pin || null
|
|
162
|
-
if (e.target.closest('#pdBack')) {
|
|
375
|
+
const pin = e.target.closest('#pdPin'); if (pin) { pin.disabled = true; closeMenus(); pinDash(pin.dataset.pin || null); return; }
|
|
376
|
+
if (e.target.closest('#pdBack')) { closeMenus(); setView(M.pinned); return; }
|
|
163
377
|
if (e.target.closest('#pdEdit')) openDashEdit(curDash()); else if (e.target.closest('#pcNew')) openChartEdit(null);
|
|
164
378
|
});
|
|
165
|
-
|
|
166
|
-
/* ── dashboards, charts and reports are made and changed in a chat (initiative premium-reports-from-chat, slice C; the Insight Studio is removed).
|
|
167
|
-
* Edit, New chart, the + menu and Shape it open the Chat page: with ?open= it opens that one in the tab beside the chat, with ?say= it puts a first
|
|
168
|
-
* message in the box for the PM to send. Every save is still the PM's press in that tab. ── */
|
|
169
|
-
/* the switches under On your dashboards in a measure's dialog still save a dashboard here (POST /api/premium-dashboards/save) */
|
|
379
|
+
/* dashboards, charts and reports are shaped in a chat (premium-reports-from-chat): ?open= opens the item beside the chat, ?say= puts a first message in the box */
|
|
170
380
|
async function saveDash(body) { return pmPost('/api/premium-dashboards/save', Object.assign({ ws: M.board.ws, board: M.board.id }, body)); }
|
|
171
381
|
function toChat(o) {
|
|
172
382
|
const q = new URLSearchParams(); if (M.board.ws) q.set('ws', M.board.ws);
|
|
@@ -189,37 +399,161 @@ $('#dashBody').addEventListener('pointermove', (e) => {
|
|
|
189
399
|
});
|
|
190
400
|
$('#dashBody').addEventListener('pointerleave', () => $$('#dashBody .mch.hv').forEach((x) => chartAt(x)));
|
|
191
401
|
|
|
192
|
-
/* ──
|
|
402
|
+
/* ── Outcomes (G2): shipped work against what it promised, and the verdict ──────────────────────────────────────────────────────────────── */
|
|
403
|
+
const OUT_G = { verdict: 'Needs your verdict', window: 'In their window', decided: 'Decided' };
|
|
404
|
+
function outRow(r) {
|
|
405
|
+
const g = r.goal;
|
|
406
|
+
const promise = g ? `<div class="ins-prom"><span class="cz-pill q ins-type">${esc(g.type)}</span><span class="pt">${esc(g.title)}${g.targetTxt ? ' ' + esc((g.baseTxt ? g.baseTxt + ' → ' : '') + g.targetTxt) : ''}${g.by ? ' by ' + esc(g.by) : ''}</span>${barHtml({ done: g.done, timeGone: null, tone: g.tone })}<b style="color:${PACE_C[g.pace.tone] || 'inherit'}">${esc(g.nowTxt ? g.nowTxt + (g.targetTxt ? ' of ' + g.targetTxt : '') : 'no reading')}</b></div>`
|
|
407
|
+
: `<span class="note">${r.anchor ? 'Anchored to ' + esc(r.anchor) + ', which is not a goal with readings.' : 'No goal is anchored, so nothing was promised to measure.'}</span>`;
|
|
408
|
+
const verdict = r.group === 'verdict' ? `<button type="button" class="ins-dec" data-verdict="${esc(r.id)}" aria-haspopup="dialog">${SV(CHK)}Decide</button>`
|
|
409
|
+
: r.group === 'decided' ? `<span class="cz-pill ${r.status === 'done' ? 'ok' : 'q'}">${r.status === 'done' ? 'Done' : 'Cancelled'}</span>` : `<span class="note">${r.idx === 6 ? 'Being monitored' : 'Too early'}</span>`;
|
|
410
|
+
return `<div class="ins-tr ins-row ins-ocols" role="row" data-ini="${esc(r.id)}"><div class="nm" role="cell"><a href="/premium-initiative.html?${wsQ()}id=${encodeURIComponent(r.id)}"><b>${esc(r.title)}</b></a>${trackHtml(r)}</div>`
|
|
411
|
+
+ `<div role="cell">${promise}</div><div role="cell" class="note">${esc(r.stageLabel ? 'In ' + r.stageLabel : '')}${r.owner ? ' · ' + esc(r.owner) : ''}</div>`
|
|
412
|
+
+ `<div role="cell" class="note">${esc(r.end ? 'Ends ' + r.end : 'No end date')}</div><div role="cell">${verdict}</div></div>`;
|
|
413
|
+
}
|
|
414
|
+
function drawOutcomes() {
|
|
415
|
+
const L = (M.outcomes || []).filter((r) => hit(r.title, r.goal && r.goal.title));
|
|
416
|
+
const need = L.filter((r) => r.group === 'verdict');
|
|
417
|
+
$('#outText').innerHTML = !M.initiativesRead ? 'The board’s initiatives are not read yet, so no shipped work is listed.'
|
|
418
|
+
: !L.length ? 'No initiative is past Build yet. Shipped work shows here, with what its goal promised.'
|
|
419
|
+
: (need.length ? `<b>${esc(need[0].title)} needs your verdict.</b> ` : '') + esc(L.length + (L.length === 1 ? ' initiative is' : ' initiatives are') + ' past Build: ' + need.length + ' to decide, ' + L.filter((r) => r.group === 'window').length + ' in their window, ' + L.filter((r) => r.group === 'decided').length + ' decided.');
|
|
420
|
+
const head = '<div class="ins-tr ins-th ins-ocols" role="row"><div role="columnheader">Shipped initiative</div><div role="columnheader">What it promised · and what happened so far</div><div role="columnheader">Where it is</div><div role="columnheader">Window</div><div role="columnheader">Verdict</div></div>';
|
|
421
|
+
const groups = Object.keys(OUT_G).map((k) => { const G = L.filter((r) => r.group === k); return G.length ? `<div class="ins-grp" role="row"><span role="cell">${OUT_G[k]}</span> <span class="q">${G.length}</span></div>` + G.map(outRow).join('') : ''; }).join('');
|
|
422
|
+
$('#outTbl').innerHTML = head + (groups || '<div class="ins-empty">Nothing to judge yet.</div>');
|
|
423
|
+
}
|
|
424
|
+
$('#outTbl').addEventListener('click', (e) => { const b = e.target.closest('[data-verdict]'); if (b) openVerdict((M.outcomes || []).find((r) => r.id === b.dataset.verdict)); });
|
|
425
|
+
|
|
426
|
+
/* ── the side panel: New goal, New dashboard, the verdict ───────────────────────────────────────────────────────────────────────────── */
|
|
427
|
+
let sideKind = null, sideBack = null;
|
|
428
|
+
function openSide(o) {
|
|
429
|
+
sideKind = o.kind; sideBack = document.activeElement;
|
|
430
|
+
$('#sideEye').textContent = o.eye; $('#sideTitle').textContent = o.title; $('#sideTools').innerHTML = o.tools || '';
|
|
431
|
+
$('#sideBody').innerHTML = o.body; $('#sideNote').textContent = o.note; $('#sideMsg').textContent = '';
|
|
432
|
+
$('#sideAct').innerHTML = `<button type="button" class="ins-primary" id="sideGo">${SV(CHK)}${esc(o.go)}</button>`;
|
|
433
|
+
$('#side').hidden = false; document.body.classList.add('ins-sideon');
|
|
434
|
+
const f = $('#sideBody input, #sideBody textarea, #sideBody button'); if (f) f.focus();
|
|
435
|
+
}
|
|
436
|
+
function closeSide() {
|
|
437
|
+
$('#side').hidden = true; document.body.classList.remove('ins-sideon'); sideKind = null;
|
|
438
|
+
if (selecting) { selecting = false; picked.clear(); drawGoals(); drawSel(); }
|
|
439
|
+
if (sideBack && sideBack.focus) sideBack.focus();
|
|
440
|
+
}
|
|
441
|
+
$('#sideX').addEventListener('click', closeSide);
|
|
442
|
+
$('#sideAct').addEventListener('click', (e) => { if (e.target.closest('#sideGo')) (SIDE_GO[sideKind] || (() => {}))(); });
|
|
443
|
+
const seg = (name, opts, on) => `<div class="cz-seg" role="radiogroup" aria-label="${esc(name)}" data-seg="${esc(name)}">${opts.map((o) => `<button type="button" role="radio" aria-checked="${o === on}" aria-pressed="${o === on}" data-v="${esc(o)}">${esc(o)}</button>`).join('')}</div>`;
|
|
444
|
+
$('#sideBody').addEventListener('click', (e) => {
|
|
445
|
+
const b = e.target.closest('[data-seg] [data-v]'); if (b) { for (const x of $$('[data-v]', b.parentElement)) { const on = x === b; x.setAttribute('aria-checked', String(on)); x.setAttribute('aria-pressed', String(on)); } if (sideKind === 'goal') goalHint(); return; }
|
|
446
|
+
const o = e.target.closest('.ins-opt'); if (o) { for (const x of $$('.ins-opt', o.parentElement)) { const on = x === o; x.classList.toggle('on', on); x.setAttribute('aria-checked', String(on)); } return; }
|
|
447
|
+
const t = e.target.closest('.ins-tog'); if (t) { const on = t.getAttribute('aria-checked') !== 'true'; t.setAttribute('aria-checked', String(on)); t.classList.toggle('on', on); return; }
|
|
448
|
+
const rm = e.target.closest('[data-unpick]'); if (rm) { picked.delete(rm.dataset.unpick); drawGoals(); drawSel(); drawDashSide(); }
|
|
449
|
+
});
|
|
450
|
+
const segVal = (name) => { const b = $(`#sideBody [data-seg="${name}"] [aria-checked="true"]`); return b ? b.dataset.v : null; };
|
|
451
|
+
const UNIT_OF = { Percentage: '%', Duration: 'days', Amount: '$', Count: '' };
|
|
452
|
+
function goalHint() {
|
|
453
|
+
const ty = segVal('Type'), u = $('#ngU'); if (u && !u.dataset.touched) u.value = UNIT_OF[ty] != null ? UNIT_OF[ty] : u.value;
|
|
454
|
+
}
|
|
455
|
+
function openNewGoal() {
|
|
456
|
+
const objs = [...new Set(M.goals.map((g) => g.pillar).filter(Boolean))];
|
|
457
|
+
const p = periods()[0];
|
|
458
|
+
openSide({ kind: 'goal', eye: 'New goal', title: 'A goal PMOS reads on a schedule', go: 'Save goal', note: 'Initiatives can anchor to it once it is saved.',
|
|
459
|
+
body: `<label class="ins-fl">Name<input class="ins-inp" id="ngName" maxlength="120" placeholder="For example: Partner activation"></label>`
|
|
460
|
+
+ `<label class="ins-fl">Objective<input class="ins-inp" id="ngObj" maxlength="80" list="ngObjs" placeholder="The objective it serves"><datalist id="ngObjs">${objs.map((o) => `<option value="${esc(o)}">`).join('')}</datalist></label>`
|
|
461
|
+
+ `<p class="ins-fl">Type</p>${seg('Type', ['Percentage', 'Count', 'Amount', 'Duration'], 'Percentage')}`
|
|
462
|
+
+ `<div class="ins-2"><label class="ins-fl">Baseline<input class="ins-inp" id="ngBase" inputmode="decimal" maxlength="16" placeholder="24"></label><label class="ins-fl">Target<input class="ins-inp" id="ngTgt" inputmode="decimal" maxlength="16" placeholder="50"></label></div>`
|
|
463
|
+
+ `<div class="ins-2"><label class="ins-fl">Unit<input class="ins-inp" id="ngU" maxlength="12" value="%"></label><label class="ins-fl">By<input class="ins-inp" id="ngBy" type="date" value="${esc(iso(p.to))}"></label></div>`
|
|
464
|
+
+ '<p class="note">Better is read from the baseline and the target: a target above the baseline means up is better. Readings are added where the KR metrics are kept, or by a connected source. PMOS never guesses a missing reading.</p>'
|
|
465
|
+
+ '<div class="ins-box note">A <b>Done or not</b> goal and a <b>Stay within</b> budget are not KR metrics yet. Ask for one in Home, and PMOS proposes it as a health budget or a milestone.</div>' });
|
|
466
|
+
$('#ngU').addEventListener('input', () => { $('#ngU').dataset.touched = '1'; });
|
|
467
|
+
}
|
|
468
|
+
async function saveGoal() {
|
|
469
|
+
const v = (id) => $(id).value.trim(), m = $('#sideMsg');
|
|
470
|
+
const fields = { metric: v('#ngName'), baseline: Number(v('#ngBase')), target: Number(v('#ngTgt')), by: v('#ngBy'), unit: v('#ngU'), pillar: v('#ngObj') || undefined };
|
|
471
|
+
if (!fields.metric) { m.textContent = 'Give the goal a name.'; $('#ngName').focus(); return; }
|
|
472
|
+
if (v('#ngBase') === '' || !Number.isFinite(fields.baseline) || v('#ngTgt') === '' || !Number.isFinite(fields.target)) { m.textContent = 'Type a number for the baseline and the target.'; return; }
|
|
473
|
+
if (fields.baseline === fields.target) { m.textContent = 'The target must differ from the baseline.'; return; }
|
|
474
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(fields.by)) { m.textContent = 'Pick the date it is due.'; return; }
|
|
475
|
+
$('#sideGo').disabled = true; m.textContent = 'Saving.';
|
|
476
|
+
const res = await pmPost('/api/records/kr-metrics/add', { ws: M.board.ws, fields, why: 'New goal from Insights' });
|
|
477
|
+
$('#sideGo').disabled = false;
|
|
478
|
+
if (!res || res.ok !== true) { m.textContent = (res && res.error) || 'The goal could not be saved. Nothing changed.'; return; }
|
|
479
|
+
closeSide(); toast('Saved ' + fields.metric + '. It shows on Goals; it is drawn after two readings.'); await load();
|
|
480
|
+
}
|
|
481
|
+
function drawSel() {
|
|
482
|
+
$('#selBar').hidden = !selecting;
|
|
483
|
+
$('#selN').textContent = picked.size + (picked.size === 1 ? ' goal selected' : ' goals selected');
|
|
484
|
+
}
|
|
485
|
+
$('#selCancel').addEventListener('click', closeSide);
|
|
486
|
+
function openNewDash() {
|
|
487
|
+
if (!M.board.id) { toast('A dashboard is saved on a board, and this workspace has none.'); return; }
|
|
488
|
+
selecting = true; picked.clear(); setTab('goals'); drawGoals(); drawSel();
|
|
489
|
+
openSide({ kind: 'dash', eye: 'New dashboard · a saved view of Goals', title: 'New dashboard', go: 'Save dashboard', note: 'Saved in this workspace. It shows under View and in Library.', body: '' });
|
|
490
|
+
drawDashSide();
|
|
491
|
+
}
|
|
492
|
+
function drawDashSide() {
|
|
493
|
+
const keep = { n: ($('#ndName') || {}).value || '', q: ($('#ndQ') || {}).value || '', pin: $('#ndPin') ? $('#ndPin').getAttribute('aria-checked') === 'true' : false };
|
|
494
|
+
const L = [...picked].map((id) => M.goals.find((g) => g.id === id)).filter(Boolean);
|
|
495
|
+
$('#sideBody').innerHTML = `<form class="ins-desc" id="ndAsk"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/></svg><input id="ndAskIn" maxlength="300" placeholder="Or describe it, and PMOS shapes it in a chat" aria-label="Describe the dashboard"><button type="submit" class="cz-ib solid" aria-label="Describe it in a chat" title="Describe it in a chat">${SV('M12 19V5M6 11l6-6 6 6')}</button></form>`
|
|
496
|
+
+ `<label class="ins-fl">Name<input class="ins-inp" id="ndName" maxlength="60" value="${esc(keep.n)}" placeholder="For example: Partner first week"></label>`
|
|
497
|
+
+ `<label class="ins-fl">The question it answers<input class="ins-inp" id="ndQ" maxlength="200" value="${esc(keep.q)}" placeholder="Are new partners getting value in their first week?"></label>`
|
|
498
|
+
+ `<p class="ins-fl">Charts <span class="q">${L.length} picked on the left</span></p>`
|
|
499
|
+
+ (L.length ? `<div class="ins-picked">${L.map((g) => `<div class="ins-pk"><b>${esc(g.title)}</b><span class="note">${esc(g.key ? 'drawn as a line' : 'no series yet')}</span><button type="button" class="cz-ib" data-unpick="${esc(g.id)}" aria-label="Take ${esc(g.title)} off" title="Take it off">${SV('M6 6l12 12M18 6L6 18')}</button></div>`).join('')}</div>` : '<p class="note">Press goals in the table to add them.</p>')
|
|
500
|
+
+ `<div class="ins-pinrow"><button type="button" class="ins-tog${keep.pin ? ' on' : ''}" role="switch" aria-checked="${keep.pin}" id="ndPin" aria-label="Pin, so it opens first"></button><span>Pin, so it opens first</span></div>`
|
|
501
|
+
+ '<p class="note">A chart’s form (line, bars, number or meter) is set on the dashboard afterwards: Edit opens it beside a chat.</p>';
|
|
502
|
+
$('#ndAsk').addEventListener('submit', (e) => { e.preventDefault(); const t = $('#ndAskIn').value.trim(); toChat({ say: 'Make a dashboard of ' + t }); });
|
|
503
|
+
}
|
|
504
|
+
async function saveNewDash() {
|
|
505
|
+
const m = $('#sideMsg'), name = $('#ndName').value.trim();
|
|
506
|
+
if (!name) { m.textContent = 'Give the dashboard a name.'; $('#ndName').focus(); return; }
|
|
507
|
+
if (!picked.size) { m.textContent = 'Select at least one goal in the table.'; return; }
|
|
508
|
+
$('#sideGo').disabled = true; m.textContent = 'Saving.';
|
|
509
|
+
const res = await saveDash({ name, purpose: $('#ndQ').value.trim(), charts: [...picked] });
|
|
510
|
+
$('#sideGo').disabled = false;
|
|
511
|
+
if (!res || res.ok !== true) { m.textContent = (res && res.error) || 'The dashboard could not be saved. Nothing changed.'; return; }
|
|
512
|
+
const id = res.id || (res.dashboard && res.dashboard.id) || null, pin = $('#ndPin').getAttribute('aria-checked') === 'true';
|
|
513
|
+
closeSide(); toast('Saved ' + name + '. It shows under View and in Library.');
|
|
514
|
+
if (pin && id) await pinDash(id); else await load();
|
|
515
|
+
if (id) setView(id);
|
|
516
|
+
}
|
|
517
|
+
function openVerdict(r) {
|
|
518
|
+
if (!r) return;
|
|
519
|
+
const g = r.goal, c = g && g.key ? byKey(g.key) : null;
|
|
520
|
+
openSide({ kind: 'verdict', eye: 'Evaluate · your verdict', title: r.title, go: 'Record verdict', note: 'Opens Home with your verdict; PMOS records the evaluation there. Nothing is sent.',
|
|
521
|
+
tools: `<a class="cz-ib" href="/premium-initiative.html?${wsQ()}id=${encodeURIComponent(r.id)}" aria-label="Open the initiative" title="Open the initiative">${SV(DOCI)}</a>`,
|
|
522
|
+
body: (g ? `<p class="ins-fl">${esc(g.title)} <span class="q">the goal it is anchored to</span></p>${c ? `<div class="ntw pdchart">${tileHtml(c)}</div>` : ''}<div class="ins-kv3"><span><small>Promised</small><b>${esc(g.targetTxt || '—')}${g.by ? ' by ' + esc(g.by) : ''}</b></span><span><small>So far</small><b style="color:${PACE_C[g.pace.tone] || 'inherit'}">${esc(g.nowTxt || '—')}</b></span><span><small>Pace</small><b>${esc(g.pace.head)}</b></span></div>`
|
|
523
|
+
: '<p class="note">No goal with readings is anchored to it, so there is nothing measured to judge against. Judge it on what you saw.</p>')
|
|
524
|
+
+ '<p class="ins-fl">Your verdict</p><div class="ins-opts" role="radiogroup" aria-label="Your verdict">'
|
|
525
|
+
+ [['Keep', 'It stays as built. The Board moves it to Done.'], ['Iterate', 'Keep it, and start a linked initiative in Triage for the next step.'], ['Stop', 'Archive it and say why. The code stays until a chore removes it.']]
|
|
526
|
+
.map(([k, t], i) => `<button type="button" class="ins-opt${i === 1 ? ' on' : ''}" role="radio" aria-checked="${i === 1}" data-vd="${k}"><i class="rd"></i><span><b>${k}</b><small>${esc(t)}</small></span></button>`).join('') + '</div>'
|
|
527
|
+
+ '<label class="ins-fl">What we learned<textarea class="ins-ta" id="vdLearn" maxlength="600" placeholder="What the numbers and the work say"></textarea></label>' });
|
|
528
|
+
SIDE_GO.verdict = () => {
|
|
529
|
+
const v = ($('#sideBody .ins-opt.on') || {}).dataset || {}, learned = $('#vdLearn').value.trim();
|
|
530
|
+
location.href = homeAsk('verdict', 'Record my verdict on ' + r.title + ' (' + r.id + '): ' + (v.vd || 'Iterate') + '.' + (learned ? ' What we learned: ' + learned : ''));
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
const SIDE_GO = { goal: saveGoal, dash: saveNewDash, verdict: () => {} };
|
|
534
|
+
|
|
535
|
+
/* the + menu */
|
|
536
|
+
$('#newMenu').addEventListener('click', (e) => {
|
|
537
|
+
const b = e.target.closest('[data-new]'); if (!b) return; closeMenus();
|
|
538
|
+
if (b.dataset.new === 'goal') openNewGoal();
|
|
539
|
+
else if (b.dataset.new === 'dash') openNewDash();
|
|
540
|
+
else if (b.dataset.new === 'chart') openChartEdit(null);
|
|
541
|
+
else openReportEdit(null);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
/* ── the help popover: what lives on Insights, and the goal types (AgInsConcepts, AgInsTypes) ─────────────────────────────────────────── */
|
|
545
|
+
$('#helpPop').innerHTML = '<h2>What lives on Insights</h2><p class="note">Four things, each built from the one before. Only the first is data; the other three are ways of looking at it.</p><div class="ins-hc">'
|
|
546
|
+
+ [['Goal', 'A number PMOS reads on a schedule, with a target and a date: a KR metric. It shows as a row on Goals. Initiatives anchor to it.'], ['Chart', 'One goal drawn one way: line, bars, number or meter, with its target line. It lives on a dashboard.'], ['Dashboard', 'A saved view of Goals for one question. Always live, never sent. Pin one and it opens first.'], ['Report', 'A written update for an audience on a schedule. PMOS drafts each cycle; you review and issue it. Reports are made in Home and listed in Library.']]
|
|
547
|
+
.map(([t, d]) => `<div><b>${t}</b><p>${d}</p></div>`).join('') + '</div>'
|
|
548
|
+
+ '<h3>Every goal has a type, a direction and a period</h3><div class="ins-ht">'
|
|
549
|
+
+ [['Percentage', 'Baseline, target, up or down is better.', 'Hit, or how many points short.'], ['Count', 'A target count.', 'Hit, or how many short.'], ['Amount', 'A unit (money, users, tickets), baseline, target.', 'Hit, or the gap.'], ['Duration', 'Baseline, target. Usually down is better.', 'Hit, or how far off.']]
|
|
550
|
+
.map(([t, s, j]) => `<div><b>${t}</b><span>${s}</span><span>${j}</span></div>`).join('') + '</div>'
|
|
551
|
+
+ '<p class="note"><b>Period.</b> A goal has a start (its first reading) and an end (its date). On every goal, the bar under Now has a mark for how much of that time has gone, so ahead or behind is visible without reading a forecast.</p>';
|
|
552
|
+
|
|
553
|
+
/* ── Library (G2): reports, then dashboards; asks and what PMOS found in your work ────────────────────────────────────────────────────── */
|
|
193
554
|
let askTimer = 0;
|
|
194
|
-
const dismissing = new Map();
|
|
195
|
-
const ASKST = { running: ['Working', '
|
|
196
|
-
const insLine = (t, q) => `<span class="nil${q ? ' q' : ''}">${ICO(AIC)}<span>${esc(t)}</span></span>`;
|
|
197
|
-
function dashRow(D) {
|
|
198
|
-
const I = D.insight || {}, f = I.finds && I.finds[0], on = M.pinned === D.id, shown = curDash().id === D.id && !$('#cDash').hidden;
|
|
199
|
-
const line = I.none ? '' : insLine(f ? f.text : I.calmText);
|
|
200
|
-
const meta = `<span class="t">Dashboard</span>${on ? '<span class="s issued">Pinned</span>' : ''}${shown ? '<span>Shown above</span>' : ''}<span>${D.total} ${D.total === 1 ? 'chart' : 'charts'}</span>${D.off ? `<span class="s none">${D.off} behind</span>` : D.total ? '<span>All on their line</span>' : ''}`;
|
|
201
|
-
return `<div class="dmr" role="listitem"><button class="dmo" data-d="${esc(D.id)}"><span class="dmi c-Dash">${ICO(DASHI)}</span><span class="dmn"><b>${esc(D.name)}</b>${line || `<small>${esc(I.none ? 'No chart is drawn on it yet.' : '')}</small>`}<span class="dmm">${meta}</span></span></button>`
|
|
202
|
-
+ (pinnable(D) ? `<button class="npin" data-pin="${esc(D.id)}" aria-pressed="${on}" aria-label="${on ? 'Unpin' : 'Pin'} ${esc(D.name)}" title="${on ? 'Unpin' : 'Pin to the top of Insights'}">${ICO(PINI)}</button>` : '') + '</div>';
|
|
203
|
-
}
|
|
204
|
-
/* A report row's insight is the opening sentence of its latest file, marked as quoted from it. With no file it says no draft is written yet. */
|
|
205
|
-
function setupRow(s) {
|
|
206
|
-
const L = s.latest, line = L && L.lead ? insLine('“' + L.lead + '”', true) : '';
|
|
207
|
-
const from = L ? (L.lead ? 'From the ' + L.date + ' file' : 'The ' + L.date + ' file has no sentence to quote') : 'No draft is written yet';
|
|
208
|
-
return `<div class="dmr" role="listitem"><button class="dmo" data-setup="${esc(s.id)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(s.name)}</b>${line}<small>${esc([from, s.label, s.audience ? 'for ' + s.audience : ''].filter(Boolean).join(' · '))}</small><span class="dmm"><span class="t">Report</span><span class="s ${s.paused ? 'none' : 'issued'}">${s.paused ? 'Paused' : s.drafting ? 'Drafting' : 'Set up'}</span>${s.next && !s.paused ? `<span>Next draft ${esc(s.next)}</span>` : ''}</span></span></button></div>`;
|
|
209
|
-
}
|
|
210
|
-
/* One row per report (PM 2026-10-22: "Each report should have a list of issued/archived/draft report, so there's no duplication of the same report
|
|
211
|
-
* on the Insight page"): its name, the opening sentence of its latest cycle, and how many cycles are draft, issued and archived. The row opens the
|
|
212
|
-
* latest cycle in the reader, whose cycle chip lists the others. */
|
|
213
|
-
function repRow(g) {
|
|
214
|
-
const live = g.files.filter((x) => !x.archived), L = live[0], n = (f) => live.filter(f).length, d = n((x) => x.state !== 'issued'), i = n((x) => x.state === 'issued'), s = g.setup;
|
|
215
|
-
const pills = [d ? `<span class="s draft">${d} draft</span>` : '', i ? `<span class="s issued">${i} issued</span>` : ''].join('');
|
|
216
|
-
const st = s ? (s.paused ? '<span>Paused</span>' : s.drafting ? '<span>Drafting</span>' : s.next ? `<span>Next draft ${esc(s.next)}</span>` : '') : '<span>No template</span>';
|
|
217
|
-
return `<div class="dmr" role="listitem"><button class="dmo" data-rpt="${esc(g.id)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(g.name)}</b>${L.lead ? insLine('“' + L.lead + '”', true) : ''}<small>${esc('Latest: ' + (L.date || L.slot) + (s && s.label ? ' · ' + s.label : '') + (s && s.audience ? ' · for ' + s.audience : ''))}</small><span class="dmm"><span class="t">Report</span>${pills}${st}</span></span></button></div>`;
|
|
218
|
-
}
|
|
219
|
-
/** The report files grouped by report: a set-up report with files is one report row, one with none keeps its set-up row, and a cadence with
|
|
220
|
-
* files and no template is a report row of its own. Files keep their order (newest first, archived last). Archived cycles are hidden (PM
|
|
221
|
-
* 2026-10-22: "Archived report should be hidden"): a report whose cycles are all archived has no row (a set-up one keeps its set-up row), and
|
|
222
|
-
* its archived cycles stay reachable from the reader's cycle chip. */
|
|
555
|
+
const dismissing = new Map();
|
|
556
|
+
const ASKST = { running: ['Working', 'q'], ready: ['Proposal ready, not set up', 'you'], failed: ['Failed', 'red'] };
|
|
223
557
|
function reportGroups() {
|
|
224
558
|
const R = M.reports, by = new Map();
|
|
225
559
|
for (const f of R.missing ? [] : R.rows) { if (!by.has(f.cadence)) by.set(f.cadence, []); by.get(f.cadence).push(f); }
|
|
@@ -229,54 +563,62 @@ function reportGroups() {
|
|
|
229
563
|
for (const [id, fs] of by) if (shown(fs)) out.push({ kind: 'file', x: { id, name: id, setup: null, files: fs } });
|
|
230
564
|
return out;
|
|
231
565
|
}
|
|
232
|
-
const
|
|
233
|
-
const
|
|
234
|
-
function
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
return {
|
|
566
|
+
const dots = (fs) => `<span class="ins-dots" aria-hidden="true">${fs.slice(0, 8).reverse().map((x) => `<i class="${x.state === 'issued' ? 'is' : 'dr'}"></i>`).join('')}</span>`;
|
|
567
|
+
const lrow = (attr, name, sub, when, st, from, act) => `<div class="ins-tr ins-row ins-lcols" role="listitem"><button type="button" class="ins-lrow" ${attr} aria-haspopup="dialog"><span class="lic">${SV(DOCI)}</span><span class="nm"><b>${esc(name)}</b><small>${esc(sub)}</small></span><span class="note">${esc(when)}</span><span>${st}</span><span class="ins-from">${from}</span><span class="ins-act">${act}</span></button></div>`;
|
|
568
|
+
function repRow(g) {
|
|
569
|
+
const live = g.files.filter((x) => !x.archived), L = live[0], n = (f) => live.filter(f).length, d = n((x) => x.state !== 'issued'), i = n((x) => x.state === 'issued'), s = g.setup;
|
|
570
|
+
const st = `${dots(live)}<small class="note">${[d ? d + ' draft' : '', i ? i + ' issued' : ''].filter(Boolean).join(' · ')}${s && !s.paused && s.next ? ' · next ' + esc(s.next) : s && s.paused ? ' · paused' : ''}</small>`;
|
|
571
|
+
return lrow(`data-rpt="${esc(g.id)}"`, g.name, [L.lead ? '“' + L.lead + '”' : 'Latest: ' + (L.date || L.slot), s && s.audience ? s.audience : '', s && s.output ? s.output : ''].filter(Boolean).join(' · '),
|
|
572
|
+
s && s.label ? s.label : 'No template', st, s && s.source ? `<span class="cz-pill q">${esc(s.source === 'work' ? 'Your work' : s.source)}</span>` : '', d ? '<span class="cz-pill you">Review draft</span>' : '');
|
|
573
|
+
}
|
|
574
|
+
const setupRow = (s) => { const L = s.latest; return lrow(`data-setup="${esc(s.id)}"`, s.name, [L && L.lead ? '“' + L.lead + '”' : L ? 'From the ' + L.date + ' file' : 'No draft is written yet', s.audience ? 'for ' + s.audience : ''].filter(Boolean).join(' · '), s.label || '',
|
|
575
|
+
`<small class="note">${s.paused ? 'Paused' : s.drafting ? 'Drafting' : s.next ? 'First draft ' + esc(s.next) : 'Set up'}</small>`, s.source ? `<span class="cz-pill q">${esc(s.source === 'work' ? 'Your work' : s.source)}</span>` : '', '<span class="cz-pill q">Set up</span>'); };
|
|
576
|
+
const askRow = (a) => lrow(`data-ask="${esc(a.id)}"`, a.proposal && a.proposal.name ? a.proposal.name : a.text, 'You asked: ' + a.text, a.changed ? 'Changed once' : '', `<small class="note">${esc(ASKST[a.state][0])}</small>`, '', a.state === 'ready' ? '<span class="cz-pill you">Review proposal</span>' : '');
|
|
577
|
+
const foundRow = (f) => lrow(`data-found="${esc(f.id)}"`, f.name, f.why, f.confidence || '', `<small class="note">${f.evidence.length} ${f.evidence.length === 1 ? 'sign' : 'signs'} in your work</small>`, '', '<span class="cz-pill q">Review</span>');
|
|
578
|
+
function miniHtml(c) {
|
|
579
|
+
const d = c.pts.map((p, i) => (i ? 'L' : 'M') + (5 + p.fx * 120).toFixed(1) + ',' + (4 + (1 - p.fy) * 18).toFixed(1)).join(''), l = c.pts[c.pts.length - 1];
|
|
580
|
+
return `<span class="ins-mini"><small>${esc(c.title)}</small><b>${esc(c.v)}</b><svg viewBox="0 0 130 26" aria-hidden="true"><path d="${d}L125,26L5,26Z" class="ar"/><path d="${d}" class="ln"/><circle cx="${(5 + l.fx * 120).toFixed(1)}" cy="${(4 + (1 - l.fy) * 18).toFixed(1)}" r="3" style="fill:${c.off ? 'var(--cz-dot-late)' : 'var(--cz-dot-ok)'}"/></svg></span>`;
|
|
581
|
+
}
|
|
582
|
+
function dashCard(D) {
|
|
583
|
+
const L = D.keys.map(byKey).filter(Boolean), on = M.pinned === D.id;
|
|
584
|
+
const pill = !L.length ? '<span class="cz-pill q">No chart</span>' : D.off ? `<span class="cz-pill late">${D.off} behind</span>` : '<span class="cz-pill ok">On course</span>';
|
|
585
|
+
const sub = D.id === 'all' ? 'Every goal · PMOS keeps it' : D.saved ? (D.purpose || D.charts.length + ' goals') : 'The goals of one objective';
|
|
586
|
+
return `<div class="ins-dcard" role="listitem"><button type="button" class="ins-dopen" data-d="${esc(D.id)}" aria-label="Open ${esc(D.id === 'all' ? 'All goals' : D.name)} on Goals"><span class="ins-dh"><b>${esc(D.id === 'all' ? 'All goals' : D.name)}</b>${pill}</span><span class="ins-minis">${L.slice(0, 2).map(miniHtml).join('') || '<span class="note">No goal on it has a series yet.</span>'}</span><small class="note">${esc(sub)}</small></button>`
|
|
587
|
+
+ (pinnable(D) ? `<button type="button" class="cz-ib ins-pin${on ? ' on' : ''}" data-pin="${esc(D.id)}" aria-pressed="${on}" aria-label="${on ? 'Unpin' : 'Pin'} ${esc(D.name)}" title="${on ? 'Unpin' : 'Pin, so it opens first'}">${SV(PINI)}</button>` : '') + '</div>';
|
|
238
588
|
}
|
|
239
589
|
function drawList() {
|
|
240
|
-
const R = M.reports, found = (R.found || []).filter((f) => !dismissing.has(f.id)), asks = R.asks || [];
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
$('#repCap').textContent = String(
|
|
244
|
-
const F3 = [['all', 'All',
|
|
245
|
-
$('#listSeg').innerHTML = F3.map(([k, t, n]) => `<button type="button" data-f="${k}" aria-pressed="${listF === k}">${t}<
|
|
246
|
-
$('#listF').
|
|
247
|
-
$('#
|
|
248
|
-
$('#
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
+ empty +
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
$('#listPager').innerHTML =
|
|
260
|
-
: `<span class="note">${from}–${to} of ${L.length}</span><span class="pg" role="group" aria-label="Pages"><button data-pg="${listP - 1}" ${listP === 1 ? 'disabled' : ''} aria-label="Previous page">‹</button>${Array.from({ length: pages }, (_, i) => `<button data-pg="${i + 1}"${i + 1 === listP ? ' aria-current="page"' : ''} aria-label="Page ${i + 1}">${i + 1}</button>`).join('')}<button data-pg="${listP + 1}" ${listP === pages ? 'disabled' : ''} aria-label="Next page">›</button></span>`;
|
|
590
|
+
const R = M.reports, found = (R.found || []).filter((f) => !dismissing.has(f.id) && hit(f.name, f.why)), asks = (R.asks || []).filter((a) => hit(a.text));
|
|
591
|
+
const reps = reportGroups().filter((g) => hit(g.x.name)), dashes = M.dashboards.filter((d) => hit(d.name));
|
|
592
|
+
const nRep = reps.length + asks.length;
|
|
593
|
+
$('#repCap').textContent = String(nRep + dashes.length);
|
|
594
|
+
const F3 = [['all', 'All', nRep + dashes.length], ['rep', 'Reports', nRep], ['dash', 'Dashboards', dashes.length]];
|
|
595
|
+
$('#listSeg').innerHTML = F3.map(([k, t, n]) => `<button type="button" class="cz-chip${listF === k ? ' on' : ''}" data-f="${k}" aria-pressed="${listF === k}">${t} <b>${n}</b></button>`).join('');
|
|
596
|
+
$('#listF').textContent = F3.find((f) => f[0] === listF)[1];
|
|
597
|
+
$('#sugB').hidden = !found.length;
|
|
598
|
+
$('#sugB').innerHTML = SV('M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z') + found.length + (found.length === 1 ? ' suggestion' : ' suggestions') + ' from your work';
|
|
599
|
+
$('#sugB').setAttribute('aria-expanded', String(sugOpen));
|
|
600
|
+
const empty = R.missing ? '<div class="ins-empty"><b>The report files could not be read</b>, so none is listed.</div>'
|
|
601
|
+
: R.setupsOk === false ? '<div class="ins-empty"><b>The report setups could not be read</b>, so what PMOS found and what you set up are not listed.</div>' : '';
|
|
602
|
+
const rhead = '<div class="ins-tr ins-th ins-lcols ins-lhead" role="presentation"><span></span><span>Report · audience</span><span>When</span><span>Issued · next</span><span>Built from</span><span></span></div>';
|
|
603
|
+
const repRows = reps.map((g) => g.kind === 'setup' ? setupRow(g.x) : repRow(g.x)).join('') + asks.map(askRow).join('');
|
|
604
|
+
const sug = found.length && sugOpen ? `<div class="ins-sec"><h3>Found in your work</h3><span class="q">${found.length}</span></div><div class="ins-tbl" id="repFound" role="list">${found.map(foundRow).join('')}</div>` : '<span id="repFound" hidden></span>';
|
|
605
|
+
const repBlock = listF === 'dash' ? '' : `<div class="ins-sec"><h3>Reports</h3><span class="q">${nRep} · by next due</span></div>` + empty
|
|
606
|
+
+ (nRep ? `<div class="ins-tbl" id="repAsks">${rhead}<div role="list">${repRows}</div></div>` : !empty ? '<div class="ins-empty"><b>No report is set up and no report file is on record.</b> Reports are made in Home: press New, then New report.</div>' : '') + sug;
|
|
607
|
+
const dashBlock = listF === 'rep' ? '' : `<div class="ins-sec"><h3>Dashboards</h3><span class="q">${dashes.length} · a dashboard is a saved view of Goals</span></div><div class="ins-dgrid" role="list">${dashes.map(dashCard).join('')}</div>`;
|
|
608
|
+
$('#repBody').innerHTML = `<div id="listRows" aria-label="Dashboards and reports">${repBlock}${dashBlock}</div>`;
|
|
609
|
+
$('#listPager').innerHTML = '';
|
|
261
610
|
clearTimeout(askTimer);
|
|
262
|
-
if (asks.some((a) => a.state === 'running')) askTimer = setTimeout(load, 5000);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
$('#listF').addEventListener('click', () => {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
$('#listSeg').addEventListener('click', (e) => { const b = e.target.closest('[data-f]'); if (!b) return; fMenu(false); if (b.dataset.f === listF) return; listF = b.dataset.f; listP = 1; drawList(); $('#listF').focus(); });
|
|
269
|
-
$('#listPager').addEventListener('click', (e) => { const b = e.target.closest('[data-pg]'); if (!b || b.disabled) return; listP = +b.dataset.pg; drawList(); $('#cRep').scrollIntoView({ block: 'nearest' }); });
|
|
270
|
-
const menu = (open) => { $('#listMenu').hidden = !open; $('#listNew').setAttribute('aria-expanded', String(open)); };
|
|
271
|
-
$('#listNew').addEventListener('click', () => { const open = $('#listMenu').hidden; menu(open); if (open) $('#listMenu button').focus(); });
|
|
272
|
-
$('#listMenu').addEventListener('click', (e) => { const b = e.target.closest('button'); if (!b) return; menu(false); if (b.id === 'pdNew') openDashEdit(null); else if (b.id === 'repNew') openReportEdit(null); });
|
|
273
|
-
document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !$('#listMenu').hidden) { menu(false); $('#listNew').focus(); } });
|
|
274
|
-
document.addEventListener('click', (e) => { if (!$('#listMenu').hidden && !e.target.closest('.newm')) menu(false); });
|
|
611
|
+
if ((R.asks || []).some((a) => a.state === 'running')) askTimer = setTimeout(load, 5000);
|
|
612
|
+
}
|
|
613
|
+
$('#listSeg').addEventListener('click', (e) => { const b = e.target.closest('[data-f]'); if (!b || b.dataset.f === listF) return; listF = b.dataset.f; drawList(); });
|
|
614
|
+
$('#listF').addEventListener('click', () => { /* the chips are always shown; kept for the pages that press it */ });
|
|
615
|
+
$('#sugB').addEventListener('click', () => { sugOpen = !sugOpen; drawList(); });
|
|
616
|
+
$('#listMenu').addEventListener('click', (e) => { const b = e.target.closest('button'); if (!b) return; closeMenus(); if (b.id === 'lmDash') openNewDash(); else if (b.id === 'lmRep') openReportEdit(null); });
|
|
275
617
|
$('#repBody').addEventListener('click', (e) => {
|
|
276
618
|
const pin = e.target.closest('[data-pin]');
|
|
277
|
-
if (pin) { pin.disabled = true; pinDash(M.pinned === pin.dataset.pin ? null : pin.dataset.pin
|
|
619
|
+
if (pin) { pin.disabled = true; pinDash(M.pinned === pin.dataset.pin ? null : pin.dataset.pin); return; }
|
|
278
620
|
const d = e.target.closest('[data-d]');
|
|
279
|
-
if (d) {
|
|
621
|
+
if (d) { setView(d.dataset.d); try { $('#cDash').scrollIntoView({ behavior: 'smooth', block: 'start' }); } catch { /* no scroll */ } return; }
|
|
280
622
|
const rp = e.target.closest('[data-rpt]');
|
|
281
623
|
if (rp) { const g = reportGroups().find((x) => x.kind === 'file' && x.x.id === rp.dataset.rpt); if (g) openReport(g.x.files.find((x) => !x.archived), { ws: M.board.ws, name: g.x.setup ? g.x.setup.name : null, cycles: g.x.files, onIssue: () => load(), onChange: () => load() }); return; }
|
|
282
624
|
const f = e.target.closest('[data-found]'), a = e.target.closest('[data-ask]'), s = e.target.closest('[data-setup]');
|
|
@@ -295,7 +637,7 @@ $('#repAsk').addEventListener('submit', async (e) => {
|
|
|
295
637
|
inp.value = ''; toast('Asked. A background run is working on a proposal. Nothing is set up yet.'); await load();
|
|
296
638
|
});
|
|
297
639
|
|
|
298
|
-
/* ── the report dialogs: each press is one existing /api/report-setups/* route (
|
|
640
|
+
/* ── the report dialogs: each press is one existing /api/report-setups/* route (briefing-premium-reports R2 to R4) ─────────────────────── */
|
|
299
641
|
const repPost = (sub, body) => pmPost('/api/report-setups/' + sub, Object.assign({ ws: M.board.ws }, body));
|
|
300
642
|
function repDlg(o) {
|
|
301
643
|
openDlg({ eye: o.eye + ' · real data', title: o.title, sub: o.sub || M.board.name, say: o.say, stream: turnA(ptx(o.say)), noteKey: popKey('report', M.board.ws, o.title), facts: o.facts, label: 'Report',
|
|
@@ -311,13 +653,11 @@ function repDlg(o) {
|
|
|
311
653
|
closeDlg(); await load();
|
|
312
654
|
};
|
|
313
655
|
}
|
|
314
|
-
/* Words for a refused press: what the server said, then how to go on. A reason (set-up | dismissed | gone) means the list this window came from is out of date, so it is read again and a retry would only repeat the refusal. */
|
|
315
656
|
const pressFailed = (res, plain) => {
|
|
316
657
|
const e = res && res.error ? String(res.error) : plain;
|
|
317
658
|
if (res && res.reason) return e + ' This window is out of date. Close it; the list has been read again.';
|
|
318
659
|
return e + ' Nothing was recorded. Press the button to try again.';
|
|
319
660
|
};
|
|
320
|
-
/* A press: post, then say the result in words, or keep the dialog open with the server's refusal. */
|
|
321
661
|
const press = (sub, body, said) => async (m) => {
|
|
322
662
|
m.textContent = 'Recording.';
|
|
323
663
|
const res = await repPost(sub, body);
|
|
@@ -345,7 +685,7 @@ function openFound(f) {
|
|
|
345
685
|
function openAsk(a) {
|
|
346
686
|
if (!a) return;
|
|
347
687
|
if (a.state === 'running') {
|
|
348
|
-
repDlg({ eye: 'Your request', title: a.text, say: 'A background run is working on a proposal. It proposes only; nothing is set up until you press Set it up.', html:
|
|
688
|
+
repDlg({ eye: 'Your request', title: a.text, say: 'A background run is working on a proposal. It proposes only; nothing is set up until you press Set it up.', html: '<p class="lede" style="margin:0">A background run is working on this request. This page checks again every 5 seconds.</p>', acts: [['cancel', 'Cancel the request', 1]], on: { cancel: press('cancel', { id: a.id }, 'Request cancelled.') } });
|
|
349
689
|
return;
|
|
350
690
|
}
|
|
351
691
|
if (a.state === 'failed') {
|
|
@@ -377,16 +717,12 @@ function openSetup(s) {
|
|
|
377
717
|
} });
|
|
378
718
|
}
|
|
379
719
|
|
|
380
|
-
/* ──
|
|
381
|
-
function drawDock() { $('#dN').textContent = M.dock.needs; $('#dLab').textContent = M.dock.label; $('#dNext').innerHTML = M.dock.next ? `<i></i>First <b>${esc(M.dock.next)}</b>` : 'No measure is behind its line'; }
|
|
382
|
-
|
|
383
|
-
/* ── the dialog: the measure's record, no press, the read-only agent beside it ───────────────────────────────── */
|
|
720
|
+
/* ── the goal's dialog: its record and readings, the read-only agent beside it, and the switches that put it on a dashboard ─────────────── */
|
|
384
721
|
function cardHtml(c) { return `<div class="acard" id="card"><p class="ct">What this page can do</p><p class="nodef" id="holdWhy">${esc(c.dialog.hold)} The switches under On your dashboards save a dashboard and change no record.</p></div>`; }
|
|
385
722
|
function paneHtml(c) {
|
|
386
723
|
const p = c.dialog.pane;
|
|
387
|
-
return `<article class="paper doc"><p class="dpath">${esc(p.file)}</p><h3 class="d1">${esc(c.title)}</h3><p>${esc(c.dialog.say)}</p><div class="ntw pdchart">${tileHtml(c)}</div><div class="kv2">${c.dialog.facts.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div><h3 class="h2">All ${c.pts.length} readings</h3><div class="kv2">${p.rows.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div>${onDashHtml(c)}<p class="xn">Read from the KR metric record. The line status is the record's own: the straight line from its baseline to its target. Where this page says where a
|
|
724
|
+
return `<article class="paper doc"><p class="dpath">${esc(p.file)}</p><h3 class="d1">${esc(c.title)}</h3><p>${esc(c.dialog.say)}</p><div class="ntw pdchart">${tileHtml(c)}</div><div class="kv2">${c.dialog.facts.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div><h3 class="h2">All ${c.pts.length} readings</h3><div class="kv2">${p.rows.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div>${onDashHtml(c)}<p class="xn">Read from the KR metric record. The line status is the record's own: the straight line from its baseline to its target. Where this page says where a goal lands by its date, that is a straight line through its last four readings, carried to that date.</p></article>`;
|
|
388
725
|
}
|
|
389
|
-
/* Add to a dashboard (PRD D6): one switch per saved dashboard of the board. A press saves that dashboard with the chart added or taken off. */
|
|
390
726
|
function onDashHtml(c) {
|
|
391
727
|
if (!M.board.id) return '';
|
|
392
728
|
const L = savedDash();
|
|
@@ -414,78 +750,28 @@ function openChart(c) {
|
|
|
414
750
|
}
|
|
415
751
|
$('#dBody').addEventListener('click', (e) => { const lt = e.target.closest('#logT'); if (lt) { const c = $('#alog').classList.toggle('col'); lt.setAttribute('aria-expanded', !c); } });
|
|
416
752
|
|
|
417
|
-
/* ──
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
if (!BM) return;
|
|
427
|
-
$('#bmCap').textContent = BM.header;
|
|
428
|
-
$('#bmHint').innerHTML = (BM.lead ? `<b class="mflag">${esc(BM.lead)}</b> ` : '') + esc(BM.body) + ' Press a measure to set its target. The Board draws the same target.';
|
|
429
|
-
$('#bmBody').style.gridTemplateColumns = 'repeat(' + Math.min(4, BM.tiles.length) + ',minmax(0,1fr))';
|
|
430
|
-
$('#bmBody').innerHTML = BM.tiles.map(MT.tileHtml).join('');
|
|
431
|
-
$('#bmNote').textContent = BM.note;
|
|
432
|
-
$('#bmLead').hidden = !BM.lead; $('#bmLead').textContent = BM.lead || ''; // the one line left in view; ⓘ opens the hint and the note
|
|
433
|
-
}
|
|
434
|
-
async function bmLoad() {
|
|
435
|
-
clearTimeout(bmTimer);
|
|
436
|
-
if (!M || !M.board || !M.board.ws) { $('#cBm').hidden = true; return; }
|
|
437
|
-
let r = null;
|
|
438
|
-
try { const res = await fetch('/api/board-metrics-premium?ws=' + encodeURIComponent(M.board.ws) + '&weeks=' + bmWeeks, { credentials: 'same-origin' }); r = await res.json(); } catch { r = null; }
|
|
439
|
-
if (!r || !r.ok || r.state !== 'ready') { BM = null; bmDraw(); $('#bmCap').textContent = 'not read'; $('#bmHint').textContent = 'The Board measures could not be read, so none is shown.' + (r && r.error ? ' The reason: ' + r.error : ''); $('#bmLead').hidden = false; $('#bmLead').textContent = $('#bmHint').textContent; $('#bmBody').innerHTML = ''; $('#bmNote').textContent = ''; return; }
|
|
440
|
-
BM = r.model; bmDraw();
|
|
441
|
-
if (BM.pending) bmTimer = setTimeout(bmLoad, 4000); // the workflow engine is still deriving Blocked and Idle
|
|
442
|
-
}
|
|
443
|
-
function bmOpen(i) {
|
|
444
|
-
const t = BM && BM.tiles[i]; if (!t) return;
|
|
445
|
-
const vals = t.ser ? `<h3 class="sh">Values</h3><div class="vtb">${t.ser.map((v, j) => `<div><span>${esc(t.wk[j])}</span><b>${v == null ? (t.since ? 'Not kept yet' : 'No runs') : esc(MT.fmt(t, v))}</b></div>`).join('')}</div>` : '';
|
|
446
|
-
const form = t.absent ? `<p class="note" style="margin:12px 0 0">A target can be set once this measure is counted.</p>`
|
|
447
|
-
: `<div class="addf" style="margin-top:14px"><label>Target (${t.lowBetter ? 'at most' : 'at least'})<input id="bmT" inputmode="decimal" maxlength="12" value="${t.tg != null ? esc(String(t.tg)) : ''}" placeholder="For example: ${t.key === 'corrections' ? '10' : t.key === 'merges' ? '5' : '0'}"></label>
|
|
448
|
-
<p class="note" id="bmM" role="status" style="margin:0;min-height:1.2em"></p><div class="cact"><button class="cta" id="bmGo">Save target</button>${t.tg != null ? '<button class="cta alt" id="bmClr">Clear target</button>' : ''}</div></div>`;
|
|
449
|
-
// popup context slice 5: the first line reads the numbers, and says when the trunk was fetched, so two empty weeks are not taken for a quiet trunk
|
|
450
|
-
const lt = (iso) => { const d = new Date(iso); return Number.isNaN(d.getTime()) ? '' : d.getDate() + ' ' + d.toLocaleString('en-GB', { month: 'short' }) + ' ' + String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0'); };
|
|
451
|
-
const fetched = t.trunk ? (t.trunk.fetched_at ? `${t.trunk.ref} was last fetched ${lt(t.trunk.fetched_at)}` : `${t.trunk.ref} has no fetch on record`) : '';
|
|
452
|
-
const tgt = t.tg != null ? ` The target is ${t.tg}; change it or clear it here.` : ' No target is set; type one and save it.';
|
|
453
|
-
const say = t.absent ? `${t.label} is not shown: ${t.why}`
|
|
454
|
-
: t.quiet ? `${t.label} was ${t.quiet.peak} in the week to ${t.quiet.week}, then 0 for the last two weeks. That is a quiet trunk or an old fetch: ${fetched || 'the fetch time is not known'}.${tgt}`
|
|
455
|
-
: `${t.label} is ${t.value}, ${t.text}.${t.change ? ' ' + t.change.txt + '.' : ''}${fetched ? ' ' + fetched + '.' : ''}${tgt}`;
|
|
456
|
-
const facts = MT.factRows(t, BM.repo, BM.weeks).concat(t.trunk ? [['Trunk read', t.trunk.ref + (t.trunk.fetched_at ? ', fetched ' + lt(t.trunk.fetched_at) : ', no fetch on record')]] : []);
|
|
457
|
-
const pane = `<article class="paper doc"><p class="lede" style="margin:0 0 10px">${esc(t.def)}</p>${kv(facts)}${form}${vals}<p class="note" style="margin-top:12px">${esc(BM.note)}</p></article>`;
|
|
458
|
-
openDlg({ eye: 'Board measure · real data', title: t.label, sub: BM.repo, say, stream: turnA(ptx(say)), noteKey: popKey('measure', BM.repo, t.key || t.label), facts, pane, label: 'Measure' });
|
|
459
|
-
$('#oMain').onchange = null;
|
|
460
|
-
$('#oMain').onclick = async (e) => {
|
|
461
|
-
const go = e.target.closest('#bmGo'), clr = e.target.closest('#bmClr'); if (!go && !clr) return;
|
|
462
|
-
const target = clr ? null : $('#bmT').value.trim();
|
|
463
|
-
if (go && target === '') { $('#bmM').textContent = 'Type a number first.'; return; }
|
|
464
|
-
(go || clr).disabled = true; $('#bmM').textContent = 'Saving.';
|
|
465
|
-
const res = await pmPost('/api/board-metric-targets/save', { ws: M.board.ws, key: t.key, target });
|
|
466
|
-
(go || clr).disabled = false;
|
|
467
|
-
if (!res || res.ok !== true) { $('#bmM').textContent = (res && res.error) || 'The target could not be saved.'; return; }
|
|
468
|
-
closeDlg(); toast(clr ? 'The target of ' + t.label + ' is cleared.' : 'The target of ' + t.label + ' is ' + target + '.');
|
|
469
|
-
bmLoad();
|
|
470
|
-
};
|
|
753
|
+
/* ── load ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
754
|
+
function drawDock() { $('#dN').textContent = M.dock.needs; $('#dLab').textContent = M.dock.label; $('#dNext').textContent = M.dock.next ? 'First ' + M.dock.next : 'No goal is behind its line'; }
|
|
755
|
+
function redraw() { if (!M) return; drawBar(); drawStrip(); drawGoals(); drawDash(); drawOutcomes(); drawList(); }
|
|
756
|
+
function draw() {
|
|
757
|
+
if (!dash || !M.dashboards.some((d) => d.id === dash)) dash = M.pinned || 'all';
|
|
758
|
+
$('#snap').textContent = M.header.text;
|
|
759
|
+
$('#snap').title = 'Every figure on this page comes from a KR metric record. A goal with fewer than two readings is listed, not drawn.';
|
|
760
|
+
setPageGaps(((M.header && M.header.missing) || []).length);
|
|
761
|
+
redraw(); drawDock();
|
|
471
762
|
}
|
|
472
|
-
MT.wireTiles($('#bmBody'), () => (BM ? BM.tiles : []), bmOpen);
|
|
473
|
-
$('#bmRange').addEventListener('click', (e) => { const b = e.target.closest('[data-w]'); if (!b || +b.dataset.w === bmWeeks) return; bmWeeks = +b.dataset.w; try { localStorage.setItem(BM_KEY, String(bmWeeks)); } catch { /* not kept */ } bmDraw(); bmLoad(); });
|
|
474
|
-
|
|
475
|
-
/* ── load ─────────────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
476
|
-
function draw() { drawHead(); if (!dash || !M.dashboards.some((d) => d.id === dash)) dash = M.pinned || 'all'; drawDash(); drawList(); drawDock(); onScroll(); }
|
|
477
763
|
async function load() {
|
|
478
764
|
const p = new URLSearchParams(location.search), q = [p.get('ws') ? 'ws=' + encodeURIComponent(p.get('ws')) : '', p.get('board') ? 'board=' + encodeURIComponent(p.get('board')) : ''].filter(Boolean).join('&');
|
|
479
765
|
let r = null, status = 0;
|
|
480
766
|
try { const res = await fetch('/api/insights-premium' + (q ? '?' + q : ''), { credentials: 'same-origin' }); status = res.status; r = await res.json(); } catch { r = null; }
|
|
481
767
|
if (!r || !r.ok) {
|
|
482
768
|
$('#snap').textContent = 'The records could not be read';
|
|
483
|
-
$('#insEye').textContent = '
|
|
769
|
+
$('#insEye').textContent = ''; $('#insWhy').textContent = ''; $('#askWhy').hidden = true;
|
|
484
770
|
$('#brief').textContent = 'The KR metric records could not be read, so this page shows nothing rather than guess.' + (r && r.error ? ' The reason: ' + r.error : status ? ' (the server answered ' + status + ')' : ' The server did not answer.');
|
|
485
771
|
setTimeout(load, 15000);
|
|
486
772
|
return;
|
|
487
773
|
}
|
|
488
774
|
M = r.model; draw(); bmLoad();
|
|
489
775
|
}
|
|
490
|
-
|
|
776
|
+
{ const t = new URLSearchParams(location.search).get('tab'); if (t === 'outcomes' || t === 'library') setTab(t); else setTab('goals'); }
|
|
491
777
|
load();
|