create-pmos 0.610.0 → 0.612.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 +135 -27
- package/payload/KIT-VERSION +2 -2
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/board-columns-test.js +2 -1
- package/workspace/board-deliveries-test.js +2 -1
- package/workspace/board-programs-test.js +7 -3
- package/workspace/board-publish-ui-test.js +2 -1
- package/workspace/board-shared-ui-test.js +2 -1
- package/workspace/board-workflows-test.js +2 -1
- package/workspace/briefing-premium-board-test.js +3 -2
- package/workspace/briefing-premium-calendar-2-test.js +3 -2
- package/workspace/briefing-premium-calendar-3-test.js +1 -1
- package/workspace/briefing-premium-calendar-test.js +1 -1
- package/workspace/briefing-premium-doc-edit-test.js +2 -1
- package/workspace/briefing-premium-insights-test.js +4 -3
- package/workspace/briefing-premium-test.js +3 -2
- package/workspace/calm-timeline-test.js +2 -1
- package/workspace/changelog.json +134 -0
- package/workspace/core-docs-workflow-test.js +2 -1
- package/workspace/ev-everywhere-test.js +3 -2
- package/workspace/guide/home.md +2 -2
- package/workspace/guide/index.md +4 -0
- package/workspace/guide/layout.md +97 -3
- package/workspace/guide/programs.md +16 -2
- package/workspace/guide/routine.md +65 -0
- package/workspace/guide/scheduled-tasks-and-cli.md +1 -1
- package/workspace/guide/settings-and-switches.md +2 -2
- package/workspace/impact-screens-test.js +3 -1
- package/workspace/ini-workflow-test.js +2 -1
- package/workspace/lib/board-premium.js +12 -4
- package/workspace/lib/classic-board.js +15 -0
- package/workspace/lib/cos-chat.js +1 -0
- package/workspace/lib/doc-library.js +43 -12
- package/workspace/lib/doc-path.js +30 -0
- package/workspace/lib/engine/boards.js +4 -2
- package/workspace/lib/events-place.js +368 -0
- package/workspace/lib/events-stated.js +129 -0
- package/workspace/lib/initiative-chat.js +1 -0
- package/workspace/lib/insights-premium.js +13 -1
- package/workspace/lib/library-find.js +162 -0
- package/workspace/lib/library-items.js +250 -0
- package/workspace/lib/notes.js +9 -1
- package/workspace/lib/plan-items.js +17 -3
- package/workspace/lib/route-modules.js +4 -0
- package/workspace/lib/routes-artefacts.js +5 -2
- package/workspace/lib/routes-boards.js +6 -2
- package/workspace/lib/routes-doc-sheet.js +1 -0
- package/workspace/lib/routes-events-place.js +203 -0
- package/workspace/lib/routes-library.js +155 -0
- package/workspace/lib/routes-pop-work.js +39 -0
- package/workspace/lib/routes-report-setups.js +32 -1
- package/workspace/lib/routes-today-log.js +48 -0
- package/workspace/lib/routine-reports.js +84 -0
- package/workspace/lib/status-when.js +36 -0
- package/workspace/lib/task-items.js +5 -3
- package/workspace/lib/today-log.js +131 -0
- package/workspace/live-pill-round-test.js +10 -7
- package/workspace/metric-drafts-ui-test.js +3 -1
- package/workspace/milestone-pins-test.js +2 -1
- package/workspace/milestone-suggest-test.js +3 -1
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/panels-test.js +2 -1
- package/workspace/premium-board-actions-test.js +3 -1
- package/workspace/premium-rec-tab-test.js +2 -1
- package/workspace/premium-vw-backlog-test.js +3 -1
- package/workspace/premium-vw-item-test.js +3 -1
- package/workspace/premium-vw-jira-test.js +3 -1
- package/workspace/premium-vw-meet-test.js +2 -1
- package/workspace/premium-vw-notes-test.js +3 -2
- package/workspace/product-lane-test.js +2 -1
- package/workspace/program-charter-test.js +3 -1
- package/workspace/program-leave-test.js +2 -1
- package/workspace/program-order-test.js +2 -1
- package/workspace/program-panel-test.js +3 -1
- package/workspace/public/pm/artefact-kind.js +87 -0
- package/workspace/public/pm/bd-ini-panel.js +77 -12
- package/workspace/public/pm/bd-prog-panel.js +55 -8
- package/workspace/public/pm/bd-span.js +5 -0
- package/workspace/public/pm/bd-work.css +192 -0
- package/workspace/public/pm/bd-work.js +483 -0
- package/workspace/public/pm/cozy-bar.css +11 -0
- package/workspace/public/pm/cozy-bar.js +99 -0
- package/workspace/public/pm/cozy-day-pick.css +27 -0
- package/workspace/public/pm/cozy-day-pick.js +97 -0
- package/workspace/public/pm/cozy-ev.css +2 -5
- package/workspace/public/pm/cozy-events-view.js +274 -0
- package/workspace/public/pm/cozy-events.css +179 -0
- package/workspace/public/pm/cozy-events.js +278 -0
- package/workspace/public/pm/cozy-evmodel.js +1 -1
- package/workspace/public/pm/cozy-goals.css +172 -0
- package/workspace/public/pm/cozy-library.css +125 -0
- package/workspace/public/pm/cozy-live-pill.js +1 -0
- package/workspace/public/pm/cozy-nav.js +6 -7
- package/workspace/public/pm/cozy-pick.css +3 -0
- package/workspace/public/pm/cozy-pop-work.css +224 -0
- package/workspace/public/pm/cozy-pop-work.js +668 -0
- package/workspace/public/pm/cozy-popup.css +11 -2
- package/workspace/public/pm/cozy-popup.js +67 -9
- package/workspace/public/pm/cozy-routine-job.js +203 -0
- package/workspace/public/pm/cozy-routine-model.js +219 -0
- package/workspace/public/pm/cozy-routine-pop.js +318 -0
- package/workspace/public/pm/cozy-routine.css +155 -0
- package/workspace/public/pm/cozy-routine.js +335 -0
- package/workspace/public/pm/cozy-schedwork.js +6 -5
- package/workspace/public/pm/cozy-settings.js +1 -5
- package/workspace/public/pm/cozy-status-when.js +48 -0
- package/workspace/public/pm/cozy-today-app.js +236 -0
- package/workspace/public/pm/cozy-today-model.js +176 -0
- package/workspace/public/pm/cozy-today-page.css +100 -0
- package/workspace/public/pm/cozy-today-view.js +76 -0
- package/workspace/public/pm/cozy-viewer.js +19 -8
- package/workspace/public/pm/cozy-vw-mtg.css +39 -0
- package/workspace/public/pm/goals-model.js +205 -0
- package/workspace/public/pm/goals-open.js +124 -0
- package/workspace/public/pm/home-app.js +18 -3
- package/workspace/public/pm/home-chat.js +4 -2
- package/workspace/public/pm/home-ini.js +43 -10
- package/workspace/public/pm/ini-edit.js +3 -1
- package/workspace/public/pm/ini-view-model.js +1 -1
- package/workspace/public/pm/library-model.js +197 -0
- package/workspace/public/pm/library-open.js +37 -0
- package/workspace/public/pm/page-chat.js +12 -2
- package/workspace/public/pm/pop-work-model.js +493 -0
- package/workspace/public/pm/premium-board.js +204 -17
- package/workspace/public/pm/premium-goals.js +213 -0
- package/workspace/public/pm/premium-library.js +436 -0
- package/workspace/public/pm/premium-shell.js +1 -1
- package/workspace/public/pm/premium-vw-mtg.js +79 -1
- package/workspace/public/pm/scope-chip.js +204 -0
- package/workspace/public/premium-board.html +1 -0
- package/workspace/public/premium-events.html +44 -0
- package/workspace/public/premium-goals.html +37 -0
- package/workspace/public/premium-library.html +39 -0
- package/workspace/public/premium-routine.html +33 -0
- package/workspace/public/today.html +50 -0
- package/workspace/ready-dash-ui-test.js +3 -1
- package/workspace/rename-test.js +2 -1
- package/workspace/run-tests.js +4 -1
- package/workspace/server.js +4 -2
- package/workspace/sort-order-test.js +2 -1
- package/workspace/split-merge-ui-test.js +3 -1
- package/workspace/stage-card-tasks-test.js +3 -1
- package/workspace/stage-card-test.js +2 -1
- package/workspace/task-delete-test.js +2 -1
- package/workspace/task-links-test.js +2 -1
- package/workspace/task-milestones-test.js +4 -2
- package/workspace/task-plans-test.js +3 -1
- package/workspace/task-press-test.js +3 -1
- package/workspace/task-views-test.js +3 -1
- package/workspace/test-lists/doc-path.json +9 -0
- package/workspace/test-lists/events-place.json +11 -0
- package/workspace/test-lists/goals-place.json +9 -0
- package/workspace/test-lists/library-place.json +9 -0
- package/workspace/test-lists/pop-work.json +9 -0
- package/workspace/test-lists/routine-place.json +9 -0
- package/workspace/test-lists/status-when.json +9 -0
- package/workspace/test-lists/today-log.json +9 -0
- package/workspace/test-lists/work-view.json +9 -0
- package/workspace/timeline-holds-test.js +3 -1
- package/workspace/tk-tasks-test.js +2 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/* pm/cozy-routine-model.js — Routine's table, as data (initiative routine-place, slice 8 of the six-place navigation; board 11 on Exploring 2;
|
|
2
|
+
* done test planning/done-tests/routine-place.md T2). PURE: no DOM and no fetch, so node tests it (routine-place.test.js).
|
|
3
|
+
*
|
|
4
|
+
* routineRows({ reports, refresh, tasks, spaces }, now) → [row] everything that repeats, as one kind of row
|
|
5
|
+
* reports GET /api/report-setups/routine rows of every workspace, each with { ws, wsName } (lib/routine-reports.js)
|
|
6
|
+
* refresh GET /api/refresh rows (lib/routes-refresh.js): what PMOS reads (run 'skill', a service of Your tools is a row of its own) and
|
|
7
|
+
* PMOS's own jobs (run 'job'); rows that only follow a change (run 'change') are not routines
|
|
8
|
+
* tasks GET /api/schedules?all=1 schedules that have not ended: your own scheduled tasks
|
|
9
|
+
* spaces the product ids and names, so a report named "<product> · Heads-up" reads "Heads-up"
|
|
10
|
+
* A report shows once: the same name in two products folds into one row (the one that runs first). "What it does" says who it tells, never the
|
|
11
|
+
* product. When is never empty: the setup's repeat, else the schedule that drafts it (report-<id>), else the repeat its id names.
|
|
12
|
+
* row: { key, kind: reports | reads | jobs | tasks, group: wait | reports | reads | jobs | tasks, name, does, when, next, on, wait, ws, id }
|
|
13
|
+
* on true or false: the switch that pauses it; null: no switch (a report with no setup, a service that follows Your tools)
|
|
14
|
+
* off true when it does not run now (its switch is off, or the switch of Your tools for a service)
|
|
15
|
+
* wait { act, label, say } on a row of Waits for you: its one ✓ (confirm the definition, or move it to the product it is about)
|
|
16
|
+
* routineGroups(rows, kind) → [{ id, title, rows }] the groups in order; a group with no row is left out (zero is silence)
|
|
17
|
+
* didLine(done, now) → { n, recent, shown, text } | null the one "PMOS did" line over GET /api/autonomy done of every product
|
|
18
|
+
* KINDS the filter: All, Reports, Reads, PMOS jobs, Your tasks
|
|
19
|
+
*
|
|
20
|
+
* Every word comes from a field of a record. A field the record leaves silent is '' and its cell is empty; nothing is filled with a guess. */
|
|
21
|
+
import { atOf, everyLine } from './cozy-evmodel.js';
|
|
22
|
+
|
|
23
|
+
export const KINDS = [['all', 'All'], ['reports', 'Reports'], ['reads', 'Reads'], ['jobs', 'PMOS jobs'], ['tasks', 'Your tasks']];
|
|
24
|
+
/** A work copy's product: "pmos-idpf ⑂ initiative/psle-paywall-lock" → "pmos-idpf". A branch name never shows (round 3 item 2). */
|
|
25
|
+
export const productName = (n) => String(n || '').split(' ⑂ ')[0].trim();
|
|
26
|
+
/** The Type word of each kind (round 2): the first column after the name. */
|
|
27
|
+
export const TYPES = { reports: 'Report', reads: 'Read', jobs: 'PMOS job', tasks: 'Your task' };
|
|
28
|
+
/** How many rows of each kind, for the counts on the kinds. */
|
|
29
|
+
export function kindCounts(rows) {
|
|
30
|
+
const n = { all: 0, reports: 0, reads: 0, jobs: 0, tasks: 0 };
|
|
31
|
+
for (const r of rows || []) { n.all++; if (r.kind in n) n[r.kind]++; }
|
|
32
|
+
return n;
|
|
33
|
+
}
|
|
34
|
+
/** The products a set of rows shows (a folded report counts each of its products). */
|
|
35
|
+
export const productsOf = (rows) => [...new Set((rows || []).flatMap((r) => r.wss || []))];
|
|
36
|
+
export const GROUPS = [['wait', 'Waits for you'], ['reports', 'Reports'], ['reads', 'PMOS reads'], ['jobs', 'PMOS jobs'], ['tasks', 'Your tasks']];
|
|
37
|
+
const DAY = 86400000;
|
|
38
|
+
const DAYN = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
|
|
39
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
40
|
+
const firstUp = (s) => s.replace(/^./, (c) => c.toUpperCase());
|
|
41
|
+
|
|
42
|
+
const MONS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
43
|
+
const D3 = { Mon: 'Mon', Tue: 'Tue', Wed: 'Wed', Thu: 'Thu', Fri: 'Fri', Sat: 'Sat', Sun: 'Sun' };
|
|
44
|
+
const EVERY = { daily: 'Every day', weekly: 'Every week', 'bi-weekly': 'Every two weeks', biweekly: 'Every two weeks', monthly: 'Every month' };
|
|
45
|
+
const midnight = (t) => { const d = new Date(t); d.setHours(0, 0, 0, 0); return d.getTime(); };
|
|
46
|
+
const nth = (n) => n + (n % 100 >= 11 && n % 100 <= 13 ? 'th' : ['th', 'st', 'nd', 'rd'][n % 10] || 'th');
|
|
47
|
+
/** A day in the fewest words (audit item 3): "Tonight" (from 18:00 to 06:00 the next morning), "Today", "Tomorrow", else "2 Dec".
|
|
48
|
+
* A time already past says Today: PMOS runs it on its next round. */
|
|
49
|
+
export function dayWord(t, now = Date.now()) {
|
|
50
|
+
const x = typeof t === 'number' ? t : Date.parse(t || '');
|
|
51
|
+
if (!Number.isFinite(x)) return '';
|
|
52
|
+
const d = new Date(x), dd = Math.round((midnight(x) - midnight(now)) / DAY), h = d.getHours();
|
|
53
|
+
if (dd <= 0) return h >= 18 && x > now ? 'Tonight' : 'Today';
|
|
54
|
+
if (dd === 1) return h < 6 ? 'Tonight' : 'Tomorrow';
|
|
55
|
+
return d.getDate() + ' ' + MONS[d.getMonth()];
|
|
56
|
+
}
|
|
57
|
+
/** "2 Dec, 09:00": a day and a time, for the setup box's Next. */
|
|
58
|
+
export function dayTime(t) {
|
|
59
|
+
const x = typeof t === 'number' ? t : Date.parse(t || '');
|
|
60
|
+
if (!Number.isFinite(x)) return '';
|
|
61
|
+
const d = new Date(x);
|
|
62
|
+
return d.getDate() + ' ' + MONS[d.getMonth()] + ', ' + String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0');
|
|
63
|
+
}
|
|
64
|
+
/** A schedule in short plain words (audit item 2): "Every day, 17:30", "Every Friday, 16:00", "Every two weeks, Wed 09:00",
|
|
65
|
+
* "Every month on the 2nd, 09:00", "Every hour at :15". '' when there is no schedule. */
|
|
66
|
+
export function whenWords(s) {
|
|
67
|
+
if (!s || typeof s !== 'object' || !s.cadence) return '';
|
|
68
|
+
const t = String(s.time || '09:00'), d = s.day || 'Mon';
|
|
69
|
+
if (s.cadence === 'hourly') return 'Every hour at :' + t.slice(-2);
|
|
70
|
+
if (s.cadence === 'daily') return 'Every day, ' + t;
|
|
71
|
+
if (s.cadence === 'weekly') return 'Every ' + (DAYN[d] || d) + ', ' + t;
|
|
72
|
+
if (s.cadence === 'bi-weekly') return 'Every two weeks, ' + (D3[d] || d) + ' ' + t;
|
|
73
|
+
if (s.cadence === 'monthly') return 'Every month on the ' + nth(+s.dayOfMonth || 1) + ', ' + t;
|
|
74
|
+
if (s.cadence === 'once') return 'Once, ' + (s.date || '') + ', ' + t;
|
|
75
|
+
return firstUp(String(s.cadence));
|
|
76
|
+
}
|
|
77
|
+
/** When a report drafts next, as a time: its setup's next draft, moved on by its repeat while that is already past. null when it does not say. */
|
|
78
|
+
export function nextAt(r, now = Date.now()) {
|
|
79
|
+
let t = Date.parse((r && r.next) || '');
|
|
80
|
+
if (!Number.isFinite(t)) return null;
|
|
81
|
+
const c = r.schedule && r.schedule.cadence;
|
|
82
|
+
for (let i = 0; t <= now && i < 1000; i++) {
|
|
83
|
+
const d = new Date(t);
|
|
84
|
+
if (c === 'daily') d.setDate(d.getDate() + 1); else if (c === 'weekly') d.setDate(d.getDate() + 7);
|
|
85
|
+
else if (c === 'bi-weekly') d.setDate(d.getDate() + 14); else if (c === 'monthly') d.setMonth(d.getMonth() + 1); else break;
|
|
86
|
+
t = d.getTime();
|
|
87
|
+
}
|
|
88
|
+
return t;
|
|
89
|
+
}
|
|
90
|
+
/** A report's Next: Paused when its switch is off, else the day it drafts next. */
|
|
91
|
+
function reportNext(r, now) {
|
|
92
|
+
if (r.status === 'paused') return 'Paused';
|
|
93
|
+
const t = nextAt(r, now);
|
|
94
|
+
return t ? dayWord(t, now) : '';
|
|
95
|
+
}
|
|
96
|
+
/** "the steering committee of Project Ascent": an audience read inside a sentence. */
|
|
97
|
+
const inLine = (a) => String(a || '').trim().replace(/^(The|A|An|Your|You)\b/, (w) => w.toLowerCase());
|
|
98
|
+
/** What a report does: who it tells (audit item 1). Never the product. A report that names no reader goes to you. */
|
|
99
|
+
function reportDoes(r) {
|
|
100
|
+
return 'Tells ' + (inLine(shortWho(r.audience)) || 'you');
|
|
101
|
+
}
|
|
102
|
+
/** Who a report tells, short enough for one cell: "The attendees of the MySPH & Identity Platform biweekly product update" → "The attendees of the
|
|
103
|
+
* biweekly update"? No: the words after "of" name a meeting PMOS cannot shorten honestly, so they stay only when the whole fits (48 letters). */
|
|
104
|
+
function shortWho(a) {
|
|
105
|
+
const s = String(a || '').trim().replace(/\s*\([^)]*\)\s*$/, '');
|
|
106
|
+
if (s.length <= 48) return s;
|
|
107
|
+
return s.split(/\s+(?:of|for|in|at|from|on|and)\s+/i)[0].trim();
|
|
108
|
+
}
|
|
109
|
+
/** One short sentence of what a read or a job does (round 3 item 5): the words before the first comma, when the whole is long. */
|
|
110
|
+
const shortDoes = (t) => { const s = str(t).replace(/\.\s.*$/, '').replace(/\.$/, ''); return s.length > 56 && s.indexOf(', ') > 12 ? s.slice(0, s.indexOf(', ')) : s; };
|
|
111
|
+
/** A read or a job's schedule in the same words as a report's: "Daily at 06:45" → "Every day, 06:45", "Every Friday at 15:30" → "Every Friday, 15:30". */
|
|
112
|
+
const plainEvery = (t) => str(t).replace(/^Daily at (\d{1,2}:\d{2})$/, 'Every day, $1').replace(/^Every (\w+day) at (\d{1,2}:\d{2})$/, 'Every $1, $2');
|
|
113
|
+
/** A report's name as a person says it (audit item 4): no "definition (proposed)", no "<product> · " in front. */
|
|
114
|
+
export function reportName(name, spaces) {
|
|
115
|
+
let s = String(name || '').trim().replace(/\s*\(proposed\)$/i, '').replace(/\s+(definition|template)$/i, '').trim();
|
|
116
|
+
const m = /^(.+?) · (.+)$/.exec(s);
|
|
117
|
+
if (m && spaces && spaces.has(productName(m[1]).toLowerCase())) s = m[2].trim();
|
|
118
|
+
return firstUp(s);
|
|
119
|
+
}
|
|
120
|
+
/** Your task's repeat in words: "Every hour at :15", "Every Friday, 16:00". */
|
|
121
|
+
export function taskWhen(s) {
|
|
122
|
+
if (!s) return '';
|
|
123
|
+
return whenWords({ ...s, cadence: s.cadence || 'weekly' });
|
|
124
|
+
}
|
|
125
|
+
/** A read or a job's Next: Paused, Stuck, Missed, Running now, or when it runs next. */
|
|
126
|
+
function refreshNext(r, now) {
|
|
127
|
+
if (!r.on) return 'Paused';
|
|
128
|
+
if (r.stall) return 'Stuck since ' + atOf(r.stall.since, now);
|
|
129
|
+
if (r.missed_at) return 'Missed ' + atOf(r.missed_at, now);
|
|
130
|
+
if (r.state === 'running') return 'Running now';
|
|
131
|
+
// a read runs every few minutes: its Next says nothing a person needs, so it is left empty (board 11)
|
|
132
|
+
return r.next_at && !r.often ? dayWord(r.next_at, now) : '';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function routineRows({ reports = [], refresh = [], tasks = [], spaces = [], jobs = null } = {}, now = Date.now()) {
|
|
136
|
+
const out = [];
|
|
137
|
+
// the products by id and name, so "pmos · Heads-up" reads "Heads-up"
|
|
138
|
+
const sp = new Set(spaces.concat(reports.flatMap((r) => [r && r.ws, r && r.wsName])).filter(Boolean).map((x) => productName(x).toLowerCase()));
|
|
139
|
+
// one report shown once (audit item 4): the same report in two products folds into one row, the one that runs first
|
|
140
|
+
const rank = (r) => (r.status === 'active' ? 4 : r.status === 'paused' ? 3 : r.act && r.act.act === 'confirm' ? 2 : 1);
|
|
141
|
+
const byName = new Map();
|
|
142
|
+
for (const r of reports) {
|
|
143
|
+
if (!r || !r.id) continue;
|
|
144
|
+
// a report with no setup whose one act is a move is a definition left in the wrong product: not a row a person can read (audit item 4)
|
|
145
|
+
if (!r.status && r.act && r.act.act === 'move') continue;
|
|
146
|
+
const name = reportName(r.name || r.id, sp) || r.id, k = name.toLowerCase(), had = byName.get(k);
|
|
147
|
+
const wss = [...new Set(((had && had.wss) || []).concat(productName(r.wsName || r.ws) || []))];
|
|
148
|
+
byName.set(k, !had || rank(r) > rank(had.r) ? { r, name, wss } : { ...had, wss });
|
|
149
|
+
}
|
|
150
|
+
for (const { r, name, wss } of byName.values()) {
|
|
151
|
+
// round 3 item 1: every row of the table repeats and has the same switch. A report PMOS proposes is off, marked Proposed, and its switch
|
|
152
|
+
// is the yes. A report with no setup and nothing proposed is a one-time report: it leaves the table for the fold line under Reports.
|
|
153
|
+
const a = !r.status && r.act && r.act.act === 'confirm' ? r.act : null;
|
|
154
|
+
const once = !r.status && !a;
|
|
155
|
+
const drafts = tasks.find((t) => t && t.skill === 'report-' + r.id && !t.endedReason);
|
|
156
|
+
const draft = !!(r.latest && r.latest.state === 'draft');
|
|
157
|
+
out.push({
|
|
158
|
+
key: 'r:' + (r.ws || '') + ':' + r.id, kind: 'reports', type: TYPES.reports, wss, group: a ? 'wait' : once ? 'once' : 'reports', ws: r.ws || '', id: r.id, name,
|
|
159
|
+
does: reportDoes(r), when: once ? '' : whenWords(r.schedule) || str(r.when) || taskWhen(drafts) || EVERY[r.id] || '', late: !!a,
|
|
160
|
+
next: a ? 'Proposed' : once ? (draft ? 'A draft waits' : '') : reportNext(r, now),
|
|
161
|
+
on: once ? null : a ? false : r.status === 'active', off: !once && (!!a || r.status === 'paused'), proposed: !!a, draft,
|
|
162
|
+
// a name a PM cannot read (an id, a path, a branch) is held back and counted in one grey line (round 3 item 2)
|
|
163
|
+
unclear: /[/⑂]/.test(name) || /^[a-z0-9]+(?:[-_.][a-z0-9]+)*$/.test(name),
|
|
164
|
+
wait: a ? { act: a.act, label: 'Start it', say: 'PMOS proposes it. Turn it on to start it' } : null,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
for (const r of refresh) {
|
|
168
|
+
if (!r || !r.id || (r.run !== 'skill' && r.run !== 'job')) continue;
|
|
169
|
+
const kind = r.run === 'skill' ? 'reads' : 'jobs';
|
|
170
|
+
if (r.run === 'skill' && Array.isArray(r.svcs) && r.svcs.length) {
|
|
171
|
+
// each service of Your tools is a row with its OWN true switch (round 3, PR 2): a service is off when its own rhythm is "only when you
|
|
172
|
+
// press read" (kind manual), so nothing new is stored; it is on when Your tools is on and its rhythm is not manual.
|
|
173
|
+
for (const v of r.svcs) {
|
|
174
|
+
if (!v || !v.id) continue;
|
|
175
|
+
const mine = !(v.own && v.schedule && v.schedule.kind === 'manual'), on = !!r.on && mine;
|
|
176
|
+
const sv = { on, stall: r.stall && v.reading && (!r.stall.svcs || r.stall.svcs.includes(v.id)) ? r.stall : null, missed_at: v.missed_at, state: v.reading ? 'running' : '', next_at: v.next_at, often: true };
|
|
177
|
+
const when = plainEvery(everyLine(v.own && mine ? v.schedule_text : r.schedule_text));
|
|
178
|
+
out.push({ key: 'j:' + r.id + '.' + v.id, kind, type: TYPES[kind], wss: [], group: kind, ws: '', id: r.id + '.' + v.id, parent: r.id, svc: v.id, name: v.label || v.id,
|
|
179
|
+
does: 'Puts what is new in ' + (v.label || v.id) + ' into Today', when, next: refreshNext({ ...sv, often: /^Every (\d+ min|hour)/.test(when) }, now), on, off: !on, late: !!(on && (sv.stall || sv.missed_at)), wait: null });
|
|
180
|
+
}
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
// a job whose schedule lives in its own setting (Horizon scan, Report finder) takes it from there; "Set in …" never shows (round 2 note 3)
|
|
184
|
+
const own = jobs && jobs[r.id];
|
|
185
|
+
// a job that is on never has an empty When: before its setting is read, it says the rhythm the code uses by default
|
|
186
|
+
const when = plainEvery(everyLine(r.schedule_text)) || (own && own.when) || (r.on && JOB_DEFAULT[r.id]) || '';
|
|
187
|
+
out.push({ key: 'j:' + r.id, kind, type: TYPES[kind], wss: [], group: kind, ws: '', id: r.id, name: r.label || r.id, does: shortDoes(r.what),
|
|
188
|
+
when, next: refreshNext({ ...r, next_at: r.next_at || (own && own.next) || null, often: /^Every (\d+ min|hour)/.test(when) }, now), on: !!r.on, off: !r.on, late: !!(r.on && (r.stall || r.missed_at)), wait: null });
|
|
189
|
+
}
|
|
190
|
+
for (const s of tasks) {
|
|
191
|
+
if (!s || !s.id || s.endedReason) continue;
|
|
192
|
+
const on = s.enabled !== false;
|
|
193
|
+
out.push({ key: 't:' + s.id, kind: 'tasks', type: TYPES.tasks, wss: s.wsName || s.ws ? [s.wsName || s.ws] : [], group: 'tasks', ws: s.ws || '', id: s.id, name: s.name || s.skill || s.id, does: s.skill || s.task ? 'Runs ' + (s.skill || s.task) : '',
|
|
194
|
+
when: taskWhen(s), next: !on ? 'Paused' : s.next ? dayWord(s.next, now) : '', on, off: !on, late: false, wait: null });
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The rhythm Horizon scan (lib/scan.js DEFAULT_CADENCE daily) and Report finder (lib/report-setups.js finder weekly) run on by default. */
|
|
200
|
+
const JOB_DEFAULT = { scan: 'Every working day', finder: 'Every week' };
|
|
201
|
+
|
|
202
|
+
/** The groups in order, for one kind or all. A group with no row is not drawn. */
|
|
203
|
+
export function routineGroups(rows, kind = 'all') {
|
|
204
|
+
const mine = (rows || []).filter((r) => kind === 'all' || r.kind === kind);
|
|
205
|
+
return GROUPS.map(([id, title]) => ({ id, title, rows: mine.filter((r) => r.group === id) })).filter((g) => g.rows.length);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** "PMOS did 76 things since yesterday. It showed you 2 of them." → null when nothing was done in the 14 days the log keeps. */
|
|
209
|
+
export function didLine(done, now = Date.now()) {
|
|
210
|
+
const all = (done || []).filter((d) => d && d.ref);
|
|
211
|
+
if (!all.length) return null;
|
|
212
|
+
const recent = all.filter((d) => { const t = Date.parse(d.at || ''); return Number.isFinite(t) && now - t <= DAY; });
|
|
213
|
+
const shown = recent.filter((d) => d.way === 'show').length;
|
|
214
|
+
const n = recent.length;
|
|
215
|
+
const thing = (k) => (k === 1 ? 'one thing' : k + ' things');
|
|
216
|
+
const text = n ? 'PMOS did ' + thing(n) + ' since yesterday.' : 'PMOS did ' + thing(all.length) + ' in the last 14 days.';
|
|
217
|
+
const sub = n && shown ? (shown === n ? 'It showed you each of them.' : 'It showed you ' + shown + ' of them. The others were small and it did them quietly.') : n ? 'Each was small, so it did them quietly.' : 'Nothing since yesterday.';
|
|
218
|
+
return { n: all.length, recent: n, shown, text, sub };
|
|
219
|
+
}
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/* pm/cozy-routine-pop.js — a routine in the one popup (initiative routine-place, slice 8 of the six-place navigation; board 10 on Exploring 2;
|
|
2
|
+
* done test planning/done-tests/routine-place.md T3, T4).
|
|
3
|
+
*
|
|
4
|
+
* Press a row of Routine: the popup of slice 2 (cozy-popup.js) opens, the routine on the left and Ask PMOS on the right, already about it.
|
|
5
|
+
* A REPORT the newest issue to read; above it one ✦ line "Issue this draft to <who it tells>?" with ✓ and ✕ while that issue is a draft
|
|
6
|
+
* and the report's one act is Issue (lib/report-acts.js); the issue chooser, Draft or Issued, and the pencil that opens the full
|
|
7
|
+
* report reader (premium-report-read.js: Edit, Present, Share, Download stay there). Beside it ONE grey box, the setup: On,
|
|
8
|
+
* Repeats, Next, Tells, After the run, Built from, then the issues (press one to read it). Press a value to change it, or tell
|
|
9
|
+
* PMOS in the chat ("send it on Thursdays"). A field the record leaves silent is not drawn.
|
|
10
|
+
* A report that waits for your word (its definition, or a move to the product it is about) shows that one ✦ line instead.
|
|
11
|
+
* The chat is the report's own conversation (report-flow.js chatOf), so a change PMOS writes goes to the report's own session.
|
|
12
|
+
* Above the issue, the INSTRUCTION (round 3 item 3): the body of the report's definition, what each issue covers, in plain words. The
|
|
13
|
+
* pencil makes it a text box; ✓ saves it (POST /api/doc/save with the text as read, so a file changed since is refused), with Undo.
|
|
14
|
+
* A report with no definition shows its purpose read-only. ▶ in the header drafts the next issue now (POST /api/report-setups/draft).
|
|
15
|
+
* ⋯ holds Delete for a report that is set up (POST /api/report-setups/remove: its schedule stops; its issues stay) and Drop for one
|
|
16
|
+
* PMOS proposes (POST /api/report-setups/drop). Both are sent when their 10 s of Undo have passed (the page's later()).
|
|
17
|
+
* ANY OTHER pm/cozy-routine-job.js.
|
|
18
|
+
*
|
|
19
|
+
* WRITES, each the PM's press on a route that exists: ✓ issue → GET /api/report/draft (the sha as read) then POST /api/report/issue, which
|
|
20
|
+
* freezes the issue; nothing is sent outward, the PM sends it from their own mail, as today. On → /api/report-setups/pause | resume.
|
|
21
|
+
* Repeats → /api/report-setups/edit { schedule }. Tells → /api/report-setups/edit { audience } on Enter or leaving the field. ✓ of a waiting
|
|
22
|
+
* report → /api/report-setups/confirm | move. ✕ hides the ✦ line for that issue on this computer.
|
|
23
|
+
* reportHtml(R, now) — pure, for the tests: R = { row, text, path, hide, msg, busy, editTells } */
|
|
24
|
+
import { mdHtml } from './chat-md.js';
|
|
25
|
+
import { CADENCES, chatOf } from './report-flow.js';
|
|
26
|
+
import { nextAt, dayTime } from './cozy-routine-model.js';
|
|
27
|
+
|
|
28
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
29
|
+
const svg = (d, n = 16) => `<svg viewBox="0 0 24 24" width="${n}" height="${n}" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
|
|
30
|
+
const I = { play: 'M8 5l11 7-11 7z', trash: 'M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3', undo: 'M9 14L4 9l5-5M4 9h10a6 6 0 0 1 0 12h-3',
|
|
31
|
+
check: 'M5 12.5l4.5 4.5L19 7.5', x: 'M6 6l12 12M18 6L6 18', pen: 'M5 19l1-4L16.5 4.5l3 3L9 18z', spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z' };
|
|
32
|
+
const MONS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
33
|
+
const DAYS = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
|
|
34
|
+
/** "18 Nov", from a YYYY-MM-DD slot. */
|
|
35
|
+
export const dayMon = (s) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(s || '')); return m ? +m[3] + ' ' + MONS[+m[2] - 1] : String(s || ''); };
|
|
36
|
+
/** "Issue 2 · 18 Nov": issues are counted from the first. */
|
|
37
|
+
export function issueName(issues, path) {
|
|
38
|
+
const L = (issues || []).slice().sort((a, b) => (a.slot < b.slot ? -1 : 1)), i = L.findIndex((x) => x.path === path);
|
|
39
|
+
return i < 0 ? '' : 'Issue ' + (i + 1) + ' · ' + dayMon(L[i].slot);
|
|
40
|
+
}
|
|
41
|
+
/** Where a report is built from, in words: "Your work", "Goals", "A dashboard" (lib/report-setups.js sources), with the product. */
|
|
42
|
+
export function builtFrom(row) {
|
|
43
|
+
const s = String((row && row.source) || '');
|
|
44
|
+
const w = s === 'work' ? 'Your work' : /^intelligence:/.test(s) ? 'Goals' : /^dashboard:/.test(s) ? 'A dashboard' : /^ready:/.test(s) ? 'A ready-made report' : s ? s.replace(/^./, (c) => c.toUpperCase()) : '';
|
|
45
|
+
return [row && row.wsName, w].filter(Boolean).join(' · ');
|
|
46
|
+
}
|
|
47
|
+
/** The Repeats choices: the four cadences in short words that fit the box (audit item 8), the current one selected (a cadence PMOS does not
|
|
48
|
+
* offer stays as it is). */
|
|
49
|
+
const SHORT = { daily: 'Daily', weekly: 'Weekly', 'bi-weekly': '2 weeks', monthly: 'Monthly' };
|
|
50
|
+
export function repeatChoices(sch) {
|
|
51
|
+
const cur = sch && sch.cadence;
|
|
52
|
+
const L = CADENCES.map(([v, l]) => [v, SHORT[v] || l, v === cur]);
|
|
53
|
+
if (cur && !L.some((x) => x[2])) L.push([cur, cur, true]);
|
|
54
|
+
return L;
|
|
55
|
+
}
|
|
56
|
+
const nth = (n) => n + (n % 100 >= 11 && n % 100 <= 13 ? 'th' : ['th', 'st', 'nd', 'rd'][n % 10] || 'th');
|
|
57
|
+
const at = (sch) => (sch && sch.cadence === 'monthly' ? nth(+sch.dayOfMonth || 1) + ' ' : sch && sch.day && sch.cadence !== 'daily' ? (DAYS[sch.day] || sch.day).slice(0, 3) + ' ' : '') + ((sch && sch.time) || '');
|
|
58
|
+
/** Who a report tells, in the fewest words for the setup box (audit item 8): "The 6 attendees of the biweekly update" → "6 attendees". */
|
|
59
|
+
export function shortAudience(a) {
|
|
60
|
+
const s = String(a || '').trim().replace(/^(the|a|an)\s+/i, '').split(/\s+(?:of|for|in|at|from|on)\s+/i)[0].trim();
|
|
61
|
+
return s ? s.replace(/^./, (c) => c.toUpperCase()) : '';
|
|
62
|
+
}
|
|
63
|
+
/** The report as a person reads it (audit item 7): no frontmatter, no title line (the header names it), no PMOS note markers, readable times
|
|
64
|
+
* in place of ISO ones, no id after a name, and no heading left with nothing under it. Pure. */
|
|
65
|
+
export function cleanReport(t) {
|
|
66
|
+
let s = fm(t).replace(/<!--[\s\S]*?-->[ \t]*\r?\n?/g, '').replace(/^\s*#\s+[^\n]*\n+/, '');
|
|
67
|
+
s = s.replace(/(?<![\w/.-])\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?/g, (m) => dayTime(Date.parse(m)) || m);
|
|
68
|
+
s = s.replace(/(?<![\w/.-])(\d{4})-(\d{2})-(\d{2})(?![\w/-]|\.\w)/g, (m, y, mo, d) => (+mo >= 1 && +mo <= 12 ? +d + ' ' + MONS[+mo - 1] : m));
|
|
69
|
+
s = s.replace(/ \(([a-z0-9]+(?:-[a-z0-9]+)+)\)/g, '');
|
|
70
|
+
const L = s.split(/\r?\n/), keep = [];
|
|
71
|
+
const lv = (l) => { const m = /^(#{1,6})\s/.exec(l); return m ? m[1].length : 0; };
|
|
72
|
+
for (let i = 0; i < L.length; i++) {
|
|
73
|
+
const h = lv(L[i]);
|
|
74
|
+
if (h) { let j = i + 1; while (j < L.length && !L[j].trim()) j++; if (j >= L.length || (lv(L[j]) && lv(L[j]) <= h)) continue; }
|
|
75
|
+
keep.push(L[i]);
|
|
76
|
+
}
|
|
77
|
+
return keep.join('\n').replace(/\n{3,}/g, '\n\n').trim();
|
|
78
|
+
}
|
|
79
|
+
const sw = (on, label) => `<button type="button" class="rt-sw" role="switch" aria-checked="${!!on}" data-rp="on" aria-label="${esc(label)}" title="${esc(label)}"></button>`;
|
|
80
|
+
const kv = (k, v, cls = '') => `<div class="rp-r${cls}"><span>${esc(k)}</span>${v}</div>`;
|
|
81
|
+
const fm = (t) => String(t || '').replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
|
|
82
|
+
|
|
83
|
+
/** A definition's body, the Instruction: the text after its frontmatter. */
|
|
84
|
+
export const insOf = (t) => String(t || '').replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '').replace(/^\s+|\s+$/g, '');
|
|
85
|
+
/** The definition with a new body, its frontmatter kept as it is. */
|
|
86
|
+
export const withIns = (t, body) => { const m = /^---\r?\n[\s\S]*?\r?\n---\r?\n?/.exec(String(t || '')); return (m ? m[0].replace(/\r?\n?$/, '\n') + '\n' : '') + String(body || '').trim() + '\n'; };
|
|
87
|
+
/** The Instruction in a few plain lines: no heading marks, no list marks. */
|
|
88
|
+
const insPlain = (t) => { const b = insOf(t), pu = /(?:^|\n)## Purpose[^\n]*\n([\s\S]*?)(?=\n## |$)/.exec(b); return lines(pu ? pu[1] : b); };
|
|
89
|
+
const lines = (t) => String(t).split(/\r?\n/).map((l) => l.replace(/^#+\s*/, '').replace(/^\s*[-*]\s+/, '').trim()).filter(Boolean).join(' · ');
|
|
90
|
+
|
|
91
|
+
const FRAME_WORDS = { headline: 'Headline', timeline: 'Timeline', initiatives: 'Initiatives', new: 'New since last report', decided: 'Decided this cycle', needs: 'Needs your call', sources: 'Sources' };
|
|
92
|
+
/** What a proposed report would be, read from its definition only (nothing guessed): the sections it would hold, its schedule sentence, who it
|
|
93
|
+
* tells, what it learned from earlier copies, and the day its definition was written. A part the file does not say is left out. Pure. */
|
|
94
|
+
export function proposalOf(t) {
|
|
95
|
+
const txt = String(t || ''), fm = (/^---\r?\n([\s\S]*?)\r?\n---/.exec(txt) || [])[1] || '';
|
|
96
|
+
const key = (k) => { const m = new RegExp('^' + k + ':\\s*(.*)$', 'm').exec(fm); return m ? m[1].trim().replace(/^["']|["']$/g, '') : ''; };
|
|
97
|
+
const body = insOf(txt);
|
|
98
|
+
const sec = (h) => { const m = new RegExp('(?:^|\\n)## ' + h + '[^\\n]*\\n([\\s\\S]*?)(?=\\n## |$)').exec(body); return m ? m[1].trim() : ''; };
|
|
99
|
+
let holds = sec('Sections').split(/\r?\n/).map((l) => /^\s*(?:\d+\.|[-*])\s+(.+)$/.exec(l)).filter(Boolean).map((m) => {
|
|
100
|
+
const x = m[1].replace(/`[^`]*`/g, '').replace(/\s+/g, ' ').trim(), i = x.indexOf('. ');
|
|
101
|
+
return i > 0 ? { h: x.slice(0, i), d: (x.slice(i + 2).split(/(?<=[.!?])\s/)[0] || '').trim() } : { h: x.replace(/\.$/, ''), d: '' };
|
|
102
|
+
});
|
|
103
|
+
if (!holds.length) { const ids = /^sections:\s*\[(.*)\]/m.exec(fm); if (ids) holds = ids[1].split(',').map((x) => x.trim()).filter((x) => FRAME_WORDS[x]).map((x) => ({ h: FRAME_WORDS[x], d: '' })); }
|
|
104
|
+
const learned = sec('Learned from earlier copies');
|
|
105
|
+
return { holds, schedule: (sec('Schedule').split(/\r?\n/)[0] || '').trim(), audience: key('audience'), learned: learned && !/^None yet/i.test(learned) ? learned.split(/\r?\n/)[0].trim() : '', written: key('timestamp') };
|
|
106
|
+
}
|
|
107
|
+
/** The one line on why PMOS proposes it, from a record: what earlier copies taught it, the drafts it already wrote, or its definition's day. */
|
|
108
|
+
export function whyOf(r, p) {
|
|
109
|
+
if (p && p.learned) return 'PMOS learned it from earlier copies: ' + p.learned.replace(/\.?$/, '.');
|
|
110
|
+
const n = (r.issues || []).length;
|
|
111
|
+
if (n) return 'PMOS has drafted it ' + (n === 1 ? 'once' : n + ' times') + ' without a schedule' + (r.latest && r.latest.slot ? ', last on ' + dayMon(r.latest.slot) : '') + '.';
|
|
112
|
+
if (p && p.written) return 'PMOS wrote its definition on ' + dayMon(p.written) + (r.source === 'work' ? ', from your work.' : '.');
|
|
113
|
+
return '';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The Instruction section. Pure. */
|
|
117
|
+
export function insHtml(R) {
|
|
118
|
+
const r = R.row || {};
|
|
119
|
+
if (R.insEdit) {
|
|
120
|
+
return `<section class="rj-sec rp-ins" aria-label="Instruction"><h6>Instruction</h6><label class="vh" for="rpIns">Instruction</label>`
|
|
121
|
+
+ `<textarea id="rpIns" class="rj-ins" data-rp="ins" rows="8" placeholder="What each issue covers, the tone, the length, what to leave out">${esc(R.insText != null ? R.insText : insOf(R.def))}</textarea>`
|
|
122
|
+
+ `<div class="rj-act"><button type="button" class="rp-y" data-rp="ins-save" aria-label="Save the instruction" title="Save the instruction"${R.busy ? ' disabled' : ''}>${svg(I.check, 14)}</button>`
|
|
123
|
+
+ `<button type="button" class="rp-n" data-rp="ins-x" aria-label="Keep it as it was" title="Keep it as it was">${svg(I.x, 14)}</button><span class="rj-hint">PMOS follows it from the next issue.</span></div></section>`;
|
|
124
|
+
}
|
|
125
|
+
const words = R.def ? insPlain(R.def) : '';
|
|
126
|
+
if (words) {
|
|
127
|
+
return `<section class="rj-sec rp-ins" aria-label="Instruction"><h6>Instruction<button type="button" class="rp-ed" data-rp="ins-ed" aria-label="Change the instruction" title="Change the instruction">${svg(I.pen, 15)}</button></h6>`
|
|
128
|
+
+ `<p class="rj-txt rp-insx">${esc(words)}</p></section>`;
|
|
129
|
+
}
|
|
130
|
+
if (r.purpose) return `<section class="rj-sec rp-ins" aria-label="Instruction"><h6>Instruction</h6><p class="rj-txt rp-insx">${esc(r.purpose)}</p><p class="rj-hint">To change it, tell PMOS on the right.</p></section>`;
|
|
131
|
+
return '';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The report in the popup, as html. Pure. */
|
|
135
|
+
export function reportHtml(R, now = Date.now()) {
|
|
136
|
+
const r = R.row || {}, issues = r.issues || [], cur = issues.find((x) => x.path === R.path) || r.latest || null;
|
|
137
|
+
const a = r.act || null, who = r.audience || '';
|
|
138
|
+
const nope = R.hide && cur && R.hide.has(cur.path);
|
|
139
|
+
// the one ✦ line: a waiting definition or move, else a draft to issue
|
|
140
|
+
let sg = '';
|
|
141
|
+
// a report PMOS proposes has no ✓ line: its switch in the setup is the yes (round 3 item 1)
|
|
142
|
+
const proposed = !!(a && a.act === 'confirm' && !r.status);
|
|
143
|
+
if (a && ((a.act === 'confirm' && !proposed) || a.act === 'move')) {
|
|
144
|
+
const t = a.act === 'confirm' ? 'Its definition waits for your word. Start it as it is?' : 'It is about ' + (a.toName || 'another product') + '. Move it there?';
|
|
145
|
+
sg = `<div class="rp-sg" role="group" aria-label="PMOS suggests"><h5>${svg(I.spark, 13)}PMOS suggests</h5><div><span>${esc(t)}</span>`
|
|
146
|
+
+ `<button type="button" class="rp-y" data-rp="${a.act}" aria-label="${esc(a.act === 'confirm' ? 'Yes, start it' : a.label)}" title="${esc(a.act === 'confirm' ? 'Yes, start it' : a.label)}"${R.busy ? ' disabled' : ''}>${svg(I.check, 14)}</button></div></div>`;
|
|
147
|
+
} else if (a && a.act === 'issue' && cur && cur.state === 'draft' && cur.path === (r.latest && r.latest.path) && !nope) {
|
|
148
|
+
sg = `<div class="rp-sg" role="group" aria-label="PMOS suggests"><h5>${svg(I.spark, 13)}PMOS suggests</h5><div><span>${esc('Issue this draft' + (who ? ' to ' + who.replace(/^(The|A|An|Your|You)\b/, (w) => w.toLowerCase()) : '') + '?')}</span>`
|
|
149
|
+
+ `<button type="button" class="rp-y" data-rp="issue" aria-label="Yes, issue it" title="Yes, issue it"${R.busy ? ' disabled' : ''}>${svg(I.check, 14)}</button>`
|
|
150
|
+
+ `<button type="button" class="rp-n" data-rp="nope" aria-label="Not now" title="Not now">${svg(I.x, 14)}</button></div></div>`;
|
|
151
|
+
}
|
|
152
|
+
// a proposal shows what he says yes to, before he turns it on (design check item 1): what it will hold, and why PMOS proposes it
|
|
153
|
+
const pr = proposed ? proposalOf(R.def) : null;
|
|
154
|
+
if (pr) {
|
|
155
|
+
const why = whyOf(r, pr);
|
|
156
|
+
sg = (pr.holds.length ? `<section class="rj-sec rp-hold" aria-label="What it will hold"><h6>What it will hold</h6><ol>${pr.holds.map((x) => `<li><b>${esc(x.h)}</b>${x.d ? '. ' + esc(x.d) : ''}</li>`).join('')}</ol></section>` : '')
|
|
157
|
+
+ (why ? `<section class="rj-sec" aria-label="Why PMOS proposes it"><h6>Why PMOS proposes it</h6><p class="rj-txt">${esc(why)}</p></section>` : '');
|
|
158
|
+
}
|
|
159
|
+
const pick = issues.length > 1 ? `<label class="vh" for="rpIss">Issue</label><select id="rpIss" class="rp-ch" data-rp="pick">${issues.map((x) => `<option value="${esc(x.path)}"${cur && x.path === cur.path ? ' selected' : ''}>${esc(issueName(issues, x.path))}</option>`).join('')}</select>`
|
|
160
|
+
: cur ? `<span class="rp-ch">${esc(issueName(issues, cur.path))}</span>` : '';
|
|
161
|
+
const meta = cur ? `<div class="rp-m">${pick}<span>${cur.state === 'issued' ? 'Issued' : 'Draft'}</span><button type="button" class="rp-ed" data-rp="edit" aria-label="Change the text" title="Change the text">${svg(I.pen, 17)}</button></div>` : '';
|
|
162
|
+
const body = !cur ? (proposed ? '' : '<p class="rp-q">No issue is written yet. PMOS drafts the first one on its day.</p>')
|
|
163
|
+
: R.text == null ? '<p class="rp-q">Reading the issue.</p>' : R.err ? `<p class="rp-q">${esc(R.err)}</p>` : `<div class="rp-txt">${mdHtml(cleanReport(R.text))}</div>`;
|
|
164
|
+
// the setup: only what the records say
|
|
165
|
+
const s = r.schedule;
|
|
166
|
+
const rows = [];
|
|
167
|
+
if (proposed) {
|
|
168
|
+
rows.push(kv('On', `<button type="button" class="rt-sw" role="switch" aria-checked="false" data-rp="confirm" aria-label="Proposed by PMOS. Turn it on to start it" title="Proposed. Turn on to start it"${R.busy ? ' disabled' : ''}></button>`));
|
|
169
|
+
// its schedule with the time of day, as its definition says it; else the table's words
|
|
170
|
+
const at = pr && pr.schedule ? pr.schedule.replace(/\.$/, '') : r.when;
|
|
171
|
+
if (at) rows.push(kv('Repeats', `<em title="${esc(at)}">${esc(at)}</em>`));
|
|
172
|
+
const tw = who || (pr && pr.audience) || '';
|
|
173
|
+
if (tw) rows.push(kv('Tells', `<em title="${esc(tw)}">${esc(shortAudience(tw))}</em>`));
|
|
174
|
+
}
|
|
175
|
+
if (r.status) rows.push(kv('On', sw(r.status === 'active', r.status === 'active' ? 'On. Press to pause it' : 'Paused. Press to start it again')));
|
|
176
|
+
if (r.status && s) rows.push(kv('Repeats', `<label class="vh" for="rpRep">Repeats</label><select id="rpRep" class="rp-sel" data-rp="rep"${R.busy ? ' disabled' : ''}>${repeatChoices(s).map(([v, l, on]) => `<option value="${esc(v)}"${on ? ' selected' : ''}>${esc(l + (on && at(s) ? ', ' + at(s) : ''))}</option>`).join('')}</select>`));
|
|
177
|
+
else if (r.when && !proposed) rows.push(kv('Repeats', `<em>${esc(r.when)}</em>`));
|
|
178
|
+
const nx = r.status === 'active' ? nextAt(r, now) : null;
|
|
179
|
+
if (nx) rows.push(kv('Next', `<em>${esc(dayTime(nx))}</em>`));
|
|
180
|
+
if (r.status) rows.push(kv('Tells', R.editTells ? `<label class="vh" for="rpTells">Tells</label><input id="rpTells" class="rp-in" data-rp="tells" value="${esc(who)}" maxlength="120">`
|
|
181
|
+
: `<button type="button" class="rp-sel" data-rp="tells-ed" aria-label="${esc('Tells: ' + (who || 'nobody named') + '. Press to change it')}" title="${esc(who)}">${esc(shortAudience(who) || 'Name who reads it')}</button>`));
|
|
182
|
+
else if (who && !proposed) rows.push(kv('Tells', `<em title="${esc(who)}">${esc(shortAudience(who))}</em>`));
|
|
183
|
+
if (r.status) rows.push(kv('After the run', '<em>You issue it</em>'));
|
|
184
|
+
if (builtFrom(r)) rows.push(kv('Built from', `<em>${esc(builtFrom(r))}</em>`));
|
|
185
|
+
const iss = issues.map((x) => `<button type="button" class="rp-r rp-i${cur && x.path === cur.path ? ' cur' : ''}" data-rp="open" data-path="${esc(x.path)}"><span>${esc(issueName(issues, x.path))}</span><em${x.state === 'draft' ? ' class="w"' : ''}>${x.state === 'issued' ? 'Issued' : 'Draft'}</em></button>`).join('');
|
|
186
|
+
const box = `<aside class="rp-box" aria-label="Setup"><h6>Setup</h6>${rows.join('')}${iss ? `<h6>Issues</h6>${iss}` : ''}`
|
|
187
|
+
+ (proposed ? '<p>PMOS proposes this report. Turn it on to start it. To drop it, use the menu at the top.</p>' : '')
|
|
188
|
+
+ (r.status ? '<p>To change the setup, press a value. Or tell PMOS on the right, for example “send it on Thursdays”.</p>' : '') + '</aside>';
|
|
189
|
+
const msg = `<p class="rp-msg" role="status">${esc(R.msg || '')}${R.insUndo != null ? ' <button type="button" class="rj-undo" data-rp="ins-undo">Undo</button>' : ''}</p>`;
|
|
190
|
+
return `<div class="rp-w"><div class="rp-main">${sg}${insHtml(R)}${meta}${body}${msg}</div>${box}</div>`;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/* ── the popup: open, draw, presses ── */
|
|
194
|
+
const NOPE = 'pmos.routine.nope.';
|
|
195
|
+
const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch { /* a private window */ } } };
|
|
196
|
+
let P = null; // the report shown: { R, body, h }
|
|
197
|
+
const q = (o) => Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
|
|
198
|
+
|
|
199
|
+
/** Open a report row of Routine in the popup. h: { VW, http: { pmGet, pmPost }, reload(), toast(text) } */
|
|
200
|
+
export async function openReport(row, h) {
|
|
201
|
+
const hide = new Set(); for (const x of row.issues || []) if (store.get(NOPE + x.path)) hide.add(x.path);
|
|
202
|
+
const R = { row, path: row.latest ? row.latest.path : '', text: null, err: '', hide, msg: '', busy: false, editTells: false, def: null, insEdit: false, insText: null, insUndo: null };
|
|
203
|
+
const me = P = { R, body: null, h };
|
|
204
|
+
const PC = await import('./page-chat.js');
|
|
205
|
+
const base = PC.targetOf({ id: 'report-' + row.id, kind: 'report', title: row.name }, row.ws);
|
|
206
|
+
// the report's own conversation (chatOf), with the one chip and empty line every popup has: "In: <name>" (design check item 2)
|
|
207
|
+
const t = { ...base, ...chatOf({ name: row.name, audience: row.audience, output: row.output, latest: row.latest }, row.id), ws: row.ws || undefined, scope: base.scope, role: base.role, empty: base.empty, placeholder: base.placeholder };
|
|
208
|
+
delete t.intro;
|
|
209
|
+
// the header (audit item 6): ← and "Routine ›" go back to the page, and a small Report chip (cozy-viewer.js draws both)
|
|
210
|
+
// ▶ drafts the next issue now; ⋯ deletes a report that is set up, or drops one PMOS proposes (each with Undo, round 3 item 3)
|
|
211
|
+
const more = row.status && h.later ? [{ label: 'Delete this report', icon: I.trash, on: () => { h.later({ key: row.key || 'r:' + row.id }, '/api/report-setups/remove', { ws: row.ws || undefined, id: row.id }, row.name + ' is deleted. Its issues stay in Library.'); h.VW.closePop(); } }]
|
|
212
|
+
: row.proposed && h.later ? [{ label: 'Drop this proposal', icon: I.x, on: () => { h.later({ key: row.key || 'r:' + row.id }, '/api/report-setups/drop', { ws: row.ws || undefined, id: row.id }, row.name + ' is dropped. PMOS stops proposing it.'); h.VW.closePop(); } }] : null;
|
|
213
|
+
h.VW.open({ id: 'routine:' + row.ws + ':' + row.id, kind: 'Report', title: row.name, icon: 'report', from: 'Routine', kindChip: 'Report',
|
|
214
|
+
presses: row.status ? [{ act: 'run', label: 'Draft the next issue now', icon: I.play, solid: true }] : [],
|
|
215
|
+
more,
|
|
216
|
+
onPress: (act) => { if (act === 'run') runNow(me); },
|
|
217
|
+
pop: { id: 'report-' + row.id, kind: 'report', title: row.name, ws: row.ws || undefined, target: t },
|
|
218
|
+
render: (b) => { me.body = b; draw(me); wire(me); },
|
|
219
|
+
onClose: () => { if (P === me) P = null; } });
|
|
220
|
+
read(me); readDef(me);
|
|
221
|
+
return me;
|
|
222
|
+
}
|
|
223
|
+
function draw(me) { if (me.body && me.body.isConnected) me.body.innerHTML = reportHtml(me.R); }
|
|
224
|
+
async function read(me) {
|
|
225
|
+
const R = me.R; if (!R.path) { R.text = ''; draw(me); return; }
|
|
226
|
+
try {
|
|
227
|
+
const r = await fetch('/api/doc?' + q({ ws: R.row.ws, path: R.path }), { credentials: 'same-origin' });
|
|
228
|
+
R.text = r.ok ? await r.text() : ''; R.err = r.ok ? '' : 'The issue could not be read.';
|
|
229
|
+
} catch { R.text = ''; R.err = 'The issue could not be read.'; }
|
|
230
|
+
if (P === me) draw(me);
|
|
231
|
+
}
|
|
232
|
+
/** The definition as the file holds it: the Instruction, and the base a save is checked against. */
|
|
233
|
+
async function readDef(me) {
|
|
234
|
+
const R = me.R; if (!R.row.definition) return;
|
|
235
|
+
try { const r = await fetch('/api/doc?' + q({ ws: R.row.ws, path: R.row.definition }), { credentials: 'same-origin' }); R.def = r.ok ? await r.text() : null; } catch { R.def = null; }
|
|
236
|
+
if (P === me) draw(me);
|
|
237
|
+
}
|
|
238
|
+
/** ▶ Draft the next issue now, and show it. */
|
|
239
|
+
async function runNow(me) {
|
|
240
|
+
const R = me.R; if (R.busy) return;
|
|
241
|
+
R.busy = true; draw(me);
|
|
242
|
+
const r = await me.h.http.pmPost('/api/report-setups/draft', { ws: R.row.ws || undefined, id: R.row.id }).catch(() => null);
|
|
243
|
+
R.busy = false;
|
|
244
|
+
if (r && r.ok && r.drafted && r.drafted.path) { R.path = r.drafted.path; R.text = null; R.msg = 'Drafted. The new issue is on the left.'; }
|
|
245
|
+
else R.msg = said(r, '');
|
|
246
|
+
await refresh(me); if (P === me) { draw(me); read(me); }
|
|
247
|
+
}
|
|
248
|
+
const said = (r, ok) => (r && r.ok !== false && !(r && r.error) ? ok : 'Nothing changed: ' + ((r && r.error) || 'the server did not answer') + '.');
|
|
249
|
+
async function refresh(me) {
|
|
250
|
+
const j = await me.h.http.pmGet('/api/report-setups/routine?' + q({ ws: me.R.row.ws })).catch(() => null);
|
|
251
|
+
const row = j && j.ok && (j.reports || []).find((x) => x.id === me.R.row.id);
|
|
252
|
+
if (row) me.R.row = { ...row, ws: me.R.row.ws, wsName: me.R.row.wsName };
|
|
253
|
+
if (me.h.reload) me.h.reload();
|
|
254
|
+
}
|
|
255
|
+
function wire(me) {
|
|
256
|
+
const b = me.body; if (!b || b.__rp) return; b.__rp = true;
|
|
257
|
+
const post = me.h.http.pmPost, R = me.R;
|
|
258
|
+
const act = async (fn) => { if (R.busy) return; R.busy = true; R.insUndo = null; draw(me); try { R.msg = await fn(); } finally { R.busy = false; } await refresh(me); if (P === me) draw(me); };
|
|
259
|
+
b.addEventListener('click', async (e) => {
|
|
260
|
+
const t = e.target.closest('[data-rp]'); if (!t || t.tagName === 'SELECT' || t.tagName === 'INPUT') return;
|
|
261
|
+
const k = t.dataset.rp, row = R.row, ws = row.ws || undefined;
|
|
262
|
+
if (k === 'open') { R.path = t.dataset.path; R.text = null; R.msg = ''; draw(me); read(me); return; }
|
|
263
|
+
if (k === 'nope') { store.set(NOPE + R.path, '1'); R.hide.add(R.path); R.msg = 'PMOS will not ask about this draft again.'; draw(me); return; }
|
|
264
|
+
if (k === 'edit') { const M = await import('./premium-report-read.js'); me.h.VW.drill(); M.openReportView(R.path, { ws: row.ws, name: row.name }); return; }
|
|
265
|
+
if (k === 'ins-ed') { R.insEdit = true; R.insText = null; R.msg = ''; draw(me); const i = b.querySelector('#rpIns'); if (i) i.focus(); return; }
|
|
266
|
+
if (k === 'ins-x') { R.insEdit = false; R.insText = null; draw(me); return; }
|
|
267
|
+
if (k === 'ins-save' || k === 'ins-undo') {
|
|
268
|
+
const base = R.def, prev = insOf(base);
|
|
269
|
+
const next = k === 'ins-undo' ? R.insUndo : String(R.insText != null ? R.insText : prev).trim();
|
|
270
|
+
if (next == null) return;
|
|
271
|
+
if (k === 'ins-save' && next === prev) { R.insEdit = false; draw(me); return; }
|
|
272
|
+
return act(async () => {
|
|
273
|
+
const x = await post('/api/doc/save', { ws, path: row.definition, base, text: withIns(base, next) });
|
|
274
|
+
if (!(x && x.ok)) return x && x.error === 'stale' ? 'Not saved: the instruction changed since you opened it. Close and open it again.' : said(x, '');
|
|
275
|
+
R.insEdit = false; R.insText = null;
|
|
276
|
+
R.insUndo = k === 'ins-save' ? prev : null;
|
|
277
|
+
await readDef(me);
|
|
278
|
+
return k === 'ins-save' ? 'Saved. PMOS follows it from the next issue.' : 'Undone. The instruction is as it was.';
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
if (k === 'tells-ed') { R.editTells = true; draw(me); const i = b.querySelector('#rpTells'); if (i) { i.focus(); i.select(); } return; }
|
|
282
|
+
if (k === 'on') return act(async () => { const on = row.status !== 'active'; return said(await post('/api/report-setups/' + (on ? 'resume' : 'pause'), { ws, id: row.id }), on ? 'On. PMOS drafts it on its day again.' : 'Paused. PMOS does not draft it until you turn it on.'); });
|
|
283
|
+
if (k === 'confirm') return act(async () => said(await post('/api/report-setups/confirm', { ws, id: row.id }), 'Started. Its drafts follow the definition as it is.'));
|
|
284
|
+
if (k === 'move') return act(async () => said(await post('/api/report-setups/move', { ws, id: row.id, to: row.act.to }), 'Moved to ' + row.act.toName + '. It drafts there from now on.'));
|
|
285
|
+
if (k === 'issue') {
|
|
286
|
+
return act(async () => {
|
|
287
|
+
const c = /\/([^/]+)\/(\d{4}-\d{2}-\d{2})\.md$/.exec(R.path) || [];
|
|
288
|
+
const cur = await me.h.http.pmGet('/api/report/draft?' + q({ ws: row.ws, cadence: c[1], slot: c[2] })).catch(() => null);
|
|
289
|
+
if (!cur || !cur.sha) return 'Not issued: the draft could not be read. Open it with the pencil and issue it there.';
|
|
290
|
+
const r = await post('/api/report/issue', { ws, cadence: c[1], slot: c[2], sha: cur.sha });
|
|
291
|
+
if (r && r.ok) { if (me.h.toast) me.h.toast('Issued. Send it from your own mail.'); return 'Issued. It stays as it is now. Send it from your own mail.'; }
|
|
292
|
+
return said(r, '');
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
b.addEventListener('input', (e) => { const t = e.target; if (t.dataset && t.dataset.rp === 'ins') R.insText = t.value; });
|
|
297
|
+
b.addEventListener('change', (e) => {
|
|
298
|
+
const t = e.target; if (!t.dataset) return;
|
|
299
|
+
if (t.dataset.rp === 'pick') { R.path = t.value; R.text = null; R.msg = ''; draw(me); read(me); return; }
|
|
300
|
+
if (t.dataset.rp === 'rep') {
|
|
301
|
+
const row = R.row, s = row.schedule || {}, v = t.value;
|
|
302
|
+
const sch = { cadence: v, time: s.time || '09:00', ...(v === 'weekly' || v === 'bi-weekly' ? { day: s.day || 'Mon' } : {}), ...(v === 'monthly' ? { dayOfMonth: s.dayOfMonth || 1 } : {}), ...(s.anchor && v === 'bi-weekly' ? { anchor: s.anchor } : {}) };
|
|
303
|
+
act(async () => said(await post('/api/report-setups/edit', { ws: row.ws || undefined, id: row.id, schedule: sch }), 'Saved. ' + (CADENCES.find((x) => x[0] === v) || [0, v])[1] + '.'));
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
const tells = (i) => {
|
|
307
|
+
if (!R.editTells) return;
|
|
308
|
+
R.editTells = false;
|
|
309
|
+
const v = String(i.value || '').trim(), row = R.row;
|
|
310
|
+
if (!v || v === (row.audience || '')) { draw(me); return; }
|
|
311
|
+
act(async () => said(await post('/api/report-setups/edit', { ws: row.ws || undefined, id: row.id, audience: v }), 'Saved. It tells ' + v + '.'));
|
|
312
|
+
};
|
|
313
|
+
b.addEventListener('keydown', (e) => {
|
|
314
|
+
const t = e.target; if (!t.dataset || t.dataset.rp !== 'tells') return;
|
|
315
|
+
if (e.key === 'Enter') { e.preventDefault(); tells(t); } else if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); R.editTells = false; draw(me); }
|
|
316
|
+
});
|
|
317
|
+
b.addEventListener('focusout', (e) => { const t = e.target; if (t.dataset && t.dataset.rp === 'tells') tells(t); });
|
|
318
|
+
}
|