create-pmos 0.270.0 → 0.271.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.
@@ -3,7 +3,8 @@
3
3
  * line, what stands out), the Reports card, the dock and the standard dialog.
4
4
  * briefing-premium-reports adds the PM's presses, each through pmPost and so behind the launch nonce: a saved dashboard (POST /api/premium-dashboards/save,
5
5
  * PRD D2 to D6) and the report presses of the console's Reports workspace (POST /api/report-setups/ask | change | cancel | setup | dismiss | pause | resume |
6
- * draft, PRD R2 to R4). Nothing else posts, and nothing is sent outward. */
6
+ * draft, PRD R2 to R4). premium-studio-chart adds a saved chart (POST /api/premium-charts/save, PRD C1, C10) and its four forms (C3). Nothing else posts, and
7
+ * nothing is sent outward. */
7
8
  import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, crumbHtml, wireCrumb, kv } from './premium-shell.js';
8
9
  import { pmPost } from './http.js';
9
10
  import { openStudio } from './premium-studio.js';
@@ -15,7 +16,7 @@ const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
15
16
  const DOCI = '<path d="M6 3h9l4 4v14H6z"/><path d="M14 3v5h5M9 13h6M9 17h4"/>';
16
17
  const CHV2 = '<svg class="i" viewBox="0 0 24 24"><path d="M9 6l6 6-6 6"/></svg>';
17
18
  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"/>';
18
- const byKey = (k) => (M && M.charts || []).find((c) => c.key === k) || null;
19
+ const byKey = (k) => (M && (M.charts || []).concat(M.mine || []) || []).find((c) => c.key === k) || null;
19
20
  const savedDash = () => (M.dashboards || []).filter((d) => d.saved);
20
21
 
21
22
  /* ── header ───────────────────────────────────────────────────────────────────────────────────────────────────── */
@@ -35,14 +36,59 @@ function drawHead() {
35
36
  /* ── charts ───────────────────────────────────────────────────────────────────────────────────────────────────── */
36
37
  const W = 220, H = 60, P = 5;
37
38
  const X = (fx) => P + fx * (W - 2 * P), Y = (fy) => P + (1 - fy) * (H - 2 * P);
39
+ /* A chart is drawn in one of four forms (initiative premium-studio-chart C3). The page and the Insight Studio share this drawing. A KR metric's own chart
40
+ * is a line; a chart the PM saved carries its form. Bars and a meter start at zero, so a series with a value below zero is drawn as a line and says so. */
41
+ const unitTxt = (c, v) => { const u = c.unit || '', s = String(Math.round(v * 100) / 100); return u ? (/^[A-Za-z]/.test(u) ? s + ' ' + u : s + u) : s; };
42
+ function chgHtml(c) {
43
+ return c.step === 0 ? '' : `<span class="mchg ${c.good === null ? '' : c.good ? 'good' : 'bad'}">${c.step > 0 ? '▲ ' : '▼ '}${esc(Math.abs(c.step) + (c.unit && /^[%°]/.test(c.unit) ? c.unit : c.unit ? ' ' + c.unit : ''))} since the last reading</span>`;
44
+ }
45
+ const chipOf = (c) => `<i class="mchip ${c.chipKind === 'bad' ? 'warn' : c.chipKind}">${esc(c.chip)}</i>`;
46
+ const capOf = (c) => 'on ' + c.at + (c.targetTxt ? ' · ' + c.targetTxt : '');
38
47
  function tileHtml(c) {
48
+ const f = c.form || 'line', neg = c.pts.some((p) => p.v < 0) || (c.target !== null && c.target < 0);
49
+ const h = f === 'number' ? numTile(c) : f === 'bars' && !neg ? barsTile(c) : f === 'meter' && !neg && c.target !== null ? meterTile(c) : lineTile(c, f !== 'line' && f !== 'number' ? (neg ? 'A value is below zero, so it is drawn as a line.' : 'No target is set, so it is drawn as a line.') : '');
50
+ return h + (c.note ? `<p class="mnote">${esc(c.note)}</p>` : '');
51
+ }
52
+ function lineTile(c, why) {
39
53
  const d = c.pts.map((p, i) => (i ? 'L' : 'M') + X(p.fx).toFixed(1) + ',' + Y(p.fy).toFixed(1)).join('');
40
54
  const last = c.pts[c.pts.length - 1];
41
- const cls = c.chipKind === 'bad' ? 'warn' : c.chipKind;
42
- const chg = c.step === 0 ? '' : `<span class="mchg ${c.good === null ? '' : c.good ? 'good' : 'bad'}">${c.step > 0 ? '▲ ' : '▼ '}${esc(Math.abs(c.step) + (c.unit && /^[%°]/.test(c.unit) ? c.unit : c.unit ? ' ' + c.unit : ''))} since the last reading</span>`;
43
- return `<div class="mt1 mch ${c.chipKind}${c.off ? ' off' : ''}" data-key="${esc(c.key)}" tabindex="0" role="img" aria-label="${esc(c.title)}, ${c.pts.length} readings, now ${esc(c.v)}${c.targetTxt ? ', ' + esc(c.targetTxt) : ''}. Use the arrow keys to read each reading."><span class="mlab">${esc(c.title)}<i class="mchip ${cls}">${esc(c.chip)}</i></span><b class="mval">${esc(c.v)}</b><em class="mwk">${esc('on ' + c.at + (c.targetTxt ? ' · ' + c.targetTxt : ''))}</em>${chg}`
55
+ return `<div class="mt1 mch ${c.chipKind}${c.off ? ' off' : ''}" data-key="${esc(c.key)}" tabindex="0" role="img" aria-label="${esc(c.title)}, ${c.pts.length} readings, now ${esc(c.v)}${c.targetTxt ? ', ' + esc(c.targetTxt) : ''}. Use the arrow keys to read each reading."><span class="mlab">${esc(c.title)}${chipOf(c)}</span><b class="mval">${esc(c.v)}</b><em class="mwk">${esc(capOf(c))}</em>${chgHtml(c)}`
44
56
  + `<svg viewBox="0 0 ${W} ${H}"><path class="ar" d="${d}L${X(1)},${H}L${X(0)},${H}Z"/>${c.ty !== null ? `<line class="tg" x1="${P}" x2="${W - P}" y1="${Y(c.ty)}" y2="${Y(c.ty)}"/>` : ''}<path class="ln2" d="${d}"/><line class="cx" x1="0" x2="0" y1="0" y2="${H}"/><circle class="dt" cx="${X(last.fx)}" cy="${Y(last.fy)}" r="3.5"/></svg>`
45
- + `<span class="mfoot"><i>${esc(c.ticks[0])}</i>${c.target !== null ? '<i class="tgl">dashed line is the target</i>' : ''}<i>${esc(c.ticks[1])}</i></span></div>`;
57
+ + `<span class="mfoot"><i>${esc(c.ticks[0])}</i>${c.target !== null ? '<i class="tgl">dashed line is the target</i>' : ''}<i>${esc(c.ticks[1])}</i></span>${why ? `<span class="mwhy">${esc(why)}</span>` : ''}</div>`;
58
+ }
59
+ function barsTile(c) {
60
+ const n = c.pts.length, hi = Math.max(...c.pts.map((p) => p.v), c.target !== null ? c.target : 0) || 1, pc = (v) => (v / hi * 84).toFixed(1);
61
+ const cols = c.pts.map((p, i) => `<span class="bw" title="${esc(p.d + ': ' + p.txt)}">${i === n - 1 ? `<b class="bl">${esc(p.txt)}</b>` : ''}<i class="${i === n - 1 ? 'bk' : 'bg'}" style="height:${pc(p.v)}%"></i></span>`).join('');
62
+ return `<div class="mt1 mfm bars ${c.chipKind}${c.off ? ' off' : ''}" data-key="${esc(c.key)}" role="img" aria-label="${esc(c.title)}, ${n} readings as bars from zero, now ${esc(c.v)}${c.targetTxt ? ', ' + esc(c.targetTxt) : ''}"><span class="mlab">${esc(c.title)}${chipOf(c)}</span><b class="mval">${esc(c.v)}</b><em class="mwk">${esc(capOf(c))}</em>${chgHtml(c)}`
63
+ + `<div class="bplot">${cols}${c.target !== null ? `<i class="btg" style="bottom:${pc(c.target)}%"></i>` : ''}</div>`
64
+ + `<span class="mfoot"><i>${esc(c.ticks[0])}</i><i class="tgl">${c.target !== null ? 'dashed line is the target' : 'bars start at zero'}</i><i>${esc(c.ticks[1])}</i></span></div>`;
65
+ }
66
+ function numTile(c) {
67
+ const d = c.pts.map((p, i) => (i ? 'L' : 'M') + X(p.fx).toFixed(1) + ',' + (2 + (1 - p.fy) * 26).toFixed(1)).join('');
68
+ return `<div class="mt1 mfm num ${c.chipKind}${c.off ? ' off' : ''}" data-key="${esc(c.key)}" role="img" aria-label="${esc(c.title)}, now ${esc(c.v)}${c.targetTxt ? ', ' + esc(c.targetTxt) : ''}"><span class="mlab">${esc(c.title)}${chipOf(c)}</span><b class="mval mhero">${esc(c.v)}</b><em class="mwk">${esc(capOf(c))}</em>${chgHtml(c)}`
69
+ + `<svg class="nspk" viewBox="0 0 ${W} 30" aria-hidden="true"><path d="${d}"/></svg></div>`;
70
+ }
71
+ function meterTile(c) {
72
+ const v = c.pts[c.pts.length - 1].v, tg = c.target, hi = Math.max(v, tg) * 1.15 || 1, lower = c.dir < 0, ok = lower ? v <= tg : v >= tg;
73
+ return `<div class="mt1 mfm prg ${c.chipKind}${c.off ? ' off' : ''}" data-key="${esc(c.key)}" role="img" aria-label="${esc(c.title)} is ${esc(c.v)} against ${lower ? 'a limit' : 'a target'} of ${esc(unitTxt(c, tg))}. ${ok ? 'It is on the right side of it.' : 'It is not there yet.'}"><span class="mlab">${esc(c.title)}${chipOf(c)}</span><b class="mval">${esc(c.v)}</b><em class="mwk">${esc(ok ? (lower ? 'Within the limit' : 'At or past the target') : (lower ? 'Over the limit' : 'Short of the target'))}</em>`
74
+ + `<div class="mtrk"><i class="mfil ${ok ? 'ok' : 'warn'}" style="width:${(v / hi * 100).toFixed(1)}%"></i><i class="mtgt" style="left:${(tg / hi * 100).toFixed(1)}%"></i></div>`
75
+ + `<span class="mfoot"><i>0</i><i class="tgl">${lower ? 'limit' : 'target'} ${esc(unitTxt(c, tg))}</i><i>${esc(unitTxt(c, hi))}</i></span></div>`;
76
+ }
77
+ /* The Studio's draft drawn from a measure's chart (premium-studio-chart C2, C7): the latest `range` readings, against the draft's target, as the server's
78
+ * lib/insights-premium.js mineOf draws a saved chart. Every point is a reading of the record. */
79
+ function deriveChart(base, d) {
80
+ const all = base.pts, pts0 = d.range ? all.slice(-d.range) : all.slice();
81
+ if (pts0.length < 2) return null;
82
+ const tg = d.target === null || d.target === undefined || d.target === '' ? null : +d.target;
83
+ const day = (p) => Date.parse(String(p.at).slice(0, 10) + 'T00:00:00Z');
84
+ const t0 = day(pts0[0]), span = day(pts0[pts0.length - 1]) - t0 || 1;
85
+ const ys = pts0.map((p) => p.v).concat(tg !== null ? [tg] : []), lo = Math.min(...ys), hi = Math.max(...ys), range = hi - lo || 1;
86
+ const pts = pts0.map((p) => Object.assign({}, p, { fx: (day(p) - t0) / span, fy: (p.v - lo) / range }));
87
+ const now = pts[pts.length - 1], prev = pts[pts.length - 2], step = Math.round((now.v - prev.v) * 100) / 100, dir = d.better === 'lower' ? -1 : 1;
88
+ return Object.assign({}, base, {
89
+ key: 'draft', title: d.title || base.title, form: d.form, note: d.note || '', pts, v: now.txt, at: now.d, target: tg, targetTxt: tg !== null ? 'target ' + unitTxt(base, tg) : '',
90
+ ty: tg !== null ? (tg - lo) / range : null, step, dir, good: step ? step * dir > 0 : null, ticks: [pts[0].d, now.d],
91
+ });
46
92
  }
47
93
  /* Point at reading j: the cursor line, the dot, the value and the date move to it. Without j the tile returns to the latest reading. */
48
94
  function chartAt(t, j) {
@@ -81,14 +127,14 @@ function drawDash() {
81
127
  $('#dashBody').innerHTML = `<div class="mprog" role="progressbar" aria-label="Measures on their line" aria-valuemin="0" aria-valuemax="${tot}" aria-valuenow="${tot - off}"><b style="width:${(tot - off) / tot * 100}%"></b></div>`
82
128
  + findingsHtml()
83
129
  + `<p class="mhint" style="margin-top:6px"><b>${tot - off} of ${tot}</b> on their line${off ? `. <b class="mflag">${off} ${off === 1 ? 'is' : 'are'} behind it.</b>` : '.'} Each chart is one KR metric, drawn at the dates of its readings. A gap between readings is left as a gap. The dashed line is the target.</p>`
84
- + `<div class="ngrid">${L.map((c) => `<div class="ntw">${tileHtml(c)}<div class="ntf"><button class="lk" data-open="${esc(c.key)}">Details</button></div></div>`).join('')}</div>` + noSeriesHtml();
130
+ + `<div class="ngrid">${L.map((c) => tileWrap(c)).join('')}</div>` + mineHtml() + noSeriesHtml();
85
131
  }
86
132
  /* The bar under the switch: a saved dashboard's purpose and Edit, and New dashboard (PRD D3/D4). Hidden when the page has no board to save on. */
87
133
  function drawDashBar(D) {
88
134
  const bar = $('#dashBar'); bar.hidden = !M.board.id;
89
135
  if (bar.hidden) return;
90
136
  bar.innerHTML = (D.saved ? `<p class="note pdp">${D.main ? '<b>Main dashboard.</b> ' : ''}${esc(D.purpose)}</p><button class="dmcta alt" id="pdEdit" aria-haspopup="dialog">Edit</button>` : '')
91
- + '<button class="dmcta alt" id="pdNew" aria-haspopup="dialog">New dashboard</button>';
137
+ + '<button class="dmcta alt" id="pdNew" aria-haspopup="dialog">New dashboard</button>' + (M.charts.length ? '<button class="dmcta alt" id="pcNew" aria-haspopup="dialog">New chart</button>' : '');
92
138
  }
93
139
  function drawSaved(D, L) {
94
140
  const off = D.off, tot = L.length;
@@ -96,20 +142,33 @@ function drawSaved(D, L) {
96
142
  const checks = D.checks.length ? `<p class="note pdck">${D.checks.map(esc).join(' ')}</p>` : '';
97
143
  $('#dashBody').innerHTML = (tot ? `<div class="mprog" role="progressbar" aria-label="Measures on their line" aria-valuemin="0" aria-valuemax="${tot}" aria-valuenow="${tot - off}"><b style="width:${(tot - off) / tot * 100}%"></b></div>`
98
144
  + `<p class="mhint" style="margin-top:6px"><b>${tot - off} of ${tot}</b> on their line${off ? `. <b class="mflag">${off} ${off === 1 ? 'is' : 'are'} behind it.</b>` : '.'} The charts are drawn in the order you saved. The dashed line is the target.</p>`
99
- + `<div class="ngrid">${L.map((c) => `<div class="ntw">${tileHtml(c)}<div class="ntf"><button class="lk" data-open="${esc(c.key)}">Details</button></div></div>`).join('')}</div>`
145
+ + `<div class="ngrid">${L.map((c) => tileWrap(c)).join('')}</div>`
100
146
  : `<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;
101
147
  }
148
+ /* A tile with its footer: Details, and Edit for a chart the PM saved (premium-studio-chart C4). */
149
+ 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>`;
150
+ /* 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. */
151
+ function mineHtml() {
152
+ const L = M.mine || [], G = M.mineGone || [];
153
+ if (!L.length && !G.length) return '';
154
+ return `<p class="label ngl">Your charts · ${L.length + G.length}</p>` + (L.length ? `<div class="ngrid">${L.map(tileWrap).join('')}</div>` : '')
155
+ + G.map((g) => `<div class="nempty" role="listitem" style="margin-bottom:6px"><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('');
156
+ }
102
157
  function noSeriesHtml() {
103
158
  const N = M.noSeries; if (!N.length) return '';
104
159
  return `<p class="label ngl">No series recorded · ${N.length}</p><div class="dplist" role="list">${N.map((n) => `<div class="nempty" role="listitem" style="margin-bottom:6px"><p><b>${esc(n.title)}</b>${n.pillar ? ' · ' + esc(n.pillar) : ''}<br>${esc(n.why)} It is not drawn.</p></div>`).join('')}</div>`;
105
160
  }
106
161
  $('#dashTabs').addEventListener('click', (e) => { const b = e.target.closest('[data-d]'); if (!b) return; dash = b.dataset.d; drawDash(); });
107
- $('#dashBar').addEventListener('click', (e) => { if (e.target.closest('#pdEdit')) openDashEdit(curDash()); else if (e.target.closest('#pdNew')) openDashEdit(null); });
162
+ $('#dashBar').addEventListener('click', (e) => { if (e.target.closest('#pdEdit')) openDashEdit(curDash()); else if (e.target.closest('#pdNew')) openDashEdit(null); else if (e.target.closest('#pcNew')) openChartEdit(null); });
108
163
 
109
164
  /* ── a dashboard is made and edited in the Insight Studio (initiative premium-studio-dashboard). Its one press posts POST /api/premium-dashboards/save. ── */
110
165
  async function saveDash(body) { return pmPost('/api/premium-dashboards/save', Object.assign({ ws: M.board.ws, board: M.board.id }, body)); }
111
- function openDashEdit(D) { openStudio({ M, D, tile: tileHtml, save: saveDash, done: async (id) => { dash = id || 'all'; await load(); } }); }
112
- $('#dashBody').addEventListener('click', (e) => { const o = e.target.closest('[data-open]'); if (o) openChart(byKey(o.dataset.open)); });
166
+ async function saveChart(body) { return pmPost('/api/premium-charts/save', Object.assign({ ws: M.board.ws, board: M.board.id }, body)); }
167
+ const studioOf = (o) => openStudio(Object.assign({ M, tile: tileHtml, derive: deriveChart, save: saveDash, saveChart, done: async (id) => { dash = id || dash; if (!M.dashboards.some((d) => d.id === dash)) dash = 'all'; await load(); } }, o));
168
+ function openDashEdit(D) { studioOf({ mode: 'dash', D, done: async (id) => { dash = id || 'all'; await load(); } }); }
169
+ /* A chart is made and edited in the Studio's Chart mode (initiative premium-studio-chart). Save posts POST /api/premium-charts/save. */
170
+ function openChartEdit(id) { studioOf({ mode: 'chart', C: id ? (M.mineSaved || []).find((x) => x.id === id) || null : null }); }
171
+ $('#dashBody').addEventListener('click', (e) => { const o = e.target.closest('[data-open]'); if (o) { openChart(byKey(o.dataset.open)); return; } const ed = e.target.closest('[data-ced]'); if (ed) openChartEdit(ed.dataset.ced); });
113
172
  $('#dashBody').addEventListener('keydown', (e) => {
114
173
  const t = e.target.closest && e.target.closest('.mch'); if (!t || !/^Arrow(Left|Right)$/.test(e.key)) return;
115
174
  e.preventDefault(); const c = byKey(t.dataset.key), j = +(t.dataset.j == null ? c.pts.length - 1 : t.dataset.j); chartAt(t, j + (e.key === 'ArrowRight' ? 1 : -1));