create-pmos 0.611.0 → 0.613.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 +105 -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/briefing-premium-board-test.js +1 -1
- 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-insights-test.js +1 -1
- package/workspace/briefing-premium-test.js +1 -1
- package/workspace/changelog.json +104 -0
- package/workspace/guide/layout.md +52 -18
- package/workspace/guide/programs.md +3 -3
- package/workspace/guide/routine.md +28 -13
- package/workspace/guide/settings-and-switches.md +1 -1
- package/workspace/lib/board-premium.js +12 -4
- 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 +190 -38
- 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 +196 -24
- package/workspace/lib/notes.js +3 -0
- package/workspace/lib/plan-items.js +17 -3
- 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 +47 -10
- package/workspace/lib/routes-library.js +74 -8
- package/workspace/lib/routes-report-setups.js +13 -2
- package/workspace/lib/routine-reports.js +36 -4
- package/workspace/lib/status-when.js +36 -0
- package/workspace/lib/task-items.js +5 -3
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-vw-meet-test.js +2 -1
- package/workspace/premium-vw-notes-test.js +3 -2
- package/workspace/public/pm/artefact-kind.js +87 -0
- package/workspace/public/pm/bd-ini-panel.js +6 -6
- package/workspace/public/pm/bd-span.js +7 -1
- package/workspace/public/pm/bd-work.css +62 -0
- package/workspace/public/pm/bd-work.js +195 -68
- 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 +0 -4
- package/workspace/public/pm/cozy-events-view.js +165 -33
- package/workspace/public/pm/cozy-events.css +75 -3
- package/workspace/public/pm/cozy-events.js +86 -18
- package/workspace/public/pm/cozy-goals.css +172 -0
- package/workspace/public/pm/cozy-library.css +106 -17
- package/workspace/public/pm/cozy-nav.js +2 -3
- package/workspace/public/pm/cozy-pick.css +3 -0
- package/workspace/public/pm/cozy-pop-work.css +83 -24
- package/workspace/public/pm/cozy-pop-work.js +313 -72
- 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 +139 -31
- package/workspace/public/pm/cozy-routine-pop.js +164 -42
- package/workspace/public/pm/cozy-routine.css +61 -8
- package/workspace/public/pm/cozy-routine.js +207 -28
- package/workspace/public/pm/cozy-settings.js +1 -5
- package/workspace/public/pm/cozy-status-when.js +48 -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-chat.js +4 -2
- package/workspace/public/pm/home-ini.js +8 -6
- 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 +170 -42
- package/workspace/public/pm/library-open.js +8 -5
- package/workspace/public/pm/page-chat.js +12 -2
- package/workspace/public/pm/pop-work-model.js +199 -41
- package/workspace/public/pm/premium-board.js +108 -43
- package/workspace/public/pm/premium-goals.js +213 -0
- package/workspace/public/pm/premium-library.js +376 -62
- 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 +207 -0
- package/workspace/public/premium-events.html +3 -1
- package/workspace/public/premium-goals.html +37 -0
- package/workspace/public/premium-library.html +15 -7
- package/workspace/public/premium-routine.html +2 -0
- package/workspace/server.js +2 -1
- package/workspace/test-lists/doc-path.json +9 -0
- package/workspace/test-lists/goals-place.json +9 -0
- package/workspace/test-lists/status-when.json +9 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
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
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
3
|
*
|
|
4
|
-
* routineRows({ reports, refresh, tasks,
|
|
4
|
+
* routineRows({ reports, refresh, tasks, spaces }, now) → [row] everything that repeats, as one kind of row
|
|
5
5
|
* reports GET /api/report-setups/routine rows of every workspace, each with { ws, wsName } (lib/routine-reports.js)
|
|
6
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
7
|
* PMOS's own jobs (run 'job'); rows that only follow a change (run 'change') are not routines
|
|
8
8
|
* tasks GET /api/schedules?all=1 schedules that have not ended: your own scheduled tasks
|
|
9
|
-
*
|
|
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.
|
|
10
12
|
* row: { key, kind: reports | reads | jobs | tasks, group: wait | reports | reads | jobs | tasks, name, does, when, next, on, wait, ws, id }
|
|
11
13
|
* on true or false: the switch that pauses it; null: no switch (a report with no setup, a service that follows Your tools)
|
|
12
14
|
* off true when it does not run now (its switch is off, or the switch of Your tools for a service)
|
|
@@ -16,33 +18,109 @@
|
|
|
16
18
|
* KINDS the filter: All, Reports, Reads, PMOS jobs, Your tasks
|
|
17
19
|
*
|
|
18
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. */
|
|
19
|
-
import {
|
|
21
|
+
import { atOf, everyLine } from './cozy-evmodel.js';
|
|
20
22
|
|
|
21
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 || []))];
|
|
22
36
|
export const GROUPS = [['wait', 'Waits for you'], ['reports', 'Reports'], ['reads', 'PMOS reads'], ['jobs', 'PMOS jobs'], ['tasks', 'Your tasks']];
|
|
23
37
|
const DAY = 86400000;
|
|
24
38
|
const DAYN = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
|
|
25
39
|
const str = (v) => (typeof v === 'string' ? v : '');
|
|
26
40
|
const firstUp = (s) => s.replace(/^./, (c) => c.toUpperCase());
|
|
27
41
|
|
|
28
|
-
|
|
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. */
|
|
29
91
|
function reportNext(r, now) {
|
|
30
92
|
if (r.status === 'paused') return 'Paused';
|
|
31
|
-
|
|
32
|
-
return
|
|
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();
|
|
33
108
|
}
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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);
|
|
38
119
|
}
|
|
39
|
-
/** Your task's repeat in words: "Every hour at :15", "Every Friday
|
|
120
|
+
/** Your task's repeat in words: "Every hour at :15", "Every Friday, 16:00". */
|
|
40
121
|
export function taskWhen(s) {
|
|
41
122
|
if (!s) return '';
|
|
42
|
-
|
|
43
|
-
return s.cadence === 'hourly' ? 'Every hour at :' + t.slice(-2) : s.cadence === 'daily' ? 'Every day at ' + t : s.cadence === 'weekly' ? 'Every ' + d + ' at ' + t
|
|
44
|
-
: s.cadence === 'bi-weekly' ? 'Every other ' + d + ' at ' + t : s.cadence === 'monthly' ? 'On day ' + (s.dayOfMonth || 1) + ' of each month at ' + t
|
|
45
|
-
: s.cadence === 'once' ? 'Once, ' + (s.date || '') + ' at ' + t : String(s.cadence || '');
|
|
123
|
+
return whenWords({ ...s, cadence: s.cadence || 'weekly' });
|
|
46
124
|
}
|
|
47
125
|
/** A read or a job's Next: Paused, Stuck, Missed, Running now, or when it runs next. */
|
|
48
126
|
function refreshNext(r, now) {
|
|
@@ -50,47 +128,77 @@ function refreshNext(r, now) {
|
|
|
50
128
|
if (r.stall) return 'Stuck since ' + atOf(r.stall.since, now);
|
|
51
129
|
if (r.missed_at) return 'Missed ' + atOf(r.missed_at, now);
|
|
52
130
|
if (r.state === 'running') return 'Running now';
|
|
53
|
-
|
|
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) : '';
|
|
54
133
|
}
|
|
55
134
|
|
|
56
|
-
export function routineRows({ reports = [], refresh = [], tasks = [],
|
|
135
|
+
export function routineRows({ reports = [], refresh = [], tasks = [], spaces = [], jobs = null } = {}, now = Date.now()) {
|
|
57
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();
|
|
58
142
|
for (const r of reports) {
|
|
59
143
|
if (!r || !r.id) continue;
|
|
60
|
-
|
|
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');
|
|
61
157
|
out.push({
|
|
62
|
-
key: 'r:' + (r.ws || '') + ':' + r.id, kind: 'reports', group: a ? 'wait' : 'reports', ws: r.ws || '', id: r.id, name
|
|
63
|
-
does: reportDoes(r
|
|
64
|
-
next: a ?
|
|
65
|
-
on:
|
|
66
|
-
|
|
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,
|
|
67
165
|
});
|
|
68
166
|
}
|
|
69
167
|
for (const r of refresh) {
|
|
70
168
|
if (!r || !r.id || (r.run !== 'skill' && r.run !== 'job')) continue;
|
|
71
169
|
const kind = r.run === 'skill' ? 'reads' : 'jobs';
|
|
72
170
|
if (r.run === 'skill' && Array.isArray(r.svcs) && r.svcs.length) {
|
|
73
|
-
//
|
|
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.
|
|
74
173
|
for (const v of r.svcs) {
|
|
75
174
|
if (!v || !v.id) continue;
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
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 });
|
|
79
180
|
}
|
|
80
181
|
continue;
|
|
81
182
|
}
|
|
82
|
-
|
|
83
|
-
|
|
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 });
|
|
84
189
|
}
|
|
85
190
|
for (const s of tasks) {
|
|
86
191
|
if (!s || !s.id || s.endedReason) continue;
|
|
87
192
|
const on = s.enabled !== false;
|
|
88
|
-
out.push({ key: 't:' + s.id, kind: 'tasks', 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) : '',
|
|
89
|
-
when: taskWhen(s), next: !on ? 'Paused' : s.next ?
|
|
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 });
|
|
90
195
|
}
|
|
91
196
|
return out;
|
|
92
197
|
}
|
|
93
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
|
+
|
|
94
202
|
/** The groups in order, for one kind or all. A group with no row is not drawn. */
|
|
95
203
|
export function routineGroups(rows, kind = 'all') {
|
|
96
204
|
const mine = (rows || []).filter((r) => kind === 'all' || r.kind === kind);
|
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
* PMOS in the chat ("send it on Thursdays"). A field the record leaves silent is not drawn.
|
|
10
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
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
|
-
*
|
|
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.
|
|
13
18
|
*
|
|
14
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
|
|
15
20
|
* freezes the issue; nothing is sent outward, the PM sends it from their own mail, as today. On → /api/report-setups/pause | resume.
|
|
@@ -17,12 +22,13 @@
|
|
|
17
22
|
* report → /api/report-setups/confirm | move. ✕ hides the ✦ line for that issue on this computer.
|
|
18
23
|
* reportHtml(R, now) — pure, for the tests: R = { row, text, path, hide, msg, busy, editTells } */
|
|
19
24
|
import { mdHtml } from './chat-md.js';
|
|
20
|
-
import { nextOf } from './cozy-evmodel.js';
|
|
21
25
|
import { CADENCES, chatOf } from './report-flow.js';
|
|
26
|
+
import { nextAt, dayTime } from './cozy-routine-model.js';
|
|
22
27
|
|
|
23
28
|
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
24
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>`;
|
|
25
|
-
const I = {
|
|
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' };
|
|
26
32
|
const MONS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
27
33
|
const DAYS = { Mon: 'Monday', Tue: 'Tuesday', Wed: 'Wednesday', Thu: 'Thursday', Fri: 'Friday', Sat: 'Saturday', Sun: 'Sunday' };
|
|
28
34
|
/** "18 Nov", from a YYYY-MM-DD slot. */
|
|
@@ -38,18 +44,93 @@ export function builtFrom(row) {
|
|
|
38
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()) : '';
|
|
39
45
|
return [row && row.wsName, w].filter(Boolean).join(' · ');
|
|
40
46
|
}
|
|
41
|
-
/** The Repeats choices: the four cadences, the current one selected (a cadence PMOS does not
|
|
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' };
|
|
42
50
|
export function repeatChoices(sch) {
|
|
43
51
|
const cur = sch && sch.cadence;
|
|
44
|
-
const L = CADENCES.map(([v, l]) => [v, l, v === cur]);
|
|
52
|
+
const L = CADENCES.map(([v, l]) => [v, SHORT[v] || l, v === cur]);
|
|
45
53
|
if (cur && !L.some((x) => x[2])) L.push([cur, cur, true]);
|
|
46
54
|
return L;
|
|
47
55
|
}
|
|
48
|
-
const
|
|
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
|
+
}
|
|
49
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>`;
|
|
50
80
|
const kv = (k, v, cls = '') => `<div class="rp-r${cls}"><span>${esc(k)}</span>${v}</div>`;
|
|
51
81
|
const fm = (t) => String(t || '').replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/, '');
|
|
52
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
|
+
|
|
53
134
|
/** The report in the popup, as html. Pure. */
|
|
54
135
|
export function reportHtml(R, now = Date.now()) {
|
|
55
136
|
const r = R.row || {}, issues = r.issues || [], cur = issues.find((x) => x.path === R.path) || r.latest || null;
|
|
@@ -57,37 +138,56 @@ export function reportHtml(R, now = Date.now()) {
|
|
|
57
138
|
const nope = R.hide && cur && R.hide.has(cur.path);
|
|
58
139
|
// the one ✦ line: a waiting definition or move, else a draft to issue
|
|
59
140
|
let sg = '';
|
|
60
|
-
|
|
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')) {
|
|
61
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?';
|
|
62
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>`
|
|
63
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>`;
|
|
64
147
|
} else if (a && a.act === 'issue' && cur && cur.state === 'draft' && cur.path === (r.latest && r.latest.path) && !nope) {
|
|
65
|
-
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 : '') + '?')}</span>`
|
|
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>`
|
|
66
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>`
|
|
67
150
|
+ `<button type="button" class="rp-n" data-rp="nope" aria-label="Not now" title="Not now">${svg(I.x, 14)}</button></div></div>`;
|
|
68
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
|
+
}
|
|
69
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>`
|
|
70
160
|
: cur ? `<span class="rp-ch">${esc(issueName(issues, cur.path))}</span>` : '';
|
|
71
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>` : '';
|
|
72
|
-
const body = !cur ? '<p class="rp-q">No issue is written yet. PMOS drafts the first one on its day.</p>'
|
|
73
|
-
: 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(
|
|
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>`;
|
|
74
164
|
// the setup: only what the records say
|
|
75
165
|
const s = r.schedule;
|
|
76
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
|
+
}
|
|
77
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')));
|
|
78
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>`));
|
|
79
|
-
else if (r.when) rows.push(kv('Repeats', `<em>${esc(r.when)}</em>`));
|
|
80
|
-
|
|
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>`));
|
|
81
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">`
|
|
82
|
-
: `<button type="button" class="rp-sel" data-rp="tells-ed" aria-label="${esc('Tells: ' + (who || 'nobody named') + '. Press to change it')}">${esc(who || 'Name who reads it')}</button>`));
|
|
83
|
-
else if (who) rows.push(kv('Tells', `<em>${esc(who)}</em>`));
|
|
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>`));
|
|
84
183
|
if (r.status) rows.push(kv('After the run', '<em>You issue it</em>'));
|
|
85
184
|
if (builtFrom(r)) rows.push(kv('Built from', `<em>${esc(builtFrom(r))}</em>`));
|
|
86
|
-
const iss = issues.
|
|
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('');
|
|
87
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>' : '')
|
|
88
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>';
|
|
89
|
-
const msg =
|
|
90
|
-
return `<div class="rp-w"><div class="rp-main">${sg}${meta}${body}${msg}</div>${box}</div>`;
|
|
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>`;
|
|
91
191
|
}
|
|
92
192
|
|
|
93
193
|
/* ── the popup: open, draw, presses ── */
|
|
@@ -99,18 +199,25 @@ const q = (o) => Object.entries(o).filter(([, v]) => v != null && v !== '').map(
|
|
|
99
199
|
/** Open a report row of Routine in the popup. h: { VW, http: { pmGet, pmPost }, reload(), toast(text) } */
|
|
100
200
|
export async function openReport(row, h) {
|
|
101
201
|
const hide = new Set(); for (const x of row.issues || []) if (store.get(NOPE + x.path)) hide.add(x.path);
|
|
102
|
-
const R = { row, path: row.latest ? row.latest.path : '', text: null, err: '', hide, msg: '', busy: false, editTells: false };
|
|
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 };
|
|
103
203
|
const me = P = { R, body: null, h };
|
|
104
204
|
const PC = await import('./page-chat.js');
|
|
105
205
|
const base = PC.targetOf({ id: 'report-' + row.id, kind: 'report', title: row.name }, row.ws);
|
|
106
|
-
|
|
107
|
-
t
|
|
108
|
-
|
|
109
|
-
|
|
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); },
|
|
110
217
|
pop: { id: 'report-' + row.id, kind: 'report', title: row.name, ws: row.ws || undefined, target: t },
|
|
111
218
|
render: (b) => { me.body = b; draw(me); wire(me); },
|
|
112
219
|
onClose: () => { if (P === me) P = null; } });
|
|
113
|
-
read(me);
|
|
220
|
+
read(me); readDef(me);
|
|
114
221
|
return me;
|
|
115
222
|
}
|
|
116
223
|
function draw(me) { if (me.body && me.body.isConnected) me.body.innerHTML = reportHtml(me.R); }
|
|
@@ -122,6 +229,22 @@ async function read(me) {
|
|
|
122
229
|
} catch { R.text = ''; R.err = 'The issue could not be read.'; }
|
|
123
230
|
if (P === me) draw(me);
|
|
124
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
|
+
}
|
|
125
248
|
const said = (r, ok) => (r && r.ok !== false && !(r && r.error) ? ok : 'Nothing changed: ' + ((r && r.error) || 'the server did not answer') + '.');
|
|
126
249
|
async function refresh(me) {
|
|
127
250
|
const j = await me.h.http.pmGet('/api/report-setups/routine?' + q({ ws: me.R.row.ws })).catch(() => null);
|
|
@@ -132,13 +255,29 @@ async function refresh(me) {
|
|
|
132
255
|
function wire(me) {
|
|
133
256
|
const b = me.body; if (!b || b.__rp) return; b.__rp = true;
|
|
134
257
|
const post = me.h.http.pmPost, R = me.R;
|
|
135
|
-
const act = async (fn) => { if (R.busy) return; R.busy = true; draw(me); try { R.msg = await fn(); } finally { R.busy = false; } await refresh(me); if (P === me) draw(me); };
|
|
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); };
|
|
136
259
|
b.addEventListener('click', async (e) => {
|
|
137
260
|
const t = e.target.closest('[data-rp]'); if (!t || t.tagName === 'SELECT' || t.tagName === 'INPUT') return;
|
|
138
261
|
const k = t.dataset.rp, row = R.row, ws = row.ws || undefined;
|
|
139
262
|
if (k === 'open') { R.path = t.dataset.path; R.text = null; R.msg = ''; draw(me); read(me); return; }
|
|
140
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; }
|
|
141
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
|
+
}
|
|
142
281
|
if (k === 'tells-ed') { R.editTells = true; draw(me); const i = b.querySelector('#rpTells'); if (i) { i.focus(); i.select(); } return; }
|
|
143
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.'); });
|
|
144
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.'));
|
|
@@ -154,6 +293,7 @@ function wire(me) {
|
|
|
154
293
|
});
|
|
155
294
|
}
|
|
156
295
|
});
|
|
296
|
+
b.addEventListener('input', (e) => { const t = e.target; if (t.dataset && t.dataset.rp === 'ins') R.insText = t.value; });
|
|
157
297
|
b.addEventListener('change', (e) => {
|
|
158
298
|
const t = e.target; if (!t.dataset) return;
|
|
159
299
|
if (t.dataset.rp === 'pick') { R.path = t.value; R.text = null; R.msg = ''; draw(me); read(me); return; }
|
|
@@ -176,21 +316,3 @@ function wire(me) {
|
|
|
176
316
|
});
|
|
177
317
|
b.addEventListener('focusout', (e) => { const t = e.target; if (t.dataset && t.dataset.rp === 'tells') tells(t); });
|
|
178
318
|
}
|
|
179
|
-
|
|
180
|
-
/** Open a read, a job or one of your tasks in the popup: the setup cozy-schedwork.js draws. h: { VW, reload() } */
|
|
181
|
-
export async function openJob(row, h) {
|
|
182
|
-
const SW = await import('./cozy-schedwork.js');
|
|
183
|
-
const kind = row.kind === 'tasks' ? 'task' : 'job';
|
|
184
|
-
let sub = 'sw:' + kind + ':' + row.id, msg = '', body = null;
|
|
185
|
-
const draw = () => { if (body && body.isConnected) body.innerHTML = `<div class="cz ev-st rp-job">${SW.swBody(sub)}${msg ? `<p class="ev-small rp-msg" role="status">${esc(msg)}</p>` : ''}</div>`; };
|
|
186
|
-
const fresh = () => { if (h.reload) h.reload(); };
|
|
187
|
-
const H = { go: (k) => { if (!k || k === 'list') { h.VW.closePop(); return; } sub = 'sw:' + k; msg = ''; draw(); }, say: (m) => { msg = m; }, draw, fresh };
|
|
188
|
-
h.VW.open({ id: 'routine:' + row.key, kind: row.kind === 'tasks' ? 'Your task' : row.kind === 'reads' ? 'PMOS reads' : 'PMOS job', title: row.name, icon: row.kind === 'tasks' ? 'task' : row.kind === 'reads' ? 'source' : 'gear',
|
|
189
|
-
pop: { id: 'routine-' + row.id, kind: 'routine', title: row.name },
|
|
190
|
-
render: (b) => {
|
|
191
|
-
body = b; draw();
|
|
192
|
-
b.addEventListener('click', (e) => { const t = e.target.closest('button, a'); if (t && body.contains(t)) SW.swPress(t, H); });
|
|
193
|
-
b.addEventListener('change', (e) => { SW.swChange(e.target, H); });
|
|
194
|
-
} });
|
|
195
|
-
await SW.swLoad(draw);
|
|
196
|
-
}
|