create-pmos 0.397.0 → 0.398.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 +13 -13
- 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-adddoc-test.js +101 -52
- package/workspace/briefing-premium-board-test.js +252 -128
- package/workspace/briefing-premium-calendar-2-test.js +135 -198
- package/workspace/briefing-premium-calendar-3-test.js +143 -418
- package/workspace/briefing-premium-calendar-test.js +86 -196
- package/workspace/briefing-premium-doc-edit-test.js +95 -83
- package/workspace/briefing-premium-initiative-test.js +159 -296
- package/workspace/briefing-premium-insights-test.js +337 -219
- package/workspace/briefing-premium-metrics-test.js +53 -97
- package/workspace/briefing-premium-products-test.js +40 -27
- package/workspace/briefing-premium-sources-test.js +66 -48
- package/workspace/briefing-premium-test.js +150 -647
- package/workspace/briefing-premium-work-test.js +88 -283
- package/workspace/changelog.json +12 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
- package/workspace/guide/briefing-premium.md +3 -1
- package/workspace/guide/home.md +47 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-premium.js +85 -19
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +62 -14
- package/workspace/lib/insights-records.js +101 -0
- package/workspace/lib/jira-tickets.js +1 -1
- package/workspace/lib/route-modules.js +4 -0
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-insights-premium.js +12 -3
- package/workspace/lib/routes-insights-records.js +129 -0
- package/workspace/lib/routes-notes.js +1 -0
- package/workspace/lib/routes-viewer.js +108 -0
- package/workspace/lib/transcript-steps.js +123 -0
- package/workspace/lib/viewer-meeting.js +205 -0
- package/workspace/lib/viewer-report.js +89 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-board-actions-test.js +85 -75
- package/workspace/premium-briefing-depth-test.js +66 -53
- package/workspace/premium-chat-attach-test.js +54 -63
- package/workspace/premium-chat-chart-tab-test.js +35 -37
- package/workspace/premium-chat-context-test.js +19 -18
- package/workspace/premium-chat-goal-view-test.js +23 -23
- package/workspace/premium-chat-notes-test.js +26 -31
- package/workspace/premium-chat-report-tab-test.js +32 -28
- package/workspace/premium-chat-term-test.js +16 -16
- package/workspace/premium-chat-viewer-test.js +60 -59
- package/workspace/premium-core-doc-issue-test.js +50 -43
- package/workspace/premium-html-viewer-test.js +14 -17
- package/workspace/premium-phone-card-test.js +7 -2
- package/workspace/premium-phone-room-test.js +41 -35
- package/workspace/premium-report-read-test.js +115 -197
- package/workspace/premium-viewer-download-test.js +19 -22
- package/workspace/premium-viewer-flicker-test.js +11 -16
- package/workspace/premium-viewer-share-test.js +6 -9
- package/workspace/premium-viewer-test.js +41 -60
- package/workspace/premium-vw-backlog-test.js +53 -33
- package/workspace/premium-vw-cal-test.js +82 -128
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +11 -10
- package/workspace/premium-vw-item-test.js +50 -49
- package/workspace/premium-vw-jira-test.js +53 -27
- package/workspace/premium-vw-meet-test.js +118 -187
- package/workspace/premium-vw-notes-test.js +85 -108
- package/workspace/premium-vw-rec-test.js +72 -194
- package/workspace/premium-vw-slides-test.js +46 -50
- package/workspace/premium-welcome-test.js +3 -2
- package/workspace/premium-work-depth-test.js +61 -53
- package/workspace/public/pm/bd-acts.js +305 -0
- package/workspace/public/pm/bd-span.js +186 -82
- package/workspace/public/pm/bd-stages.js +25 -11
- package/workspace/public/pm/c3-doc-sheet.js +1 -1
- package/workspace/public/pm/c3-md.js +3 -395
- package/workspace/public/pm/c3-phone-detail.js +1 -1
- package/workspace/public/pm/c3-phone-model.js +3 -68
- package/workspace/public/pm/chat-term.js +3 -3
- package/workspace/public/pm/cozy-board.css +497 -230
- package/workspace/public/pm/cozy-home.css +570 -142
- package/workspace/public/pm/cozy-home.js +5 -3
- package/workspace/public/pm/cozy-insights.css +296 -167
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +17 -6
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-viewer.css +3 -3
- package/workspace/public/pm/cozy-viewer.js +144 -0
- package/workspace/public/pm/cozy-vw.css +485 -0
- package/workspace/public/pm/cozy.css +83 -1
- package/workspace/public/pm/home-adddoc.js +48 -0
- package/workspace/public/pm/home-app.js +905 -0
- package/workspace/public/pm/home-around.js +515 -0
- package/workspace/public/pm/home-chat.js +459 -0
- package/workspace/public/pm/home-data.js +312 -0
- package/workspace/public/pm/home-draft.js +68 -0
- package/workspace/public/pm/home-more.js +249 -0
- package/workspace/public/pm/home-phone-card.js +109 -0
- package/workspace/public/pm/home-work.js +519 -0
- package/workspace/public/pm/phone-moment.js +69 -0
- package/workspace/public/pm/pm-work-view.js +1 -1
- package/workspace/public/pm/premium-attach.js +4 -0
- package/workspace/public/pm/premium-board.js +423 -394
- package/workspace/public/pm/premium-chart-tab.js +110 -62
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +25 -21
- package/workspace/public/pm/premium-insights.js +792 -568
- package/workspace/public/pm/premium-meeting.js +61 -549
- package/workspace/public/pm/premium-notes.js +1 -1
- package/workspace/public/pm/premium-report-frame.css +20 -0
- package/workspace/public/pm/premium-report-read.js +509 -480
- package/workspace/public/pm/premium-report-tab.js +87 -63
- package/workspace/public/pm/premium-shell.js +72 -119
- package/workspace/public/pm/premium-viewer.js +22 -1
- package/workspace/public/pm/premium-vw-cal.js +187 -48
- package/workspace/public/pm/premium-vw-doc.css +6 -0
- package/workspace/public/pm/premium-vw-doc.js +40 -2
- package/workspace/public/pm/premium-vw-file.js +2 -2
- package/workspace/public/pm/premium-vw-meet.js +6 -83
- package/workspace/public/pm/premium-vw-mtg.js +731 -0
- package/workspace/public/pm/premium-vw-notes.js +56 -69
- package/workspace/public/pm/premium-vw-open.js +35 -0
- package/workspace/public/pm/premium-vw-page.js +16 -0
- package/workspace/public/pm/premium-vw-rec.js +11 -218
- package/workspace/public/pm/premium-vw-slides.css +5 -0
- package/workspace/public/pm/premium-vw-slides.js +44 -8
- package/workspace/public/pm/term-view.js +22 -0
- package/workspace/public/premium-board.html +28 -70
- package/workspace/public/premium-initiative.html +8 -48
- package/workspace/public/premium-insights.html +22 -60
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium.html +16 -107
- package/workspace/server.js +18 -3
- package/workspace/test-files.json +1 -0
- package/workspace/test-lists/home-libs.json +9 -0
- package/workspace/test-lists/premium-report-read.json +1 -1
- package/workspace/test-lists/premium-vw-agreed.json +9 -0
- package/workspace/test-lists/premium-vw-notes.json +1 -1
- package/workspace/public/pm/premium-work.js +0 -729
- package/workspace/public/pm/premium.js +0 -1146
|
@@ -1,729 +0,0 @@
|
|
|
1
|
-
/* pm/premium-work.js — the premium My work page (initiative briefing-premium-work, slice 4). Reads GET /api/my-work-premium and draws the model
|
|
2
|
-
* lib/my-work-premium.js builds from the list the Work page reads: the hero, the Work queue, Waiting on others, the dock and the standard dialog.
|
|
3
|
-
* Every press goes to the Work page's own route under /api/pm-items, /api/pm-jobs or /api/my-work; this file adds no writer. A control with nothing honest to write stays off and says why.
|
|
4
|
-
* My work depth (initiative premium-work-depth): the dialog's tool row (Edit, Who does each step, Not before, Someday), the Focus bar and its jobs, the agent on an item
|
|
5
|
-
* (draft, stop, edit, post after a confirm, send back, try again), and keys and swipe on the rows. */
|
|
6
|
-
import { pmPost } from './http.js';
|
|
7
|
-
import { mdRender } from './markdown.js';
|
|
8
|
-
import { $, $$, esc, openDlg, popKey, closeDlg, setMode, toast, loadThread, onScroll, wireRail, logHtml, turnA, turnU, ptx, CHECK, RM, S, setPageGaps, chatAbout } from './premium-shell.js';
|
|
9
|
-
|
|
10
|
-
let M = null; // the model
|
|
11
|
-
let openR = null; // the row whose dialog is open
|
|
12
|
-
const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
|
|
13
|
-
const GLYPH = {
|
|
14
|
-
Jira: '<path d="M12 3l8 8-8 8-8-8z"/><path d="M9 11l3 3 3-3"/>',
|
|
15
|
-
Slack: '<path d="M9 4 7 20M17 4l-2 16M4.5 9h15M4 15h15"/>',
|
|
16
|
-
Board: '<path d="M12 3 3 8l9 5 9-5z"/><path d="m3 13 9 5 9-5"/>',
|
|
17
|
-
Yours: '<path d="M4 20l4-1 11-11-3-3L5 16z"/>',
|
|
18
|
-
};
|
|
19
|
-
const mdHtml = (t) => { try { const d = document.createElement('div'); d.append(...mdRender(String(t)).blocks.map((b) => b.node || b)); return d.innerHTML; } catch { return '<p class="tt">' + esc(t) + '</p>'; } }; // mdRender builds nodes, never a string, so nothing in a draft runs
|
|
20
|
-
const KIND = { ask: 'You asked', draft: 'Agent drafted', edit: 'You edited it', note: 'You sent it back', sent: 'Posted', post: 'Posted' };
|
|
21
|
-
const turnsHtml = (a) => (a.turns && a.turns.length ? `<h3 class="h2">Conversation with the agent</h3><ol class="agturns">${a.turns.map((t, i) => `<li class="${t.who}"><b>${esc(t.who === 'agent' ? 'Agent' : 'You')}</b> ${esc(KIND[t.kind] || t.kind || 'said')}${t.at ? ' · ' + esc(String(t.at).slice(0, 10)) : ''}${t.text ? `<span>${esc(t.text)}</span>` : ''}${t.body ? `<button class="xtb" data-p="round" data-i="${i}" aria-expanded="${ui.round === i}">${t.who === 'agent' ? 'View round' : 'View your edit'}</button>${ui.round === i ? `<div class="mdr">${mdHtml(t.body)}</div>` : ''}` : ''}</li>`).join('')}</ol>` : '');
|
|
22
|
-
const glyph = (src) => GLYPH[src] || '<circle cx="12" cy="12" r="4"/>';
|
|
23
|
-
/* Home (initiative premium-agreed-design, H2) holds My work: the capture box, the Work queue, Waiting on others, the weekly review and Untouched
|
|
24
|
-
* are groups of Home's list. There the Briefing owns the summary, the place menu and the page's conversation, so this file draws only its own cards. */
|
|
25
|
-
const HOME = document.body.classList.contains('cz-home');
|
|
26
|
-
if (!HOME) wireRail('work');
|
|
27
|
-
const WS = new URLSearchParams(location.search).get('ws') || '';
|
|
28
|
-
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
29
|
-
const dayLabel = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso || ''); return m ? +m[3] + ' ' + MON[+m[2] - 1] : ''; };
|
|
30
|
-
const addIso = (iso, n) => new Date(Date.parse(iso + 'T00:00:00Z') + n * 86400000).toISOString().slice(0, 10);
|
|
31
|
-
const nextMonday = (iso) => addIso(iso, ((1 - new Date(iso + 'T00:00:00Z').getUTCDay() + 7) % 7) || 7);
|
|
32
|
-
const hhmm = (iso) => { const d = new Date(iso); return Number.isNaN(d.getTime()) ? '' : String(d.getHours()).padStart(2, '0') + ':' + String(d.getMinutes()).padStart(2, '0'); };
|
|
33
|
-
const SVG = { sun: '<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2"/>', moon: '<path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/>', eye: '<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>' };
|
|
34
|
-
|
|
35
|
-
/* ── hero and header ───────────────────────────────────────────────────────────────────────────────────── */
|
|
36
|
-
function drawHero() {
|
|
37
|
-
if (HOME) return;
|
|
38
|
-
$('#date').textContent = M.date;
|
|
39
|
-
$('#brief').innerHTML = M.hero.map((s) => s.parts.map((p) => (p.s ? `<span class="k">${esc(p.t)}</span>` : esc(p.t))).join('')).join(' ');
|
|
40
|
-
$('#snap').textContent = M.header.text;
|
|
41
|
-
setPageGaps(((M.header && M.header.missing) || []).length);
|
|
42
|
-
$('#snap').title = 'Every figure on this page comes from an item on your list. A date shows only when one was set.';
|
|
43
|
-
}
|
|
44
|
-
function drawDock() { if (HOME) return; $('#dN').textContent = M.dock.needs; $('#dLab').textContent = M.dock.needs === 0 ? 'to clear' : M.dock.label; $('#dNext').innerHTML = M.dock.next ? `<i></i>Next <b>${esc(M.dock.next)}</b>` : 'Nothing more on your list'; }
|
|
45
|
-
|
|
46
|
-
/* ── the Work queue ─────────────────────────────────────────────────────────────────────────────────────── */
|
|
47
|
-
function rowHtml(r, o = {}) {
|
|
48
|
-
const inbox = r.list === 'inbox' || r.list === 'tray' || r.list === 'done', sm = o.sm;
|
|
49
|
-
const sd = sm ? null : sideOf(r);
|
|
50
|
-
const desc = sd ? ` aria-description="${esc((sd.r ? 'Right arrow: ' + sd.r.label + '. ' : '') + (sd.l ? 'Left arrow: ' + sd.l.label + '. ' : '') + 'J and K move between rows.')}"` : '';
|
|
51
|
-
let lead;
|
|
52
|
-
if (sm === 'wait') lead = `<span class="avp" aria-hidden="true">${esc(((r.sub.match(/waiting on (\S)/) || [])[1] || '·'))}</span>`;
|
|
53
|
-
else if (inbox) lead = `<span class="wgl" title="${esc(r.src)}">${ICO(glyph(r.src))}</span>`;
|
|
54
|
-
else if (r.agent === 'ready') lead = `<button class="wck dec" data-open="${esc(r.key)}" aria-label="Review the agent draft: ${esc(r.title)}" title="An agent draft is ready. Open it to review.">${ICO('<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>')}</button>`;
|
|
55
|
-
else lead = `<button class="wck" data-ck="${esc(r.id)}" aria-pressed="false" aria-label="Mark done: ${esc(r.title)}">${CHECK}</button>`;
|
|
56
|
-
const meta = r.chip ? `<span class="wm"><span class="due${r.overdue ? ' od' : ''}">${esc(r.chip)}</span></span>` : '';
|
|
57
|
-
const ag = AG_CHIP[r.agent], chip = ag ? `<em class="wag ${ag[0]}"><i></i>${ag[1]}</em>` : '';
|
|
58
|
-
const sug = !sm && r.sug ? `<span class="wsg" title="${esc(r.sug.b + ' ' + r.sug.t)}">${ICO('<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>')}<span><b>${esc(r.sug.b)}</b> ${esc(r.sug.t)}</span></span>` : '';
|
|
59
|
-
const fs = !sm && !r.focus && focusIds().has(r.id) ? '<em class="xfc sug">Suggested focus</em>' : '';
|
|
60
|
-
return `<div class="wrw"><div class="wrow${sm ? ' sm' : ''}${inbox ? ' inb' : ''}${o.first ? ' first' : ''}" data-key="${esc(r.key)}">${lead}<button class="wrh" aria-haspopup="dialog"${desc}><span class="wtx"><span class="wtit">${esc(r.title)}${o.first ? '<em class="tgf">Do this first</em>' : ''}${r.focus ? '<em class="xfc">Focus</em>' : ''}${fs}</span><span class="ws">${chip}${esc(r.sub)}</span>${sug}</span>${meta}</button></div></div>`;
|
|
61
|
-
}
|
|
62
|
-
/* One card, one tab for each place a thing waits. A tab draws its groups in two columns. An item an agent works on stays in its own tab with a chip (PM, 2026-10-20). */
|
|
63
|
-
let qTab = null;
|
|
64
|
-
const Q_ROW = ['today', 'inbox']; // the tabs always in the row; Upcoming, Someday, Kept and Done wait under More (premium-calmer-first-screen)
|
|
65
|
-
const AG_CHIP = { ready: ['ready', 'Draft ready'], queued: ['run', 'Agent working'], working: ['run', 'Agent working'], sending: ['run', 'Agent working'], failed: ['fail', 'Agent stopped'] };
|
|
66
|
-
const Q_EMPTY = { today: 'Nothing is placed for today.', inbox: 'Nothing waits to be sorted. Add a line above and it lands here first.', upcoming: 'Nothing has a later date.', someday: 'Nothing is parked.', kept: 'Nothing kept yet.', done: 'Nothing done this week.' };
|
|
67
|
-
function groupHtml(g, tab) {
|
|
68
|
-
const first = tab === 'today' ? g.rows.find((r) => r.overdue) || null : null;
|
|
69
|
-
return g.rows.map((r) => rowHtml(r, { first: first && r.key === first.key })).join('') + (g.more ? `<p class="note">${g.more} more ${g.more === 1 ? 'item is' : 'items are'} not shown here.</p>` : '');
|
|
70
|
-
}
|
|
71
|
-
function drawQueue() {
|
|
72
|
-
const Q = M.queue, tabs = Q.tabs;
|
|
73
|
-
if (!qTab || !tabs.some((t) => t.key === qTab)) qTab = Q.start;
|
|
74
|
-
const cur = tabs.find((t) => t.key === qTab);
|
|
75
|
-
$('#qCap').innerHTML = `<b>${Q.n}</b> to clear` + Q.cap.map((c) => ' · ' + esc(c)).join('');
|
|
76
|
-
const tb = (t) => `<button type="button" role="tab" class="qtb" id="qt-${t.key}" data-tab="${t.key}" aria-selected="${t.key === qTab}" aria-controls="qBody" tabindex="${t.key === qTab ? 0 : -1}">${esc(t.label)}<em>${t.n}</em></button>`;
|
|
77
|
-
const inRow = (t) => Q_ROW.includes(t.key) || t.key === qTab, rest = tabs.filter((t) => !inRow(t));
|
|
78
|
-
$('#qTabs').innerHTML = tabs.filter(inRow).map(tb).join('');
|
|
79
|
-
$('#qMore').hidden = !rest.length; $('#qMore').setAttribute('aria-expanded', 'false');
|
|
80
|
-
$('#qMenu').hidden = true; $('#qMenu').innerHTML = rest.map(tb).join('');
|
|
81
|
-
$('#qBody').setAttribute('aria-labelledby', 'qt-' + qTab);
|
|
82
|
-
let h = '';
|
|
83
|
-
if (!cur.n) h = `<p class="empty3${qTab === 'inbox' ? '' : ' plain'}">${qTab === 'inbox' ? CHECK : ''}${Q_EMPTY[qTab]}</p>`;
|
|
84
|
-
else for (const g of cur.groups) {
|
|
85
|
-
if (cur.groups.length > 1) h += `<div class="wsec" data-lane="${g.key}"><span class="label">${esc(g.label)}</span><em>${g.n ? g.n + ' · ' + esc(g.hint) : 'empty'}</em></div>`;
|
|
86
|
-
h += groupHtml(g, qTab);
|
|
87
|
-
}
|
|
88
|
-
$('#qBody').innerHTML = h;
|
|
89
|
-
$('#qBody').dataset.tab = qTab;
|
|
90
|
-
$('#qNote').textContent = cur.note;
|
|
91
|
-
const sel = $('#qTabs [aria-selected="true"]'), bar = $('#qTabs'); // one row that scrolls sideways on a phone: keep the chosen tab in view
|
|
92
|
-
if (sel && bar.scrollWidth > bar.clientWidth) bar.scrollLeft = Math.max(0, sel.offsetLeft - (bar.clientWidth - sel.offsetWidth) / 2);
|
|
93
|
-
}
|
|
94
|
-
const pickTab = (e) => { const b = e.target.closest('[data-tab]'); if (!b) return; qTab = b.dataset.tab; drawQueue(); const n = $(`#qTabs [data-tab="${qTab}"]`); if (n) n.focus(); };
|
|
95
|
-
$('#qTabs').addEventListener('click', pickTab);
|
|
96
|
-
$('#qMenu').addEventListener('click', pickTab);
|
|
97
|
-
$('#qMore').addEventListener('click', () => { const m = $('#qMenu'), on = m.hidden; m.hidden = !on; $('#qMore').setAttribute('aria-expanded', String(on)); if (on) { const f = m.querySelector('.qtb'); if (f) f.focus(); } });
|
|
98
|
-
document.addEventListener('click', (e) => { if (!e.target.closest('#qMenu, #qMore') && !$('#qMenu').hidden) { $('#qMenu').hidden = true; $('#qMore').setAttribute('aria-expanded', 'false'); } });
|
|
99
|
-
$('#qMenu').addEventListener('keydown', (e) => { if (e.key === 'Escape') { $('#qMenu').hidden = true; $('#qMore').setAttribute('aria-expanded', 'false'); $('#qMore').focus(); } });
|
|
100
|
-
$('#qTabs').addEventListener('keydown', (e) => {
|
|
101
|
-
if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft' && e.key !== 'Home' && e.key !== 'End') return;
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
const ks = M.queue.tabs.map((t) => t.key), i = ks.indexOf(qTab);
|
|
104
|
-
qTab = ks[e.key === 'Home' ? 0 : e.key === 'End' ? ks.length - 1 : (i + (e.key === 'ArrowRight' ? 1 : -1) + ks.length) % ks.length];
|
|
105
|
-
drawQueue(); $(`#qTabs [data-tab="${qTab}"]`).focus();
|
|
106
|
-
});
|
|
107
|
-
function drawWaiting() {
|
|
108
|
-
const W = M.waiting;
|
|
109
|
-
$('#waitCap').textContent = W.cap;
|
|
110
|
-
$('#waitBody').innerHTML = W.rows.length ? W.rows.map((r) => rowHtml(r, { sm: 'wait' })).join('') + (W.more ? `<p class="note">${W.more} more not shown here.</p>` : '') : '<p class="empty3 plain">Nobody owes you anything.</p>';
|
|
111
|
-
}
|
|
112
|
-
function drawReview() {
|
|
113
|
-
const R = M.review; $('#revCard').hidden = !R.n;
|
|
114
|
-
$('#revCap').textContent = R.n + ' ' + (R.n === 1 ? 'item' : 'items');
|
|
115
|
-
$('#revTxt').innerHTML = `<b>${R.n}</b> ${R.n === 1 ? 'item has' : 'items have'} sat untouched for ${R.days} days. Open one to keep it or let it go.`;
|
|
116
|
-
}
|
|
117
|
-
function drawFriday() {
|
|
118
|
-
const F = M.friday; if (!F) return;
|
|
119
|
-
$('#hFr').textContent = F.title; $('#frCap').textContent = F.cap;
|
|
120
|
-
$('#frBody').innerHTML = `<ol class="frl">${F.steps.map((s, i) => `<li><button type="button" class="frs" data-fr="${s.key}"${s.n ? '' : ' disabled'}><i>${i + 1}</i><span>${esc(s.label)}</span><b>${s.n}</b></button></li>`).join('')}</ol>`
|
|
121
|
-
+ `<div class="cact two"><button type="button" class="cta" data-fr="${F.start || ''}"${F.start ? '' : ' disabled'}><span>${F.start ? 'Start the review' : 'Nothing to review'}</span></button></div><p class="note" style="margin-top:12px">${esc(F.note)}</p>`;
|
|
122
|
-
}
|
|
123
|
-
$('#frBody').addEventListener('click', (e) => {
|
|
124
|
-
const b = e.target.closest('[data-fr]'); if (!b || !b.dataset.fr || !M || !M.friday) return;
|
|
125
|
-
const st = M.friday.steps.find((x) => x.key === b.dataset.fr); const r = st && st.first ? rowOf(st.first) : null;
|
|
126
|
-
if (r) openRow(r); else toast('Nothing to open here.');
|
|
127
|
-
});
|
|
128
|
-
function draw() { drawHero(); drawFriday(); drawFocus(); drawQueue(); drawWaiting(); drawReview(); drawDock(); onScroll(); backFocus(); }
|
|
129
|
-
const rowOf = (key) => (M && M.rows || []).find((r) => r.key === key) || null;
|
|
130
|
-
|
|
131
|
-
/* ── the dialog: detail first, the presses of the Work page, the tool row, the agent, the read-only agent beside it ─────────────────── */
|
|
132
|
-
const NOTYET = [['later-today', 'Later today'], ['tomorrow', 'Tomorrow'], ['next-week', 'Next week']];
|
|
133
|
-
const WHO = [['you', 'You'], ['agent-drafts', 'Agent drafts'], ['agent-does', 'Agent does']];
|
|
134
|
-
const PRIS = ['P1', 'P2', 'P3', ''];
|
|
135
|
-
let dlgKind = null; // 'item' | 'fjobs': what the open dialog shows
|
|
136
|
-
let ui = {}; // what is typed or opened in the item dialog; kept across a redraw
|
|
137
|
-
const freshUi = () => ({ xp: null, ed: null, dd: '', sn: '', ask: null, body: null, editing: false, confirm: false, back: false, note: '', wo: '', pick: null, round: null, more: false, dpick: null, pane: '', sheet: false });
|
|
138
|
-
const dlgOpen = () => $('#dlg').classList.contains('on');
|
|
139
|
-
const paras = (t) => String(t || '').split(/\n{2,}/).filter((x) => x.trim()).map((x) => `<p>${esc(x.trim()).replace(/\n/g, '<br>')}</p>`).join('');
|
|
140
|
-
|
|
141
|
-
/* the choice the console offers on an agent offer: the agent draft (suggested), Do it today, Not before next Monday. Each runs a route that already exists. */
|
|
142
|
-
function choicesHtml(r, a) {
|
|
143
|
-
const nm = nextMonday(M.today), pick = ui.pick || 'agent';
|
|
144
|
-
const opts = [['agent', 'Suggested', 'Let the agent draft this', a.mine ? 'Drafts it here in PMOS. Nothing leaves PMOS.' : `Drafts it here in PMOS. Nothing goes to ${esc(a.where || 'anyone')}.`]];
|
|
145
|
-
if (r.list !== 'today') opts.push(['today', '', 'Do it today', 'Moves to Today']);
|
|
146
|
-
opts.push(['nb', '', 'Not before ' + dayLabel(nm), 'Out of Today until then']);
|
|
147
|
-
const go = pick === 'agent' ? ['ag-brief', 'Let the agent draft this'] : pick === 'today' ? ['ag-today', 'Do it today'] : ['ag-nb', 'Not before ' + dayLabel(nm)];
|
|
148
|
-
return `<div class="xch" role="radiogroup" aria-label="What to do with this">${opts.map((o) => `<button class="xco" role="radio" data-p="pick" data-v="${o[0]}" aria-checked="${pick === o[0]}">${o[1] ? `<em>${o[1]}</em>` : ''}<b>${esc(o[2])}</b><span>${o[3]}</span></button>`).join('')}</div>`
|
|
149
|
-
+ `<div class="cact two"><button class="cta" data-p="${go[0]}"><span>${esc(go[1])}</span></button></div>`;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/* the console's "Or decide" cards: Post (outward, suggested), Edit, Keep as a draft, Mark done. One go button does the picked one. */
|
|
153
|
-
const DECIDE = (a, step, w) => [
|
|
154
|
-
...(!a.mine || step ? [['post', step ? 'Do the step' : 'Post it to ' + w, 'Suggested', [['lock', step ? 'Outward: exactly this step' : 'Outward: exactly this text'], ['out', step ? 'A session with Chrome does it' : 'Goes to ' + w + ' as you']]]] : []),
|
|
155
|
-
['edit', 'Edit the draft', '', [[null, step ? 'The step then uses your version' : a.mine ? 'Your version replaces the draft here' : 'Post then sends your version']]],
|
|
156
|
-
['keep', 'Keep it as a draft', a.mine ? 'Suggested' : '', [[null, 'Nothing leaves PMOS']]],
|
|
157
|
-
['done', 'Mark it done', '', [[null, 'Closes the item. Nothing is posted']]],
|
|
158
|
-
];
|
|
159
|
-
function decideHtml(r, a, step, w) {
|
|
160
|
-
const opts = DECIDE(a, step, w), pick = opts.some((o) => o[0] === ui.dpick) ? ui.dpick : opts[0][0], cur = opts.find((o) => o[0] === pick);
|
|
161
|
-
const go = { post: ['ag-post', cur[1]], edit: ['ag-save', 'Save my version'], keep: ['ag-keep', 'Keep it as a draft'], done: ['ag-done', 'Mark it done'] }[pick];
|
|
162
|
-
let h = `<p class="xlab">Or decide</p><div class="xch" role="radiogroup" aria-label="What to do with the draft">${opts.map((o) => `<button class="xco" role="radio" data-p="dpick" data-v="${o[0]}" aria-checked="${pick === o[0]}">${o[2] ? `<em>${o[2]}</em>` : ''}<b>${esc(o[1])}</b>${o[3].map((f) => `<span class="${f[0] ? 'xwarn' : ''}">${esc(f[1])}</span>`).join('')}</button>`).join('')}</div>`;
|
|
163
|
-
if (ui.editing) h += `<label class="whyl" for="agBody">Your text for the draft</label><textarea class="ta" id="agBody" rows="8">${esc(ui.body == null ? (a.draft && a.draft.body) || '' : ui.body)}</textarea>`;
|
|
164
|
-
if (ui.confirm) {
|
|
165
|
-
const txt = ui.editing && ui.body != null ? ui.body : (a.draft && a.draft.body) || (a.draft && a.draft.summary) || '';
|
|
166
|
-
h += `<div class="xcon" role="group" aria-label="Confirm"><p><b>${step ? 'Do this step?' : `Post this to ${esc(w)} as you?`}</b></p>`
|
|
167
|
-
+ (step ? `<p>A new session with Chrome does exactly this step and nothing else:</p><p class="xq">${esc(step)}</p>` : `<p>Exactly this text goes:</p><p class="xq">${esc(txt).replace(/\n/g, '<br>')}</p>`)
|
|
168
|
-
+ `<div class="cact two"><button class="cta" data-p="ag-go"><span>${step ? 'Do the step now' : `Post it to ${esc(w)} now`}</span></button><button class="cta alt" data-p="ag-no"><span>Not yet</span></button></div></div>`;
|
|
169
|
-
} else {
|
|
170
|
-
h += `<div class="cact two"><button class="cta" data-p="${go[0]}"><span>${esc(go[1])}</span></button>${ui.editing ? '<button class="cta alt" data-p="ag-edit"><span>Use the agent’s text</span></button>' : ''}<button class="cta alt" data-p="ag-back" aria-expanded="${ui.back}"><span>Send it back with a note</span></button></div>`;
|
|
171
|
-
if (ui.back) h += `<label class="whyl" for="agNote">Tell the agent what to change</label><textarea class="ta" id="agNote" rows="3" maxlength="500">${esc(ui.note)}</textarea><div class="cact two"><button class="cta" data-p="ag-sendback"${ui.note.trim() ? '' : ' disabled'}><span>Send it back</span></button></div><p class="nodef">The agent drafts it again. ${a.mine ? 'Nothing leaves PMOS.' : `Nothing goes to ${esc(w)} or to anyone.`}</p>`;
|
|
172
|
-
}
|
|
173
|
-
return h;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/* the agent block: one state, the controls that state allows, and nothing is posted before the confirm */
|
|
177
|
-
function agentHtml(r) {
|
|
178
|
-
const a = r.dialog.agent, h = a ? agentInner(r) : '';
|
|
179
|
-
return h ? `<div class="agblk" data-state="${esc(a.state)}"><p class="ct">The agent</p>${h}</div>` : '';
|
|
180
|
-
}
|
|
181
|
-
function agentInner(r) {
|
|
182
|
-
const a = r.dialog.agent;
|
|
183
|
-
if (!a) return '';
|
|
184
|
-
const w = a.where || 'anyone', dr = a.draft;
|
|
185
|
-
const draftBox = (dr && (dr.body || dr.summary) ? '<p class="nodef">The draft is on the right.</p>' : '') + turnsHtml(a); // the draft itself sits in the detail panel
|
|
186
|
-
let h = '';
|
|
187
|
-
if (a.state === 'suggest') {
|
|
188
|
-
h = `<p class="nodef">${a.mine ? 'The agent can draft a first version of this for you. You read it here. Nothing leaves PMOS.' : `The agent can draft this for you. You read it here first. Nothing goes to ${esc(w)} until you post it.`}</p>`
|
|
189
|
-
+ `<label class="whyl" for="agAsk">What the agent will do</label><input id="agAsk" maxlength="500" autocomplete="off" value="${esc(ui.ask == null ? a.ask : ui.ask)}">`
|
|
190
|
-
+ choicesHtml(r, a);
|
|
191
|
-
} else if (a.state === 'queued' || a.state === 'working' || a.state === 'sending') {
|
|
192
|
-
const line = a.state === 'queued' ? 'Queued. The agent starts as soon as a session is free. You can close this page.'
|
|
193
|
-
: a.state === 'sending' ? `Posting to ${esc(w)}. A session does exactly the step you approved and nothing else.`
|
|
194
|
-
: 'The agent is working on it. You can close this page: the item keeps its state.' + (a.started_at ? ' Started at ' + esc(hhmm(a.started_at)) + '.' : '');
|
|
195
|
-
h = `<p class="nodef" role="status">${line}</p>${draftBox}${a.state === 'sending' ? '' : '<div class="cact two"><button class="cta alt" data-p="ag-stop"><span>Stop</span></button></div>'}`;
|
|
196
|
-
} else if (a.state === 'ready') {
|
|
197
|
-
const step = dr && dr.step;
|
|
198
|
-
h = `<p class="nodef">${step ? 'Draft ready. The step has not run.' : `Draft ready. Nothing went to ${esc(a.mine ? 'anyone' : w)}.`}</p>`;
|
|
199
|
-
h += draftBox + decideHtml(r, a, step, w);
|
|
200
|
-
} else if (a.state === 'failed') {
|
|
201
|
-
h = `<p class="nodef" role="status">${a.asks && a.error ? esc(a.error.charAt(0).toUpperCase() + a.error.slice(1)) + ' Nothing was sent.' : `The agent stopped${a.error ? ': ' + esc(a.error) : '.'} Nothing was sent.`}</p>${draftBox}`
|
|
202
|
-
+ `<div class="cact two"><button class="cta" data-p="ag-retry"><span>Try again</span></button><button class="cta alt" data-p="ag-stop"><span>Stop</span></button></div>`;
|
|
203
|
-
} else if (a.state === 'sent') {
|
|
204
|
-
h = `<p class="nodef" role="status">${a.mine ? 'The draft is kept on this item.' : `You posted it to ${esc(w)}${a.sent_at ? ' at ' + esc(hhmm(a.sent_at)) : ''}.`}${a.link ? ` <a href="${esc(a.link)}" target="_blank" rel="noopener">Open what was posted</a>` : ''}</p>${draftBox}`;
|
|
205
|
-
}
|
|
206
|
-
return h;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/* the dialog's fields (initiative premium-simple-ui): one labelled field for each choice, showing its value from the record, with a chevron.
|
|
210
|
-
* A field opens its panel under it, one at a time. When holds Today, Not yet, Not before and Someday; Waiting on, Who does it and Priority · Due
|
|
211
|
-
* hold the Waiting, Steps and Edit panels. Since 2026-10-20 they sit in a sheet behind Edit ▾ (see cardInner). Every press is the same route as before. */
|
|
212
|
-
const CHEV = '<svg class="i chev" viewBox="0 0 24 24"><path d="m6 9 6 6 6-6"/></svg>';
|
|
213
|
-
const PLACE = { today: ['Today', ''], inbox: ['Inbox', 'not placed yet'], tray: ['Not placed yet', 'you added it'], upcoming: ['Upcoming', ''], waiting: ['Waiting', ''], someday: ['Someday', ''] };
|
|
214
|
-
function whenOf(r) {
|
|
215
|
-
const d = r.dialog, nb = d.defer && d.defer > M.today ? d.defer : null;
|
|
216
|
-
if (nb) return ['Not before ' + dayLabel(nb), 'off your lists until then'];
|
|
217
|
-
const p = PLACE[r.list] || ['On your list', ''];
|
|
218
|
-
return r.list === 'upcoming' && d.edit.due ? [p[0], 'due ' + dayLabel(d.edit.due)] : p;
|
|
219
|
-
}
|
|
220
|
-
function fieldHtml(k, label, val, sub, open) {
|
|
221
|
-
return `<button class="ffd" data-p="xt" data-k="${k}" aria-expanded="${open}"><span class="ffv"><small>${esc(label)}</small><b>${esc(val)}${sub ? ` <em>· ${esc(sub)}</em>` : ''}</b></span>${CHEV}</button>`;
|
|
222
|
-
}
|
|
223
|
-
function panelHtml(r, x) {
|
|
224
|
-
const d = r.dialog, a = d.write.actions, S = d.steps || [];
|
|
225
|
-
if (x === 'agent') return `<div class="xpan agblk" data-state="${esc(d.agent.state)}">${agentInner(r)}</div>`;
|
|
226
|
-
if (x === 'when') {
|
|
227
|
-
const o = (attrs, l, sub) => `<button class="fopt" ${attrs}><span>${l}</span>${sub ? `<small>${sub}</small>` : ''}</button>`;
|
|
228
|
-
return `<div class="xpan fmenu" role="group" aria-label="When">${a.includes('flag') ? o('data-p="flag"', 'Today') : ''}${NOTYET.map(([k, t]) => o(`data-p="notyet" data-when="${k}"`, t, 'comes back by itself')).join('')}`
|
|
229
|
-
+ o('data-p="xt" data-k="defer"', 'Not before a date…', 'leaves your lists') + o(`data-p="xt" data-k="someday" aria-pressed="${d.someday}"`, d.someday ? 'Bring back from Someday' : 'Someday') + '</div>';
|
|
230
|
-
}
|
|
231
|
-
if (x === 'wait') return `<div class="xpan"><div class="cact two"><input id="wOn" class="why one" maxlength="80" placeholder="A name" aria-label="Waiting on" autocomplete="off" value="${esc(ui.wo)}"><button class="cta quiet" data-p="waiting" id="wBtn"${ui.wo.trim() ? '' : ' disabled'}><span>Wait for them</span></button></div></div>`;
|
|
232
|
-
if (x === 'edit') {
|
|
233
|
-
const e = ui.ed || (ui.ed = { title: d.edit.title, due: d.edit.due, priority: d.edit.priority, wo: d.edit.waiting_on, job: d.edit.job }), ro = !!d.edit.title_ro;
|
|
234
|
-
return `<div class="xpan"><label class="xf"><span>Title</span><input id="xeT" maxlength="250" value="${esc(e.title)}"${ro ? ' disabled' : ''}></label>${ro ? `<p class="note">${esc(d.edit.title_ro)}</p>` : ''}`
|
|
235
|
-
+ `<label class="xf"><span>Due</span><input type="date" id="xeD" value="${esc(e.due)}"></label>`
|
|
236
|
-
+ `<div class="xf"><span>Priority</span><span class="seg2" role="group" aria-label="Priority">${PRIS.map((p) => `<button data-p="xpri" data-v="${p}" aria-pressed="${e.priority === p}">${p || 'None'}</button>`).join('')}</span></div>`
|
|
237
|
-
+ `<label class="xf"><span>Waiting on</span><input id="xeW" maxlength="80" value="${esc(e.wo)}" placeholder="A name moves it to Waiting"></label>`
|
|
238
|
-
+ `<label class="xf"><span>Job</span><select id="xeJ"><option value="">No job</option>${(M.jobs || []).map((j) => `<option value="${esc(j.id)}"${e.job === j.id ? ' selected' : ''}>${esc(j.name)}</option>`).join('')}</select></label>`
|
|
239
|
-
+ `<div class="cact two"><button class="cta" data-p="xsave">${CHECK}<span>Save</span></button><button class="cta alt" data-p="xt" data-k="edit"><span>Cancel</span></button></div></div>`;
|
|
240
|
-
}
|
|
241
|
-
if (x === 'steps') {
|
|
242
|
-
return `<div class="xpan"><ul class="xsteps">${S.map((s) => `<li><span class="xst">${esc(s.text)}</span><span class="seg2" role="group" aria-label="Who does: ${esc(s.text)}">${WHO.map(([k, l]) => `<button data-p="xwho" data-sid="${esc(s.id)}" data-v="${k}" aria-pressed="${s.who === k}">${l}</button>`).join('')}</span></li>`).join('') || '<li class="note">No steps yet.</li>'}</ul>`
|
|
243
|
-
+ `<p class="note">A step that sends something to a person is only ever drafted by the agent. You release it.</p>`
|
|
244
|
-
+ `<div class="xadd"><input id="xsIn" maxlength="200" placeholder="Add a step" aria-label="A new step" value="${esc(ui.sn)}"><button class="cta alt" data-p="xsadd">Add</button></div></div>`;
|
|
245
|
-
}
|
|
246
|
-
if (x === 'defer') {
|
|
247
|
-
const dd = ui.dd || '';
|
|
248
|
-
return `<div class="xpan"><p class="note">It leaves your lists until that day.</p><span class="seg2" role="group" aria-label="Quick dates"><button data-p="xdq" data-v="${addIso(M.today, 1)}">Tomorrow</button><button data-p="xdq" data-v="${nextMonday(M.today)}">Monday</button><button data-p="xdq" data-v="${addIso(M.today, 7)}">In a week</button></span>`
|
|
249
|
-
+ `<label class="xf"><span>Or a date</span><input type="date" id="xdD" min="${addIso(M.today, 1)}" value="${esc(dd)}"></label>`
|
|
250
|
-
+ `<div class="cact two"><button class="cta" data-p="xdgo"${dd ? '' : ' disabled'}>${CHECK}<span>Not before ${dd ? esc(dayLabel(dd)) : 'that day'}</span></button>${d.defer ? '<button class="cta alt" data-p="xdclr"><span>Clear the date</span></button>' : ''}</div></div>`;
|
|
251
|
-
}
|
|
252
|
-
return '';
|
|
253
|
-
}
|
|
254
|
-
/* the fields live at dialog level (PM, 2026-10-20: "accessible on popup level instead of on the beginning of the chat, and hidden when not needed"):
|
|
255
|
-
* one row beside the Detail / Conversation switch holds Edit ▾ and Done; Edit opens a sheet with the fields and Keep it / Drop it, closed by default,
|
|
256
|
-
* so the conversation gets the whole body. A field with nothing to set for this item (Waiting on when the item cannot wait and waits on nobody) is left out. */
|
|
257
|
-
const SLIDERS = '<svg class="i" viewBox="0 0 24 24"><path d="M4 7h10M18 7h2M4 17h4M12 17h8"/><circle cx="16" cy="7" r="2"/><circle cx="10" cy="17" r="2"/></svg>';
|
|
258
|
-
function cardInner(r) {
|
|
259
|
-
const d = r.dialog, a = d.write.actions, x = ui.xp || '', S = d.steps || [], e = d.edit, ag = d.agent;
|
|
260
|
-
const steps = S.length ? S.length + (S.length === 1 ? ' step' : ' steps') : 'no steps yet';
|
|
261
|
-
const whos = [...new Set(S.map((s) => (WHO.find((w) => w[0] === s.who) || [0, 'You'])[1]))];
|
|
262
|
-
const fld = (k, label, val, sub, open = x === k) => fieldHtml(k, label, val, sub, open) + (open ? panelHtml(r, k) : '');
|
|
263
|
-
const when = whenOf(r), sum = [when[0], e.waiting_on ? 'waiting on ' + e.waiting_on : '', e.priority || '', e.due ? 'due ' + dayLabel(e.due) : ''].filter(Boolean).join(' · ');
|
|
264
|
-
let f = '';
|
|
265
|
-
if (ag && ag.state === 'suggest') f += fld('agent', 'The agent', 'Can draft this for you', ag.mine ? 'nothing leaves PMOS' : 'you read it first');
|
|
266
|
-
f += `<div class="ffds">`
|
|
267
|
-
+ fieldHtml('when', 'When', when[0], when[1], x === 'when' || x === 'defer') + (x === 'when' || x === 'defer' ? panelHtml(r, x) : '')
|
|
268
|
-
+ (a.includes('waiting') || e.waiting_on ? fld('wait', 'Waiting on', e.waiting_on || 'Nobody', '') : '')
|
|
269
|
-
+ fld('steps', 'Who does it', whos.length ? whos.join(', ') : 'You', steps)
|
|
270
|
-
+ fld('edit', 'Priority · Due', e.priority || 'None', e.due ? 'due ' + dayLabel(e.due) : 'no date')
|
|
271
|
-
+ `</div>`;
|
|
272
|
-
f += `<div class="fbar"><div class="fmeta">${a.includes('keep') ? '<button class="flink" data-p="keep">Keep it</button>' : ''}<button class="flink" data-p="remove">Drop it</button></div></div>`;
|
|
273
|
-
return `<div class="ibrow"><button class="ichip" id="iTog" data-p="sheet" aria-expanded="${!!ui.sheet}" aria-controls="iSheet" title="Edit when, who and priority">${SLIDERS}<span>Edit</span><em class="isum">${esc(sum)}</em>${CHEV}</button>`
|
|
274
|
-
+ `<button class="cta fdone" data-p="done">${CHECK}<span>Done</span></button></div>`
|
|
275
|
-
+ `<div class="isheet" id="iSheet" role="group" aria-label="Item fields"${ui.sheet ? ' data-esc-layer' : ' hidden'}>${f}</div>`
|
|
276
|
-
+ '<p class="nodef err" id="cardErr" role="alert" hidden></p>';
|
|
277
|
-
}
|
|
278
|
-
/* an agent that is working, ready, failed or posted needs the PM's eye, so its block stays in the conversation; one that only can draft is a field in the sheet */
|
|
279
|
-
const agCardInner = (r) => (r.dialog.agent && r.dialog.agent.state !== 'suggest' ? agentHtml(r) : '');
|
|
280
|
-
const agCardHtml = (r) => { const h = agCardInner(r); return h ? `<div class="acard" id="agCard">${h}</div>` : ''; };
|
|
281
|
-
/* the bar sits in the switch row (#dTabs), which the dialog shows at every width while an item is open */
|
|
282
|
-
function mountBar(r) {
|
|
283
|
-
unmountBar();
|
|
284
|
-
$('#dTabs').insertAdjacentHTML('beforeend', `<div class="ibar" id="card">${cardInner(r)}</div>`);
|
|
285
|
-
$('#dlg').classList.add('itm');
|
|
286
|
-
}
|
|
287
|
-
/* Home (premium-agreed-design) loads this file beside premium.js, whose row dialogs carry their own #card in the conversation: this file's
|
|
288
|
-
* card is only the bar in the switch row, so every lookup of it is scoped to #dTabs and never removes or redraws the Briefing's card */
|
|
289
|
-
const myBar = () => $('#dTabs #card');
|
|
290
|
-
function unmountBar() { const c = myBar(); if (c) c.remove(); $('#dlg').classList.remove('itm'); }
|
|
291
|
-
function placeSheet() {
|
|
292
|
-
const s = $('#iSheet'); if (!s || s.hidden) return;
|
|
293
|
-
const dl = $('#dlg').getBoundingClientRect(), t = $('#dTabs').getBoundingClientRect();
|
|
294
|
-
s.style.maxHeight = Math.max(200, dl.bottom - t.bottom - 20) + 'px';
|
|
295
|
-
}
|
|
296
|
-
function paneHtml(r) {
|
|
297
|
-
const p = r.dialog.pane, ag = r.dialog.agent, dr = ag && ag.draft && (ag.draft.body || ag.draft.summary) ? ag.draft : null;
|
|
298
|
-
let h = '';
|
|
299
|
-
if (dr) {
|
|
300
|
-
const long = String(dr.body || '').length > 900 || String(dr.body || '').split('\n').length > 16, clip = long && !ui.all;
|
|
301
|
-
h += `<article class="paper doc agpane"><div class="agpt"><p class="agtag"><span class="agst">${ag.state === 'sent' ? 'Posted' : 'Draft'}</span> ${ag.mine ? 'Draft for you' : 'Draft for ' + esc(ag.ref || ag.where || 'the item')}</p><span class="agver">${ag.round ? 'Round ' + ag.round : 'Agent draft'}${ag.round_at ? ' · ' + esc(hhmm(ag.round_at)) : ''}</span><span class="agpa"><button class="xtb" data-pp="open" type="button">Open</button><button class="xtb" data-pp="copy" type="button">Copy</button></span></div><p class="note">Agent draft · not checked</p>`
|
|
302
|
-
+ (dr.step ? `<p class="agstep">Step when you approve: ${esc(dr.step)}</p>` : '')
|
|
303
|
-
+ `<div class="mdr${clip ? ' clipd' : ''}">${mdHtml(dr.body || dr.summary)}</div>${long ? `<button class="xtb" data-pp="all" type="button" aria-expanded="${!clip}">${clip ? 'Show all' : 'Show less'}</button>` : ''}</article>`;
|
|
304
|
-
}
|
|
305
|
-
// the dialog head already shows the title and its line, so the pane opens the source and keeps the record behind Details
|
|
306
|
-
const kv = p.rows && p.rows.length ? `<div class="kv2">${p.rows.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div>` : '';
|
|
307
|
-
const sc = r.dialog.source;
|
|
308
|
-
if (sc) return h + srcHtml(sc) + `<details class="paper doc wkdet"><summary>Details</summary>${kv}<p class="xn">${esc(p.file)}</p></details>`;
|
|
309
|
-
return h + `<article class="paper doc">${kv}<p class="xn">The item as your list holds it · ${esc(p.file)}</p></article>`;
|
|
310
|
-
}
|
|
311
|
-
/* the message, ticket or thread the item came from, as the brief stored it: nothing is read live on open */
|
|
312
|
-
function srcHtml(sc) {
|
|
313
|
-
const by = [sc.who, sc.where ? 'in ' + sc.where : ''].filter(Boolean).join(' ');
|
|
314
|
-
let g = `<p class="agtag"><span class="agst">${esc(sc.name || 'Source')}</span>${by ? ' ' + esc(by) : ''}</p>`;
|
|
315
|
-
if (sc.thread && sc.thread.length) g += `<div class="wksrc">${sc.thread.map((m) => `<p class="wkmsg"><b>${esc(m.who || 'Someone')}</b>${m.at ? ` <span class="xn">${esc(m.at)}</span>` : ''}<br>${esc(m.text)}</p>`).join('')}</div>`;
|
|
316
|
-
else if (sc.quote) g += `<blockquote class="wkq">${esc(sc.quote)}</blockquote>`;
|
|
317
|
-
if (sc.ask && !(sc.thread && sc.thread.length) && !sc.quote) g += `<p><b>Asked:</b> ${esc(sc.ask)}</p>`;
|
|
318
|
-
if (sc.about) g += `<p>${esc(sc.about)}</p>`;
|
|
319
|
-
for (const rf of sc.refs || []) g += `<p class="wkref"><b>${rf.link ? `<a href="${esc(rf.link)}" target="_blank" rel="noopener">${esc(rf.label)}</a>` : esc(rf.label)}</b></p>${rf.lines.length ? `<ul>${rf.lines.map((l) => `<li>${esc(l)}</li>`).join('')}</ul>` : ''}`;
|
|
320
|
-
if (sc.evidence) g += `<p class="xn">Evidence: ${esc(sc.evidence)}</p>`;
|
|
321
|
-
if (sc.link) g += `<p><a class="xtb" href="${esc(sc.link)}" target="_blank" rel="noopener">Open in ${esc(sc.name || 'its source')}</a></p>`;
|
|
322
|
-
return `<article class="paper doc wksrcp">${g}</article>`;
|
|
323
|
-
}
|
|
324
|
-
const paneLabel = (r) => (r.dialog.agent && r.dialog.agent.draft && (r.dialog.agent.draft.body || r.dialog.agent.draft.summary) ? 'Draft and item record' : r.dialog.pane.label);
|
|
325
|
-
const paneSig = (r) => JSON.stringify([r.dialog.agent && r.dialog.agent.draft, r.dialog.agent && r.dialog.agent.round, r.dialog.agent && r.dialog.agent.state, r.dialog.pane]);
|
|
326
|
-
/* the detail panel follows the item: a draft that lands while the dialog is open shows at once */
|
|
327
|
-
function paintPane() {
|
|
328
|
-
if (!openR || dlgKind !== 'item') return;
|
|
329
|
-
const sg = paneSig(openR) + (ui.all ? 'A' : ''); if (sg === ui.pane) return;
|
|
330
|
-
ui.pane = sg; const m = $('#oMain'), top = m.scrollTop;
|
|
331
|
-
m.innerHTML = paneHtml(openR); $('#oLab').textContent = paneLabel(openR); m.scrollTop = top;
|
|
332
|
-
}
|
|
333
|
-
$('#oMain').addEventListener('click', async (e) => {
|
|
334
|
-
const b = e.target.closest('[data-pp]'); if (!b || dlgKind !== 'item' || !openR) return;
|
|
335
|
-
const ag = openR.dialog.agent, txt = (ag && ag.draft && (ag.draft.body || ag.draft.summary)) || '';
|
|
336
|
-
if (b.dataset.pp === 'all') { ui.all = !ui.all; ui.pane = ''; paintPane(); return; }
|
|
337
|
-
if (b.dataset.pp === 'copy') { try { await navigator.clipboard.writeText(txt); toast('Draft copied.'); } catch (_) { toast('Copy did not work here. Select the text and copy it.'); } }
|
|
338
|
-
else { const u = URL.createObjectURL(new Blob([txt], { type: 'text/plain;charset=utf-8' })); window.open(u, '_blank', 'noopener'); setTimeout(() => URL.revokeObjectURL(u), 60000); }
|
|
339
|
-
});
|
|
340
|
-
function openRow(r) {
|
|
341
|
-
if (!r) return;
|
|
342
|
-
openR = r; dlgKind = 'item'; ui = freshUi(); const d = r.dialog;
|
|
343
|
-
openDlg({ eye: d.eye + ' · real data', title: r.title, sub: r.sub, say: d.say, stream: turnA(logHtml(d)) + turnA(ptx(d.say)) + agCardHtml(r), noteKey: r.key, pane: paneHtml(r), label: paneLabel(r) });
|
|
344
|
-
ui.pane = paneSig(r);
|
|
345
|
-
mountBar(r);
|
|
346
|
-
loadThread(r.key);
|
|
347
|
-
setTimeout(() => { const b = $('#dBody'); b.scrollTop = b.scrollHeight; }, 120);
|
|
348
|
-
}
|
|
349
|
-
/* redraw the card from what the model and the typed state hold; `sel` is the control to focus again */
|
|
350
|
-
function paint(sel) {
|
|
351
|
-
const c = myBar(); if (!c || !openR) return;
|
|
352
|
-
c.innerHTML = cardInner(openR); placeSheet();
|
|
353
|
-
const ac = $('#agCard'), ah = agCardInner(openR);
|
|
354
|
-
if (ac && ah) ac.innerHTML = ah; else if (ac) ac.remove(); else if (ah) $('#dBody .stream').insertAdjacentHTML('beforeend', agCardHtml(openR));
|
|
355
|
-
if (sel) { const f = $(sel, c) || $(sel, $('#dBody')); if (f) f.focus(); }
|
|
356
|
-
}
|
|
357
|
-
function showErr(msg) { const e = $('#cardErr'); if (!e) { toast(msg); return; } e.textContent = msg; e.hidden = false; }
|
|
358
|
-
const sigOf = (r) => JSON.stringify([r.dialog.agent, r.dialog.steps, r.dialog.defer, r.dialog.someday, r.dialog.edit, r.dialog.write.actions]);
|
|
359
|
-
/* after a new model: a dialog that is open follows its row, and redraws only when the row's own record changed */
|
|
360
|
-
function refreshOpen() {
|
|
361
|
-
const n = rowOf(openR.key);
|
|
362
|
-
if (!n) { closeDlg(); openR = null; return; }
|
|
363
|
-
const changed = sigOf(n) !== sigOf(openR);
|
|
364
|
-
openR = n;
|
|
365
|
-
if (changed) { paint(); paintPane(); }
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/* a press: the page waits for the route's answer; a refusal shows its reason and changes nothing.
|
|
369
|
-
* o = { send(): the route's answer, say: string | (res) => string, undo(): the reverse press, keep: stay in the dialog, list: pressed on a row, not in the dialog, focus: selector } */
|
|
370
|
-
const post = (path, body) => pmPost(path, body);
|
|
371
|
-
function toastUndo(msg, undo) {
|
|
372
|
-
const t = $('#toast'); t.innerHTML = `${esc(msg)} <button class="undo" type="button">Undo</button>`; t.classList.add('on');
|
|
373
|
-
const b = $('.undo', t); b.onclick = async () => { t.classList.remove('on'); const r = await undo(); if (!r || r.ok !== true) toast((r && r.error) || 'It could not be undone.'); await load(); };
|
|
374
|
-
clearTimeout(toastUndo.t); toastUndo.t = setTimeout(() => t.classList.remove('on'), 8000);
|
|
375
|
-
}
|
|
376
|
-
async function commit(o) {
|
|
377
|
-
if (!o.list) $$('#card button, #agCard button').forEach((b) => { b.disabled = true; });
|
|
378
|
-
const res = await o.send();
|
|
379
|
-
if (!res || res.ok !== true) {
|
|
380
|
-
const msg = (res && res.error) || 'The press was not recorded.';
|
|
381
|
-
if (o.list) toast(msg); else { paint(); showErr(msg); }
|
|
382
|
-
return false;
|
|
383
|
-
}
|
|
384
|
-
const said = typeof o.say === 'function' ? o.say(res) : o.say;
|
|
385
|
-
if (o.keep) {
|
|
386
|
-
await load(); paint(o.focus); if (said) toast(said);
|
|
387
|
-
} else {
|
|
388
|
-
if (!o.list) { closeDlg(); openR = null; }
|
|
389
|
-
if (o.undo) toastUndo(said, o.undo); else toast(said);
|
|
390
|
-
await load();
|
|
391
|
-
}
|
|
392
|
-
return true;
|
|
393
|
-
}
|
|
394
|
-
const SAID = { done: 'Marked done.', notyet: 'Put off. It comes back by itself.', flag: 'Moved to Today.', waiting: 'Now waiting.', remove: 'Dropped.', keep: 'Kept.' };
|
|
395
|
-
const reopen = (id) => () => post('/api/pm-items/reopen', { id });
|
|
396
|
-
const doneP = (r, o = {}) => commit({ ...o, send: () => post('/api/pm-items/done', { id: r.id, ...(o.how ? { how: o.how } : {}) }), say: o.say || SAID.done, undo: reopen(r.id) });
|
|
397
|
-
const deferP = (r, until, o = {}) => commit({ ...o, send: () => post('/api/pm-items/defer', { id: r.id, until }),
|
|
398
|
-
say: until ? `Not before ${dayLabel(until)}. It leaves your lists until then.` : 'Date cleared.', undo: () => post('/api/pm-items/defer', { id: r.id, until: r.dialog.defer || null }) });
|
|
399
|
-
const somedayP = (r, o = {}) => commit({ ...o, send: () => post(r.dialog.someday ? '/api/pm-items/unpark' : '/api/pm-items/someday', { id: r.id }),
|
|
400
|
-
say: r.dialog.someday ? 'Brought back.' : 'Moved to Someday.', undo: () => post(r.dialog.someday ? '/api/pm-items/someday' : '/api/pm-items/unpark', { id: r.id }) });
|
|
401
|
-
const todayP = (r, o = {}) => commit({ ...o, send: () => post('/api/pm-items/flag', { id: r.id, flagged: true }), say: SAID.flag, undo: () => post('/api/pm-items/flag', { id: r.id, flagged: false }) });
|
|
402
|
-
|
|
403
|
-
/* the edit: only what changed; Undo writes the old values back through the same routes */
|
|
404
|
-
function saveEdit(r) {
|
|
405
|
-
const o = r.dialog.edit, e = ui.ed, id = r.id, fields = {}, old = {};
|
|
406
|
-
const t = e.title.trim();
|
|
407
|
-
if (!o.title_ro && t && t !== o.title) { fields.title = t; old.title = o.title; }
|
|
408
|
-
if (e.due !== o.due) { fields.due = e.due || null; old.due = o.due || null; }
|
|
409
|
-
if (e.priority !== o.priority) { fields.priority = e.priority || null; old.priority = o.priority || null; }
|
|
410
|
-
if (e.job !== o.job) { fields.job = e.job || null; old.job = o.job || null; }
|
|
411
|
-
const wo = e.wo.trim(), woChanged = wo !== o.waiting_on;
|
|
412
|
-
if (!Object.keys(fields).length && !woChanged) { showErr('Nothing changed.'); return; }
|
|
413
|
-
return commit({
|
|
414
|
-
send: async () => {
|
|
415
|
-
let res = { ok: true };
|
|
416
|
-
if (Object.keys(fields).length) res = await post('/api/pm-items/edit', { id, fields });
|
|
417
|
-
if (res && res.ok === true && woChanged) res = await post('/api/pm-items/waiting', { id, on: wo || null });
|
|
418
|
-
return res;
|
|
419
|
-
},
|
|
420
|
-
say: woChanged && wo ? `Saved. It now waits on ${wo}.` : 'Saved.',
|
|
421
|
-
undo: async () => {
|
|
422
|
-
let res = { ok: true };
|
|
423
|
-
if (Object.keys(old).length) res = await post('/api/pm-items/edit', { id, fields: old });
|
|
424
|
-
if (res && res.ok === true && woChanged) res = await post('/api/pm-items/waiting', { id, on: o.waiting_on || null });
|
|
425
|
-
return res;
|
|
426
|
-
},
|
|
427
|
-
});
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/* the dialog's clicks */
|
|
431
|
-
function dlgClick(b, r) {
|
|
432
|
-
const id = r.id, k = b.dataset.p, d = r.dialog, a = d.agent || {};
|
|
433
|
-
switch (k) {
|
|
434
|
-
case 'notyet': return commit({ send: () => post('/api/pm-items/notyet', { id, when: b.dataset.when }), say: SAID.notyet });
|
|
435
|
-
case 'waiting': return commit({ send: () => post('/api/pm-items/waiting', { id, on: ($('#wOn').value || '').trim() }), say: SAID.waiting });
|
|
436
|
-
case 'done': return doneP(r);
|
|
437
|
-
case 'sheet': ui.sheet = !ui.sheet; if (!ui.sheet) ui.xp = null; return paint(ui.sheet ? '#iSheet .ffd' : '#iTog');
|
|
438
|
-
case 'remove': return commit({ send: () => post('/api/pm-items/remove', { id }), say: SAID.remove, undo: () => post('/api/pm-items/undo', { id }) });
|
|
439
|
-
case 'flag': return todayP(r);
|
|
440
|
-
case 'keep': return commit({ send: () => post('/api/pm-items/keep', { id }), say: SAID.keep });
|
|
441
|
-
case 'pick': ui.pick = b.dataset.v; return paint(`[data-p="pick"][data-v="${b.dataset.v}"]`);
|
|
442
|
-
case 'ag-today': return todayP(r);
|
|
443
|
-
case 'ag-nb': return deferP(r, nextMonday(M.today));
|
|
444
|
-
case 'round': ui.round = ui.round === +b.dataset.i ? null : +b.dataset.i; return paint(`[data-p="round"][data-i="${b.dataset.i}"]`);
|
|
445
|
-
case 'more': ui.more = !ui.more; if (!ui.more) ui.xp = null; return paint('[data-p="more"]');
|
|
446
|
-
case 'xt': {
|
|
447
|
-
const t = b.dataset.k;
|
|
448
|
-
if (t === 'someday') return somedayP(r);
|
|
449
|
-
ui.xp = ui.xp === t ? null : t; if (t === 'edit') ui.ed = null;
|
|
450
|
-
return paint(ui.xp ? `.xpan input:not([disabled]),.xpan button` : `[data-k="${t}"]`);
|
|
451
|
-
}
|
|
452
|
-
case 'xpri': ui.ed.priority = b.dataset.v; return paint(`[data-p="xpri"][data-v="${b.dataset.v}"]`);
|
|
453
|
-
case 'xsave': return saveEdit(r);
|
|
454
|
-
case 'xwho': return commit({ keep: true, focus: `[data-p="xwho"][data-sid="${b.dataset.sid}"][data-v="${b.dataset.v}"]`, send: () => post('/api/pm-items/steps/who', { step_id: b.dataset.sid, who: b.dataset.v }),
|
|
455
|
-
say: (res) => (res.forced ? 'Set to Agent drafts: it sends something to a person.' : 'Step set to ' + (WHO.find((x) => x[0] === (res.who || b.dataset.v)) || [0, b.dataset.v])[1] + '.') });
|
|
456
|
-
case 'xsadd': {
|
|
457
|
-
const text = ui.sn.trim(); if (!text) { $('#xsIn').focus(); return null; }
|
|
458
|
-
return commit({ keep: true, focus: '#xsIn', send: async () => { const res = await post('/api/pm-items/steps/add', { id, text }); if (res && res.ok === true) { ui.sn = ''; ui.addedForced = !!res.forced; } return res; },
|
|
459
|
-
say: () => (ui.addedForced ? 'Step added as Agent drafts: it sends something to a person.' : 'Step added.') });
|
|
460
|
-
}
|
|
461
|
-
case 'xdq': return deferP(r, b.dataset.v);
|
|
462
|
-
case 'xdgo': return ui.dd ? deferP(r, ui.dd) : null;
|
|
463
|
-
case 'xdclr': return deferP(r, null);
|
|
464
|
-
case 'ag-brief': {
|
|
465
|
-
const own = (($('#agAsk') || {}).value || '').trim();
|
|
466
|
-
return commit({ keep: true, send: () => post('/api/my-work/act', { action: 'brief', item: id, instruction: own || a.ask, ws: WS }),
|
|
467
|
-
say: a.mine ? 'Handed to the agent. Its draft stays here in PMOS.' : `Handed to the agent. Nothing goes to ${a.where} until you post it.` });
|
|
468
|
-
}
|
|
469
|
-
case 'ag-stop': return commit({ keep: true, send: () => post('/api/my-work/stop', { item: id }), say: 'Stopped. Nothing was kept.' });
|
|
470
|
-
case 'ag-retry': return commit({ keep: true, send: () => post('/api/my-work/decide', { item: id, action: 'retry' }), say: 'The agent tries again.' });
|
|
471
|
-
case 'ag-edit': ui.editing = false; ui.body = null; ui.confirm = false; ui.dpick = 'post'; return paint('[data-p="dpick"][data-v="post"]');
|
|
472
|
-
case 'ag-save': return commit({ keep: true, send: () => post('/api/my-work/decide', { item: id, action: 'edit', body: ui.body }), say: a.mine ? 'Saved. The draft stays here.' : `Saved. Post sends your text to ${a.where}.` });
|
|
473
|
-
case 'ag-post': ui.confirm = true; return paint('[data-p="ag-go"]');
|
|
474
|
-
case 'dpick': ui.dpick = b.dataset.v; ui.confirm = false; if (ui.dpick === 'edit' && !ui.editing) { ui.editing = true; if (ui.body == null) ui.body = (a.draft && a.draft.body) || ''; } return paint(`[data-p="dpick"][data-v="${b.dataset.v}"]`);
|
|
475
|
-
case 'ag-keep': closeDlg(); openR = null; toast(a.mine ? 'Kept. The draft stays on this item.' : 'Kept as a draft. Nothing was posted.'); return null;
|
|
476
|
-
case 'ag-no': ui.confirm = false; return paint('[data-p="ag-post"]');
|
|
477
|
-
case 'ag-go': {
|
|
478
|
-
const body = { item: id, action: 'approve' };
|
|
479
|
-
if (ui.editing && ui.body != null && ui.body !== ((a.draft && a.draft.body) || '')) body.body = ui.body;
|
|
480
|
-
return commit({ keep: true, send: () => post('/api/my-work/decide', body), say: a.draft && a.draft.step ? 'Approved. A session with Chrome does exactly this step.' : 'Approved. A session posts exactly this text.' }).then((ok) => { if (ok) { ui.confirm = false; paint(); } return ok; });
|
|
481
|
-
}
|
|
482
|
-
case 'ag-back': ui.back = !ui.back; return paint(ui.back ? '#agNote' : '[data-p="ag-back"]');
|
|
483
|
-
case 'ag-sendback': {
|
|
484
|
-
const note = ui.note.trim(); if (!note) { showErr('Say what to change first: type a note, then send it back.'); return null; }
|
|
485
|
-
return commit({ keep: true, send: () => post('/api/my-work/decide', { item: id, action: 'revise', note }), say: 'Sent back with your note. The agent drafts it again.' }).then((ok) => { if (ok) { ui.back = false; ui.note = ''; paint(); } return ok; });
|
|
486
|
-
}
|
|
487
|
-
case 'ag-done': return doneP(r, { how: 'agent', say: 'Done. Nothing was posted.' });
|
|
488
|
-
default: return null;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
const FIELD = { xeT: 'title', xeD: 'due', xeW: 'wo', xeJ: 'job' };
|
|
492
|
-
const onInput = (e) => {
|
|
493
|
-
const t = e.target, id = t.id;
|
|
494
|
-
if (id === 'wOn') { ui.wo = t.value; const b = $('#wBtn'); if (b) b.disabled = !t.value.trim(); }
|
|
495
|
-
else if (ui.ed && FIELD[id]) ui.ed[FIELD[id]] = t.value;
|
|
496
|
-
else if (id === 'xsIn') ui.sn = t.value;
|
|
497
|
-
else if (id === 'xdD') { ui.dd = t.value; const g = $('[data-p="xdgo"]'); if (g) { g.disabled = !t.value; g.lastChild.textContent = 'Not before ' + (t.value ? dayLabel(t.value) : 'that day'); } }
|
|
498
|
-
else if (id === 'agAsk') ui.ask = t.value;
|
|
499
|
-
else if (id === 'agBody') ui.body = t.value;
|
|
500
|
-
else if (id === 'agNote') { ui.note = t.value; const g = $('[data-p="ag-sendback"]'); if (g) g.disabled = !t.value.trim(); }
|
|
501
|
-
};
|
|
502
|
-
const onChange = (e) => { if (ui.ed && e.target.id === 'xeJ') ui.ed.job = e.target.value; };
|
|
503
|
-
const onClick = (e) => {
|
|
504
|
-
const lt = e.target.closest('#logT');
|
|
505
|
-
if (lt && e.pmLog) return; // Home: premium.js already toggled the activity log for this press; a second toggle would shut it again
|
|
506
|
-
if (lt) { e.pmLog = true; const c = $('#alog').classList.toggle('col'); lt.setAttribute('aria-expanded', !c); return; }
|
|
507
|
-
const b = e.target.closest('[data-p]');
|
|
508
|
-
if (!b || b.disabled || !openR || dlgKind !== 'item') return;
|
|
509
|
-
dlgClick(b, openR);
|
|
510
|
-
};
|
|
511
|
-
/* the conversation and the bar in the switch row take the same presses */
|
|
512
|
-
for (const host of [$('#dBody'), $('#dTabs')]) { host.addEventListener('input', onInput); host.addEventListener('change', onChange); host.addEventListener('click', onClick); }
|
|
513
|
-
const shutSheet = (focus) => { if (!ui.sheet) return; ui.sheet = false; ui.xp = null; paint(focus ? '#iTog' : null); };
|
|
514
|
-
/* the sheet closes on a press outside it, and Escape closes it before the dialog */
|
|
515
|
-
document.addEventListener('pointerdown', (e) => { if (ui.sheet && dlgKind === 'item' && !e.target.closest('#card')) shutSheet(false); });
|
|
516
|
-
addEventListener('keydown', (e) => { if (e.key === 'Escape' && ui.sheet && dlgKind === 'item' && $('#iSheet')) { e.stopImmediatePropagation(); shutSheet(true); } }, true);
|
|
517
|
-
addEventListener('resize', placeSheet);
|
|
518
|
-
/* the bar belongs to the item dialog: it goes when the dialog closes or another dialog takes its place */
|
|
519
|
-
new MutationObserver(() => { if (myBar() && (!dlgOpen() || dlgKind !== 'item' || !openR || $('#dTitle').textContent !== openR.title)) unmountBar(); })
|
|
520
|
-
.observe($('#dlg'), { attributes: true, attributeFilter: ['class'], childList: true, subtree: true, characterData: true });
|
|
521
|
-
|
|
522
|
-
/* ── Focus and jobs: the bar under the add line, and its dialog ─────────────────────────────────────────────────────────────── */
|
|
523
|
-
/* the item ids of the first suggestion: their rows carry a quiet "Suggested focus" tag */
|
|
524
|
-
const focusIds = () => new Set(((M && M.focus && M.focus.suggestions[0]) || {}).item_ids || []);
|
|
525
|
-
const fBody = (f) => ({ key: f.key, title: f.title, why: f.why, item_ids: f.item_ids, job: f.job || null });
|
|
526
|
-
function drawFocus() {
|
|
527
|
-
const F = M.focus, nx = F.suggestions[0], acc = F.accepted;
|
|
528
|
-
const say = nx ? `Suggested · ${nx.title} · ${nx.why}` : acc.length ? 'Your focus today · ' + acc.map((a) => a.title).join(' · ') : 'Nothing to suggest · Nothing more to suggest today';
|
|
529
|
-
const n = nx ? F.suggestions.length + ' suggested' : acc.length ? acc.length + ' in focus' : '';
|
|
530
|
-
$('#xFocus').innerHTML = `<button type="button" class="xfq${nx ? ' on' : ''}" data-xf="more" aria-haspopup="dialog" title="${esc(say)}" aria-label="Focus and jobs. ${esc(say)}">Focus${n ? `<em>${esc(n)}</em>` : ''}</button>`;
|
|
531
|
-
}
|
|
532
|
-
const titleOfKey = (k) => {
|
|
533
|
-
const m = /^(job|item):(.+)$/.exec(k || '');
|
|
534
|
-
if (!m) return 'A suggestion';
|
|
535
|
-
if (m[1] === 'job') { const j = (M.jobs || []).find((x) => x.id === m[2]); return j ? j.name : 'A job'; }
|
|
536
|
-
const r = rowOf('work:' + m[2]); return r ? r.title : 'An item';
|
|
537
|
-
};
|
|
538
|
-
function focusDlgHtml() {
|
|
539
|
-
const F = M.focus, titles = (ids) => ids.map((i) => { const r = rowOf('work:' + i); return r ? r.title : null; }).filter(Boolean);
|
|
540
|
-
const card = (f, state) => `<div class="xit${state === 'no' ? ' decided' : ''}"><span class="xt">${esc(f.title)}</span>${f.why ? `<p class="xwhy">${esc(f.why)}</p>` : ''}${f.item_ids && f.item_ids.length ? `<p>${esc(titles(f.item_ids).join(' · '))}</p>` : ''}<div class="xacts">`
|
|
541
|
-
+ (state === 'acc' ? `<p class="xdone">${CHECK}<span>In focus today.</span></p><button class="cta alt" data-fx="clr" data-k="${esc(f.key)}"><span>Clear</span></button>`
|
|
542
|
-
: state === 'no' ? `<p class="xdone"><span>Not today.</span></p><button class="cta alt" data-fx="clr" data-k="${esc(f.key)}"><span>Clear</span></button>`
|
|
543
|
-
: `<button class="cta" data-fx="acc" data-k="${esc(f.key)}">${CHECK}<span>Accept</span></button><button class="cta alt" data-fx="no" data-k="${esc(f.key)}"><span>Not today</span></button>`) + '</div></div>';
|
|
544
|
-
const rows = F.accepted.map((f) => card(f, 'acc')).concat(F.suggestions.map((f) => card(f, 'sug')), F.dismissed.map((k) => card({ key: k, title: titleOfKey(k), why: '', item_ids: [] }, 'no')));
|
|
545
|
-
const jobs = (M.jobs || []).map((j) => `<div class="xit"><span class="xt">${esc(j.name)}</span><p class="xwhy">When ${esc(j.when)}, I want ${esc(j.want)}, so ${esc(j.so)}.</p><p class="xwhy">${j.open} open ${j.open === 1 ? 'item' : 'items'}</p></div>`).join('');
|
|
546
|
-
const ok = /when .+,\s*i want .+,\s*so .+/i.test(ui.job || '');
|
|
547
|
-
return '<p class="xwhy" style="margin:0 0 6px">PMOS suggests at most three, from your Today list: overdue first, then due today. Rules only, no model call.</p>'
|
|
548
|
-
+ `<div class="xlist">${rows.join('') || '<p class="note">Nothing is in Today, so there is nothing to suggest.</p>'}</div>`
|
|
549
|
-
+ '<h3 class="d2">Your jobs</h3>' + `<div class="xlist">${jobs || '<p class="note">You have no jobs yet. A job is something that matters to you, which items can serve.</p>'}</div>`
|
|
550
|
-
+ `<div class="xit"><span class="xt">Add a job</span><input id="xjIn" maxlength="300" placeholder="When …, I want …, so …" aria-label="A new job: when, I want, so" value="${esc(ui.job || '')}"><div class="xacts"><button class="cta" data-fx="jadd"${ok ? '' : ' disabled'}><span>Add the job</span></button></div></div>`
|
|
551
|
-
+ '<p class="note" style="margin-top:14px">Focus starts empty each day. Give an item a job from its Edit panel.</p>';
|
|
552
|
-
}
|
|
553
|
-
function drawFocusDlg() { const o = $('#oMain'); if (o && dlgKind === 'fjobs') o.innerHTML = `<article class="paper doc">${focusDlgHtml()}</article>`; }
|
|
554
|
-
function openFocus() {
|
|
555
|
-
openR = null; dlgKind = 'fjobs'; ui = freshUi();
|
|
556
|
-
const n = M.focus.suggestions.length;
|
|
557
|
-
const say = n ? `I suggest ${n} ${n === 1 ? 'thing' : 'things'} to focus on today, grouped by the job they serve. Accept the ones you will do; Not today hides one until tomorrow.` : 'Nothing is in Today, so there is nothing to suggest. Your jobs are below.';
|
|
558
|
-
openDlg({ eye: 'My work · real data', title: 'Focus and jobs', sub: 'Today · ' + n + ' suggested', say, stream: turnA(ptx(say)), noteKey: popKey('focus', 'today'), pane: '<article class="paper doc"></article>', label: 'Focus and jobs' });
|
|
559
|
-
setMode('detail'); drawFocusDlg();
|
|
560
|
-
}
|
|
561
|
-
async function focusPress(kind, key) {
|
|
562
|
-
const F = M.focus, f = F.suggestions.concat(F.accepted).find((x) => x.key === key);
|
|
563
|
-
const call = (path, body) => async () => { const res = await post(path, body); if (res && res.ok === true) { await load(); drawFocusDlg(); } else toast((res && res.error) || 'The press was not recorded.'); return res; };
|
|
564
|
-
if (kind === 'acc' && f) { const body = fBody(f); const res = await call('/api/pm-items/focus/accept', body)(); if (res && res.ok === true) toastUndo('In focus today.', async () => post('/api/pm-items/focus/clear', { key })); return; }
|
|
565
|
-
if (kind === 'no') { const res = await call('/api/pm-items/focus/dismiss', { key })(); if (res && res.ok === true) toastUndo('Not suggested again today.', async () => post('/api/pm-items/focus/clear', { key })); return; }
|
|
566
|
-
if (kind === 'clr') { const was = F.accepted.find((x) => x.key === key); const res = await call('/api/pm-items/focus/clear', { key })(); if (res && res.ok === true) { if (was) toastUndo('Cleared.', async () => post('/api/pm-items/focus/accept', fBody(was))); else toast('Cleared.'); } }
|
|
567
|
-
}
|
|
568
|
-
$('#oMain').addEventListener('input', (e) => { if (e.target.id !== 'xjIn') return; ui.job = e.target.value; const g = $('[data-fx="jadd"]'); if (g) g.disabled = !/when .+,\s*i want .+,\s*so .+/i.test(ui.job); });
|
|
569
|
-
$('#oMain').addEventListener('click', async (e) => {
|
|
570
|
-
const b = e.target.closest('[data-fx]'); if (!b || b.disabled || dlgKind !== 'fjobs') return;
|
|
571
|
-
const k = b.dataset.fx;
|
|
572
|
-
if (k === 'jadd') {
|
|
573
|
-
const line = (ui.job || '').trim(); b.disabled = true;
|
|
574
|
-
const res = await post('/api/pm-jobs/add', { line });
|
|
575
|
-
if (!res || res.ok !== true) { b.disabled = false; toast((res && res.error) || 'The job was not added.'); return; }
|
|
576
|
-
ui.job = ''; await load(); drawFocusDlg();
|
|
577
|
-
toastUndo('Job added.', async () => post('/api/pm-jobs/delete', { id: res.job.id }));
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
focusPress(k, b.dataset.k);
|
|
581
|
-
});
|
|
582
|
-
document.addEventListener('click', async (e) => {
|
|
583
|
-
const b = e.target.closest('#xFocus [data-xf]'); if (!b) return;
|
|
584
|
-
if (b.dataset.xf === 'more') { openFocus(); return; }
|
|
585
|
-
const nx = M.focus.suggestions[0]; if (!nx) return;
|
|
586
|
-
b.disabled = true;
|
|
587
|
-
const res = await post('/api/pm-items/focus/accept', fBody(nx));
|
|
588
|
-
if (!res || res.ok !== true) { b.disabled = false; toast((res && res.error) || 'The press was not recorded.'); return; }
|
|
589
|
-
toastUndo('In focus today.', async () => post('/api/pm-items/focus/clear', { key: nx.key }));
|
|
590
|
-
await load(); const n = $('#xFocus button'); if (n) n.focus();
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
/* ── the list: a check marks done, a row opens its dialog, keys and swipe act on a row ───────────────────────────────────── */
|
|
594
|
-
$('#qBody').addEventListener('click', async (e) => { await listClick(e); });
|
|
595
|
-
$('#waitBody').addEventListener('click', (e) => { listClick(e); });
|
|
596
|
-
async function listClick(e) {
|
|
597
|
-
const ck = e.target.closest('.wck');
|
|
598
|
-
if (ck && ck.dataset.open) { openRow(rowOf(ck.dataset.open)); return; }
|
|
599
|
-
if (ck) {
|
|
600
|
-
const id = ck.dataset.ck;
|
|
601
|
-
ck.setAttribute('aria-pressed', 'true');
|
|
602
|
-
const res = await pmPost('/api/pm-items/done', { id });
|
|
603
|
-
if (!res || res.ok !== true) { ck.setAttribute('aria-pressed', 'false'); toast((res && res.error) || 'The press was not recorded.'); return; }
|
|
604
|
-
toastUndo(SAID.done, () => pmPost('/api/pm-items/reopen', { id })); await load(); return;
|
|
605
|
-
}
|
|
606
|
-
const row = e.target.closest('.wrow'); if (row && e.target.closest('.wrh')) openRow(rowOf(row.dataset.key));
|
|
607
|
-
}
|
|
608
|
-
$('#revBtn').onclick = () => { const id = (M.review.ids || [])[0]; const r = (M.rows || []).find((x) => x.id === id); if (r) openRow(r); };
|
|
609
|
-
|
|
610
|
-
/* what a row does on its right and left: the same as the arrow keys and the drag. A row in Waiting has none. */
|
|
611
|
-
function sideOf(r) {
|
|
612
|
-
if (!r || r.list === 'waiting') return null;
|
|
613
|
-
const o = { list: true };
|
|
614
|
-
if (r.list === 'today') return {
|
|
615
|
-
r: r.agent === 'ready' ? { label: 'Review', ic: SVG.eye, fn: () => openRow(r) } : { label: 'Done', ic: null, fn: () => doneP(r, o) },
|
|
616
|
-
l: { label: 'Tomorrow', ic: SVG.moon, fn: () => deferP(r, addIso(M.today, 1), o) },
|
|
617
|
-
};
|
|
618
|
-
return { r: { label: 'In Today', ic: SVG.sun, fn: () => todayP(r, o) }, l: r.list === 'someday' ? null : { label: 'Someday', ic: SVG.moon, fn: () => somedayP(r, o) } };
|
|
619
|
-
}
|
|
620
|
-
let refocus = null; // the row to focus again once the list is drawn: { box, key, i }
|
|
621
|
-
function rowAct(r, side, box, i) {
|
|
622
|
-
const s = sideOf(r), a = s && s[side];
|
|
623
|
-
if (!a) return;
|
|
624
|
-
refocus = { box, key: r.key, i };
|
|
625
|
-
a.fn();
|
|
626
|
-
}
|
|
627
|
-
const rowsIn = (box) => $$('.wrow:not(.sm) .wrh', $(box));
|
|
628
|
-
function backFocus() {
|
|
629
|
-
if (!refocus) return;
|
|
630
|
-
const f = refocus; refocus = null;
|
|
631
|
-
const L = rowsIn(f.box), el = $(`${f.box} .wrow[data-key="${f.key}"] .wrh`) || L[Math.min(f.i, L.length - 1)];
|
|
632
|
-
if (el) el.focus();
|
|
633
|
-
}
|
|
634
|
-
for (const box of ['#qBody']) {
|
|
635
|
-
const root = $(box);
|
|
636
|
-
root.addEventListener('keydown', (e) => {
|
|
637
|
-
const h = e.target.closest && e.target.closest('.wrh');
|
|
638
|
-
if (!h || e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
|
|
639
|
-
const L = rowsIn(box), i = L.indexOf(h);
|
|
640
|
-
if (i < 0) return;
|
|
641
|
-
if (e.key === 'j' || e.key === 'k') { e.preventDefault(); const n = L[i + (e.key === 'j' ? 1 : -1)]; if (n) n.focus(); return; }
|
|
642
|
-
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') { e.preventDefault(); rowAct(rowOf(h.closest('.wrow').dataset.key), e.key === 'ArrowRight' ? 'r' : 'l', box, i); }
|
|
643
|
-
});
|
|
644
|
-
/* the drag: locks to sideways after 8 px, hands a vertical move of more than 12 px back to the page, acts past 90 px */
|
|
645
|
-
let sw = null, sup = 0; const TH = 90;
|
|
646
|
-
root.addEventListener('pointerdown', (e) => {
|
|
647
|
-
const r = e.target.closest('.wrow:not(.sm)');
|
|
648
|
-
if (!r || e.button > 0 || e.target.closest('.wck')) return;
|
|
649
|
-
const row = rowOf(r.dataset.key); if (!row || !sideOf(row)) return;
|
|
650
|
-
sw = { r, row, x: e.clientX, y: e.clientY, on: false, dx: 0, id: e.pointerId };
|
|
651
|
-
});
|
|
652
|
-
root.addEventListener('pointermove', (e) => {
|
|
653
|
-
if (!sw || e.pointerId !== sw.id) return;
|
|
654
|
-
const dx = e.clientX - sw.x, dy = e.clientY - sw.y;
|
|
655
|
-
if (!sw.on) {
|
|
656
|
-
if (Math.abs(dy) > 12 && Math.abs(dy) > Math.abs(dx)) { sw = null; return; }
|
|
657
|
-
if (Math.abs(dx) < 8 || Math.abs(dy) > Math.abs(dx)) return;
|
|
658
|
-
sw.on = true; try { sw.r.setPointerCapture(e.pointerId); } catch { /* none */ }
|
|
659
|
-
sw.w = sw.r.closest('.wrw'); sw.w.classList.add('xsw'); sw.w.insertAdjacentHTML('afterbegin', '<div class="xrv" aria-hidden="true"></div>'); sw.rv = $('.xrv', sw.w); sw.r.classList.add('xdr');
|
|
660
|
-
}
|
|
661
|
-
sw.dx = dx;
|
|
662
|
-
const side = dx > 0 ? 'r' : 'l', a = sideOf(sw.row)[side];
|
|
663
|
-
sw.rv.className = 'xrv ' + side;
|
|
664
|
-
sw.rv.innerHTML = a ? (a.ic ? `<svg class="i" viewBox="0 0 24 24">${a.ic}</svg>` : CHECK) + '<span>' + esc(a.label) + '</span>' : '';
|
|
665
|
-
sw.rv.style.setProperty('--d', RM ? (Math.abs(dx) >= TH && a ? 1 : 0) : a ? Math.min(1, Math.abs(dx) / TH) : 0);
|
|
666
|
-
if (!RM) sw.r.style.setProperty('--dx', dx * 0.55 + 'px');
|
|
667
|
-
});
|
|
668
|
-
const end = (e) => {
|
|
669
|
-
if (!sw) return;
|
|
670
|
-
const s = sw; sw = null;
|
|
671
|
-
if (!s.on) return;
|
|
672
|
-
sup = Date.now();
|
|
673
|
-
s.r.classList.remove('xdr'); s.r.style.removeProperty('--dx'); if (s.rv) s.rv.remove(); if (s.w) s.w.classList.remove('xsw');
|
|
674
|
-
if (e.type !== 'pointercancel' && Math.abs(s.dx) > TH) rowAct(s.row, s.dx > 0 ? 'r' : 'l', box, rowsIn(box).findIndex((h) => h.closest('.wrow') === s.r));
|
|
675
|
-
};
|
|
676
|
-
root.addEventListener('pointerup', end); root.addEventListener('pointercancel', end);
|
|
677
|
-
root.addEventListener('click', (e) => { if (Date.now() - sup < 120) { e.stopPropagation(); e.preventDefault(); } }, true);
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
/* ── add: one line, read by the Work page's own parser ─────────────────────────────────────────────────────── */
|
|
681
|
-
/* the hint under the add box shows while the box has focus; a message about a press stays until the next keystroke (premium-calmer-first-screen) */
|
|
682
|
-
const CAP_HINT = $('#capHint').textContent;
|
|
683
|
-
const sayCap = (t) => { $('#capHint').textContent = t; $('#tx').classList.add('said'); };
|
|
684
|
-
$('#capIn').addEventListener('input', () => { if ($('#tx').classList.contains('said')) { $('#tx').classList.remove('said'); $('#capHint').textContent = CAP_HINT; } });
|
|
685
|
-
$('#cap').addEventListener('submit', async (e) => {
|
|
686
|
-
e.preventDefault();
|
|
687
|
-
const inp = $('#capIn'), line = inp.value.trim();
|
|
688
|
-
if (!line) { sayCap('Write one line to add.'); return; }
|
|
689
|
-
const go = $('.capb'); go.disabled = true;
|
|
690
|
-
const res = await pmPost('/api/pm-items/add', { line });
|
|
691
|
-
go.disabled = false;
|
|
692
|
-
if (!res || res.ok !== true) { sayCap((res && res.error) || 'It was not added.'); return; }
|
|
693
|
-
inp.value = '';
|
|
694
|
-
const it = res.item || {};
|
|
695
|
-
if (!it.due) qTab = 'inbox'; // a line with no date waits in the inbox, so the queue opens there
|
|
696
|
-
const bits = [it.due ? 'due ' + it.due : null, it.priority].filter(Boolean);
|
|
697
|
-
sayCap('Added: ' + (it.title || line) + (bits.length ? ' (' + bits.join(', ') + ')' : '') + '. It is in your inbox until you place it.');
|
|
698
|
-
await load();
|
|
699
|
-
const fresh = it.id ? rowOf('work:' + it.id) : null; // a new item opens at once, so it can be placed
|
|
700
|
-
if (fresh) openRow(fresh);
|
|
701
|
-
});
|
|
702
|
-
|
|
703
|
-
/* ── load ────────────────────────────────────────────────────────────────────────────────────────────────── */
|
|
704
|
-
/* ?item=<id> (a row of the Briefing's "What you need to do"): open that item's dialog once, after the first read. */
|
|
705
|
-
let ASKED = new URLSearchParams(location.search).get('item');
|
|
706
|
-
function openAsked() {
|
|
707
|
-
if (!ASKED) return;
|
|
708
|
-
const r = rowOf('work:' + ASKED); ASKED = null;
|
|
709
|
-
if (r) openRow(r); else toast('That item is not on your list any more.');
|
|
710
|
-
}
|
|
711
|
-
async function load() {
|
|
712
|
-
let r = null, status = 0;
|
|
713
|
-
try { const res = await fetch('/api/my-work-premium', { credentials: 'same-origin' }); status = res.status; r = await res.json(); } catch { r = null; }
|
|
714
|
-
if (HOME && (!r || !r.ok)) { $('#qNote').textContent = 'Your list could not be read, so it shows nothing rather than guess.' + (r && r.error ? ' The reason: ' + r.error : ''); return; }
|
|
715
|
-
if (!r || !r.ok) {
|
|
716
|
-
$('#snap').textContent = 'Your list could not be read';
|
|
717
|
-
$('#brief').textContent = 'My work could not read your list, so it shows nothing rather than guess.' + (r && r.error ? ' The reason: ' + r.error : status ? ' (the server answered ' + status + ')' : ' The server did not answer.');
|
|
718
|
-
return;
|
|
719
|
-
}
|
|
720
|
-
M = r.model; draw();
|
|
721
|
-
openAsked();
|
|
722
|
-
const mine = dlgOpen() && ((dlgKind === 'item' && openR && S.key === openR.key) || (dlgKind === 'fjobs' && S.key === popKey('focus', 'today')));
|
|
723
|
-
if (mine && dlgKind === 'item') refreshOpen(); else if (mine) drawFocusDlg();
|
|
724
|
-
}
|
|
725
|
-
setInterval(() => { if (M && M.agents && M.agents.counts.running > 0 && !document.hidden) load(); }, 15000); // an agent's state changes without a press
|
|
726
|
-
if (!HOME) { chatAbout('work:this-page', 'My work'); $('#brief').textContent = 'Reading your list.'; } // the rail's Chat opens the Chat page on this page's conversation (premium-chat-page)
|
|
727
|
-
/* Home: a row of Needs you that is an item of your list opens that item's dialog here (premium.js sends it). */
|
|
728
|
-
document.addEventListener('pmos:item', (e) => { ASKED = e.detail && e.detail.id; if (M) openAsked(); });
|
|
729
|
-
load();
|