create-pmos 0.265.0 → 0.267.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-board-test.js +1 -1
- package/workspace/briefing-premium-calendar-2-test.js +231 -0
- package/workspace/guide/briefing-premium.md +9 -2
- package/workspace/lib/board-premium.js +29 -3
- package/workspace/lib/initiative-premium.js +8 -0
- package/workspace/lib/routes-board-premium.js +15 -4
- package/workspace/lib/routes-initiative-premium.js +1 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +209 -0
- package/workspace/public/pm/premium-acts.js +281 -0
- package/workspace/public/pm/premium-board.js +36 -7
- package/workspace/public/pm/premium-initiative.js +9 -2
- package/workspace/public/pm/premium-meeting.js +160 -22
- package/workspace/public/pm/premium.css +29 -0
- package/workspace/public/premium-board.html +3 -2
- package/workspace/public/premium-initiative.html +1 -1
- package/workspace/test-files.json +2 -0
- package/workspace/test-lists/briefing-premium.json +2 -0
- package/workspace/test-lists/premium-board-actions.json +9 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/* premium-board-actions-test.js — the board presses of the premium Board and initiative pages (initiative premium-board-actions; planning/prd/premium-board-actions-prd.md A1 to A12).
|
|
4
|
+
* A real server on a scratch `team` repository (planning/initiatives, pmos/state), never the PMOS checkout. The real pages press the real routes:
|
|
5
|
+
* T triage (accept, decline) · N New initiative · M move and Undo · L hold, resume, cancel, reopen, archive, restore · I the initiative page's bar
|
|
6
|
+
* S the PMOS-self board (a model answer, since only the embedded checkout is self) · P the POST allow-list and the refusals · F floors */
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const { spawn } = require('child_process');
|
|
10
|
+
const { findBrowser } = require('./lib/find-browser');
|
|
11
|
+
const T = require('./test-run').configure({ name: 'premium-board-actions' });
|
|
12
|
+
const { makeRepos, codeRepo, write, git } = require('./plan-test-repos');
|
|
13
|
+
const BP = require('./lib/board-premium.js');
|
|
14
|
+
const F = require('./fixtures/board-premium-facts.js');
|
|
15
|
+
|
|
16
|
+
const BASE = T.BASE;
|
|
17
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
18
|
+
const until = async (fn, ms = 20000, step = 150) => { const t0 = Date.now(); for (;;) { const v = await fn(); if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
|
|
19
|
+
const results = [];
|
|
20
|
+
const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + String(extra).slice(0, 500) : ''}`); };
|
|
21
|
+
const R = makeRepos('premium-board-actions');
|
|
22
|
+
const team = codeRepo(path.join(R.base, 'team'));
|
|
23
|
+
fs.mkdirSync(path.join(team, 'pmos', 'state'), { recursive: true });
|
|
24
|
+
/* a record that declares its id, so the lifecycle route knows it (the synthetic records of plan-test-repos declare none) */
|
|
25
|
+
write(team, 'planning/initiatives/pa-one.md', '---\ntype: Initiative\ntitle: Partner rate limits\ntimestamp: 2026-10-01\nid: pa-one\nlane: chore\nparent_kr: health:tech\nspecimen_test: "description-judgeable — x"\nsurface_check: "greenfield — x"\nstatus: "open — intent: limit partner calls."\n---\n# pa-one\n');
|
|
26
|
+
git(team, ['add', '-A']); git(team, ['commit', '-q', '-m', 'pa-one']);
|
|
27
|
+
let srv = null; let browser = null;
|
|
28
|
+
const finish = async (code) => {
|
|
29
|
+
if (browser) await browser.close().catch(() => {});
|
|
30
|
+
if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
|
|
31
|
+
T.killTmux(); R.cleanup();
|
|
32
|
+
const bad = results.filter((x) => !x.cond).length;
|
|
33
|
+
console.log(`\n${results.length - bad}/${results.length} premium-board-actions assertions passed`);
|
|
34
|
+
process.exit(code !== undefined ? code : (bad ? 1 : 0));
|
|
35
|
+
};
|
|
36
|
+
process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
|
|
37
|
+
|
|
38
|
+
/** Every line of a ledger the routes append to, wherever the repository keeps it. */
|
|
39
|
+
const lines = (name) => {
|
|
40
|
+
const out = [];
|
|
41
|
+
const walk = (d) => { for (const e of fs.readdirSync(d, { withFileTypes: true })) { if (e.name === '.git') continue; const p = path.join(d, e.name); if (e.isDirectory()) walk(p); else if (e.name === name) out.push(...fs.readFileSync(p, 'utf8').split('\n').filter(Boolean).map((x) => JSON.parse(x))); } };
|
|
42
|
+
walk(team); if (process.env.PMOS_STATE_DIR && fs.existsSync(process.env.PMOS_STATE_DIR)) walk(process.env.PMOS_STATE_DIR);
|
|
43
|
+
return out;
|
|
44
|
+
};
|
|
45
|
+
/** A press on a choice chip inside the dialog's pane, as a click event on the element (Playwright's pointer check races the dialog's spring). */
|
|
46
|
+
const tap = (pg, sel) => pg.$eval(sel, (b) => b.click());
|
|
47
|
+
const ALLOWED = /^\/api\/(?:boards\/(?:asks\/(?:add|accept|decline)|move|archive)|lifecycle|briefing-premium\/note)$/;
|
|
48
|
+
|
|
49
|
+
(async () => {
|
|
50
|
+
const exe = findBrowser();
|
|
51
|
+
if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
|
|
52
|
+
let chromium;
|
|
53
|
+
try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
|
|
54
|
+
srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT), PMOS_SELF_ROOT: team, PMOS_NO_OPEN: '1' }) });
|
|
55
|
+
await T.waitForServer(BASE);
|
|
56
|
+
const ready = await until(async () => { const r = await fetch(BASE + '/api/board-premium'); const j = await r.json().catch(() => null); return r.status === 200 && j && j.ok && j.state === 'ready' && j.model.initiatives.list.rows.length ? j : null; }, 90000, 400);
|
|
57
|
+
ok('A1 the real route reads the scratch board, with its stages, its new asks and no PMOS-self flag', !!ready && ready.model.board.self === false && ready.model.board.stages.length > 2 && Array.isArray(ready.model.asks.rows) && !ready.model.asks.missing, ready && JSON.stringify(ready.model.board));
|
|
58
|
+
if (!ready) return finish(1);
|
|
59
|
+
const B = ready.model.board, H = await T.pressHeaders(BASE);
|
|
60
|
+
const post = (p, body, h = H) => fetch(BASE + p, { method: 'POST', headers: h, body: JSON.stringify({ ws: B.ws, board: B.id, ...body }) }).then(async (r) => ({ status: r.status, body: await r.json().catch(() => null) }));
|
|
61
|
+
const a1 = await post('/api/boards/asks/add', { line: 'Finance wants a CSV of failed payouts each morning', source: 'Email from Rina' });
|
|
62
|
+
const a2 = await post('/api/boards/asks/add', { line: 'Can the portal get a dark mode', source: 'Support inbox' });
|
|
63
|
+
ok('setup two asks are on the board', a1.status === 200 && a2.status === 200, JSON.stringify([a1, a2]));
|
|
64
|
+
|
|
65
|
+
browser = await chromium.launch({ executablePath: exe });
|
|
66
|
+
const open = async (url, { w = 1280, h = 900 } = {}) => {
|
|
67
|
+
const ctx = await browser.newContext({ viewport: { width: w, height: h } });
|
|
68
|
+
await ctx.addInitScript(() => { try { localStorage.setItem('pmos.premium.openAs', 'popup'); } catch { /* none */ } });
|
|
69
|
+
const page = await ctx.newPage(), errors = [], posts = [];
|
|
70
|
+
page.on('pageerror', (e) => errors.push(String((e && e.message) || e)));
|
|
71
|
+
page.on('request', (rq) => { if (rq.method() === 'POST') posts.push({ path: new URL(rq.url()).pathname, body: JSON.parse(rq.postData() || '{}') }); });
|
|
72
|
+
await page.goto(BASE + url);
|
|
73
|
+
return { ctx, page, errors, posts };
|
|
74
|
+
};
|
|
75
|
+
const P = await open('/premium-board.html');
|
|
76
|
+
const p = P.page;
|
|
77
|
+
const listed = (id) => p.evaluate((x) => [...document.querySelectorAll('#ibBody .ini2')].some((b) => b.dataset.key === 'board:' + x), id);
|
|
78
|
+
const toastIs = (re) => until(() => p.evaluate((s) => { const t = document.querySelector('#toast'); return t.classList.contains('on') && new RegExp(s).test(t.textContent) ? t.textContent : null; }, re.source));
|
|
79
|
+
const dlgOn = async () => { const v = await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on'))); await sleep(800); return v; };
|
|
80
|
+
const dlgOff = () => until(() => p.evaluate(() => !document.querySelector('#dlg').classList.contains('on')));
|
|
81
|
+
ok('A2 the New asks card lists both asks with Accept and Decline', await until(() => p.evaluate(() => document.querySelectorAll('#cAsks .baa').length === 2 && document.querySelectorAll('#cAsks [data-ask^="acc:"]').length === 2)), await p.evaluate(() => (document.querySelector('#asksHost') || {}).textContent));
|
|
82
|
+
ok('A2 an ask shows its source, not an invented name', await p.evaluate(() => /Email from Rina/.test(document.querySelector('#cAsks').textContent) && !/demo/i.test(document.querySelector('#cAsks').textContent)));
|
|
83
|
+
|
|
84
|
+
/* T triage */
|
|
85
|
+
await p.click(`#cAsks [data-ask="acc:${a1.body.ask.id}"]`); await dlgOn();
|
|
86
|
+
const anc = await until(() => p.evaluate(() => { const s = document.querySelector('#paNA'); return s && s.tagName === 'SELECT' && !s.disabled ? [...s.options].map((o) => o.value) : null; }));
|
|
87
|
+
ok('T1 Accept opens the form with the anchors the board declares', !!anc && anc.includes('health:tech'), JSON.stringify(anc));
|
|
88
|
+
await p.fill('#paNT', ''); await p.click('#paNGo');
|
|
89
|
+
ok('T2 an empty title is refused on the page, before any press', await p.evaluate(() => /Give it a title/.test(document.querySelector('#paNM').textContent)) && !P.posts.some((x) => x.path === '/api/boards/asks/accept'));
|
|
90
|
+
await p.fill('#paNT', 'Daily CSV of failed payouts'); await p.selectOption('#paNA', 'health:tech'); await p.click('#paNGo');
|
|
91
|
+
ok('T3 Accept records the accept line and a new initiative, and says so', !!(await toastIs(/accepted in/)) && lines('boards.jsonl').some((l) => l.kind === 'ask-accept' && l.ask === a1.body.ask.id), JSON.stringify(lines('boards.jsonl').map((l) => l.kind)));
|
|
92
|
+
await dlgOff();
|
|
93
|
+
ok('T4 the accepted ask leaves the card', await until(() => p.evaluate((id) => !document.querySelector(`#cAsks [data-ask="acc:${id}"]`) && document.querySelectorAll('#cAsks .baa').length === 1, a1.body.ask.id)));
|
|
94
|
+
await p.click(`#cAsks [data-ask="dec:${a2.body.ask.id}"]`); await dlgOn();
|
|
95
|
+
ok('T5 Decline waits for a reason', await p.evaluate(() => document.querySelector('#paDGo').disabled));
|
|
96
|
+
await p.fill('#paDW', 'Not tied to a goal this quarter'); await p.click('#paDGo');
|
|
97
|
+
ok('T6 Decline records the reason in the board ledger', !!(await toastIs(/Ask declined/)) && lines('boards.jsonl').some((l) => l.kind === 'ask-decline' && l.why === 'Not tied to a goal this quarter'));
|
|
98
|
+
ok('T7 the card says nothing is left to triage', await until(() => p.evaluate(() => /Nothing new to triage/.test(document.querySelector('#cAsks').textContent))));
|
|
99
|
+
|
|
100
|
+
/* N New initiative */
|
|
101
|
+
ok('N1 New initiative is offered on a team board', await p.evaluate(() => !document.querySelector('#newIni').hidden));
|
|
102
|
+
await p.click('#newIni'); await dlgOn();
|
|
103
|
+
await until(() => p.evaluate(() => { const s = document.querySelector('#paNA'); return s && !s.disabled; }));
|
|
104
|
+
await p.fill('#paNT', 'Partner usage per key'); await p.click('#paNGo');
|
|
105
|
+
ok('N2 an unanchored create is refused on the page', await p.evaluate(() => /Choose an anchor/.test(document.querySelector('#paNM').textContent)));
|
|
106
|
+
await p.selectOption('#paNA', 'health:tech'); await p.click('#paNGo');
|
|
107
|
+
const made = await toastIs(/created in/);
|
|
108
|
+
const recs = fs.readdirSync(path.join(team, 'planning', 'initiatives'));
|
|
109
|
+
ok('N3 Create writes an ask, its accept and a new initiative record, as the console does', !!made && recs.some((f) => /partner-usage/.test(f)) && lines('boards.jsonl').some((l) => l.kind === 'ask' && l.line === 'Partner usage per key'), made + ' / ' + recs.join());
|
|
110
|
+
|
|
111
|
+
/* M move and Undo, from the row's menu */
|
|
112
|
+
await dlgOff();
|
|
113
|
+
await until(() => listed('pa-one'));
|
|
114
|
+
const menuBtn = '#ibBody .inim[data-im="board:pa-one"]';
|
|
115
|
+
await p.click(menuBtn);
|
|
116
|
+
const items = await until(() => p.evaluate(() => { const m = document.querySelector('.bam2'); return m ? [...m.querySelectorAll('[role="menuitem"] b')].map((b) => b.textContent) : null; }));
|
|
117
|
+
ok('M1 the row menu offers the next stage, hold, cancel and archive', !!items && /^Move to /.test(items[0]) && items.includes('Put on hold') && items.includes('Cancel') && items.includes('Archive'), JSON.stringify(items));
|
|
118
|
+
ok('M2 the menu takes the focus and the arrow keys move it; Escape closes it and gives the focus back', await (async () => {
|
|
119
|
+
const f0 = await p.evaluate(() => document.activeElement.closest('.bam2') !== null);
|
|
120
|
+
await p.keyboard.press('ArrowDown'); const f1 = await p.evaluate(() => [...document.querySelectorAll('.bam2 [role="menuitem"]')].indexOf(document.activeElement));
|
|
121
|
+
await p.keyboard.press('Escape'); const gone = await p.evaluate(() => !document.querySelector('.bam2') && document.activeElement.matches('.inim'));
|
|
122
|
+
return f0 && f1 === 1 && gone;
|
|
123
|
+
})());
|
|
124
|
+
const from = ready.model.initiatives.list.rows.find((r) => r.id === 'pa-one').acts.stage;
|
|
125
|
+
await p.click(menuBtn); await p.click('.bam2 [data-pk^="mv:"]');
|
|
126
|
+
const mv = await toastIs(/^Moved to/);
|
|
127
|
+
ok('M3 Move records one move line and says what it recorded', !!mv && lines('boards.jsonl').filter((l) => l.kind === 'move' && l.id === 'pa-one').length === 1, mv);
|
|
128
|
+
await p.click('#paUndo');
|
|
129
|
+
ok('M4 Undo writes the move back', !!(await toastIs(new RegExp('Back in ' + from))) && lines('boards.jsonl').filter((l) => l.kind === 'move' && l.id === 'pa-one').pop().to === from);
|
|
130
|
+
|
|
131
|
+
/* L hold, resume, cancel, reopen, archive, restore */
|
|
132
|
+
await until(() => listed('pa-one'));
|
|
133
|
+
await p.click(menuBtn);
|
|
134
|
+
await p.click('.bam2 [data-pk="hold"]'); await dlgOn();
|
|
135
|
+
await p.fill('#paHR', 'Waiting for the Q1 budget'); await tap(p, '#paHB [data-v="two"]'); await p.click('#paHGo');
|
|
136
|
+
const hl = await until(() => lines('lifecycle.jsonl').find((l) => l.initiative_id === 'pa-one' && l.state === 'on-hold'));
|
|
137
|
+
ok('L1 Put on hold records one on-hold line with the reason and a check-back day', !!hl && hl.reason === 'Waiting for the Q1 budget' && /^\d{4}-\d{2}-\d{2}$/.test(hl.back || ''), JSON.stringify(hl) + ' ' + await p.evaluate(() => (document.querySelector('#paHM') || {}).textContent));
|
|
138
|
+
ok('L2 the row then says On hold and its menu offers Resume', await until(async () => { const t = await p.evaluate(() => { const b = document.querySelector('#ibBody .ini2[data-key="board:pa-one"]'); return b ? b.textContent : ''; }); return /On hold/.test(t); }, 30000));
|
|
139
|
+
await p.click(menuBtn);
|
|
140
|
+
ok('L2 Resume is offered and the moves are not', await until(() => p.evaluate(() => { const m = document.querySelector('.bam2'); return m && !!m.querySelector('[data-pk="resume"]') && !m.querySelector('[data-pk^="mv:"]'); })));
|
|
141
|
+
await p.click('.bam2 [data-pk="resume"]');
|
|
142
|
+
ok('L3 Resume records an active line', await until(() => { const L = lines('lifecycle.jsonl').filter((l) => l.initiative_id === 'pa-one'); return L.length && L[L.length - 1].state === 'active'; }));
|
|
143
|
+
await until(() => p.evaluate(() => { const b = document.querySelector('#ibBody .ini2[data-key="board:pa-one"]'); return b && !/On hold/.test(b.textContent); }), 30000);
|
|
144
|
+
await p.click(menuBtn); await p.click('.bam2 [data-pk="cancel"]'); await dlgOn();
|
|
145
|
+
ok('L4 Cancel waits for a reason', await p.evaluate(() => document.querySelector('#paCGo').disabled));
|
|
146
|
+
await tap(p, '#paCW [data-v="worth"]'); await p.click('#paCGo');
|
|
147
|
+
ok('L4 Cancel records a cancelled line with the reason', await until(() => lines('lifecycle.jsonl').some((l) => l.initiative_id === 'pa-one' && l.state === 'cancelled' && l.reason === 'Not worth it now')));
|
|
148
|
+
ok('L5 the row leaves the list and the fold counts it', await until(() => p.evaluate(() => !document.querySelector('#ibBody .inil .ini2[data-key="board:pa-one"]') && /1 cancelled/.test((document.querySelector('#goneT') || {}).textContent || '')), 30000));
|
|
149
|
+
await p.click('#goneT'); await p.click('#ibBody .inim[data-im="board:pa-one"]');
|
|
150
|
+
ok('L6 a cancelled row offers Reopen only', await until(() => p.evaluate(() => { const m = document.querySelector('.bam2'); return m && [...m.querySelectorAll('[data-pk]')].map((b) => b.dataset.pk).join() === 'reopen'; })));
|
|
151
|
+
await p.click('.bam2 [data-pk="reopen"]');
|
|
152
|
+
ok('L6 Reopen records an active line', await until(() => { const L = lines('lifecycle.jsonl').filter((l) => l.initiative_id === 'pa-one'); return L[L.length - 1].state === 'active'; }));
|
|
153
|
+
await until(() => listed('pa-one'), 30000);
|
|
154
|
+
await p.click(menuBtn); await p.click('.bam2 [data-pk="archive"]'); await dlgOn();
|
|
155
|
+
await tap(p, '#paAW [data-v="dup"]'); await p.fill('#paAN', 'Same as the CSV export'); await p.click('#paAGo');
|
|
156
|
+
ok('L7 Archive records one archive line with the reason', await until(() => lines('boards.jsonl').some((l) => l.kind === 'ini-archive' && l.id === 'pa-one' && l.archived === true && l.reason === 'Duplicate: Same as the CSV export')));
|
|
157
|
+
ok('L8 the fold counts it as archived', await until(() => p.evaluate(() => /1 archived/.test((document.querySelector('#goneT') || {}).textContent || '')), 30000));
|
|
158
|
+
await p.click('#paUndo');
|
|
159
|
+
ok('L9 Undo restores it with a restore line', await until(() => lines('boards.jsonl').some((l) => l.kind === 'ini-archive' && l.id === 'pa-one' && l.archived === false)));
|
|
160
|
+
|
|
161
|
+
/* I the initiative page's bar */
|
|
162
|
+
const I = await open('/premium-initiative.html?id=pa-one&ws=' + encodeURIComponent(B.ws) + '&board=' + encodeURIComponent(B.id));
|
|
163
|
+
const ip = I.page;
|
|
164
|
+
const bar = await until(() => ip.evaluate(() => { const b = document.querySelector('#iBar'); return b && b.querySelector('[data-pk^="mv:"]') ? [...b.querySelectorAll('button')].map((x) => x.textContent.trim()) : null; }), 60000);
|
|
165
|
+
ok('I1 the bar offers the next stage and More', !!bar && bar.some((t) => /^Move to /.test(t)) && bar.includes('More'), JSON.stringify(bar));
|
|
166
|
+
const n0 = lines('boards.jsonl').filter((l) => l.kind === 'move').length;
|
|
167
|
+
await ip.click('#iBar [data-pk^="mv:"]');
|
|
168
|
+
ok('I2 a press on the bar records one move line', await until(() => lines('boards.jsonl').filter((l) => l.kind === 'move').length === n0 + 1));
|
|
169
|
+
await ip.click('#iBar [data-im="bar"]');
|
|
170
|
+
ok('I3 More lists the lifecycle presses and no move', await until(() => ip.evaluate(() => { const m = document.querySelector('.bam2'); return m && [...m.querySelectorAll('[data-pk]')].map((b) => b.dataset.pk).join() === 'hold,cancel,archive'; })));
|
|
171
|
+
await ip.keyboard.press('Escape');
|
|
172
|
+
await ip.click('#paUndo').catch(() => {});
|
|
173
|
+
|
|
174
|
+
/* S the PMOS-self board: the model says self, the page offers no move and no New initiative */
|
|
175
|
+
{
|
|
176
|
+
const m = BP.build(F.facts({ board: Object.assign({}, F.facts().board, { self: true }), asks: [] }));
|
|
177
|
+
const S = await open('/premium-board.html');
|
|
178
|
+
await S.page.route('**/api/board-premium*', (r) => r.fulfill({ contentType: 'application/json', body: JSON.stringify({ ok: true, state: 'ready', model: m, as_of: Date.now() }) }));
|
|
179
|
+
await S.page.reload();
|
|
180
|
+
await until(() => S.page.evaluate(() => document.querySelectorAll('#ibBody .ini2').length > 0));
|
|
181
|
+
ok('S1 the PMOS-self board names the router in its asks card and hides New initiative', await S.page.evaluate(() => /pmos-router/.test(document.querySelector('#cAsks').textContent) && document.querySelector('#newIni').hidden));
|
|
182
|
+
await S.page.click('#ibBody .inim');
|
|
183
|
+
ok('S2 its row menu has no move', await until(() => S.page.evaluate(() => { const x = document.querySelector('.bam2'); return x && !x.querySelector('[data-pk^="mv:"]') && !!x.querySelector('[data-pk="hold"]'); })));
|
|
184
|
+
await S.ctx.close();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/* P the POST allow-list and the refusals */
|
|
188
|
+
const all = P.posts.concat(I.posts);
|
|
189
|
+
const other = all.filter((x) => !ALLOWED.test(x.path));
|
|
190
|
+
ok('P1 the pages post only to the asks, move, lifecycle and archive routes', all.length > 10 && !other.length, JSON.stringify(other));
|
|
191
|
+
const noNonce = await post('/api/boards/move', { id: 'fx-bare', to: ready.model.board.stages[1] }, { 'Content-Type': 'application/json', Origin: BASE });
|
|
192
|
+
const lifeNo = await post('/api/lifecycle', { initiative_id: 'fx-bare', state: 'on-hold' }, { 'Content-Type': 'application/json', Origin: BASE });
|
|
193
|
+
ok('P2 a press without the launch nonce is refused', noNonce.status === 403 && lifeNo.status === 403, JSON.stringify([noNonce.status, lifeNo.status]));
|
|
194
|
+
ok('P3 no script error on either page', !P.errors.length && !I.errors.length, P.errors.concat(I.errors).join(' | '));
|
|
195
|
+
|
|
196
|
+
/* F floors */
|
|
197
|
+
{
|
|
198
|
+
const S = await open('/premium-board.html', { w: 390, h: 844 });
|
|
199
|
+
await until(() => S.page.evaluate(() => document.querySelectorAll('#ibBody .inim').length > 0), 30000);
|
|
200
|
+
const f = await S.page.evaluate(() => ({ wide: document.documentElement.scrollWidth > innerWidth + 1, small: [...document.querySelectorAll('#ibBody .inim, #cAsks button, #newIni')].filter((b) => b.offsetParent && (b.getBoundingClientRect().width < 44 || b.getBoundingClientRect().height < 44)).map((b) => b.className + ':' + Math.round(b.getBoundingClientRect().width) + 'x' + Math.round(b.getBoundingClientRect().height)) }));
|
|
201
|
+
ok('F1 at 390 px there is no sideways scroll and every new control is at least 44 px', !f.wide && !f.small.length, JSON.stringify(f));
|
|
202
|
+
await S.page.click('#ibBody .inim');
|
|
203
|
+
const mi = await until(() => S.page.evaluate(() => { const L = [...document.querySelectorAll('.bam2 [role="menuitem"]')]; return L.length ? L.every((b) => b.getBoundingClientRect().height >= 44) && document.documentElement.scrollWidth <= innerWidth + 1 : null; }));
|
|
204
|
+
ok('F2 the menu items are 44 px tall and the open menu adds no sideways scroll', !!mi);
|
|
205
|
+
await S.ctx.close();
|
|
206
|
+
}
|
|
207
|
+
await P.ctx.close(); await I.ctx.close();
|
|
208
|
+
finish();
|
|
209
|
+
})();
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/* pm/premium-acts.js — the board presses of the premium Board and initiative pages (initiative premium-board-actions).
|
|
2
|
+
*
|
|
3
|
+
* Every press is a route the console already uses, behind the launch nonce:
|
|
4
|
+
* triage POST /api/boards/asks/accept { board, ask, title, lane, anchor } · /asks/decline { board, ask, why }
|
|
5
|
+
* new POST /api/boards/asks/add { board, line, source } then /asks/accept, as the console's New initiative does
|
|
6
|
+
* move POST /api/boards/move { board, id, to }; its warnings never block
|
|
7
|
+
* hold, cancel POST /api/lifecycle { initiative_id, state: on-hold | cancelled | active, reason, back? }
|
|
8
|
+
* archive POST /api/boards/archive { board, id, archived, reason? }
|
|
9
|
+
* Each result has Undo, which writes the opposite line through the same route. The anchors of a new initiative are read from
|
|
10
|
+
* GET /api/boards/anchors. Nothing here reads or writes anything else.
|
|
11
|
+
*
|
|
12
|
+
* C, the page's context: { ws, board, boardName, self, first, reload }. A row: { id, title, acts } with acts from lib/board-premium.js actsOf
|
|
13
|
+
* (or lib/initiative-premium.js): { stages, stage, life: hold | cancelled | null, reason, back, backDay, archived: { reason, into } | null }. */
|
|
14
|
+
import { pmPost, pmGet } from './http.js';
|
|
15
|
+
import { $, $$, esc, openDlg, closeDlg, toast, turnA, ptx } from './premium-shell.js';
|
|
16
|
+
|
|
17
|
+
const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
|
|
18
|
+
const CHK = '<path d="M5 12.5l4.5 4.5L19 7.5"/>';
|
|
19
|
+
const SHD = '<path d="M12 3l8 3v6c0 5-3.5 8-8 9-4.5-1-8-4-8-9V6z"/>';
|
|
20
|
+
const DOTS = '<circle cx="5" cy="12" r="1.4"/><circle cx="12" cy="12" r="1.4"/><circle cx="19" cy="12" r="1.4"/>';
|
|
21
|
+
export const LANES = [['feature', 'Feature', 'PRD and rubric'], ['discovery', 'Discovery', 'Spike brief'], ['chore', 'Chore', 'One-paragraph intent'], ['incident', 'Incident', 'Post-hoc record'], ['content', 'Content', 'Content brief'], ['prototype', 'Prototype', 'Quick brief, grilled as dialogue']];
|
|
22
|
+
const BACK = [['two', 'In 2 weeks', 14], ['month', 'In a month', 30], ['quarter', 'Next quarter', 80], ['none', 'No date', null]];
|
|
23
|
+
const WHY = [['needed', 'No longer needed'], ['replaced', 'Replaced by another initiative'], ['worth', 'Not worth it now'], ['kill', 'Hit a kill condition'], ['other', 'Other']];
|
|
24
|
+
const AWHY = [['unrelated', 'Not related to this board'], ['stale', 'Old idea, never started'], ['dup', 'Duplicate'], ['other', 'Other']];
|
|
25
|
+
const errOf = (r, d) => (r && r.error) || d;
|
|
26
|
+
const dayIso = (n) => { const t = new Date(Date.now() + n * 86400000); return t.getFullYear() + '-' + String(t.getMonth() + 1).padStart(2, '0') + '-' + String(t.getDate()).padStart(2, '0'); };
|
|
27
|
+
|
|
28
|
+
/* ── the writes ── */
|
|
29
|
+
const post = (C, path, body) => pmPost(path, { ws: C.ws, ...body });
|
|
30
|
+
const life = (C, id, state, reason, back) => post(C, '/api/lifecycle', { initiative_id: id, state, reason: reason || '', ...(back ? { back } : {}) });
|
|
31
|
+
const arch = (C, id, archived, reason) => post(C, '/api/boards/archive', { board: C.board, id, archived, ...(reason ? { reason } : {}) });
|
|
32
|
+
const move = (C, id, to) => post(C, '/api/boards/move', { board: C.board, id, to });
|
|
33
|
+
|
|
34
|
+
/* ── the result line with Undo, in the page's own toast ── */
|
|
35
|
+
let undoT = null;
|
|
36
|
+
export function undoToast(msg, undo) {
|
|
37
|
+
const t = $('#toast'); clearTimeout(undoT);
|
|
38
|
+
t.innerHTML = `<span>${esc(msg)}</span>${undo ? '<button type="button" class="undo" id="paUndo">Undo</button>' : ''}`;
|
|
39
|
+
t.classList.add('on');
|
|
40
|
+
if (undo) $('#paUndo').onclick = async () => { const b = $('#paUndo'); b.disabled = true; await undo(); };
|
|
41
|
+
undoT = setTimeout(() => t.classList.remove('on'), undo ? 9000 : 4200);
|
|
42
|
+
}
|
|
43
|
+
async function done(C, r, msg, undo) {
|
|
44
|
+
if (!r || r.ok !== true) { toast(errOf(r, 'Nothing was recorded. The server did not say why.')); return false; }
|
|
45
|
+
undoToast(msg, undo); await C.reload(); return true;
|
|
46
|
+
}
|
|
47
|
+
const prevOf = (r) => ({ life: r.acts.life, reason: r.acts.reason, backDay: r.acts.backDay || null, archived: !!r.acts.archived });
|
|
48
|
+
/** Write the state `p` the row had before a lifecycle press, through the lifecycle route. */
|
|
49
|
+
const lifeBack = (C, r, p) => (p.life === 'hold' ? life(C, r.id, 'on-hold', p.reason, p.backDay) : p.life === 'cancelled' ? life(C, r.id, 'cancelled', p.reason) : life(C, r.id, 'active', 'undo'));
|
|
50
|
+
|
|
51
|
+
/* ── what a row can do ── */
|
|
52
|
+
export function items(C, r) {
|
|
53
|
+
const a = r.acts, cur = a.stages.indexOf(a.stage), out = [];
|
|
54
|
+
if (a.archived) return [['restore', 'Restore', 'Back in the lists, as it was']];
|
|
55
|
+
if (a.life === 'cancelled') return [['reopen', 'Reopen', 'Back to ' + (a.stage || 'its stage') + ', active again']];
|
|
56
|
+
if (!C.self && !a.life && cur >= 0) {
|
|
57
|
+
if (a.stages[cur + 1]) out.push(['mv:' + (cur + 1), 'Move to ' + a.stages[cur + 1], 'The next stage of its workflow']);
|
|
58
|
+
if (cur > 0) out.push(['mv:' + (cur - 1), 'Back to ' + a.stages[cur - 1], 'The stage before']);
|
|
59
|
+
}
|
|
60
|
+
if (a.life === 'hold') out.push(['resume', 'Resume', 'Back to ' + (a.stage || 'its stage') + ', active again']);
|
|
61
|
+
else out.push(['hold', 'Put on hold', 'Pause it; keeps its stage and work']);
|
|
62
|
+
out.push(['cancel', 'Cancel', 'Stop it for good, with a reason'], ['archive', 'Archive', 'Out of every list; restore any time']);
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function run(C, r, k) {
|
|
67
|
+
const a = r.acts, p = prevOf(r);
|
|
68
|
+
if (k.startsWith('mv:')) {
|
|
69
|
+
const to = a.stages[+k.slice(3)], from = a.stage; if (!to) return;
|
|
70
|
+
const res = await move(C, r.id, to);
|
|
71
|
+
const w = res && res.ok && Array.isArray(res.warnings) && res.warnings.length ? ' Warning: ' + res.warnings.join('; ') + '. Warnings never block.' : '';
|
|
72
|
+
await done(C, res, 'Moved to ' + to + '. Recorded as a move line in the board ledger.' + w, async () => done(C, await move(C, r.id, from), 'Back in ' + from + '. Recorded as a move line.'));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (k === 'hold') return openHold(C, r);
|
|
76
|
+
if (k === 'cancel') return openCancel(C, r);
|
|
77
|
+
if (k === 'archive') return openArchive(C, r);
|
|
78
|
+
if (k === 'resume' || k === 'reopen') {
|
|
79
|
+
await done(C, await life(C, r.id, 'active', k === 'resume' ? 'resumed' : 'reopened'), r.title + ' is active again, in ' + (a.stage || 'its stage') + '. Recorded as a lifecycle line.', async () => done(C, await lifeBack(C, r, p), 'Undone. Recorded as a lifecycle line.'));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (k === 'restore') await done(C, await arch(C, r.id, false), r.title + ' is restored. Recorded in the board ledger.', async () => done(C, await arch(C, r.id, true, a.archived.reason), r.title + ' is archived again.'));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* ── the row's menu ── */
|
|
86
|
+
let menu = null;
|
|
87
|
+
export const dotsBtn = (r) => `<button type="button" class="inim" data-im="${esc(r.key)}" aria-haspopup="menu" aria-expanded="false" aria-label="Actions for ${esc(r.title)}">${ICO(DOTS)}</button>`;
|
|
88
|
+
/** The key of the row whose menu is open, so a page that redraws can open it again on the new button. */
|
|
89
|
+
export const menuKey = () => (menu ? menu.btn.dataset.im : null);
|
|
90
|
+
export function closeMenu(back) {
|
|
91
|
+
if (!menu) return; const { m, btn } = menu; m.remove(); btn.setAttribute('aria-expanded', 'false'); menu = null; if (back) btn.focus();
|
|
92
|
+
}
|
|
93
|
+
export function openMenu(btn, C, r) {
|
|
94
|
+
if (menu && menu.btn === btn) { closeMenu(true); return; }
|
|
95
|
+
closeMenu();
|
|
96
|
+
const m = document.createElement('div'); m.className = 'dsmn bam2'; m.setAttribute('role', 'menu'); m.setAttribute('aria-label', 'Actions for ' + r.title);
|
|
97
|
+
m.innerHTML = items(C, r).map(([k, l, s]) => `<button type="button" role="menuitem" data-pk="${esc(k)}"><span><b>${esc(l)}</b><small>${esc(s)}</small></span></button>`).join('');
|
|
98
|
+
btn.parentElement.appendChild(m); btn.setAttribute('aria-expanded', 'true'); menu = { m, btn, C, r };
|
|
99
|
+
// a card clips what leaves it: near the card's foot the menu opens upward
|
|
100
|
+
const card = btn.closest('.card'); if (card && m.getBoundingClientRect().bottom > card.getBoundingClientRect().bottom - 8) m.classList.add('up');
|
|
101
|
+
const f = $('button', m); if (f) f.focus();
|
|
102
|
+
}
|
|
103
|
+
document.addEventListener('keydown', (e) => {
|
|
104
|
+
if (!menu) return;
|
|
105
|
+
if (e.key === 'Escape') { e.stopPropagation(); e.preventDefault(); closeMenu(true); return; }
|
|
106
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); const L = $$('button', menu.m), k = L.indexOf(document.activeElement); L[(k + (e.key === 'ArrowDown' ? 1 : L.length - 1)) % L.length].focus(); }
|
|
107
|
+
if (e.key === 'Tab') closeMenu();
|
|
108
|
+
}, true);
|
|
109
|
+
document.addEventListener('click', (e) => {
|
|
110
|
+
if (!menu) return;
|
|
111
|
+
const it = e.target.closest('.bam2 [data-pk]');
|
|
112
|
+
if (it) { const { C, r } = menu; closeMenu(); run(C, r, it.dataset.pk); return; }
|
|
113
|
+
if (!e.target.closest('.bam2') && !e.target.closest('[data-im]')) closeMenu();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/* ── the initiative page's bar ── */
|
|
117
|
+
export function barHtml(C, r) {
|
|
118
|
+
const a = r.acts, cur = a.stages.indexOf(a.stage), nx = a.stages[cur + 1], pv = cur > 0 ? a.stages[cur - 1] : null;
|
|
119
|
+
if (a.archived) return `<div class="lifeb"><div><b>Archived</b><span>${esc(a.archived.into ? 'Merged into ' + a.archived.into : a.archived.reason || 'No reason was given')}. It is out of every list and count of the board. Nothing is deleted.</span></div><button type="button" class="dmcta alt" data-pk="restore">Restore</button></div>`;
|
|
120
|
+
if (a.life === 'cancelled') return `<div class="lifeb"><div><b>Cancelled</b><span>${a.reason ? esc(a.reason) + '. ' : ''}It keeps its stage, work and history.</span></div><button type="button" class="dmcta alt" data-pk="reopen">Reopen</button></div>`;
|
|
121
|
+
if (a.life === 'hold') return `<div class="lifeb"><div><b>On hold${a.back ? ' · check back ' + esc(a.back) : ''}</b><span>${a.reason ? esc(a.reason) + '. ' : ''}It keeps ${esc(a.stage || 'its stage')}, its work and its history.</span></div><span class="baact"><button type="button" class="dmcta alt" data-pk="resume">Resume</button><button type="button" class="dlink" data-pk="cancel">Cancel</button></span></div>`;
|
|
122
|
+
const mv = C.self || cur < 0 ? `<span class="note">${C.self ? 'The stage comes from the repository. It moves when the files land.' : 'Its stage is not one of its workflow\'s stages, so it cannot move from here.'}</span>`
|
|
123
|
+
: `${pv ? `<button type="button" class="dmcta alt" data-pk="mv:${cur - 1}">${ICO('<path d="M15 6l-6 6 6 6"/>')}Back to ${esc(pv)}</button>` : ''}${nx ? `<button type="button" class="dmcta alt" data-pk="mv:${cur + 1}">Move to ${esc(nx)}${ICO('<path d="M9 6l6 6-6 6"/>')}</button>` : ''}`;
|
|
124
|
+
return `<div class="baiact">${mv}<span class="iamw">${dotsBtn({ key: 'bar', title: r.title }).replace('class="inim"', 'class="dmcta alt inmore"').replace(ICO(DOTS), 'More' + ICO('<path d="m6 9 6 6 6-6"/>'))}</span></div>`;
|
|
125
|
+
}
|
|
126
|
+
/** The bar's presses: a stage move or a lifecycle press runs at once, More opens the menu without the moves. */
|
|
127
|
+
export function onBar(e, C, r) {
|
|
128
|
+
if (e.target.closest('.bam2')) return false; // a menu item: the document's listener runs it
|
|
129
|
+
const m = e.target.closest('[data-im="bar"]');
|
|
130
|
+
if (m) { openMenu(m, C, { ...r, acts: { ...r.acts, stages: [] } }); return true; }
|
|
131
|
+
const b = e.target.closest('.baiact [data-pk], .lifeb [data-pk]');
|
|
132
|
+
if (!b || b.disabled) return false;
|
|
133
|
+
b.disabled = true; run(C, r, b.dataset.pk).finally(() => { b.disabled = false; });
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/* ── the dialogs: one form in the standard dialog's pane, the conversation box hidden, as Add a document does ── */
|
|
138
|
+
const happens = (L) => `<div class="bahp"><p class="label">What happens</p><ul>${L.map((t) => `<li>${ICO(CHK)}<span>${esc(t)}</span></li>`).join('')}</ul></div>`;
|
|
139
|
+
const rec = (t) => `<p class="note barec">${ICO(SHD)}<span>${esc(t)}</span></p>`;
|
|
140
|
+
const pills = (id, L, cur, lab) => `<div class="chq bapl" id="${id}" role="radiogroup" aria-label="${esc(lab)}">${L.map(([v, l]) => `<button type="button" role="radio" data-v="${v}" aria-checked="${v === cur}" aria-pressed="${v === cur}">${esc(l)}</button>`).join('')}</div>`;
|
|
141
|
+
const pick = (e, id) => { const p = e.target.closest('#' + id + ' [data-v]'); if (!p) return null; $$('#' + id + ' [data-v]').forEach((q) => { q.setAttribute('aria-pressed', q === p); q.setAttribute('aria-checked', q === p); }); return p.dataset.v; };
|
|
142
|
+
const msgP = (id) => `<p class="note" id="${id}" role="status"></p>`;
|
|
143
|
+
function form(o) {
|
|
144
|
+
openDlg({ eye: o.eye, title: o.title, sub: o.sub, say: o.say, stream: turnA(ptx(o.say)), noteKey: null, pane: `<article class="paper doc"><div class="addf">${o.body}</div></article>`, label: o.label || 'Detail' });
|
|
145
|
+
$('#askF').hidden = true; $('#askNote').hidden = true;
|
|
146
|
+
}
|
|
147
|
+
async function press(go, m, fn) {
|
|
148
|
+
go.disabled = true; m.textContent = '';
|
|
149
|
+
const r = await fn();
|
|
150
|
+
if (r && r.ok === true) return r;
|
|
151
|
+
go.disabled = false; m.textContent = errOf(r, 'Nothing was recorded. The server did not say why.'); return null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function openHold(C, r) {
|
|
155
|
+
let back = 'month';
|
|
156
|
+
form({ eye: 'Put on hold', title: 'Put on hold', sub: r.title, say: 'Say why it is paused, and when to look at it again.', body: `
|
|
157
|
+
<label><span>Why is it paused <em>optional</em></span><textarea id="paHR" rows="2" maxlength="500" placeholder="For example: waiting for the Q1 budget decision"></textarea></label>
|
|
158
|
+
<div><span class="label">Check back</span>${pills('paHB', BACK.map((q) => [q[0], q[1]]), back, 'Check back')}</div>
|
|
159
|
+
${happens(['Keeps its stage' + (r.acts.stage ? ' (' + r.acts.stage + ')' : '') + ', its work and its history.', 'Shows as On hold and leaves the on-track and need-a-look counts.', 'The check-back day shows on its page.'])}
|
|
160
|
+
${rec('Recorded: one on-hold line in lifecycle.jsonl, with your reason and the check-back day. Undo writes the state it had before.')}
|
|
161
|
+
${msgP('paHM')}<div class="cact"><button type="button" class="cta" id="paHGo">Put on hold</button><button type="button" class="cta alt" id="paHNo">Not now</button></div>` });
|
|
162
|
+
$('#oMain').onclick = async (e) => {
|
|
163
|
+
const v = pick(e, 'paHB'); if (v) { back = v; return; }
|
|
164
|
+
if (e.target.closest('#paHNo')) { closeDlg(); return; }
|
|
165
|
+
if (!e.target.closest('#paHGo')) return;
|
|
166
|
+
const bk = BACK.find((q) => q[0] === back), day = bk[2] != null ? dayIso(bk[2]) : null, why = $('#paHR').value.trim(), p = prevOf(r);
|
|
167
|
+
const res = await press($('#paHGo'), $('#paHM'), () => life(C, r.id, 'on-hold', why, day)); if (!res) return;
|
|
168
|
+
closeDlg(); await done(C, res, r.title + ' is on hold. Recorded as a lifecycle line.', async () => done(C, await lifeBack(C, r, p), r.title + ' is back as it was.'));
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function openCancel(C, r) {
|
|
172
|
+
let why = '';
|
|
173
|
+
form({ eye: 'Cancel', title: 'Cancel the initiative', sub: r.title, say: 'Pick a reason. Cancel needs one before it can record.', body: `
|
|
174
|
+
<div><span class="label">Why</span>${pills('paCW', WHY, '', 'Why')}</div>
|
|
175
|
+
<label><span>Note <em>optional</em></span><textarea id="paCN" rows="2" maxlength="400" placeholder="What did we learn, and who was told"></textarea></label>
|
|
176
|
+
${happens(['Shows as Cancelled. The counts treat it as cancelled, not done.', 'It leaves the lists. Show them, under the list, brings it back into view.', 'Keeps its stage, its work and its history. Reopen it any time.'])}
|
|
177
|
+
${rec('Recorded: one cancelled line in lifecycle.jsonl, with the reason. Undo writes the state it had before.')}
|
|
178
|
+
<p class="note" id="paCM" role="status">Pick a reason to cancel.</p><div class="cact"><button type="button" class="cta" id="paCGo" disabled>Cancel initiative</button><button type="button" class="cta alt" id="paCNo">Not now</button></div>` });
|
|
179
|
+
$('#oMain').onclick = async (e) => {
|
|
180
|
+
const v = pick(e, 'paCW'); if (v) { why = v; $('#paCGo').disabled = false; $('#paCM').textContent = ''; return; }
|
|
181
|
+
if (e.target.closest('#paCNo')) { closeDlg(); return; }
|
|
182
|
+
if (!e.target.closest('#paCGo')) return;
|
|
183
|
+
if (!why) { $('#paCM').textContent = 'Pick a reason to cancel.'; return; }
|
|
184
|
+
const n = $('#paCN').value.trim(), reason = WHY.find((q) => q[0] === why)[1] + (n ? ': ' + n : ''), p = prevOf(r);
|
|
185
|
+
const res = await press($('#paCGo'), $('#paCM'), () => life(C, r.id, 'cancelled', reason)); if (!res) return;
|
|
186
|
+
closeDlg(); await done(C, res, r.title + ' is cancelled. Recorded as a lifecycle line.', async () => done(C, await lifeBack(C, r, p), r.title + ' is back as it was.'));
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function openArchive(C, r) {
|
|
190
|
+
let why = 'unrelated';
|
|
191
|
+
form({ eye: 'Archive', title: 'Archive the initiative', sub: r.title, say: 'Archive takes it out of the board. It is not a status, and nothing is deleted.', body: `
|
|
192
|
+
<div><span class="label">Why</span>${pills('paAW', AWHY, why, 'Why')}</div>
|
|
193
|
+
<label><span>Note <em>optional</em></span><textarea id="paAN" rows="2" maxlength="200" placeholder="Anything you want to remember about it"></textarea></label>
|
|
194
|
+
${happens(['It leaves every list, count and timeline of the board.', 'Nothing is deleted. The record, its work and its history stay in the repository.', 'Restore it any time, as it was.'])}
|
|
195
|
+
${rec('Recorded: one archive line in the board ledger (boards.jsonl), with the reason. Undo and Restore write a restore line.')}
|
|
196
|
+
${msgP('paAM')}<div class="cact"><button type="button" class="cta" id="paAGo">Archive</button><button type="button" class="cta alt" id="paANo">Not now</button></div>` });
|
|
197
|
+
$('#oMain').onclick = async (e) => {
|
|
198
|
+
const v = pick(e, 'paAW'); if (v) { why = v; return; }
|
|
199
|
+
if (e.target.closest('#paANo')) { closeDlg(); return; }
|
|
200
|
+
if (!e.target.closest('#paAGo')) return;
|
|
201
|
+
const n = $('#paAN').value.trim().replace(/\s+/g, ' '), reason = AWHY.find((q) => q[0] === why)[1] + (n ? ': ' + n : '');
|
|
202
|
+
const res = await press($('#paAGo'), $('#paAM'), () => arch(C, r.id, true, reason)); if (!res) return;
|
|
203
|
+
closeDlg(); await done(C, res, r.title + ' is archived. Recorded in the board ledger.', async () => done(C, await arch(C, r.id, false), r.title + ' is restored.'));
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* ── new asks and New initiative ── */
|
|
208
|
+
export function asksHtml(C, A) {
|
|
209
|
+
const ic = ICO('<path d="M4 4h16v12H8l-4 4z"/>');
|
|
210
|
+
if (C.self) return `<section class="card baask" id="cAsks" aria-labelledby="hAsks"><div class="ch"><span class="ic">${ic}</span><h2 id="hAsks">New asks</h2><small>none</small></div><p class="note">PMOS-self has no ask source. New work starts at the pmos-router skill.</p></section>`;
|
|
211
|
+
const L = A.rows;
|
|
212
|
+
const body = A.missing ? '<p class="note">The new asks could not be read, so none is shown.</p>' : L.length ? `<div class="bal" role="list">${L.map((a) => `<div class="baa" role="listitem"><p class="baq">“${esc(a.line)}”</p><small class="bam">${esc([a.source || 'Typed in the console', a.by, a.at].filter(Boolean).join(' · '))}</small><div class="bad2">${a.draft.lane ? `<span>${esc(LANES.find((l) => l[0] === a.draft.lane)[1])}</span>` : ''}<span>${a.draft.anchor ? 'Anchor: ' + esc(a.draft.anchor) : 'No anchor suggested'}</span></div><div class="baact"><button type="button" class="dmcta" data-ask="acc:${esc(a.id)}">Accept</button><button type="button" class="dmcta alt" data-ask="dec:${esc(a.id)}">Decline</button></div></div>`).join('')}</div>` : '<p class="note">Nothing new to triage on this board.</p>';
|
|
213
|
+
return `<section class="card baask" id="cAsks" aria-labelledby="hAsks"><div class="ch"><span class="ic">${ic}</span><h2 id="hAsks">New asks</h2><small>${A.missing ? 'not read' : L.length + ' to triage'}</small></div>${body}
|
|
214
|
+
<p class="note">Accept starts an initiative in ${esc(C.first || 'the first stage')}. Decline records why. The title, lane and anchor come from the intake draft, and you can change them.</p></section>`;
|
|
215
|
+
}
|
|
216
|
+
export function onAsks(e, C, A) {
|
|
217
|
+
const b = e.target.closest('[data-ask]'); if (!b) return false;
|
|
218
|
+
const [k, id] = [b.dataset.ask.slice(0, 3), b.dataset.ask.slice(4)], a = A.rows.find((x) => x.id === id); if (!a) return true;
|
|
219
|
+
if (k === 'acc') openIniForm(C, a); else openDecline(C, a);
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let anchors = null;
|
|
224
|
+
async function anchorsOf(C) {
|
|
225
|
+
if (anchors && anchors.key === C.ws + '/' + C.board) return anchors;
|
|
226
|
+
const r = await pmGet('/api/boards/anchors?ws=' + encodeURIComponent(C.ws || '') + '&board=' + encodeURIComponent(C.board || ''));
|
|
227
|
+
anchors = { key: C.ws + '/' + C.board, list: r && r.ok && Array.isArray(r.anchors) ? r.anchors : null };
|
|
228
|
+
return anchors;
|
|
229
|
+
}
|
|
230
|
+
/** The form of New initiative (a = null) and of Accept (a = the ask): title, lane and anchor, from the intake draft when there is one. */
|
|
231
|
+
export async function openIniForm(C, a) {
|
|
232
|
+
const d = a ? a.draft : { title: '', lane: 'feature', anchor: '' };
|
|
233
|
+
const lane0 = d.lane || 'feature';
|
|
234
|
+
form({ eye: a ? 'Accept an ask' : 'New initiative', title: a ? 'Accept ask' : 'New initiative', sub: C.boardName, label: 'Initiative',
|
|
235
|
+
say: a ? 'The intake draft gives the title, lane and anchor. Change any of them, then accept.' : 'Give it a title, a lane and an anchor. It lands in ' + (C.first || 'the first stage') + '.',
|
|
236
|
+
body: `${a ? `<p class="baq">“${esc(a.line)}”</p>` : ''}
|
|
237
|
+
<label>Title<input id="paNT" maxlength="120" value="${esc(d.title)}" placeholder="For example: Per-key API usage for partners"></label>
|
|
238
|
+
<div class="two"><label>Lane<select id="paNL">${LANES.map((l) => `<option value="${l[0]}"${l[0] === lane0 ? ' selected' : ''}>${l[1]}: ${l[2]}</option>`).join('')}</select></label>
|
|
239
|
+
<label id="paNAw">Anchor<select id="paNA" disabled><option>Reading the anchors</option></select></label></div>
|
|
240
|
+
<p class="note" id="paNAh">Every initiative anchors to a KR or a declared health budget. Unanchored work is rejected.</p>
|
|
241
|
+
${rec(a ? 'Recorded: an accept line for the ask in the board ledger, and a new initiative record with the title, lane and anchor.' : 'Recorded: the title as an ask in the board ledger, its accept line, and a new initiative record with the title, lane and anchor, as the console\'s New initiative does.')}
|
|
242
|
+
${msgP('paNM')}<div class="cact"><button type="button" class="cta" id="paNGo">${a ? 'Accept into ' : 'Create in '}${esc(C.first || 'the first stage')}</button><button type="button" class="cta alt" id="paNNo">Cancel</button></div>` });
|
|
243
|
+
const A = await anchorsOf(C);
|
|
244
|
+
if (!$('#paNA')) return;
|
|
245
|
+
if (A.list && A.list.length) {
|
|
246
|
+
const has = A.list.some((x) => x.value === d.anchor);
|
|
247
|
+
$('#paNA').outerHTML = `<select id="paNA"><option value="">Choose a KR or a health budget</option>${d.anchor && !has ? `<option value="${esc(d.anchor)}" selected>Suggested: ${esc(d.anchor)}</option>` : ''}${A.list.map((x) => `<option value="${esc(x.value)}"${x.value === d.anchor ? ' selected' : ''}>${esc(x.label || x.value)}</option>`).join('')}</select>`;
|
|
248
|
+
} else {
|
|
249
|
+
$('#paNA').outerHTML = `<input id="paNA" maxlength="120" value="${esc(d.anchor)}" placeholder="For example: health:tech">`;
|
|
250
|
+
$('#paNAh').textContent = 'The declared anchors could not be read, so type one: a KR id or health:<budget>. Unanchored work is rejected.';
|
|
251
|
+
}
|
|
252
|
+
$('#oMain').onclick = async (e) => {
|
|
253
|
+
if (e.target.closest('#paNNo')) { closeDlg(); return; }
|
|
254
|
+
if (!e.target.closest('#paNGo')) return;
|
|
255
|
+
const title = $('#paNT').value.trim(), lane = $('#paNL').value, anchor = $('#paNA').value.trim(), m = $('#paNM');
|
|
256
|
+
if (!title) { m.textContent = 'Give it a title.'; $('#paNT').focus(); return; }
|
|
257
|
+
if (!anchor) { m.textContent = 'Choose an anchor. Unanchored work is rejected.'; $('#paNA').focus(); return; }
|
|
258
|
+
const res = await press($('#paNGo'), m, async () => {
|
|
259
|
+
let ask = a ? a.id : null;
|
|
260
|
+
if (!ask) { const r0 = await post(C, '/api/boards/asks/add', { board: C.board, line: title, source: 'New initiative, typed by you' }); if (!r0 || r0.ok !== true) return r0; ask = r0.ask && r0.ask.id; }
|
|
261
|
+
return post(C, '/api/boards/asks/accept', { board: C.board, ask, title, lane, anchor });
|
|
262
|
+
});
|
|
263
|
+
if (!res) return;
|
|
264
|
+
closeDlg(); await done(C, res, '“' + title + '” is ' + (a ? 'accepted' : 'created') + ' in ' + (res.stage || C.first || 'the first stage') + ', anchored to ' + anchor + '.' + (res.initiative ? ' Its record is ' + res.initiative + '.' : ''));
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
function openDecline(C, a) {
|
|
268
|
+
form({ eye: 'Decline an ask', title: 'Decline ask', sub: [a.source, a.by].filter(Boolean).join(' · ') || C.boardName, say: 'Say why. The reason is kept with the ask.', body: `<p class="baq">“${esc(a.line)}”</p>
|
|
269
|
+
<label>Reason<textarea id="paDW" rows="3" maxlength="500" placeholder="Why not? The reason is kept with the ask."></textarea></label>
|
|
270
|
+
${rec('Recorded: a decline line for the ask in the board ledger, with the reason.')}
|
|
271
|
+
${msgP('paDM')}<div class="cact"><button type="button" class="cta" id="paDGo" disabled>Decline</button><button type="button" class="cta alt" id="paDNo">Cancel</button></div>` });
|
|
272
|
+
$('#oMain').oninput = (e) => { if (e.target.id === 'paDW') $('#paDGo').disabled = !e.target.value.trim(); };
|
|
273
|
+
$('#oMain').onclick = async (e) => {
|
|
274
|
+
if (e.target.closest('#paDNo')) { closeDlg(); return; }
|
|
275
|
+
if (!e.target.closest('#paDGo')) return;
|
|
276
|
+
const why = $('#paDW').value.trim().replace(/\s+/g, ' ');
|
|
277
|
+
if (!why) { $('#paDM').textContent = 'Say why. A decline needs a reason.'; return; }
|
|
278
|
+
const res = await press($('#paDGo'), $('#paDM'), () => post(C, '/api/boards/asks/decline', { board: C.board, ask: a.id, why })); if (!res) return;
|
|
279
|
+
closeDlg(); await done(C, res, 'Ask declined. The reason is kept in the board ledger.');
|
|
280
|
+
};
|
|
281
|
+
}
|