create-pmos 0.270.0 → 0.272.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 +1 -1
- 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/state/discoveries.md +1 -1
- package/workspace/briefing-premium-insights-test.js +1 -1
- package/workspace/guide/briefing-premium.md +4 -1
- package/workspace/lib/insights-premium.js +26 -5
- package/workspace/lib/premium-charts.js +129 -0
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-insights-premium.js +4 -2
- package/workspace/lib/routes-premium-charts.js +46 -0
- package/workspace/lib/routes-premium-dashboards.js +3 -2
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-studio-chart-test.js +193 -0
- package/workspace/premium-studio-report-test.js +203 -0
- package/workspace/public/pm/premium-insights.js +84 -13
- package/workspace/public/pm/premium-studio-report.js +264 -0
- package/workspace/public/pm/premium-studio.js +259 -47
- package/workspace/public/pm/premium.css +38 -0
- package/workspace/test-lists/premium-studio-chart.json +13 -0
- package/workspace/test-lists/premium-studio-report.json +9 -0
|
@@ -1,49 +1,102 @@
|
|
|
1
|
-
/* pm/premium-studio.js — the Insight Studio on the premium Insights page
|
|
2
|
-
* The mockup's Studio (prototype/premium-ux-concept/build-src/stu.js.txt)
|
|
3
|
-
* chips, a library, a live preview and checks.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
1
|
+
/* pm/premium-studio.js — the Insight Studio on the premium Insights page: its Dashboard mode (initiative premium-studio-dashboard), its Chart mode
|
|
2
|
+
* (initiative premium-studio-chart) and its Report mode (initiative premium-studio-report, in premium-studio-report.js). The mockup's Studio (prototype/premium-ux-concept/build-src/stu.js.txt): a conversation on the left, and on the right a
|
|
3
|
+
* mode switch, a brief of chips, a library, a live preview and checks. Each mode keeps its own draft and its own Undo. A turn changes the draft in the
|
|
4
|
+
* page and writes nothing. The writes are Save and Remove, each behind the launch nonce: POST /api/premium-dashboards/save for a dashboard, and
|
|
5
|
+
* POST /api/premium-charts/save for a chart (then the dashboard's save when the chart is added to one). Report mode's writes are the existing
|
|
6
|
+
* report-setups and report-structure routes (premium-studio-report.js). Every title, value and point comes from the page's
|
|
7
|
+
* model: the KR metric records, the board's saved charts and its saved dashboards. No demo measure is drawn.
|
|
6
8
|
*
|
|
7
|
-
* openStudio(P) P = { M, D (the saved dashboard to edit, or null),
|
|
9
|
+
* openStudio(P) P = { M, mode ('dash' | 'chart' | 'rep'), D (the saved dashboard to edit, or null), C (the saved chart to edit, or null), R (the set-up
|
|
10
|
+
* report to shape, or null), tile (the page's chart tile), derive (a measure's chart and a draft → the draft's chart), save (dashboard
|
|
11
|
+
* body → answer), saveChart (chart body → answer), setup (report-setups route, body → answer), structure ({ get(id), post(route, id,
|
|
12
|
+
* body) } → answer), reportsChanged (), done (saved dashboard id | null) } */
|
|
8
13
|
import { $, esc, openDlg, closeDlg, toast, turnA, turnU, ptx, setFull } from './premium-shell.js';
|
|
14
|
+
import * as REP from './premium-studio-report.js';
|
|
9
15
|
|
|
10
16
|
const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
|
|
11
17
|
const UPI = ICO('<path d="M12 19V5M6 11l6-6 6 6"/>'), DNI = ICO('<path d="M12 5v14M6 13l6 6 6-6"/>'), XI = ICO('<path d="M6 6l12 12M18 6 6 18"/>');
|
|
12
18
|
const OKI = ICO('<path d="M5 12.5l4.5 4.5L19 7.5"/>'), WRN = ICO('<path d="M12 4 2.5 20h19z"/><path d="M12 10v4M12 17v.5"/>'), CHV = ICO('<path d="M6 9l6 6 6-6"/>');
|
|
13
19
|
const DSI = ICO('<rect x="3" y="3" width="8" height="8" rx="2"/><rect x="13" y="3" width="8" height="8" rx="2"/><rect x="3" y="13" width="8" height="8" rx="2"/><rect x="13" y="13" width="8" height="8" rx="2"/>');
|
|
14
20
|
const MAX_UNDO = 30;
|
|
21
|
+
const MODES = { chart: 'Chart', dash: 'Dashboard', rep: 'Report' };
|
|
22
|
+
const FORMN = { line: 'Line', bars: 'Bars', number: 'Number', meter: 'Meter' };
|
|
23
|
+
const FORMD = { line: 'How it moves over time. The default for a trend.', bars: 'One reading against another. Bars start at zero.', number: 'One current value, with its change and a small line.', meter: 'How far it is from its target or limit.' };
|
|
15
24
|
|
|
16
|
-
let P = null; // the page's hand
|
|
17
|
-
let st = null; // the Studio: { d: draft, h: undo
|
|
25
|
+
let P = null; // the page's hand
|
|
26
|
+
let st = null; // the Studio: { mode, d: dashboard draft, c: chart draft, r: report draft, h: { dash, chart, rep } undo stacks, pop, more, lib, ck, msg, armed, busy }
|
|
18
27
|
|
|
19
28
|
const measures = () => P.M.measures || [];
|
|
20
|
-
const
|
|
21
|
-
const
|
|
29
|
+
const mineSaved = () => P.M.mineSaved || [];
|
|
30
|
+
const chartOf = (id) => (P.M.charts || []).concat(P.M.mine || []).find((c) => c.id === id) || null;
|
|
31
|
+
const baseOf = (id) => (P.M.charts || []).find((c) => c.id === id) || null;
|
|
32
|
+
const titleOf = (id) => { const m = measures().find((x) => x.id === id) || mineSaved().find((x) => x.id === id); return m ? m.title : id; };
|
|
22
33
|
const savedDash = () => (P.M.dashboards || []).filter((x) => x.saved);
|
|
23
34
|
const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
|
|
35
|
+
const draft = () => (st.mode === 'chart' ? st.c : st.mode === 'rep' ? st.r : st.d);
|
|
24
36
|
|
|
25
|
-
/* ── the
|
|
26
|
-
const snap = () => { const h = st.h, cur = JSON.stringify(
|
|
27
|
-
const undo = () => { if (!
|
|
37
|
+
/* ── the drafts and their undo, one stack per mode ── */
|
|
38
|
+
const snap = () => { const h = st.h[st.mode], cur = JSON.stringify(draft()); if (h.length && h[h.length - 1] === cur) return; h.push(cur); if (h.length > MAX_UNDO) h.shift(); };
|
|
39
|
+
const undo = () => { const h = st.h[st.mode]; if (!h.length) return false; const v = JSON.parse(h.pop()); if (st.mode === 'chart') st.c = v; else if (st.mode === 'rep') st.r = v; else st.d = v; return true; };
|
|
28
40
|
const blank = () => ({ id: null, name: '', use: '', charts: [], main: false });
|
|
41
|
+
/* A new chart starts from the measure PMOS ranks first in What stands out, else the first measure with a series. */
|
|
42
|
+
function chartFrom(id) {
|
|
43
|
+
const top = (P.M.findings || [])[0], byKey = top && top.chart ? (P.M.charts || []).find((c) => c.key === top.chart) : null;
|
|
44
|
+
const b = (id && baseOf(id)) || byKey || (P.M.charts || [])[0];
|
|
45
|
+
return b ? { id: null, measure: b.id, title: b.title.slice(0, 60), question: '', form: 'line', range: null, target: b.target === null ? '' : String(b.target), better: b.dir < 0 ? 'lower' : 'higher', note: '', addTo: '', ft: false } : null;
|
|
46
|
+
}
|
|
47
|
+
const chartSaved = (C) => ({ id: C.id, measure: C.measure, title: C.title, question: C.question || '', form: C.form || 'line', range: C.range || null, target: C.target === null ? '' : String(C.target), better: C.better || 'higher', note: C.note || '', addTo: '', ft: true });
|
|
48
|
+
const tgOf = (c) => (c.target === '' || c.target === '-' || Number.isNaN(+c.target) ? null : +c.target);
|
|
49
|
+
const drawn = (c) => { const b = c && baseOf(c.measure); return b ? P.derive(b, { range: c.range, target: tgOf(c), form: c.form, better: c.better, title: c.title, note: c.note }) : null; };
|
|
50
|
+
function suggestForm(q) {
|
|
51
|
+
q = q.toLowerCase();
|
|
52
|
+
return /\b(on target|on track|reach|hit|meet|how far|goal|limit|close to)\b/.test(q) ? 'meter' : /\b(now|current|today|latest|how much|what is|status)\b/.test(q) ? 'number' : /\b(compare|each|per|versus|against|which)\b/.test(q) ? 'bars' : 'line';
|
|
53
|
+
}
|
|
54
|
+
const formWhy = (c) => ({ line: 'A line, because it shows how the measure moves over time.', bars: 'Bars, because they set one reading against another. They start at zero, so their length is honest.', number: 'A number tile, because one current value is the point. The small line gives the shape.', meter: 'A meter, because the question is how far the measure is from its target.' })[c.form];
|
|
29
55
|
|
|
30
56
|
/* ── the canvas ── */
|
|
31
57
|
const chip = (k, l, v) => `<button type="button" class="suc${st.pop === k ? ' on' : ''}${v === 'Not set' ? ' req' : ''}" data-st="chip|${k}" aria-expanded="${st.pop === k}"><em>${esc(l)}</em><b>${esc(v)}</b></button>`;
|
|
58
|
+
const rangeTxt = (c) => { const b = baseOf(c.measure), n = b ? b.pts.length : 0; return c.range && c.range < n ? 'Last ' + c.range + ' readings' : 'All ' + plural(n, 'reading', 'readings'); };
|
|
32
59
|
function briefHtml() {
|
|
60
|
+
if (st.mode === 'rep') return REP.brief();
|
|
61
|
+
if (st.mode === 'chart') {
|
|
62
|
+
const c = st.c; if (!c) return '';
|
|
63
|
+
const more = st.more ? chip('title', 'Title', c.title || 'Not set') + chip('better', 'Better when', c.better === 'lower' ? 'Lower' : 'Higher') + chip('note', 'Note', c.note || 'None')
|
|
64
|
+
+ chip('addTo', 'Add to', c.addTo ? (savedDash().find((x) => x.id === c.addTo) || { name: 'No dashboard' }).name : 'No dashboard') : '';
|
|
65
|
+
return `<div class="stbr" role="group" aria-label="Brief">${chip('q', 'Question', c.question || 'Not set')}${chip('measure', 'Measure', titleOf(c.measure))}${chip('form', 'Form', FORMN[c.form])}${chip('range', 'Range', rangeTxt(c))}${chip('target', 'Target', tgOf(c) === null ? 'None' : String(tgOf(c)))}`
|
|
66
|
+
+ `<button type="button" class="suc stmore" data-st="more" aria-expanded="${st.more}"><em>${st.more ? 'Fewer' : 'More'}</em><b>${st.more ? 'Title, better when, note' : 'Title, note, add to'}</b></button>${more}</div>`;
|
|
67
|
+
}
|
|
33
68
|
const d = st.d;
|
|
34
69
|
return `<div class="stbr" role="group" aria-label="Brief">${chip('name', 'Name', d.name || 'Not set')}${chip('use', 'Purpose', d.use || 'Not set')}${chip('charts', 'Charts', String(d.charts.length))}${chip('main', 'Main dashboard', d.main ? 'Yes' : 'No')}</div>`;
|
|
35
70
|
}
|
|
36
71
|
const opt = (act, l, sub, on) => `<button type="button" class="sto" data-st="${act}" aria-pressed="${!!on}"><b>${esc(l)}</b>${sub ? `<small>${esc(sub)}</small>` : ''}</button>`;
|
|
37
|
-
const field = (f, v, ph, max) => `<input class="sti" id="stI" data-stf="${f}" value="${esc(v)}" placeholder="${esc(ph)}" maxlength="${max}" aria-label="${esc(ph)}" autocomplete="off">`;
|
|
72
|
+
const field = (f, v, ph, max, mode) => `<input class="sti" id="stI" data-stf="${f}" value="${esc(v)}" placeholder="${esc(ph)}" maxlength="${max}" aria-label="${esc(ph)}" autocomplete="off"${mode ? ` inputmode="${mode}"` : ''}>`;
|
|
73
|
+
function chartTray(p) {
|
|
74
|
+
const c = st.c, b = baseOf(c.measure), n = b ? b.pts.length : 0, sg = suggestForm(c.question || '');
|
|
75
|
+
if (p === 'q') return field('question', c.question, 'For example: Are new partners activating?', 100) + '<p class="note">Write the question the chart answers. The form follows from it.</p>';
|
|
76
|
+
if (p === 'measure') return `<div class="sol">${(P.M.charts || []).map((m) => opt('set|measure|' + m.id, m.title, m.sub, c.measure === m.id)).join('')}</div>` + (measures().some((m) => !m.charted) ? '<p class="note">A measure with fewer than two readings has no series, so it cannot be charted yet.</p>' : '');
|
|
77
|
+
if (p === 'form') return `<div class="sol">${Object.keys(FORMN).map((f) => opt('set|form|' + f, FORMN[f] + (f === sg && c.question ? ' · suggested' : ''), FORMD[f], c.form === f)).join('')}</div>`;
|
|
78
|
+
if (p === 'range') return `<div class="sol">${opt('set|range|', 'All ' + plural(n, 'reading', 'readings'), 'Every reading the record holds', !c.range || c.range >= n)}${[3, 4, 6, 8, 12].filter((k) => k < n).map((k) => opt('set|range|' + k, 'Last ' + k + ' readings', '', c.range === k)).join('')}</div><p class="note">The range counts readings, because KR metric readings are not taken every week.</p>`;
|
|
79
|
+
if (p === 'target') return field('target', c.target, 'A number, or leave empty for none', 12, 'decimal') + `<div class="sor"><button type="button" class="dmcta alt" data-st="set|target|">No target</button>${b && b.target !== null ? `<button type="button" class="dmcta alt" data-st="set|target|${b.target}">Use the record's own (${esc(String(b.target))})</button>` : ''}</div>`;
|
|
80
|
+
if (p === 'title') return field('title', c.title, 'The name on the chart', 60);
|
|
81
|
+
if (p === 'better') return `<div class="sol">${opt('set|better|higher', 'Higher', 'Above the target is good', c.better !== 'lower')}${opt('set|better|lower', 'Lower', 'Below the target is good', c.better === 'lower')}</div>`;
|
|
82
|
+
if (p === 'note') return field('note', c.note, 'One line under the chart', 200);
|
|
83
|
+
if (p === 'addTo') return `<div class="sol">${opt('set|addTo|', 'No dashboard', 'Keep it under Your charts only', !c.addTo)}${savedDash().map((x) => opt('set|addTo|' + x.id, x.name, plural(x.charts.length, 'chart', 'charts') + (x.charts.includes(c.id) ? ' · it is on it' : ''), c.addTo === x.id)).join('')}</div>`;
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
38
86
|
function trayHtml() {
|
|
39
|
-
const p = st.pop
|
|
87
|
+
const p = st.pop; if (!p || !draft()) return '';
|
|
40
88
|
let h = '';
|
|
41
|
-
if (
|
|
42
|
-
else if (
|
|
43
|
-
else
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
89
|
+
if (st.mode === 'rep') h = REP.tray(p);
|
|
90
|
+
else if (st.mode === 'chart') h = chartTray(p);
|
|
91
|
+
else {
|
|
92
|
+
const d = st.d;
|
|
93
|
+
if (p === 'name') h = field('name', d.name, 'For example: Weekly partner review', 60);
|
|
94
|
+
else if (p === 'use') h = field('use', d.use, 'What routine is this for?', 200);
|
|
95
|
+
else if (p === 'main') h = `<div class="sol">${opt('set|main|1', 'Yes', 'It opens first on this board. One dashboard is main.', d.main)}${opt('set|main|0', 'No', 'Keep it as another dashboard', !d.main)}</div>`;
|
|
96
|
+
else if (p === 'charts') {
|
|
97
|
+
h = (d.charts.length ? `<ul class="sul">${d.charts.map((id, i) => `<li><span>${esc(titleOf(id))}${chartOf(id) ? '' : '<small>No series yet</small>'}</span><span class="stlc"><button type="button" data-st="mv|${i}|-1" aria-label="Move ${esc(titleOf(id))} up"${i ? '' : ' disabled'}>${UPI}</button><button type="button" data-st="mv|${i}|1" aria-label="Move ${esc(titleOf(id))} down"${i < d.charts.length - 1 ? '' : ' disabled'}>${DNI}</button><button type="button" data-st="rm|${i}" aria-label="Remove ${esc(titleOf(id))}">${XI}</button></span></li>`).join('')}</ul>` : '<p class="note">No charts yet.</p>')
|
|
98
|
+
+ '<button type="button" class="dmcta alt" data-st="lib">Add from the library</button>';
|
|
99
|
+
}
|
|
47
100
|
}
|
|
48
101
|
return h ? `<div class="sup" role="group" aria-label="Change this">${h}<button type="button" class="lk stdone" data-st="chip|${p}">Done</button></div>` : '';
|
|
49
102
|
}
|
|
@@ -55,21 +108,52 @@ function spark(c) {
|
|
|
55
108
|
}
|
|
56
109
|
function libHtml() {
|
|
57
110
|
if (!st.lib) return '';
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
111
|
+
if (st.mode === 'rep') return `<div class="stlib" role="region" aria-label="Library of ${esc(P.M.board.name || 'this board')}"><div class="stlh"><b>Library</b><small>${esc(P.M.board.name || '')}</small><button type="button" class="lk" data-st="lib">Close</button></div>${REP.libRows()}</div>`;
|
|
112
|
+
const L = measures(), Y = mineSaved();
|
|
113
|
+
let rows, yours, dl = '';
|
|
114
|
+
if (st.mode === 'chart') {
|
|
115
|
+
const c = st.c;
|
|
116
|
+
rows = L.map((m) => { const b = baseOf(m.id); return `<button type="button" class="stli" data-st="libm|${esc(m.id)}"${b ? '' : ' disabled'}>${spark(b)}<span><b>${esc(m.title)}</b><small>${esc(b ? b.sub : 'No series yet')}</small></span><em>${b ? (c && c.measure === m.id && !c.id ? 'Drawn' : 'Start from this') : 'Not drawn'}</em></button>`; }).join('');
|
|
117
|
+
yours = Y.map((y) => `<button type="button" class="stli" data-st="libs|${esc(y.id)}"${c && c.id === y.id ? ' disabled' : ''}>${spark(chartOf(y.id))}<span><b>${esc(y.title)}</b><small>${esc(FORMN[y.form] + ' · ' + titleOf(y.measure))}</small></span><em>${c && c.id === y.id ? 'Open' : 'Edit'}</em></button>`).join('');
|
|
118
|
+
} else {
|
|
119
|
+
const d = st.d, S = savedDash().filter((x) => x.id !== d.id);
|
|
120
|
+
const row = (id, title, sub, c) => { const on = d.charts.includes(id); return `<button type="button" class="stli" data-st="libc|${esc(id)}"${on ? ' disabled' : ''}>${spark(c)}<span><b>${esc(title)}</b><small>${esc(sub)}</small></span><em>${on ? 'Added' : 'Add'}</em></button>`; };
|
|
121
|
+
rows = L.map((m) => { const c = chartOf(m.id); return row(m.id, m.title, c ? c.sub : 'No series yet', c); }).join('');
|
|
122
|
+
yours = Y.map((y) => row(y.id, y.title, FORMN[y.form] + ' · ' + titleOf(y.measure), chartOf(y.id))).join('');
|
|
123
|
+
dl = S.map((x) => `<button type="button" class="stli" data-st="libd|${esc(x.id)}"><span class="stlic">${DSI}</span><span><b>${esc(x.name)}</b><small>${plural(x.charts.length, 'chart', 'charts')}</small></span><em>Add its charts</em></button>`).join('');
|
|
124
|
+
}
|
|
61
125
|
return `<div class="stlib" role="region" aria-label="Library of ${esc(P.M.board.name || 'this board')}"><div class="stlh"><b>Library</b><small>${esc(P.M.board.name || '')}</small><button type="button" class="lk" data-st="lib">Close</button></div>`
|
|
62
126
|
+ `<p class="label">Measures · ${L.length}</p>${L.length ? `<div class="stlg">${rows}</div>` : '<p class="note">No KR metric is recorded for this workspace.</p>'}`
|
|
63
|
-
+ (
|
|
127
|
+
+ (yours ? `<p class="label">Your charts · ${Y.length}</p><div class="stlg">${yours}</div>` : '')
|
|
128
|
+
+ (dl ? `<p class="label">Dashboards · ${savedDash().filter((x) => x.id !== st.d.id).length}</p><div class="stlg">${dl}</div>` : '') + '</div>';
|
|
64
129
|
}
|
|
65
130
|
function previewHtml() {
|
|
131
|
+
if (st.mode === 'rep') return REP.preview();
|
|
132
|
+
if (st.mode === 'chart') {
|
|
133
|
+
const c = st.c; if (!c) return '<p class="note">Nothing to draw: no measure of this board has two readings yet.</p>';
|
|
134
|
+
const ch = drawn(c);
|
|
135
|
+
if (!ch) return `<div class="stpvw"><p class="note"><b>${esc(titleOf(c.measure))}</b> has fewer than two readings in this range, so it has no chart.</p></div>`;
|
|
136
|
+
return `<div class="stpvw">${P.tile(ch)}<details class="stvt"><summary>Show the values</summary><div class="vtb">${ch.pts.map((p) => `<div><span>${esc(p.d)}</span><b>${esc(p.txt)}</b></div>`).join('')}</div></details><p class="stsrc">KR metric record · ${esc(titleOf(c.measure))} · ${plural(ch.pts.length, 'reading', 'readings')}</p></div>`;
|
|
137
|
+
}
|
|
66
138
|
const d = st.d, L = d.charts.map(chartOf).filter(Boolean), gone = d.charts.filter((id) => !chartOf(id));
|
|
67
139
|
return `<div class="stpvw"><h3 class="ndt">${esc(d.name || 'Untitled dashboard')}${d.main ? '<span class="npin2">Main dashboard</span>' : ''}</h3><p class="mut stuse">${esc(d.use || 'No purpose yet.')}</p>`
|
|
68
140
|
+ (L.length ? `<div class="ngrid">${L.map((c) => `<div class="ntw">${P.tile(c)}</div>`).join('')}</div>` : '<p class="note">No chart is drawn yet. Add a measure with a series.</p>')
|
|
69
141
|
+ (gone.length ? `<p class="label ngl">Not drawn · ${gone.length}</p>${gone.map((id) => `<p class="note stgone"><b>${esc(titleOf(id))}</b> has fewer than two readings, so it has no chart.</p>`).join('')}` : '') + '</div>';
|
|
70
142
|
}
|
|
71
|
-
/* The
|
|
143
|
+
/* The checks of the mockup, computed from the draft. A fix is an action the Studio can take in one press. */
|
|
72
144
|
function checks() {
|
|
145
|
+
if (st.mode === 'rep') return REP.checks();
|
|
146
|
+
if (st.mode === 'chart') {
|
|
147
|
+
const c = st.c; if (!c) return [];
|
|
148
|
+
const ch = drawn(c), pts = ch ? ch.pts.length : 0, tg = tgOf(c), trendQ = /\b(moved|move|moving|trend|over time|how has|changed|changing)\b/i.test(c.question);
|
|
149
|
+
return [
|
|
150
|
+
{ ok: !!c.question.trim(), l: 'It says what it answers', d: c.question.trim() ? '"' + c.question.trim() + '"' : 'There is no question. A chart without one is decoration.', fix: ['Write the question', 'chip|q'] },
|
|
151
|
+
{ ok: tg !== null || c.form === 'number', l: c.form === 'meter' ? 'A meter needs a target' : 'A target or limit is shown', d: tg !== null ? 'The target is ' + tg + '.' : 'There is no target, so the chart cannot say whether the measure is on track.', fix: ['Set a target', 'chip|target'] },
|
|
152
|
+
{ ok: pts >= 4 || c.form === 'number', l: 'Enough points to read a shape', d: plural(pts, 'reading', 'readings') + ' in this range.', fix: ['Use every reading', 'set|range|'] },
|
|
153
|
+
{ ok: !(trendQ && c.form !== 'line'), l: 'The form fits the question', d: trendQ && c.form !== 'line' ? 'The question is about movement. A line shows movement better than ' + FORMN[c.form].toLowerCase() + '.' : 'The form suits the question.', fix: ['Use a line', 'set|form|line'] },
|
|
154
|
+
{ ok: true, l: 'One scale', d: 'One measure, one axis. Bars and the meter start at zero.' },
|
|
155
|
+
];
|
|
156
|
+
}
|
|
73
157
|
const d = st.d, dup = d.charts.length - new Set(d.charts).size, other = savedDash().some((x) => x.main && x.id !== d.id);
|
|
74
158
|
return [
|
|
75
159
|
{ ok: !!d.name.trim(), l: 'It has a name', d: d.name.trim() || 'Give it a name.', fix: ['Name it', 'chip|name'] },
|
|
@@ -81,21 +165,29 @@ function checks() {
|
|
|
81
165
|
];
|
|
82
166
|
}
|
|
83
167
|
function checksHtml() {
|
|
84
|
-
const L = checks()
|
|
168
|
+
const L = checks(); if (!L.length) return '';
|
|
169
|
+
const bad = L.filter((x) => !x.ok), n = L.length - bad.length;
|
|
85
170
|
return `<div class="suck${bad.length ? ' bad' : ''}"><button type="button" class="suckb" data-st="ck" aria-expanded="${st.ck}">${bad.length ? WRN : OKI}<b>${n} of ${L.length} checks pass</b>${bad.length && !st.ck ? `<span>${esc(bad[0].d)}</span>` : ''}${CHV}</button>`
|
|
86
|
-
+ `<div class="mprog stbar" role="progressbar" aria-label="Checks passing" aria-valuemin="0" aria-valuemax="${L.length}" aria-valuenow="${n}" data-n="${n}"><b></b></div>`
|
|
171
|
+
+ `<div class="mprog stbar" role="progressbar" aria-label="Checks passing" aria-valuemin="0" aria-valuemax="${L.length}" aria-valuenow="${n}" data-t="${L.length}" data-n="${n}"><b></b></div>`
|
|
87
172
|
+ (st.ck ? `<ul class="sucl">${L.map((x, i) => `<li class="${x.ok ? 'ok' : 'bad'}">${x.ok ? OKI : WRN}<span><b>${esc(x.l)}</b><small>${esc(x.d)}</small></span>${!x.ok && x.fix ? `<button type="button" class="dmcta alt" data-st="fix|${i}">${esc(x.fix[0])}</button>` : ''}</li>`).join('')}</ul>` : '') + '</div>';
|
|
88
173
|
}
|
|
89
174
|
function footHtml() {
|
|
90
|
-
const
|
|
91
|
-
|
|
175
|
+
if (st.mode === 'rep') { const f = REP.footer(); return `<div class="stft"><button type="button" class="dmcta alt" data-st="undo"${f.undo ? '' : ' disabled'}>Undo</button><span class="sp"></span><button type="button" class="dmcta alt" data-st="cancel">Cancel</button><button type="button" class="dmcta" data-st="save"${f.off ? ' disabled' : ''}>${f.cta}</button></div>`; }
|
|
176
|
+
const ch = st.mode === 'chart', d = draft(), saved = !!(d && d.id), what = ch ? 'chart' : 'dashboard';
|
|
177
|
+
return `<div class="stft"><button type="button" class="dmcta alt" data-st="undo"${st.h[st.mode].length ? '' : ' disabled'}>Undo</button>${saved ? `<button type="button" class="dmcta alt" data-st="del">${st.armed ? 'Press again to remove it' : 'Remove the ' + what}</button>` : ''}<span class="sp"></span><button type="button" class="dmcta alt" data-st="cancel">Cancel</button><button type="button" class="dmcta" data-st="save"${st.busy || !d ? ' disabled' : ''}>${saved ? 'Save changes' : 'Save the ' + what}</button></div>`;
|
|
178
|
+
}
|
|
179
|
+
function guide() {
|
|
180
|
+
if (st.mode === 'rep') return REP.guide();
|
|
181
|
+
if (st.mode === 'chart') return st.c ? esc(formWhy(st.c)) + (st.c.id ? ' <button type="button" class="lk" data-st="new">Start a new one instead</button>' : '') : 'No measure of this board has two readings yet, so there is nothing to chart.';
|
|
182
|
+
return 'A dashboard answers one routine. Give it a purpose and keep it to six charts or fewer.' + (st.d.id ? ' <button type="button" class="lk" data-st="new">Start a new one instead</button>' : '');
|
|
92
183
|
}
|
|
93
|
-
const
|
|
184
|
+
const modesHtml = () => `<div class="stmd" role="group" aria-label="What to make">${Object.keys(MODES).map((k) => `<button type="button" data-st="mode|${k}" aria-pressed="${st.mode === k}">${MODES[k]}</button>`).join('')}</div>`;
|
|
94
185
|
function canvasHtml() {
|
|
95
|
-
return `<div class="stu"><div class="stt"><span class="stx"><button type="button" class="lk" data-st="lib" aria-expanded="${st.lib}">Library</button></span></div><p class="stsug" id="stG">${guide()}</p><div id="stBr">${briefHtml()}</div><div id="stTr">${trayHtml()}</div><div id="stLb">${libHtml()}</div><div id="stPv">${previewHtml()}</div><div id="stCk">${checksHtml()}</div><p class="note stmsg" id="stMsg" role="status"></p><div id="stFt">${footHtml()}</div></div>`;
|
|
186
|
+
return `<div class="stu"><div class="stt"><span id="stMd">${modesHtml()}</span><span class="stx"><button type="button" class="lk" data-st="lib" aria-expanded="${st.lib}">Library</button></span></div><p class="stsug" id="stG">${guide()}</p><div id="stBr">${briefHtml()}</div><div id="stTr">${trayHtml()}</div><div id="stLb">${libHtml()}</div><div id="stPv">${previewHtml()}</div><div id="stCk">${checksHtml()}</div><p class="note stmsg" id="stMsg" role="status"></p><div id="stFt">${footHtml()}</div></div>`;
|
|
96
187
|
}
|
|
97
188
|
function draw(parts) {
|
|
98
189
|
const all = !parts, set = (id, h) => { const e = $('#' + id); if (e) e.innerHTML = h; };
|
|
190
|
+
if (all) set('stMd', modesHtml());
|
|
99
191
|
if (all || parts.includes('g')) set('stG', guide());
|
|
100
192
|
if (all || parts.includes('br')) set('stBr', briefHtml());
|
|
101
193
|
if (all || parts.includes('tr')) set('stTr', trayHtml());
|
|
@@ -105,21 +197,46 @@ function draw(parts) {
|
|
|
105
197
|
if (all || parts.includes('ft')) set('stFt', footHtml());
|
|
106
198
|
const m = $('#stMsg'); if (m) m.textContent = st.msg;
|
|
107
199
|
const l = $('.stu [data-st="lib"]'); if (l) l.setAttribute('aria-expanded', st.lib);
|
|
200
|
+
if (all) { const i = $('#stIn'); if (i) { i.placeholder = 'Say what to change'; i.setAttribute('aria-label', 'Say what to change in the ' + ({ chart: 'chart', rep: 'report' }[st.mode] || 'dashboard')); } const h = $('#stHelp'); if (h) h.textContent = help() + (st.mode === 'rep' ? '' : ' Nothing is saved until you press Save.'); }
|
|
108
201
|
}
|
|
109
202
|
|
|
110
203
|
/* ── doing things ── */
|
|
204
|
+
function setChart(f, v) {
|
|
205
|
+
const c = st.c;
|
|
206
|
+
if (f === 'measure') { const b = baseOf(v); if (!b) return; c.measure = v; if (!c.id || !c.title) c.title = b.title.slice(0, 60); c.target = b.target === null ? '' : String(b.target); c.better = b.dir < 0 ? 'lower' : 'higher'; c.range = null; }
|
|
207
|
+
else if (f === 'form') { c.form = v; c.ft = true; }
|
|
208
|
+
else if (f === 'range') c.range = v ? +v : null;
|
|
209
|
+
else if (f === 'target') c.target = v;
|
|
210
|
+
else if (f === 'better') c.better = v === 'lower' ? 'lower' : 'higher';
|
|
211
|
+
else if (f === 'addTo') c.addTo = v;
|
|
212
|
+
}
|
|
111
213
|
function act(a) {
|
|
112
214
|
const [k, x, y] = a; st.msg = '';
|
|
113
215
|
if (k !== 'del') st.armed = false;
|
|
216
|
+
if (k === 'mode') { if (st.mode !== x) { st.mode = x; st.pop = null; st.ck = false; if (x === 'rep' && !st.r) st.r = REP.blankReport(); draw(); } return; }
|
|
114
217
|
if (k === 'chip') { st.pop = st.pop === x ? null : x; draw(['br', 'tr', 'ft']); const i = $('#stI'); if (i) { i.focus(); try { i.setSelectionRange(i.value.length, i.value.length); } catch { /* no caret */ } } return; }
|
|
218
|
+
if (k === 'more') { st.more = !st.more; if (!st.more && /^(title|better|note|addTo)$/.test(st.pop || '')) st.pop = null; draw(['br', 'tr']); return; }
|
|
115
219
|
if (k === 'lib') { st.lib = !st.lib; draw(['lb', 'tr', 'ft']); return; }
|
|
116
220
|
if (k === 'ck') { st.ck = !st.ck; draw(['ck']); return; }
|
|
117
221
|
if (k === 'fix') { const f = checks()[+x]; if (f && f.fix) act(f.fix[1].split('|')); return; }
|
|
118
|
-
if (k === 'undo') { if (undo()) { st.pop = null; draw(); } return; }
|
|
222
|
+
if (k === 'undo') { if (st.mode === 'rep' && st.r.kind === 'setup') { const u = REP.undoSetup(); if (u) u.then((a) => { st.msg = a; draw(); }); return; } if (undo()) { st.pop = null; draw(); } return; }
|
|
119
223
|
if (k === 'cancel') { closeDlg(); return; }
|
|
120
|
-
if (k === 'save') { save(); return; }
|
|
121
|
-
if (k === 'del') { remove(); return; }
|
|
122
|
-
if (k === 'new') { snap(); st.d = blank(); st.pop = null; draw(); return; }
|
|
224
|
+
if (k === 'save') { if (st.mode === 'chart') saveChart(); else if (st.mode === 'rep') REP.save(); else save(); return; }
|
|
225
|
+
if (k === 'del') { if (st.mode === 'chart') removeChart(); else remove(); return; }
|
|
226
|
+
if (k === 'new') { snap(); if (st.mode === 'chart') st.c = chartFrom(st.c && st.c.measure); else if (st.mode === 'rep') { st.r = REP.blankReport(); st.h.rep = []; } else st.d = blank(); st.pop = null; draw(); return; }
|
|
227
|
+
if (st.mode === 'rep') {
|
|
228
|
+
if (k === 'set') { if (st.r.kind !== 'new') return; snap(); REP.set(x, y || ''); st.pop = null; draw(); return; }
|
|
229
|
+
if (k === 'rsec') { REP.leaveOut(x); return; }
|
|
230
|
+
if (k === 'say') { REP.focusInput(a.slice(1).join('|')); return; }
|
|
231
|
+
if (k === 'libr') { const R = ((P.M.reports || {}).setups || []).find((q) => q.id === x); if (!R || !R.fromWork) return; st.r = REP.setupReport(R); st.h.rep = []; st.pop = null; st.lib = false; draw(); }
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (st.mode === 'chart') {
|
|
235
|
+
if (k === 'set') { snap(); setChart(x, y || ''); st.pop = null; draw(); return; }
|
|
236
|
+
if (k === 'libm') { snap(); st.c = chartFrom(x); st.pop = null; draw(); return; }
|
|
237
|
+
if (k === 'libs') { const C = mineSaved().find((q) => q.id === x); if (!C) return; snap(); st.c = chartSaved(C); st.pop = null; draw(); }
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
123
240
|
if (k === 'set' && x === 'main') { snap(); st.d.main = y === '1'; st.pop = null; draw(); return; }
|
|
124
241
|
if (k === 'dedup') { snap(); st.d.charts = st.d.charts.filter((id, i) => st.d.charts.indexOf(id) === i); draw(); return; }
|
|
125
242
|
if (k === 'mv') { const i = +x, j = i + +y, c = st.d.charts; if (j < 0 || j >= c.length) return; snap(); [c[i], c[j]] = [c[j], c[i]]; draw(); const b = $(`#stTr [data-st="mv|${j}|${y}"]`) || $(`#stTr [data-st="mv|${j}|${-y}"]`); if (b) b.focus(); return; }
|
|
@@ -130,8 +247,13 @@ function act(a) {
|
|
|
130
247
|
let typed = false; // one undo step per text field edit, not per key
|
|
131
248
|
function onInput(e) {
|
|
132
249
|
const f = e.target.dataset && e.target.dataset.stf; if (!f) return;
|
|
250
|
+
const o = draft(); if (!o || (st.mode === 'rep' && o.kind !== 'new')) return;
|
|
251
|
+
let v = e.target.value;
|
|
252
|
+
if (f === 'target') { const t = v.replace(/[^0-9.-]/g, ''); if (t !== v) { v = t; e.target.value = t; } }
|
|
133
253
|
if (!typed) { snap(); typed = true; }
|
|
134
|
-
|
|
254
|
+
o[f] = v; st.msg = '';
|
|
255
|
+
if (st.mode === 'chart' && f === 'question' && !o.ft) o.form = suggestForm(v);
|
|
256
|
+
draw(['g', 'br', 'pv', 'ck', 'ft']);
|
|
135
257
|
}
|
|
136
258
|
async function save() {
|
|
137
259
|
const d = st.d, name = d.name.trim(), use = d.use.trim();
|
|
@@ -151,14 +273,45 @@ async function remove() {
|
|
|
151
273
|
if (!res || res.ok !== true) { st.armed = false; st.msg = (res && res.error) || 'The dashboard could not be removed.'; draw(['ft']); return; }
|
|
152
274
|
closeDlg(); toast('Dashboard removed. The line is saved in the workspace\'s state folder.'); P.done(null);
|
|
153
275
|
}
|
|
276
|
+
async function saveChart() {
|
|
277
|
+
const c = st.c, title = c.title.trim(), tg = tgOf(c);
|
|
278
|
+
if (!title) { st.msg = 'Give the chart a name.'; draw(['ft']); return; }
|
|
279
|
+
if (c.target !== '' && tg === null) { st.msg = 'The target must be a number, or none.'; draw(['ft']); return; }
|
|
280
|
+
if (c.form === 'meter' && tg === null) { st.msg = 'A meter needs a target. Set one, or pick another form.'; draw(['ft']); return; }
|
|
281
|
+
st.busy = true; st.msg = 'Saving.'; draw(['ft']);
|
|
282
|
+
const res = await P.saveChart({ id: c.id || undefined, measure: c.measure, title, question: c.question.trim(), form: c.form, range: c.range, target: tg, better: c.better, note: c.note.trim() });
|
|
283
|
+
if (!res || res.ok !== true) { st.busy = false; st.msg = (res && res.error) || 'The chart could not be saved.'; draw(['ft']); return; }
|
|
284
|
+
const id = res.chart ? res.chart.id : c.id, D = c.addTo ? savedDash().find((x) => x.id === c.addTo) : null;
|
|
285
|
+
let to = '';
|
|
286
|
+
if (D && !D.charts.includes(id)) {
|
|
287
|
+
const r2 = await P.save({ id: D.id, name: D.name, purpose: D.purpose, charts: D.charts.concat([id]), main: D.main });
|
|
288
|
+
if (!r2 || r2.ok !== true) { st.busy = false; c.id = id; st.msg = 'The chart is saved, but it was not added to ' + D.name + ': ' + ((r2 && r2.error) || 'the dashboard could not be saved.'); draw(); return; }
|
|
289
|
+
to = ' and added to ' + D.name;
|
|
290
|
+
}
|
|
291
|
+
st.busy = false;
|
|
292
|
+
closeDlg(); toast('Chart "' + title + '" saved' + to + ' in the workspace\'s state folder.'); P.done(D ? D.id : null);
|
|
293
|
+
}
|
|
294
|
+
async function removeChart() {
|
|
295
|
+
if (!st.armed) { st.armed = true; st.msg = 'Removing takes the chart off this board. A dashboard that holds it lists it as removed. The measure and its record stay.'; draw(['ft']); return; }
|
|
296
|
+
st.busy = true; draw(['ft']);
|
|
297
|
+
const res = await P.saveChart({ id: st.c.id, remove: true });
|
|
298
|
+
st.busy = false;
|
|
299
|
+
if (!res || res.ok !== true) { st.armed = false; st.msg = (res && res.error) || 'The chart could not be removed.'; draw(['ft']); return; }
|
|
300
|
+
closeDlg(); toast('Chart removed. The line is saved in the workspace\'s state folder.'); P.done(null);
|
|
301
|
+
}
|
|
154
302
|
|
|
155
303
|
/* ── the conversation: the phrases the Studio understands. A turn changes the draft only; it writes nothing and starts no agent. ── */
|
|
156
304
|
const HELP = 'I understand: add or remove a measure by its name, move a measure up, down or first, call it something, it is for something, make it the main dashboard (or not), undo, and start a new one.';
|
|
305
|
+
const HELPC = 'I understand: a measure by its name, a form (line, bars, number, meter), the last N readings or all of them, target N or no target, lower or higher is better, call it something, note something, add it to a dashboard, a question, undo, and why.';
|
|
306
|
+
const help = () => (st.mode === 'chart' ? HELPC : st.mode === 'rep' ? REP.help() : HELP);
|
|
157
307
|
const clean = (s) => s.trim().replace(/^["']|["']$/g, '').replace(/[.\s]+$/, '').trim();
|
|
158
|
-
function hits(low) { return measures().map((m) => ({ m, i: low.indexOf(m.title.toLowerCase()) })).filter((x) => x.i >= 0 && x.m.title).sort((a, b) => a.i - b.i || b.m.title.length - a.m.title.length); }
|
|
308
|
+
function hits(low, L) { return (L || measures()).map((m) => ({ m, i: low.indexOf(m.title.toLowerCase()) })).filter((x) => x.i >= 0 && x.m.title).sort((a, b) => a.i - b.i || b.m.title.length - a.m.title.length); }
|
|
159
309
|
function command(text) {
|
|
160
310
|
const t = text.trim(), low = t.toLowerCase(), d = st.d, said = [];
|
|
311
|
+
if (/^undo\b/.test(low) && st.mode === 'rep' && st.r.kind === 'setup') return REP.undoSetup() || 'I changed nothing. There is no earlier version to go back to.';
|
|
161
312
|
if (/^undo\b/.test(low)) return undo() ? (st.pop = null, 'Done: one step undone.') : 'I changed nothing. There is nothing to undo.';
|
|
313
|
+
if (st.mode === 'chart') return chartCommand(t, low);
|
|
314
|
+
if (st.mode === 'rep') return REP.command(t, low);
|
|
162
315
|
if (/\b(start (a )?new|new dashboard|start over)\b/.test(low)) { snap(); st.d = blank(); return 'Done: a new, empty dashboard. Name it and say what it is for.'; }
|
|
163
316
|
const before = JSON.stringify(d); snap();
|
|
164
317
|
const nm = t.match(/(?:call it|name it|rename it to|rename it|called|named)\s+(.+?)(?=,|;|\s+and\s+(?:it|make|add|remove|for)\b|$)/i);
|
|
@@ -167,7 +320,7 @@ function command(text) {
|
|
|
167
320
|
if (us && clean(us[1])) { d.use = clean(us[1]).slice(0, 200); said.push('the purpose is "' + d.use + '"'); }
|
|
168
321
|
if (/\b(not|no longer|don't make it|do not make it)\b[^.]*\bmain\b/.test(low)) { if (d.main) { d.main = false; said.push('it is not the main dashboard'); } }
|
|
169
322
|
else if (/\bmain\b/.test(low) && /\b(make|set|mark|as)\b/.test(low)) { if (!d.main) { d.main = true; said.push('it is the main dashboard'); } }
|
|
170
|
-
const H = hits(low), verbs = H.reduce((v, x) => v.split(x.m.title.toLowerCase()).join(' '), low); // the verbs, read with the
|
|
323
|
+
const H = hits(low, measures().concat(mineSaved())), verbs = H.reduce((v, x) => v.split(x.m.title.toLowerCase()).join(' '), low); // the verbs, read with the names taken out ("Time to first call" is not "first")
|
|
171
324
|
if (H.length && /\b(remove|take off|take out|drop|delete|without)\b/.test(verbs)) {
|
|
172
325
|
H.forEach(({ m }) => { const i = d.charts.indexOf(m.id); if (i >= 0) { d.charts.splice(i, 1); said.push('removed ' + m.title); } });
|
|
173
326
|
} else if (H.length && /\b(move|put|first|top|up|down|last|bottom)\b/.test(verbs)) {
|
|
@@ -179,34 +332,93 @@ function command(text) {
|
|
|
179
332
|
} else if (H.length && /\b(add|include|show|put in|with)\b/.test(verbs)) {
|
|
180
333
|
H.forEach(({ m }) => { if (!d.charts.includes(m.id)) { d.charts.push(m.id); said.push('added ' + m.title + (chartOf(m.id) ? '' : ' (it has no series yet, so it is listed, not drawn)')); } });
|
|
181
334
|
}
|
|
182
|
-
if (JSON.stringify(d) === before) { st.h.pop(); return 'I changed nothing. ' + (H.length || !/\b(add|remove)\b/.test(low) ? HELP : 'No measure of this board has that name. Open the Library to see them.'); }
|
|
335
|
+
if (JSON.stringify(d) === before) { st.h.dash.pop(); return 'I changed nothing. ' + (H.length || !/\b(add|remove)\b/.test(low) ? HELP : 'No measure of this board has that name. Open the Library to see them.'); }
|
|
183
336
|
st.pop = null;
|
|
184
337
|
return 'Done: ' + said.join(', ') + '.';
|
|
185
338
|
}
|
|
339
|
+
function chartCommand(t, low) {
|
|
340
|
+
const c = st.c; if (!c) return 'No measure of this board has two readings yet, so I have nothing to chart.';
|
|
341
|
+
if (/^\s*why\b/.test(low)) return formWhy(c);
|
|
342
|
+
if (/\b(start (a )?new|new chart|start over)\b/.test(low)) { snap(); st.c = chartFrom(c.measure); return 'Done: a new chart of ' + titleOf(st.c.measure) + '. Say what it should answer.'; }
|
|
343
|
+
const before = JSON.stringify(c), said = []; snap();
|
|
344
|
+
const NAMING = /(?:call it|name it|title it|rename it to|called|named)\s+["“]?(.+?)(?=["”]|,|;|\.\s|\.$|\s+and\s|\s+with\s|\s+target|$)/i;
|
|
345
|
+
const nm = t.match(NAMING); if (nm && clean(nm[1])) { c.title = clean(nm[1]).slice(0, 60); said.push('named it "' + c.title + '"'); }
|
|
346
|
+
const nt = t.match(/\bnote[:\s]+(.+)$/i); if (nt && clean(nt[1])) { c.note = clean(nt[1]).slice(0, 200); said.push('note set'); }
|
|
347
|
+
const qq = t.match(/(?:question|it answers|answers)\s*[:-]\s*(.+)$/i);
|
|
348
|
+
const rest = low.replace(new RegExp(NAMING.source, 'gi'), ' ').replace(/\bnote[:\s]+.+$/i, ' ');
|
|
349
|
+
const H = hits(rest, (P.M.charts || []).map((b) => ({ id: b.id, title: b.title })));
|
|
350
|
+
if (H.length && H[0].m.id !== c.measure) { setChart('measure', H[0].m.id); said.push('measure: ' + H[0].m.title); }
|
|
351
|
+
const verbs = H.reduce((v, x) => v.split(x.m.title.toLowerCase()).join(' '), rest);
|
|
352
|
+
const lf = verbs.replace(/\b(no|not|without|don't want|do not want|instead of|rather than)\s+(?:a\s+|an\s+|the\s+)?(?:bars?|columns?|line|trend|number|tile|meter|gauge|progress|pie)(?:\s+chart)?/g, ' ');
|
|
353
|
+
let fm = null;
|
|
354
|
+
if (/\b(pie|donut|doughnut)\b/.test(lf)) said.push('no pie: a pie cannot show a trend or a target');
|
|
355
|
+
else if (/\bbars?\b|\bcolumns?\b/.test(lf)) fm = 'bars';
|
|
356
|
+
else if (/\b(meter|gauge|progress|bullet)\b/.test(lf)) fm = 'meter';
|
|
357
|
+
else if (/\b(big number|number|stat tile|kpi|tile)\b/.test(lf)) fm = 'number';
|
|
358
|
+
else if (/\bline\b|\btrend\b/.test(lf)) fm = 'line';
|
|
359
|
+
if (fm && fm !== c.form) { setChart('form', fm); said.push('form: ' + FORMN[fm].toLowerCase()); }
|
|
360
|
+
const rg = verbs.match(/\blast\s+(\d+)\s*(readings?|points?|values?|weeks?|days?|months?)?/);
|
|
361
|
+
const n = (baseOf(c.measure) || { pts: [] }).pts.length;
|
|
362
|
+
if (rg) {
|
|
363
|
+
const k = +rg[1], u = rg[2] || 'readings';
|
|
364
|
+
if (k < 2) said.push('range not changed: a range needs at least two readings');
|
|
365
|
+
else if (k >= n) { setChart('range', ''); said.push('range: all ' + n + ' readings (only ' + n + ' are recorded)'); }
|
|
366
|
+
else { setChart('range', String(k)); said.push('range: last ' + k + ' readings' + (/^(week|day|month)/.test(u) ? ' (readings are not taken every ' + u.replace(/s$/, '') + ', so I count readings)' : '')); }
|
|
367
|
+
} else if (/\b(all (the )?(readings|data|points)|whole (period|range|series)|every reading)\b/.test(verbs) && c.range) { setChart('range', ''); said.push('range: all readings'); }
|
|
368
|
+
if (/\bno target\b|\bwithout (a )?target\b/.test(verbs)) { if (c.target !== '') { setChart('target', ''); said.push('no target'); } }
|
|
369
|
+
else { const tg = verbs.match(/\b(?:target|limit)\s*(?:of|is|at|to|=)?\s*(-?\d+(?:\.\d+)?)/); if (tg) { setChart('target', tg[1]); said.push('target ' + tg[1]); } }
|
|
370
|
+
if (/lower is better|lower better|better when lower|lower the better/.test(verbs)) { setChart('better', 'lower'); said.push('lower is better'); }
|
|
371
|
+
else if (/higher is better|higher better|better when higher|higher the better/.test(verbs)) { setChart('better', 'higher'); said.push('higher is better'); }
|
|
372
|
+
const dh = verbs.match(/\badd (?:it )?to\s+(?:the\s+)?(.+?)(?:\s+dashboard)?(?=[,;.]|$)/);
|
|
373
|
+
if (dh) { const D = savedDash().find((x) => x.name.toLowerCase() === clean(dh[1]).toLowerCase()); if (D) { setChart('addTo', D.id); said.push('it will be added to ' + D.name + ' on Save'); } else said.push('no dashboard of this board is called "' + clean(dh[1]) + '"'); }
|
|
374
|
+
if (qq && clean(qq[1])) { c.question = clean(qq[1]).slice(0, 100); if (!c.ft && !fm) c.form = suggestForm(c.question); said.push('question set'); }
|
|
375
|
+
else if (/\?\s*$/.test(t) && t.split(/\s+/).length >= 3) { c.question = t.slice(0, 100); if (!c.ft && !fm) c.form = suggestForm(t); said.push('question set'); }
|
|
376
|
+
if (JSON.stringify(c) === before) { st.h.chart.pop(); return said.length ? 'I changed nothing: ' + said.join('; ') + '.' : 'I changed nothing. ' + HELPC; }
|
|
377
|
+
st.pop = null;
|
|
378
|
+
return 'Done: ' + said.join('; ') + '. ' + formWhy(c);
|
|
379
|
+
}
|
|
186
380
|
function onSay(e) {
|
|
187
381
|
e.preventDefault(); e.stopPropagation();
|
|
188
382
|
const inp = $('#stIn'), text = inp.value.trim(); if (!text) return;
|
|
189
383
|
inp.value = ''; const answer = command(text);
|
|
190
|
-
const s = $('#dBody .stream');
|
|
384
|
+
const s = $('#dBody .stream');
|
|
385
|
+
if (answer && typeof answer.then === 'function') {
|
|
386
|
+
// a structure turn: PMOS works, then its own answer replaces the working line
|
|
387
|
+
if (s) { s.insertAdjacentHTML('beforeend', turnU(text) + turnA(ptx('PMOS is working on it.'))); s.scrollTop = s.scrollHeight; }
|
|
388
|
+
const mine = s && s.lastElementChild;
|
|
389
|
+
draw();
|
|
390
|
+
answer.then((a) => { if (mine && mine.isConnected) mine.outerHTML = turnA(ptx(a)); else if (s) s.insertAdjacentHTML('beforeend', turnA(ptx(a))); if (s) s.scrollTop = s.scrollHeight; draw(); });
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (s) { s.insertAdjacentHTML('beforeend', turnU(text) + turnA(ptx(answer))); s.scrollTop = s.scrollHeight; }
|
|
191
394
|
draw();
|
|
192
395
|
}
|
|
193
396
|
|
|
194
397
|
/* ── opening ── */
|
|
195
398
|
export function openStudio(p) {
|
|
196
399
|
P = p; typed = false;
|
|
197
|
-
const D = p.D;
|
|
198
|
-
st = { d: D ? { id: D.id, name: D.name, use: D.purpose || '', charts: D.charts.slice(), main: !!D.main } : blank(), h: [], pop: null, lib: !D, ck: false, msg: '', armed: false, busy: false };
|
|
400
|
+
const D = p.D || null, C = p.C || null, Rp = p.R || null, mode = p.mode === 'chart' || p.mode === 'rep' ? p.mode : 'dash';
|
|
401
|
+
st = { mode, d: D ? { id: D.id, name: D.name, use: D.purpose || '', charts: D.charts.slice(), main: !!D.main } : blank(), c: C ? chartSaved(C) : chartFrom(null), r: null, h: { dash: [], chart: [], rep: [] }, pop: null, more: false, lib: mode === 'dash' && !D, ck: false, msg: '', armed: false, busy: false };
|
|
402
|
+
if (mode === 'rep') st.r = Rp ? REP.setupReport(Rp) : REP.blankReport();
|
|
199
403
|
const board = p.M.board.name || 'this board';
|
|
200
|
-
const say =
|
|
201
|
-
: '
|
|
202
|
-
|
|
404
|
+
const say = mode === 'rep'
|
|
405
|
+
? (Rp ? 'This is "' + Rp.name + '". ' + REP.help() : 'Say what the report answers and who reads it. I set the title, format, schedule and source from what you say, or use the brief. A new report has a fixed set of sections; you shape them once it is set up. Nothing is set up until you press Set it up.')
|
|
406
|
+
: mode === 'chart'
|
|
407
|
+
? (C ? 'This is "' + C.title + '". Tell me what to change: the form, the range, the target, or a new question. Nothing is saved until you press Save.'
|
|
408
|
+
: st.c ? 'I started from ' + titleOf(st.c.measure) + '. Tell me what the chart should answer, or pick another measure. I choose the form from the question and say why. Nothing is saved until you press Save.'
|
|
409
|
+
: 'No measure of this board has two readings yet, so there is nothing to chart.')
|
|
410
|
+
: D ? 'This is "' + D.name + '". Tell me what to change: measures to add or remove, a new purpose, or make it the main dashboard. Nothing is saved until you press Save.'
|
|
411
|
+
: 'Name the dashboard and say what it is for. Then add measures from the library, or tell me which. Nothing is saved until you press Save.';
|
|
412
|
+
openDlg({ eye: 'Insight Studio · ' + board, title: 'Insight Studio', sub: 'Make a chart, a dashboard or a report from ' + board + '. Say it, or use the brief.', stream: turnA(ptx(say)), noteKey: null, pane: canvasHtml(), label: 'Insight Studio' });
|
|
203
413
|
$('#dlg').classList.add('stud');
|
|
204
414
|
$('#askF').hidden = true; const an = $('#askNote'); if (an) an.hidden = true;
|
|
205
|
-
$('#dBody').insertAdjacentHTML('beforeend', `<form class="askbar" id="stF"><input id="stIn" placeholder="Say what to change" maxlength="400" autocomplete="off" aria-label="Say what to change
|
|
415
|
+
$('#dBody').insertAdjacentHTML('beforeend', `<form class="askbar" id="stF"><input id="stIn" placeholder="Say what to change" maxlength="400" autocomplete="off" aria-label="Say what to change"><button type="submit" aria-label="Send" title="Send">${ICO('<path d="M5 12h14M13 6l6 6-6 6"/>')}</button></form><p class="fine2" id="stHelp"></p>`);
|
|
206
416
|
$('#stF').onsubmit = onSay;
|
|
207
417
|
if (innerWidth >= 1000) setFull(true);
|
|
208
418
|
draw();
|
|
209
419
|
}
|
|
420
|
+
REP.useStudio({ get st() { return st; }, get P() { return P; }, chip: (k, l, v) => chip(k, l, v), opt: (...a) => opt(...a), field: (...a) => field(...a), draw: (x) => draw(x), snap: () => snap(),
|
|
421
|
+
done: (msg) => { closeDlg(); toast(msg); P.reportsChanged(); } });
|
|
210
422
|
/* The Studio's presses. The dialog is shared, so each listener first asks whether the Studio is what it holds. */
|
|
211
423
|
const inStudio = (e) => $('#dlg').classList.contains('stud') && $('#dlg').classList.contains('on') && e.target.closest('#oMain');
|
|
212
424
|
document.addEventListener('click', (e) => { if (!inStudio(e)) return; const t = e.target.closest('[data-st]'); if (t && !t.disabled) act(t.dataset.st.split('|')); });
|
|
@@ -897,6 +897,44 @@ a.round{color:inherit;text-decoration:none}
|
|
|
897
897
|
.stft .sp{flex:1}
|
|
898
898
|
.stft .dmcta{height:44px}
|
|
899
899
|
@media (max-width:700px){.sol{grid-template-columns:minmax(0,1fr)}.stli{grid-template-columns:72px minmax(0,1fr)}.stli .spk,.stlic{width:72px}.stli em{grid-column:2}.stt{gap:8px}.sucl li{grid-template-columns:18px minmax(0,1fr)}.sucl li .dmcta{grid-column:2;justify-self:start}}
|
|
900
|
+
/* ── Insight Studio, Chart mode (initiative premium-studio-chart): the mode switch, More, and the four chart forms the page and the Studio share ── */
|
|
901
|
+
.stt{justify-content:space-between}
|
|
902
|
+
.stmd{display:inline-flex;gap:4px;padding:4px;border-radius:999px;background:var(--well)}
|
|
903
|
+
.stmd button{min-height:44px;padding:0 16px;border-radius:999px;font-size:13.5px;font-weight:600;color:var(--ink-2)}
|
|
904
|
+
.stmd button[aria-pressed="true"]{background:var(--card-solid);color:var(--ink);box-shadow:0 1px 2px color-mix(in oklab,var(--ink) 18%,transparent)}
|
|
905
|
+
.stmd button:focus-visible{outline:2px solid var(--ember);outline-offset:1px}
|
|
906
|
+
.suc.stmore{background:transparent;box-shadow:inset 0 0 0 1px var(--hair);border-style:dashed}
|
|
907
|
+
.sor{display:flex;gap:8px;flex-wrap:wrap}.sor .dmcta{height:44px}
|
|
908
|
+
.stbar[data-t="5"][data-n="1"] b{width:20%}.stbar[data-t="5"][data-n="2"] b{width:40%}.stbar[data-t="5"][data-n="3"] b{width:60%}.stbar[data-t="5"][data-n="4"] b{width:80%}.stbar[data-t="5"][data-n="5"] b{width:100%}
|
|
909
|
+
.stu{grid-template-columns:minmax(0,1fr)}
|
|
910
|
+
.stpvw>.mt1{grid-template-columns:minmax(0,1fr)}
|
|
911
|
+
.stvt{margin-top:8px;font-size:13px}.stvt summary{cursor:pointer;color:var(--ink-2);min-height:44px;display:flex;align-items:center}
|
|
912
|
+
.stsrc{margin:8px 0 0;font-size:12px;color:var(--ink-3)}
|
|
913
|
+
.mfm .mval{font-size:28px}
|
|
914
|
+
.mfm .mhero{font-size:44px;line-height:1;letter-spacing:-.03em}
|
|
915
|
+
.mfm .nspk{width:100%;height:auto;display:block;margin-top:8px;overflow:visible}
|
|
916
|
+
.mfm .nspk path{fill:none;stroke:var(--ink-2);stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round;vector-effect:non-scaling-stroke}
|
|
917
|
+
.bplot{position:relative;display:flex;align-items:stretch;gap:2px;height:120px;margin-top:10px;border-bottom:1px solid var(--hair)}
|
|
918
|
+
.bw{flex:1 1 0;display:flex;flex-direction:column;justify-content:flex-end;align-items:center;min-width:0;position:relative}
|
|
919
|
+
.bw i{display:block;width:min(24px,64%);border-radius:4px 4px 0 0}
|
|
920
|
+
.bw i.bg{background:color-mix(in oklab,var(--ink) 20%,transparent)}
|
|
921
|
+
.bw i.bk{background:var(--ink)}
|
|
922
|
+
.bw .bl{font-size:11px!important;font-weight:650;margin-bottom:3px;white-space:nowrap;letter-spacing:0}
|
|
923
|
+
.btg{position:absolute;left:0;right:0;border-top:1px dashed var(--ink-3);height:0;pointer-events:none}
|
|
924
|
+
.mtrk{position:relative;height:12px;border-radius:999px;background:color-mix(in oklab,var(--ink) 10%,transparent);margin:16px 0 8px}
|
|
925
|
+
.mfil{position:absolute;inset:0 auto 0 0;border-radius:999px;background:var(--ink)}
|
|
926
|
+
.mfil.ok{background:var(--ok)}.mfil.warn{background:var(--ember)}
|
|
927
|
+
.mtgt{position:absolute;top:-5px;bottom:-5px;width:2px;background:var(--ink);border-radius:2px}
|
|
928
|
+
.mnote{margin:6px 0 0 4px;font-size:12.5px;color:var(--ink-2)}
|
|
929
|
+
.mt1 .mwhy{font-size:12px;color:var(--ink-3);margin-top:4px}
|
|
930
|
+
.ntf .lk+.lk{margin-left:4px}
|
|
931
|
+
/* ── Insight Studio, Report mode (initiative premium-studio-report): the report's sections in the preview ── */
|
|
932
|
+
.stsec{padding:10px 0;border-top:1px solid var(--hair)}
|
|
933
|
+
.stsec:first-of-type{margin-top:12px}
|
|
934
|
+
.stsec h4{margin:0;font-size:14.5px;font-weight:650;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
|
|
935
|
+
.stsec .mut{margin:3px 0 0;font-size:13px;line-height:1.4}
|
|
936
|
+
.stlc small{font-size:12px;color:var(--ink-3);white-space:nowrap;align-self:center}
|
|
937
|
+
.stlc button{font-size:13px;font-weight:600}
|
|
900
938
|
/* ── initiative page (initiative briefing-premium-initiative) ── */
|
|
901
939
|
.ckr.current i{background:var(--ember)}
|
|
902
940
|
.ckr.done i{background:var(--ok)}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Initiative premium-studio-chart: the Insight Studio's chart store and save route, the Insights model's saved charts, and the Studio's Chart mode against the real server on a scratch repository.",
|
|
3
|
+
"modules": [
|
|
4
|
+
"premium-charts.test.js"
|
|
5
|
+
],
|
|
6
|
+
"seconds": {
|
|
7
|
+
"premium-charts.test.js": 5,
|
|
8
|
+
"premium-studio-chart-test.js": 120
|
|
9
|
+
},
|
|
10
|
+
"panels": [
|
|
11
|
+
"premium-studio-chart-test.js"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_comment": "Initiative premium-studio-report: the Insight Studio's Report mode, setting up a report and shaping a set-up one, against the real server on a scratch repository with a stub claude for the structure job.",
|
|
3
|
+
"seconds": {
|
|
4
|
+
"premium-studio-report-test.js": 60
|
|
5
|
+
},
|
|
6
|
+
"panels": [
|
|
7
|
+
"premium-studio-report-test.js"
|
|
8
|
+
]
|
|
9
|
+
}
|