create-pmos 0.408.0 → 0.410.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 +25 -25
- package/payload/KIT-VERSION +1 -1
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/state/discoveries.md +1 -1
- package/workspace/board-programs-test.js +1 -1
- package/workspace/board-wf-shot.js +45 -0
- package/workspace/board-workflows-test.js +186 -0
- package/workspace/briefing-premium-board-test.js +2 -2
- package/workspace/briefing-premium-initiative-test.js +1 -1
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/board-workflows-facts.js +49 -0
- package/workspace/fixtures/workflows-facts.js +53 -0
- package/workspace/guide/home.md +1 -0
- package/workspace/guide/index.md +1 -0
- package/workspace/guide/programs.md +2 -1
- package/workspace/guide/workflows.md +58 -0
- package/workspace/ini-workflow-test.js +177 -0
- package/workspace/lib/board-premium.js +30 -5
- package/workspace/lib/board-trail.js +24 -7
- package/workspace/lib/briefing-premium-agent.js +3 -0
- package/workspace/lib/engine/boards.js +30 -2
- package/workspace/lib/engine/workflows.js +204 -0
- package/workspace/lib/pmos-verbs.js +3 -0
- package/workspace/lib/programs.js +22 -7
- package/workspace/lib/route-modules.js +1 -0
- package/workspace/lib/routes-boards.js +157 -7
- package/workspace/lib/routes-programs.js +5 -0
- package/workspace/lib/routes-workflows.js +105 -0
- package/workspace/lib/workflow-chat.js +26 -0
- package/workspace/lib/workflow-cli.js +141 -0
- package/workspace/lib/workflows-store.js +108 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/program-charter-test.js +243 -0
- package/workspace/program-panel-test.js +1 -1
- package/workspace/public/pm/bd-acts.js +10 -5
- package/workspace/public/pm/bd-asks.js +2 -2
- package/workspace/public/pm/bd-prog-panel.js +36 -15
- package/workspace/public/pm/bd-prog.js +14 -4
- package/workspace/public/pm/bd-views.js +128 -45
- package/workspace/public/pm/bd-wf.js +99 -0
- package/workspace/public/pm/cozy-board.css +67 -6
- package/workspace/public/pm/cozy-evmodel.js +1 -1
- package/workspace/public/pm/cozy-panel.css +12 -6
- package/workspace/public/pm/cozy-settings.js +4 -2
- package/workspace/public/pm/cozy-viewer.js +36 -9
- package/workspace/public/pm/cozy-vw-shell.css +8 -0
- package/workspace/public/pm/goal-chat.js +1 -1
- package/workspace/public/pm/home-app.js +17 -9
- package/workspace/public/pm/home-ini-model.js +2 -2
- package/workspace/public/pm/home-ini.css +30 -0
- package/workspace/public/pm/home-ini.js +52 -9
- package/workspace/public/pm/home-list.js +10 -5
- package/workspace/public/pm/home-today.js +5 -5
- package/workspace/public/pm/ini-wf-model.js +91 -0
- package/workspace/public/pm/ini-wf.js +160 -0
- package/workspace/public/pm/premium-board.js +98 -30
- package/workspace/public/pm/premium-initiative-head.js +18 -8
- package/workspace/public/pm/program-charter.css +135 -0
- package/workspace/public/pm/program-charter.js +333 -0
- package/workspace/public/pm/program-model.js +48 -5
- package/workspace/public/pm/wf-edit.js +119 -0
- package/workspace/public/pm/wf-model.js +48 -0
- package/workspace/public/pm/wf-page.css +162 -0
- package/workspace/public/pm/wf-page.js +398 -0
- package/workspace/public/pm/wf-stage.js +187 -0
- package/workspace/public/premium-workflows.html +31 -0
- package/workspace/public/premium.html +1 -0
- package/workspace/server.js +1 -1
- package/workspace/skills/workflow-setup.skill +57 -0
- package/workspace/test-lists/ini-workflow.json +6 -0
- package/workspace/test-lists/program-charter.json +9 -0
- package/workspace/test-lists/workflows-board.json +13 -0
- package/workspace/test-lists/workflows-setup.json +13 -0
- package/workspace/test-lists/workflows.json +5 -0
- package/workspace/workflows-setup-test.js +346 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/* pm/program-charter.css — a program's charter (pm/program-charter.js; canvas MsBCharter, MsB1First, MsB2Drafts, MsB3Pick, MsB5Leave,
|
|
2
|
+
* MsB6Problems, MsB7Done, MsBPhone). program-charter.js loads it once, so it works wherever the program panel opens (Board, Home).
|
|
3
|
+
* Token vars only, over pm/cozy.css; the program's purple falls back to the frames' when the page sets no --pp-prog.
|
|
4
|
+
* Motion: one warn ripple on the amber dot (warning level), none without prefers-reduced-motion: no-preference. Every class starts with pc-. */
|
|
5
|
+
.pc-vw { --pc-prog: var(--pp-prog, var(--cz-c-6b4fa3)); --pc-progbg: var(--pp-progbg, rgba(107,79,163,.10)); --pc-field: color-mix(in srgb, var(--cz-ink) 12%, transparent); --pc-amber: var(--cz-risk); --pc-amberdot: var(--pp-amber, var(--cz-c-d4a13a)); }
|
|
6
|
+
.pc { container-type: inline-size; position: relative; display: flex; flex-direction: column; gap: 14px; }
|
|
7
|
+
|
|
8
|
+
/* the fields: two columns on a desk, one on a phone */
|
|
9
|
+
.pc-fx { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
|
|
10
|
+
.pc-fx label, .pc-lab { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 800; color: var(--cz-ink3); min-width: 0; }
|
|
11
|
+
.pc-fx .w2 { grid-column: 1 / 3; }
|
|
12
|
+
.pc-fi { box-sizing: border-box; height: 40px; border-radius: 12px; background: var(--cz-card); border: 1px solid var(--pc-field); padding: 0 12px; font: inherit; font-size: 14px; font-weight: 700; color: var(--cz-ink); min-width: 0; width: 100%; outline: 0; }
|
|
13
|
+
.pc-fi::placeholder, .pc-ta::placeholder { color: var(--cz-ink3); font-weight: 600; }
|
|
14
|
+
.pc-fi:focus, .pc-ta:focus { border-color: var(--cz-blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--cz-blue) 14%, transparent); }
|
|
15
|
+
.pc-ta { box-sizing: border-box; font: inherit; font-size: 13.5px; font-weight: 700; color: var(--cz-ink); border-radius: 12px; background: var(--cz-card); border: 1px solid var(--pc-field); padding: 10px 12px; height: 66px; resize: none; outline: 0; width: 100%; }
|
|
16
|
+
.pc-sp { display: flex; align-items: center; gap: 8px; }
|
|
17
|
+
.pc-sp .pc-fd { width: 150px; }
|
|
18
|
+
.pc-sp .or { font-size: 12px; color: var(--cz-ink3); font-weight: 700; }
|
|
19
|
+
.pc-fd { box-sizing: border-box; height: 40px; border-radius: 12px; background: var(--cz-card); border: 1px solid var(--pc-field); padding: 0 10px 0 12px; font: inherit; font-size: 13px; font-weight: 700; display: inline-flex; align-items: center; gap: 8px; color: var(--cz-ink2); white-space: nowrap; cursor: pointer; min-width: 0; }
|
|
20
|
+
.pc-fd.q { color: var(--cz-ink3); font-weight: 600; }
|
|
21
|
+
.pc-fd svg, .pc-wch svg, .pc-mini svg, button.pc-ln svg { flex: none; }
|
|
22
|
+
.pc-fd span { overflow: hidden; text-overflow: ellipsis; }
|
|
23
|
+
.pc-fd:focus-visible, .pc-wch:focus-visible, .pc-ib:focus-visible, .pc-mini:focus-visible, .pc-ln:focus-visible, .pc-mi:focus-visible, .pc-ch:focus-visible, .pc-sv:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; }
|
|
24
|
+
.pc-dt { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; margin: 0; }
|
|
25
|
+
.pc-lab .pc-dt, .pc-ln .pc-dt { position: absolute; }
|
|
26
|
+
.pc .bad { box-shadow: 0 0 0 1.5px var(--pc-amberdot) !important; border-color: transparent !important; }
|
|
27
|
+
|
|
28
|
+
/* what needs a look, said in place: amber, with the warning ripple */
|
|
29
|
+
.pc-warn { margin: 0; font-size: 12px; font-weight: 700; color: var(--pc-amber); display: flex; align-items: center; gap: 6px; padding: 0 10px 8px 34px; }
|
|
30
|
+
.pc-lab .pc-warn { padding: 2px 0 0; }
|
|
31
|
+
.pc-warn i { width: 7px; height: 7px; border-radius: 50%; background: var(--pc-amberdot); flex: none; position: relative; }
|
|
32
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
33
|
+
.pc-warn i::after { content: ""; position: absolute; inset: -1.5px; border-radius: 50%; background: var(--pc-amberdot); animation: pcwarn 3s ease-out infinite; }
|
|
34
|
+
}
|
|
35
|
+
@keyframes pcwarn { 0% { transform: scale(1); opacity: .35; } 50% { transform: scale(2); opacity: 0; } 100% { transform: scale(2); opacity: 0; } }
|
|
36
|
+
|
|
37
|
+
/* the milestones: one grid per row, so every row lines up */
|
|
38
|
+
.pc-lbl { display: flex; align-items: center; font-size: 12px; font-weight: 800; color: var(--cz-ink3); margin: 0 0 6px; }
|
|
39
|
+
.pc-lim { margin-left: auto; font-weight: 600; }
|
|
40
|
+
.pc-lim.full { color: var(--pc-amber); font-weight: 700; }
|
|
41
|
+
.pc-ml { border: 1px solid var(--cz-hair); border-radius: 16px; display: flex; flex-direction: column; }
|
|
42
|
+
.pc-ml > :first-child { border-top: 0 !important; border-radius: 16px 16px 0 0; }
|
|
43
|
+
.pc-ml > :last-child { border-radius: 0 0 16px 16px; }
|
|
44
|
+
.pc-lnw { position: relative; border-top: 1px solid var(--cz-hair); }
|
|
45
|
+
.pc-ln { display: grid; grid-template-columns: 18px minmax(0, 1fr) 132px 250px 72px; align-items: center; gap: 8px; padding: 8px 10px; }
|
|
46
|
+
.pc-ln .pc-fi { height: 36px; font-size: 13px; }
|
|
47
|
+
.pc-ln .pc-fd { height: 36px; font-size: 12.5px; width: 100%; }
|
|
48
|
+
.pc-ln.sug { background: color-mix(in srgb, var(--pc-progbg) 40%, var(--cz-card)); grid-template-columns: 18px minmax(0, 1fr) 132px 250px 72px; }
|
|
49
|
+
.pc-ln.sug .pc-fi { border-style: dashed; border-color: color-mix(in srgb, var(--pc-prog) 40%, transparent); }
|
|
50
|
+
.pc-ln.dn2 .pc-fi { color: var(--cz-ink3); }
|
|
51
|
+
button.pc-ln { all: unset; box-sizing: border-box; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 8px 10px; min-height: 44px; border-top: 1px solid var(--cz-hair); font-size: 13px; }
|
|
52
|
+
button.pc-ln.dn { background: var(--bd-row, var(--cz-well)); color: var(--cz-ink3); }
|
|
53
|
+
button.pc-ln.dn b { flex: 1; font-weight: 700; color: var(--cz-ink3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
54
|
+
button.pc-ln.addl { color: var(--pc-prog); font-weight: 700; width: 100%; }
|
|
55
|
+
.pc-dm { width: 10px; height: 10px; transform: rotate(45deg); border-radius: 3px; background: var(--cz-card); border: 2px solid color-mix(in srgb, var(--pc-prog) 32%, transparent); display: inline-block; justify-self: center; box-sizing: border-box; }
|
|
56
|
+
.pc-dm.d { background: var(--pc-prog); border-color: var(--pc-prog); }
|
|
57
|
+
.pc-dm.n { border-color: var(--pc-prog); box-shadow: 0 0 0 4px var(--pc-progbg); }
|
|
58
|
+
.pc-spark { color: var(--pc-prog); display: inline-flex; justify-content: center; }
|
|
59
|
+
.pc-wch { box-sizing: border-box; height: 36px; width: 100%; border-radius: 12px; background: var(--cz-card); border: 1px solid var(--pc-field); padding: 0 8px 0 10px; font: inherit; font-size: 12.5px; font-weight: 700; color: var(--cz-ink2); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer; min-width: 0; }
|
|
60
|
+
.pc-wch span:not(.sq):not(.bx) { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; }
|
|
61
|
+
.pc-wch.ck { color: var(--cz-ink3); }
|
|
62
|
+
.pc-wch.gone { color: var(--pc-amber); border-color: color-mix(in srgb, var(--pc-amberdot) 50%, transparent); }
|
|
63
|
+
.pc .sq { width: 9px; height: 9px; transform: rotate(45deg); border-radius: 2px; background: var(--pc-prog); flex: none; margin: 0 2px; }
|
|
64
|
+
.pc .bx { width: 13px; height: 13px; border-radius: 4px; border: 1.5px solid var(--cz-ink3); flex: none; box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; }
|
|
65
|
+
.pc .bx.on { background: var(--pc-prog); border-color: var(--pc-prog); color: var(--cz-card); }
|
|
66
|
+
.pc-via { font-size: 12px; font-weight: 600; color: var(--cz-ink3); white-space: nowrap; }
|
|
67
|
+
.pc-ends { display: inline-flex; justify-content: flex-end; gap: 0; }
|
|
68
|
+
.pc-ib { width: 32px; height: 32px; border-radius: 999px; border: 0; background: transparent; color: var(--cz-ink2); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; }
|
|
69
|
+
.pc-ib.del { color: var(--cz-red); }
|
|
70
|
+
@media (hover: hover) { .pc-ib:hover { background: var(--cz-well); } }
|
|
71
|
+
.pc-mini { height: 30px; padding: 0 10px; border-radius: 999px; font: inherit; font-size: 12px; font-weight: 700; color: var(--cz-ink2); border: 1px solid var(--cz-hair); background: var(--cz-card); display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; cursor: pointer; justify-self: start; }
|
|
72
|
+
.pc-sugh { display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-size: 12.5px; color: var(--cz-ink2); background: var(--pc-progbg); }
|
|
73
|
+
.pc-sugh > svg { color: var(--pc-prog); flex: none; }
|
|
74
|
+
.pc-sugh span { flex: 1; }
|
|
75
|
+
.pc-sugh b { color: var(--pc-prog); }
|
|
76
|
+
|
|
77
|
+
/* the picker (MsB3Pick): a menu under the row's "done when" press */
|
|
78
|
+
.pc-menu { position: absolute; z-index: 6; right: 52px; top: 44px; width: 330px; background: var(--cz-card); border-radius: 18px; box-shadow: var(--cz-sheet), 0 0 0 1px var(--cz-hair); padding: 6px; display: flex; flex-direction: column; }
|
|
79
|
+
.pc-mhd { margin: 0; font-size: 11.5px; font-weight: 800; color: var(--cz-ink3); padding: 8px 10px 4px; }
|
|
80
|
+
.pc-mhd.pr { padding-top: 6px; }
|
|
81
|
+
.pc-mi { all: unset; box-sizing: border-box; cursor: pointer; display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 10px; border-radius: 12px; font-size: 13px; font-weight: 700; color: var(--cz-ink); width: 100%; }
|
|
82
|
+
@media (hover: hover) { .pc-mi:hover { background: var(--cz-well); } }
|
|
83
|
+
.pc-mi .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
84
|
+
.pc-mi .bx { width: 16px; height: 16px; border-radius: 5px; }
|
|
85
|
+
/* which ◆ stage counts for an initiative whose own workflow has two or more (D99): a quiet press under its row, a press moves to the next */
|
|
86
|
+
.pc-mi.pc-mst { min-height: 32px; padding-left: 36px; font-weight: 600; color: var(--cz-ink3); }
|
|
87
|
+
.pc-ch.pc-mst { font-weight: 600; color: var(--cz-ink3); }
|
|
88
|
+
.pc-mi .r { font-size: 12px; font-weight: 600; color: var(--cz-ink3); }
|
|
89
|
+
.pc-mi .r.lt { color: var(--pc-amber); font-weight: 700; }
|
|
90
|
+
.pc-msep { display: block; height: 1px; background: var(--cz-hair); margin: 4px 6px; }
|
|
91
|
+
|
|
92
|
+
/* leaving with changes (MsB5Leave): one question under ← */
|
|
93
|
+
.pc-ask { position: absolute; z-index: 7; left: 0; top: -4px; width: 280px; background: var(--cz-card); border-radius: 18px; box-shadow: var(--cz-sheet), 0 0 0 1px var(--cz-hair); padding: 14px; display: flex; flex-direction: column; gap: 8px; }
|
|
94
|
+
.pc-ask p { margin: 0; font-size: 13.5px; font-weight: 800; }
|
|
95
|
+
.pc-ask .t { font-size: 12px; color: var(--cz-ink2); }
|
|
96
|
+
.pc-ask .t.bad { color: var(--pc-amber); font-weight: 700; box-shadow: none !important; }
|
|
97
|
+
.pc-ask .row { display: flex; gap: 8px; margin-top: 4px; }
|
|
98
|
+
.pc-sv { height: 32px; padding: 0 14px; border-radius: 999px; border: 0; background: var(--cz-ink); color: var(--cz-card); font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; }
|
|
99
|
+
.pc-sv:disabled { opacity: .45; cursor: default; }
|
|
100
|
+
|
|
101
|
+
/* the Viewer at its side width (560 px on the Board): a milestone takes two lines, the name over its date and what it waits on */
|
|
102
|
+
@container (max-width: 720px) {
|
|
103
|
+
.pc-ln, .pc-ln.sug { grid-template-columns: 18px 128px minmax(0, 1fr) auto; }
|
|
104
|
+
.pc-ln > [data-f="name"] { grid-column: 2 / 4; grid-row: 1; }
|
|
105
|
+
.pc-ln > .pc-ends { grid-column: 4; grid-row: 1; }
|
|
106
|
+
.pc-ln > .pc-fd { grid-column: 2; grid-row: 2; }
|
|
107
|
+
.pc-ln > .pc-wch, .pc-ln > .pc-via, .pc-ln > .pc-mini { grid-column: 3 / 5; grid-row: 2; }
|
|
108
|
+
.pc-menu { right: 8px; top: 92px; }
|
|
109
|
+
.pc-sp .pc-fd { width: auto; flex: 1; }
|
|
110
|
+
}
|
|
111
|
+
@container (max-width: 520px) {
|
|
112
|
+
.pc-fx { grid-template-columns: 1fr; }
|
|
113
|
+
.pc-fx .w2 { grid-column: auto; }
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/* phone (MsBPhone): one column; a milestone's parts stack; the picker is chips under the row */
|
|
117
|
+
@media (max-width: 760px) {
|
|
118
|
+
.pc-fx { grid-template-columns: 1fr; }
|
|
119
|
+
.pc-fx .w2 { grid-column: auto; }
|
|
120
|
+
.pc-sp .pc-fd { width: auto; flex: 1; }
|
|
121
|
+
.pc-ln, .pc-ln.sug { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px; }
|
|
122
|
+
.pc-ln .pc-fi, .pc-ln .pc-fd, .pc-ln .pc-wch { flex: 1 1 100%; height: 40px; }
|
|
123
|
+
.pc-ln > .pc-dm { flex: none; margin: 2px 4px 0; }
|
|
124
|
+
.pc-ln > .pc-spark { flex: 0 0 100%; justify-content: flex-start; }
|
|
125
|
+
.pc-ln .pc-ends { flex: 1 1 100%; }
|
|
126
|
+
.pc-warn { padding: 0 10px 8px 10px; }
|
|
127
|
+
.pc-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 0 10px 12px; }
|
|
128
|
+
.pc-chips .dw { flex-basis: 100%; margin: 0; font-size: 12px; font-weight: 800; color: var(--cz-ink3); }
|
|
129
|
+
.pc-chips .or { font-size: 12px; color: var(--cz-ink3); font-weight: 700; }
|
|
130
|
+
.pc-ch { height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--cz-ink) 14%, transparent); background: var(--cz-card); font: inherit; font-size: 12.5px; font-weight: 700; color: var(--cz-ink2); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer; max-width: 100%; }
|
|
131
|
+
.pc-ch .sq { background: transparent; border: 1.5px solid currentColor; }
|
|
132
|
+
.pc-ch[aria-pressed="true"] { background: var(--pc-progbg); border-color: color-mix(in srgb, var(--pc-prog) 35%, transparent); color: var(--pc-prog); }
|
|
133
|
+
.pc-ch[aria-pressed="true"] .sq { background: var(--pc-prog); }
|
|
134
|
+
.pc-ask { left: 0; right: 0; width: auto; }
|
|
135
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/* pm/program-charter.js — a program's charter, the one place its fields and milestones are set (feedback batch item 4; canvas MsBCharter,
|
|
2
|
+
* MsB0Entry, MsB1First, MsB2Drafts, MsB3Pick, MsB4Rename, MsB5Leave, MsB6Problems, MsB7Done, MsBPhone; rules on the sticky msRules).
|
|
3
|
+
*
|
|
4
|
+
* openCharter(o) opens the charter in the Viewer as a drill-in of the program (← comes back to it). o: { VW, pmPost, p the program of
|
|
5
|
+
* GET /api/programs, st its programState, rename the Viewer's rename option for the program, nameOf(id) an initiative's
|
|
6
|
+
* title from any board read, at 'milestones' to open there, reload() reads the programs again, say(msg) the toast }
|
|
7
|
+
* The pure parts, for program-charter.test.mjs:
|
|
8
|
+
* draftOf(p, st) the form's state from the record: { title, goal, owner, why, start, target, jira, ms: [row] }
|
|
9
|
+
* changesOf(a, b) what differs, in words: ["Pilot live moved to Nov 25", "Support ready deleted", "the goal"]
|
|
10
|
+
* problemsOf(D, members) what stops a save: { span, nameless: [id], left: [{ id, ini }] } (MsB6Problems)
|
|
11
|
+
* lateOf(m, inis) the initiative a milestone waits on that is set to pass its ◆ stage after the milestone's date, or null (MsB3Pick)
|
|
12
|
+
* A row's `stages` ({ [initiative]: ◆ stage key }, D99) names which ◆ stage of an initiative's own workflow counts; the picker shows a
|
|
13
|
+
* "◆ Award" press under an initiative whose workflow has two or more, and a press moves to the next. None picked = its first ◆ stage.
|
|
14
|
+
* draftsOf(st, target) milestones drafted from the ◆ Deliver days of its initiatives, and a review at the target (MsB2Drafts)
|
|
15
|
+
* charterOut(D) the charter as POST /api/programs/save takes it: every field, with the program id and stable milestone ids
|
|
16
|
+
*
|
|
17
|
+
* The rules (msRules): the charter is the one editor: goal, owner, span, Jira (optional) and up to 12 milestones; the name is the Viewer's
|
|
18
|
+
* rename press. One Save for the whole charter, drawn only after a change; leaving with changes asks once, Save or Discard. A milestone is
|
|
19
|
+
* done when the initiatives it waits on all pass their ◆ stage, or it is a check the PM ticks. A date before an initiative's ◆ day warns in
|
|
20
|
+
* amber and does not stop a save; a span that ends before it starts, a nameless row and an initiative that left the program do. Order is by
|
|
21
|
+
* date, so there is no drag handle. Drafts are dashed and nothing is written until Save. A save resends every field and the program id, so
|
|
22
|
+
* nothing is lost (POST /api/programs/save: the last line wins); new milestones get ids from their names, never from their place. */
|
|
23
|
+
import { milestoneStep, shortDay } from './program-model.js';
|
|
24
|
+
|
|
25
|
+
const MAX = 12;
|
|
26
|
+
const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
27
|
+
const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
|
28
|
+
const SV = (d, w, sw) => `<svg viewBox="0 0 24 24" width="${w || 16}" height="${w || 16}" fill="none" stroke="currentColor" stroke-width="${sw || 1.8}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`;
|
|
29
|
+
const I = {
|
|
30
|
+
cal: 'M4 6h16v14H4zM4 10h16M8 3v4M16 3v4', chev: 'M7 10l5 5 5-5', chevR: 'M10 7l5 5-5 5', plus: 'M12 5v14M5 12h14', check: 'M5 12l5 5 9-10',
|
|
31
|
+
x: 'M6 6l12 12M18 6L6 18', del: 'M4 7h16M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3', spark: 'M12 3v4M12 17v4M3 12h4M17 12h4M6 6l2.5 2.5M15.5 15.5L18 18M6 18l2.5-2.5M15.5 8.5L18 6',
|
|
32
|
+
};
|
|
33
|
+
const ID_RE = /^[a-z0-9][a-z0-9-]{0,60}$/;
|
|
34
|
+
const slug = (t) => String(t || '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 50);
|
|
35
|
+
const dayOf = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
36
|
+
const longDay = (iso) => { const d = dayOf(iso); return d ? MON[d.getMonth()] + ' ' + d.getDate() + ', ' + d.getFullYear() : ''; };
|
|
37
|
+
const list = (a) => (a.length < 2 ? a.join('') : a.slice(0, -1).join(', ') + ' and ' + a[a.length - 1]);
|
|
38
|
+
const byDate = (a, b) => String(a.date || '9999').localeCompare(String(b.date || '9999'));
|
|
39
|
+
let seq = 0;
|
|
40
|
+
(function sheet() { // once, at import: the charter opens on the Board and in Home's Viewer, and neither page links its look
|
|
41
|
+
if (typeof document === 'undefined' || !document.head || typeof document.getElementById !== 'function' || document.getElementById('pcCss')) return;
|
|
42
|
+
const l = document.createElement('link'); l.id = 'pcCss'; l.rel = 'stylesheet';
|
|
43
|
+
try { l.href = new URL('./program-charter.css', import.meta.url).href; } catch { l.href = '/pm/program-charter.css'; }
|
|
44
|
+
document.head.appendChild(l);
|
|
45
|
+
})();
|
|
46
|
+
|
|
47
|
+
/* ── the pure parts ── */
|
|
48
|
+
/** The form's state from the record. A row: { id, name, date, waits, check, done, fixed (done by its initiatives), isNew?, draft? } */
|
|
49
|
+
export function draftOf(p, st) {
|
|
50
|
+
const S = new Map(((st && st.milestones) || []).map((m) => [m.id, m]));
|
|
51
|
+
const ms = ((p && p.milestones) || []).map((m) => {
|
|
52
|
+
const waits = (m.waits || []).slice(), check = !waits.length, s = S.get(m.id);
|
|
53
|
+
return { id: m.id, name: m.name || '', date: m.date || '', waits, stages: { ...(m.stages || {}) }, check, done: check ? m.done === true : false, fixed: !check && !!(s && s.done) };
|
|
54
|
+
});
|
|
55
|
+
return { title: (p && p.title) || '', goal: (p && p.goal) || '', owner: (p && p.owner) || '', why: (p && p.why) || '', start: (p && p.start) || '', target: (p && p.target) || '', jira: (p && p.jira) || '', ms };
|
|
56
|
+
}
|
|
57
|
+
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
58
|
+
/** A row's ◆ stage picks (D99), only for the initiatives it waits on, in a stable order: { [initiative]: stage key } */
|
|
59
|
+
const picks = (m) => Object.fromEntries(Object.entries((m && m.stages) || {}).filter(([k]) => (m.waits || []).includes(k)).sort(([a], [b]) => a.localeCompare(b)));
|
|
60
|
+
const FIELDS = [['goal', 'the goal'], ['owner', 'the owner'], ['why', 'the why'], ['jira', 'the Jira link']];
|
|
61
|
+
/** What differs between the record (a) and the form (b), in words, the milestones first (MsB5Leave). */
|
|
62
|
+
export function changesOf(a, b) {
|
|
63
|
+
const out = [], A = new Map(a.ms.map((m) => [m.id, m]));
|
|
64
|
+
for (const m of b.ms) {
|
|
65
|
+
const o = A.get(m.id), name = m.name || 'A milestone';
|
|
66
|
+
if (!o) { out.push(name + ' added'); continue; }
|
|
67
|
+
if (o.name !== m.name) out.push(o.name + ' renamed to ' + (m.name || 'nothing'));
|
|
68
|
+
if (o.date !== m.date) out.push(name + (m.date ? ' moved to ' + shortDay(m.date) : ' has no date'));
|
|
69
|
+
if (!same(o.waits, m.waits) || o.check !== m.check) out.push(name + (m.check ? ' is ticked by you' : ' waits on other initiatives'));
|
|
70
|
+
else if (!m.check && !same(picks(o), picks(m))) out.push(name + ' waits on another ◆ stage');
|
|
71
|
+
if (o.check && m.check && o.done !== m.done) out.push(name + (m.done ? ' done' : ' open again'));
|
|
72
|
+
}
|
|
73
|
+
for (const o of a.ms) if (!b.ms.some((m) => m.id === o.id)) out.push(o.name + ' deleted');
|
|
74
|
+
for (const [k, w] of FIELDS) if ((a[k] || '') !== (b[k] || '')) out.push(w);
|
|
75
|
+
if (a.start !== b.start || a.target !== b.target) out.push('the span');
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
/** The changes as one sentence: "Pilot live moved to Nov 25, Support ready deleted, and the goal." */
|
|
79
|
+
export function changesLine(L) {
|
|
80
|
+
if (!L.length) return '';
|
|
81
|
+
const s = L.length < 3 ? L.join(' and ') : L.slice(0, -1).join(', ') + ', and ' + L[L.length - 1];
|
|
82
|
+
return s.charAt(0).toUpperCase() + s.slice(1) + '.';
|
|
83
|
+
}
|
|
84
|
+
/** What stops a save (MsB6Problems): the span ends before it starts; a row with no name; a row waits on an initiative no longer in the program. */
|
|
85
|
+
export function problemsOf(D, members) {
|
|
86
|
+
const ids = new Set((members || []).map((m) => m.initiative));
|
|
87
|
+
const left = [];
|
|
88
|
+
for (const m of D.ms) for (const w of m.check ? [] : m.waits) if (!ids.has(w)) left.push({ id: m.id, ini: w });
|
|
89
|
+
return { span: !!(D.start && D.target && D.start > D.target), nameless: D.ms.filter((m) => !String(m.name).trim()).map((m) => m.id), left,
|
|
90
|
+
any: !!(D.start && D.target && D.start > D.target) || D.ms.some((m) => !String(m.name).trim()) || left.length > 0 };
|
|
91
|
+
}
|
|
92
|
+
/** The initiative a milestone waits on that is set to pass its ◆ stage after the milestone's date (the latest one), or null (MsB3Pick). */
|
|
93
|
+
export function lateOf(m, inis) {
|
|
94
|
+
if (!m || m.check || !m.date) return null;
|
|
95
|
+
let late = null;
|
|
96
|
+
for (const id of m.waits) {
|
|
97
|
+
const i = (inis || []).find((x) => x.id === id), d = i && milestoneStep(i.row, m).date;
|
|
98
|
+
if (d && d > m.date && (!late || d > late.date)) late = { id, title: i.title, date: d, label: milestoneStep(i.row, m).label };
|
|
99
|
+
}
|
|
100
|
+
return late;
|
|
101
|
+
}
|
|
102
|
+
/** Drafts from the ◆ days of its initiatives (one each, on that day), and a review at the target the PM ticks (MsB2Drafts). */
|
|
103
|
+
export function draftsOf(st, target) {
|
|
104
|
+
const out = [];
|
|
105
|
+
for (const i of (st && st.inis) || []) {
|
|
106
|
+
const s = milestoneStep(i.row);
|
|
107
|
+
if (s.date) out.push({ id: newId(), name: i.title + ' ' + (s.key === 'deliver' ? 'delivered' : 'at ' + s.label), date: s.date, waits: [i.id], check: false, done: false, isNew: true, draft: true });
|
|
108
|
+
}
|
|
109
|
+
if (target) out.push({ id: newId(), name: 'Program review', date: target, waits: [], check: true, done: false, isNew: true, draft: true });
|
|
110
|
+
return out.sort(byDate).slice(0, MAX);
|
|
111
|
+
}
|
|
112
|
+
const newId = () => 'new-' + (++seq);
|
|
113
|
+
/** The charter as POST /api/programs/save takes it. A new milestone's id comes from its name and no other milestone has it. */
|
|
114
|
+
export function charterOut(id, D) {
|
|
115
|
+
const taken = new Set(D.ms.filter((m) => !m.isNew && ID_RE.test(m.id)).map((m) => m.id));
|
|
116
|
+
const ms = D.ms.slice().sort(byDate).map((m) => {
|
|
117
|
+
let mid = m.id;
|
|
118
|
+
if (m.isNew || !ID_RE.test(mid)) { const base = slug(m.name) || 'milestone'; mid = base; for (let n = 2; taken.has(mid); n++) mid = base + '-' + n; taken.add(mid); }
|
|
119
|
+
const st = m.check ? {} : picks(m);
|
|
120
|
+
return { id: mid, name: String(m.name).replace(/\s+/g, ' ').trim(), date: m.date || '', waits: m.check ? [] : m.waits.slice(), ...(Object.keys(st).length ? { stages: st } : {}), ...(m.check ? { done: !!m.done } : {}) };
|
|
121
|
+
});
|
|
122
|
+
return { id, title: D.title, owner: D.owner.trim(), goal: D.goal.trim(), why: D.why.trim(), start: D.start || '', target: D.target || '', jira: D.jira.trim(), milestones: ms };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* ── the page ── */
|
|
126
|
+
let C = null; // the charter shown: { o, p, st, orig, D, fold, pick, ask, busy }
|
|
127
|
+
const isPhone = () => typeof matchMedia === 'function' && matchMedia('(max-width: 760px)').matches;
|
|
128
|
+
const dirty = () => !!C && changesOf(C.orig, C.D).length > 0;
|
|
129
|
+
|
|
130
|
+
function fieldsHtml(D, P) {
|
|
131
|
+
const dt = (k, iso, empty, bad) => `<button type="button" class="pc-fd${iso ? '' : ' q'}${bad ? ' bad' : ''}" data-pc="date" data-f="${k}" aria-label="${esc((k === 'start' ? 'Start ' : 'Target ') + (iso ? longDay(iso) : 'not set') + '. Change')}">${SV(I.cal, 14)}<span>${esc(iso ? longDay(iso) : empty)}</span></button><input type="date" class="pc-dt" data-f="${k}" value="${esc(iso)}" tabindex="-1" aria-hidden="true">`;
|
|
132
|
+
return `<div class="pc-fx">`
|
|
133
|
+
+ `<label class="w2">Goal<input class="pc-fi" data-f="goal" maxlength="160" value="${esc(D.goal)}" placeholder="What the program achieves, in one line" autocomplete="off"></label>`
|
|
134
|
+
+ `<label>Owner<input class="pc-fi" data-f="owner" maxlength="80" value="${esc(D.owner)}" placeholder="Who keeps the charter" autocomplete="off"></label>`
|
|
135
|
+
+ `<div class="pc-lab" role="group" aria-label="Span">Span<span class="pc-sp">${dt('start', D.start, 'No start', P.span)}<span class="or">to</span>${dt('target', D.target, 'No target', false)}</span>`
|
|
136
|
+
+ (P.span ? `<span class="pc-warn" role="alert"><i aria-hidden="true"></i>The start is after the target. Change one to save.</span>` : '') + `</div>`
|
|
137
|
+
+ `<label>Jira, optional<input class="pc-fi" data-f="jira" maxlength="40" value="${esc(D.jira)}" placeholder="A parent issue, plan or label, if you use one" autocomplete="off"></label>`
|
|
138
|
+
+ `<label class="w2">Why<textarea class="pc-ta" data-f="why" maxlength="600" placeholder="Why this program exists. It shows on the charter.">${esc(D.why)}</textarea></label>`
|
|
139
|
+
+ `</div>`;
|
|
140
|
+
}
|
|
141
|
+
const diam = (cls) => `<span class="pc-dm${cls}" aria-hidden="true"></span>`;
|
|
142
|
+
/** The ◆ stage words for a set of initiatives: "◆ Deliver" when they all count one stage name, else "their ◆ stage" (D99: each counts its own). */
|
|
143
|
+
function stepWords(inis, m) {
|
|
144
|
+
const L = [...new Set((inis || []).map((i) => milestoneStep(i.row, m).label))];
|
|
145
|
+
return L.length === 1 ? '◆ ' + L[0] : 'their ◆ stage';
|
|
146
|
+
}
|
|
147
|
+
/** The ◆ stages an initiative's own workflow has (Product feature: Deliver and Evaluate). The pick shows only with two or more. */
|
|
148
|
+
const diamondsOf = (row) => ((row && row.wfStages) || []).filter((s) => s.milestone);
|
|
149
|
+
/** The "done when" press of a row: the initiatives it waits on, or "I tick it myself" (MsBCharter); amber when one left (MsB6Problems). */
|
|
150
|
+
function whenHtml(m, gone) {
|
|
151
|
+
const open = C.pick === m.id;
|
|
152
|
+
const names = m.waits.map((w) => C.o.nameOf(w) || w);
|
|
153
|
+
const inner = m.check ? `<span class="bx" aria-hidden="true"></span><span>I tick it myself</span>` : `<span class="sq" aria-hidden="true"></span><span>${esc(names.join(', '))}</span>`;
|
|
154
|
+
const label = m.check ? 'Done when you tick it' : 'Done when these pass ' + stepWords(C.st.inis.filter((i) => m.waits.includes(i.id)), m) + ': ' + names.join(', ');
|
|
155
|
+
return `<button type="button" class="pc-wch${m.check ? ' ck' : ''}${gone ? ' gone' : ''}" data-pc="pick" data-m="${esc(m.id)}" aria-haspopup="true" aria-expanded="${open}" aria-label="${esc(label + '. Change')}">${inner}${SV(I.chev, 13, 2)}</button>`;
|
|
156
|
+
}
|
|
157
|
+
/** The picker (MsB3Pick): its initiatives per product with their ◆ days, amber when after the milestone's date, then "None: I tick it myself".
|
|
158
|
+
* A menu on a desk; chips under the row on a phone (MsBPhone). */
|
|
159
|
+
function pickHtml(m) {
|
|
160
|
+
const by = new Map();
|
|
161
|
+
for (const i of C.st.inis) { if (!by.has(i.product)) by.set(i.product, []); by.get(i.product).push(i); }
|
|
162
|
+
const step = stepWords(C.st.inis, m);
|
|
163
|
+
// an initiative it waits on whose workflow has two or more ◆ stages shows which one counts; a press moves to the next (D99)
|
|
164
|
+
const stagePress = (i, cls) => {
|
|
165
|
+
const D = diamondsOf(i.row);
|
|
166
|
+
if (m.check || !m.waits.includes(i.id) || D.length < 2) return '';
|
|
167
|
+
const s = milestoneStep(i.row, m);
|
|
168
|
+
return `<button type="button" class="${cls}" data-pc="mstage" data-m="${esc(m.id)}" data-ini="${esc(i.id)}" aria-label="${esc(i.title + ' counts ◆ ' + s.label + '. Count the next ◆ stage')}" title="Which ◆ stage counts">◆ ${esc(s.label)}</button>`;
|
|
169
|
+
};
|
|
170
|
+
if (isPhone()) {
|
|
171
|
+
const chips = C.st.inis.map((i) => { const on = !m.check && m.waits.includes(i.id); return `<button type="button" class="pc-ch" data-pc="wait" data-m="${esc(m.id)}" data-ini="${esc(i.id)}" aria-pressed="${on}"><span class="sq" aria-hidden="true"></span>${esc(i.title)}</button>${stagePress(i, 'pc-ch pc-mst')}`; }).join('');
|
|
172
|
+
return `<div class="pc-chips" role="group" aria-label="Done when these pass ${esc(step)}"><p class="dw">Done when these pass ${esc(step)}</p>${chips}<span class="or">or</span><button type="button" class="pc-ch" data-pc="tick" data-m="${esc(m.id)}" aria-pressed="${m.check}"><span class="bx" aria-hidden="true"></span>I tick it myself</button></div>`;
|
|
173
|
+
}
|
|
174
|
+
let h = `<p class="pc-mhd">Done when these pass ${esc(step)}</p>`;
|
|
175
|
+
for (const [prod, L] of by) {
|
|
176
|
+
if (by.size > 1 || prod) h += `<p class="pc-mhd pr">${esc(prod || 'This board')}</p>`;
|
|
177
|
+
h += L.map((i) => {
|
|
178
|
+
const on = !m.check && m.waits.includes(i.id), d = milestoneStep(i.row, m).date, lt = !!(d && m.date && d > m.date);
|
|
179
|
+
return `<button type="button" class="pc-mi" role="menuitemcheckbox" aria-checked="${on}" data-pc="wait" data-m="${esc(m.id)}" data-ini="${esc(i.id)}"><span class="bx${on ? ' on' : ''}" aria-hidden="true">${on ? SV(I.check, 11, 3) : ''}</span><span class="t">${esc(i.title)}</span>${d ? `<span class="r${lt ? ' lt' : ''}">${esc(shortDay(d))}</span>` : ''}</button>${stagePress(i, 'pc-mi pc-mst')}`;
|
|
180
|
+
}).join('');
|
|
181
|
+
}
|
|
182
|
+
h += `<i class="pc-msep" aria-hidden="true"></i><button type="button" class="pc-mi" role="menuitemcheckbox" aria-checked="${m.check}" data-pc="tick" data-m="${esc(m.id)}"><span class="bx${m.check ? ' on' : ''}" aria-hidden="true">${m.check ? SV(I.check, 11, 3) : ''}</span><span class="t">None: I tick it myself</span></button>`;
|
|
183
|
+
return `<div class="pc-menu" role="menu" aria-label="Done when" data-esc-layer>${h}</div>`;
|
|
184
|
+
}
|
|
185
|
+
function rowHtml(m, P) {
|
|
186
|
+
const nx = C.st.next && C.st.next.id === m.id, nameless = P.nameless.includes(m.id), gone = P.left.filter((x) => x.id === m.id);
|
|
187
|
+
const mark = m.draft ? `<span class="pc-spark" aria-hidden="true">${SV(I.spark, 14)}</span>` : diam((m.done || m.fixed) ? ' d' : nx ? ' n' : '');
|
|
188
|
+
const day = m.date ? (isPhone() ? longDay(m.date) : shortDay(m.date)) : 'No date';
|
|
189
|
+
const date = `<button type="button" class="pc-fd${m.date ? '' : ' q'}" data-pc="date" data-f="date" data-m="${esc(m.id)}" aria-label="${esc('Date ' + (m.date ? longDay(m.date) : 'not set') + '. Change')}">${SV(I.cal, 14)}<span>${esc(day)}</span></button><input type="date" class="pc-dt" data-f="date" data-m="${esc(m.id)}" value="${esc(m.date)}" tabindex="-1" aria-hidden="true">`;
|
|
190
|
+
const when = m.fixed ? `<span class="pc-via">Done by its initiatives</span>` : m.check && m.done ? `<button type="button" class="pc-mini" data-pc="reopen" data-m="${esc(m.id)}">Open again</button>` : whenHtml(m, gone.length > 0);
|
|
191
|
+
const ends = m.draft
|
|
192
|
+
? `<button type="button" class="pc-ib" data-pc="keep" data-m="${esc(m.id)}" aria-label="${esc('Keep ' + (m.name || 'this draft'))}" title="Keep">${SV(I.check, 16, 2)}</button><button type="button" class="pc-ib" data-pc="drop" data-m="${esc(m.id)}" aria-label="${esc('Drop ' + (m.name || 'this draft'))}" title="Drop">${SV(I.x, 16)}</button>`
|
|
193
|
+
: `<button type="button" class="pc-ib del" data-pc="del" data-m="${esc(m.id)}" aria-label="${esc('Delete ' + (m.name || 'this milestone'))}" title="Delete">${SV(I.del, 15)}</button>`;
|
|
194
|
+
const late = !gone.length && lateOf(m, C.st.inis);
|
|
195
|
+
const warn = gone.length ? `${esc(C.o.nameOf(gone[0].ini) || gone[0].ini)} left the program. Pick another initiative, or tick it yourself.`
|
|
196
|
+
: late ? `${esc(late.title)} is set to ${late.label === 'Deliver' ? 'deliver' : 'pass ' + esc(late.label)} on ${esc(shortDay(late.date))}, after this date.` : '';
|
|
197
|
+
return `<div class="pc-lnw${C.pick === m.id ? ' open' : ''}" role="listitem"><div class="pc-ln${m.draft ? ' sug' : ''}${m.done || m.fixed ? ' dn2' : ''}" data-m="${esc(m.id)}">${mark}`
|
|
198
|
+
+ `<input class="pc-fi${nameless ? ' bad' : ''}" data-f="name" data-m="${esc(m.id)}" maxlength="80" value="${esc(m.name)}" placeholder="${nameless ? 'Name it or delete it' : 'Name the milestone'}" aria-label="Milestone name" autocomplete="off">`
|
|
199
|
+
+ date + when + `<span class="pc-ends">${ends}</span></div>`
|
|
200
|
+
+ (warn ? `<p class="pc-warn"><i aria-hidden="true"></i>${warn}</p>` : '')
|
|
201
|
+
+ (C.pick === m.id && !isPhone() ? pickHtml(m) : '') + (isPhone() && C.pick === m.id ? pickHtml(m) : '') + `</div>`;
|
|
202
|
+
}
|
|
203
|
+
function msHtml(D, P) {
|
|
204
|
+
const rows = D.ms.slice().sort(byDate), done = rows.filter((m) => m.done || m.fixed), open = rows.filter((m) => !(m.done || m.fixed));
|
|
205
|
+
const drafts = D.ms.filter((m) => m.draft).length, full = D.ms.length >= MAX;
|
|
206
|
+
const lim = D.ms.length ? `<span class="pc-lim${full ? ' full' : ''}">${D.ms.length} of ${MAX}${full ? ' · the most a program holds' : ''}</span>` : '';
|
|
207
|
+
const withDay = C.st.inis.filter((i) => milestoneStep(i.row).date).length, step = stepWords(C.st.inis);
|
|
208
|
+
let h = '';
|
|
209
|
+
if (drafts) h += `<div class="pc-sugh">${SV(I.spark, 14)}<span><b>${drafts} ${drafts === 1 ? 'draft' : 'drafts'}</b> from the ${step} dates of its initiatives. Keep, change or drop each one.</span><button type="button" class="pc-mini" data-pc="keepall">Keep all</button></div>`;
|
|
210
|
+
else if (!D.ms.length && (withDay || D.target)) h += `<div class="pc-sugh">${SV(I.spark, 14)}<span>No milestones yet.${withDay ? ` Draft them from the ${step} dates of its ${withDay} ${withDay === 1 ? 'initiative' : 'initiatives'}.` : ' Draft a review at the target date.'}</span><button type="button" class="pc-mini" data-pc="drafts">Draft them</button></div>`;
|
|
211
|
+
if (done.length) {
|
|
212
|
+
h += `<button type="button" class="pc-ln dn" data-pc="fold" aria-expanded="${!C.fold}">${SV(C.fold ? I.chevR : I.chev, 13, 2)}<b>${done.length} done${C.fold ? ' · ' + esc(done.map((m) => m.name).join(', ')) : ''}</b></button>`;
|
|
213
|
+
if (!C.fold) h += done.map((m) => rowHtml(m, P)).join('');
|
|
214
|
+
}
|
|
215
|
+
h += open.map((m) => rowHtml(m, P)).join('');
|
|
216
|
+
if (!full) h += `<button type="button" class="pc-ln addl" data-pc="add">${SV(I.plus, 15, 2)}Add a milestone</button>`;
|
|
217
|
+
return `<section class="pc-ms" id="pcMs" aria-label="Milestones"><div class="pc-lbl">Milestones${lim}</div><div class="pc-ml" role="list">${h}</div></section>`;
|
|
218
|
+
}
|
|
219
|
+
function askHtml() {
|
|
220
|
+
const L = changesOf(C.orig, C.D), P = problemsOf(C.D, C.p.members);
|
|
221
|
+
return `<div class="pc-ask" role="alertdialog" aria-label="Save your changes?" data-esc-layer><p>Save your ${L.length} ${L.length === 1 ? 'change' : 'changes'}?</p><span class="t">${esc(changesLine(L))}</span>`
|
|
222
|
+
+ (P.any ? `<span class="t bad">Fix what is marked to save it.</span>` : '')
|
|
223
|
+
+ `<span class="row"><button type="button" class="pc-sv" data-pc="asksave"${P.any ? ' disabled' : ''}>Save</button><button type="button" class="pc-mini" data-pc="discard">Discard</button></span></div>`;
|
|
224
|
+
}
|
|
225
|
+
function bodyHtml() {
|
|
226
|
+
const P = problemsOf(C.D, C.p.members);
|
|
227
|
+
return `<div class="pc">${C.ask ? askHtml() : ''}${fieldsHtml(C.D, P)}${msHtml(C.D, P)}</div>`;
|
|
228
|
+
}
|
|
229
|
+
/** Draws again in place: the scroll, the focus and the caret stay where they were. */
|
|
230
|
+
function draw() {
|
|
231
|
+
const b = C && C.o.VW.body(); if (!b || !shown() || C.drawing) return;
|
|
232
|
+
C.drawing = true;
|
|
233
|
+
try { redraw(b); } finally { if (C) C.drawing = false; }
|
|
234
|
+
}
|
|
235
|
+
function redraw(b) {
|
|
236
|
+
const f = document.activeElement && b.contains(document.activeElement) ? document.activeElement : null;
|
|
237
|
+
const sel = f && f.dataset.f ? `[data-f="${f.dataset.f}"]${f.dataset.m ? `[data-m="${CSS.escape(f.dataset.m)}"]` : ''}:not(.pc-dt)` : f && f.dataset.pc ? `[data-pc="${f.dataset.pc}"]${f.dataset.m ? `[data-m="${CSS.escape(f.dataset.m)}"]` : ''}${f.dataset.ini ? `[data-ini="${CSS.escape(f.dataset.ini)}"]` : ''}${f.dataset.f ? `[data-f="${f.dataset.f}"]` : ''}` : null;
|
|
238
|
+
const caret = f && typeof f.selectionStart === 'number' ? [f.selectionStart, f.selectionEnd] : null;
|
|
239
|
+
const top = b.scrollTop;
|
|
240
|
+
b.innerHTML = bodyHtml();
|
|
241
|
+
b.scrollTop = top;
|
|
242
|
+
const g = sel && b.querySelector(sel);
|
|
243
|
+
if (g) { g.focus({ preventScroll: true }); if (caret && typeof g.setSelectionRange === 'function') try { g.setSelectionRange(caret[0], caret[1]); } catch { /* a date */ } }
|
|
244
|
+
presses();
|
|
245
|
+
}
|
|
246
|
+
const shown = () => { const c = C && C.o.VW.current && C.o.VW.current(); return !!(c && c.id === 'charter:' + C.p.id); };
|
|
247
|
+
/** Save is drawn only after a change, and not while something stops it (MsB6Problems draws none). */
|
|
248
|
+
function presses() {
|
|
249
|
+
if (!C) return;
|
|
250
|
+
const on = dirty() && !problemsOf(C.D, C.p.members).any && !C.busy;
|
|
251
|
+
C.o.VW.setPresses('charter:' + C.p.id, on ? [{ act: 'save', label: 'Save the charter', icon: I.check, text: 'Save', solid: true }] : null);
|
|
252
|
+
}
|
|
253
|
+
const rowOf = (id) => C.D.ms.find((m) => m.id === id);
|
|
254
|
+
|
|
255
|
+
async function save() {
|
|
256
|
+
if (!C || C.busy || problemsOf(C.D, C.p.members).any) return false;
|
|
257
|
+
C.busy = true; presses();
|
|
258
|
+
const p = C.p, out = charterOut(p.id, C.D);
|
|
259
|
+
const r = await C.o.pmPost('/api/programs/save', { ws: p.home || undefined, program: out }).catch(() => null);
|
|
260
|
+
if (!C || C.p !== p) return false;
|
|
261
|
+
C.busy = false;
|
|
262
|
+
if (!r || r.ok === false) { C.o.say((r && r.error) || 'The charter was not saved. The server did not say why.'); presses(); return false; }
|
|
263
|
+
// the record now holds the form: new rows keep the ids the save gave them
|
|
264
|
+
const fresh = r.program || { ...p, ...out, members: p.members, milestones: out.milestones };
|
|
265
|
+
C.p = { ...p, ...fresh, members: p.members, home: p.home };
|
|
266
|
+
C.D = draftOf(C.p, C.st);
|
|
267
|
+
C.orig = JSON.parse(JSON.stringify(C.D));
|
|
268
|
+
C.o.say('Charter saved.');
|
|
269
|
+
if (C.o.reload) await C.o.reload();
|
|
270
|
+
draw();
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
function act(b) {
|
|
274
|
+
const a = b.dataset.pc, id = b.dataset.m, m = id ? rowOf(id) : null;
|
|
275
|
+
if (a !== 'pick' && a !== 'wait' && a !== 'tick' && a !== 'mstage') C.pick = null;
|
|
276
|
+
if (a === 'date') { const i = b.parentNode.querySelector(`.pc-dt[data-f="${b.dataset.f}"]${id ? `[data-m="${CSS.escape(id)}"]` : ''}`) || b.nextElementSibling; if (i) { try { i.showPicker(); } catch { i.focus(); i.click(); } } return; }
|
|
277
|
+
if (a === 'pick') C.pick = C.pick === id ? null : id;
|
|
278
|
+
else if (a === 'wait' && m) { if (m.check) { m.check = false; m.done = false; m.waits = []; } const k = b.dataset.ini; m.waits = m.waits.includes(k) ? m.waits.filter((x) => x !== k) : m.waits.concat(k); if (!m.waits.includes(k) && m.stages) delete m.stages[k]; if (!m.waits.length) m.check = true; }
|
|
279
|
+
else if (a === 'mstage' && m) { // the next ◆ stage of that initiative's own workflow counts (D99)
|
|
280
|
+
const i = C.st.inis.find((x) => x.id === b.dataset.ini), D = i ? diamondsOf(i.row) : [];
|
|
281
|
+
if (D.length > 1) { const k = D.findIndex((s) => s.key === milestoneStep(i.row, m).key); m.stages = { ...(m.stages || {}), [i.id]: D[(k + 1) % D.length].key }; }
|
|
282
|
+
}
|
|
283
|
+
else if (a === 'tick' && m) { m.check = true; m.waits = []; }
|
|
284
|
+
else if (a === 'reopen' && m) m.done = false;
|
|
285
|
+
else if (a === 'del' && m) C.D.ms = C.D.ms.filter((x) => x !== m);
|
|
286
|
+
else if (a === 'drop' && m) C.D.ms = C.D.ms.filter((x) => x !== m);
|
|
287
|
+
else if (a === 'keep' && m) m.draft = false;
|
|
288
|
+
else if (a === 'keepall') C.D.ms.forEach((x) => { x.draft = false; });
|
|
289
|
+
else if (a === 'drafts') C.D.ms = draftsOf(C.st, C.D.target);
|
|
290
|
+
else if (a === 'fold') C.fold = !C.fold;
|
|
291
|
+
else if (a === 'add' && C.D.ms.length < MAX) { const n = { id: newId(), name: '', date: '', waits: [], check: true, done: false, isNew: true }; C.D.ms.push(n); draw(); const i = C.o.VW.body().querySelector(`[data-f="name"][data-m="${n.id}"]`); if (i) i.focus(); return; }
|
|
292
|
+
else if (a === 'asksave') { const go = C.ask; C.ask = null; save().then((ok) => { if (ok && go) go(); else draw(); }); return; }
|
|
293
|
+
else if (a === 'discard') { const go = C.ask; C.ask = null; C.D = JSON.parse(JSON.stringify(C.orig)); if (go) go(); return; }
|
|
294
|
+
draw();
|
|
295
|
+
}
|
|
296
|
+
function onInput(e) {
|
|
297
|
+
const t = e.target, f = t.dataset && t.dataset.f; if (!f || !C || C.drawing) return;
|
|
298
|
+
if (e.type === 'change' && !t.classList.contains('pc-dt')) return; // typing is read as it happens; a blur adds nothing
|
|
299
|
+
if (t.dataset.m) { const m = rowOf(t.dataset.m); if (!m) return; if (f === 'name') m.name = t.value; else if (f === 'date') m.date = t.value; }
|
|
300
|
+
else C.D[f] = t.value;
|
|
301
|
+
// a date or a name problem changes what the row says; plain typing only changes whether Save shows
|
|
302
|
+
if (f === 'date' || f === 'start' || f === 'target' || (f === 'name' && (!t.value.trim() || t.classList.contains('bad')))) draw(); else presses();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function openCharter(o) {
|
|
306
|
+
const p = o.p;
|
|
307
|
+
const before = typeof window !== 'undefined' ? window : null;
|
|
308
|
+
C = { o, p, st: o.st, D: null, orig: null, fold: true, pick: null, ask: null, busy: false };
|
|
309
|
+
C.D = draftOf(p, o.st); C.orig = JSON.parse(JSON.stringify(C.D));
|
|
310
|
+
const unload = (e) => { if (dirty()) { e.preventDefault(); e.returnValue = ''; } };
|
|
311
|
+
o.VW.open({ kind: 'Charter', title: o.title || p.title, sub: 'Charter', icon: 'doc', id: 'charter:' + p.id, back: true, rename: o.rename,
|
|
312
|
+
onPress: (a) => { if (a === 'save') save(); },
|
|
313
|
+
// leaving with changes asks once, under ← (MsB5Leave): Save or Discard; Escape closes the question and stays
|
|
314
|
+
guard: (go) => { if (!C || !dirty()) return false; C.ask = go; C.pick = null; draw(); const s = C.o.VW.body() && C.o.VW.body().querySelector('[data-pc="asksave"]:not([disabled]),[data-pc="discard"]'); if (s) s.focus(); return true; },
|
|
315
|
+
render: (body) => {
|
|
316
|
+
body.classList.add('pc-vw');
|
|
317
|
+
body.innerHTML = bodyHtml();
|
|
318
|
+
body.onclick = (e) => { const b = e.target.closest('[data-pc]'); if (b && body.contains(b) && !b.disabled) { act(b); return; } if (C && C.pick && !e.target.closest('.pc-menu')) { C.pick = null; draw(); } };
|
|
319
|
+
body.oninput = onInput;
|
|
320
|
+
body.onchange = onInput;
|
|
321
|
+
body.onkeydown = (e) => {
|
|
322
|
+
if (e.key !== 'Escape' || !C) return;
|
|
323
|
+
if (C.ask) { e.preventDefault(); e.stopPropagation(); C.ask = null; draw(); }
|
|
324
|
+
else if (C.pick) { e.preventDefault(); e.stopPropagation(); const id = C.pick; C.pick = null; draw(); const b = body.querySelector(`[data-pc="pick"][data-m="${CSS.escape(id)}"]`); if (b) b.focus(); }
|
|
325
|
+
};
|
|
326
|
+
if (before) before.addEventListener('beforeunload', unload);
|
|
327
|
+
if (o.at === 'milestones') { const s = body.querySelector('#pcMs'); if (s) requestAnimationFrame(() => s.scrollIntoView({ block: 'start' })); }
|
|
328
|
+
presses();
|
|
329
|
+
},
|
|
330
|
+
onClose: () => { if (before) before.removeEventListener('beforeunload', unload); C = null; } });
|
|
331
|
+
}
|
|
332
|
+
/** The charter's form, when the program it shows is renamed from its header: the name changes in the form too, and stays saved. */
|
|
333
|
+
export function renamed(id, title) { if (C && C.p.id === id) { C.p = { ...C.p, title }; C.D.title = title; C.orig.title = title; } }
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* programState(p, rowsOf, now) { state, spread, span, products, inis, missing, milestones, next, tasks, openTasks }
|
|
5
5
|
* programOf(programs, ws, ini) the program an initiative of a workspace is in, or null
|
|
6
|
+
* milestoneStep(row, m) { key, label, at, date } the ◆ stage milestone m counts for an initiative, and its day
|
|
6
7
|
* milestoneTrack(st, cap) { done, shown, more, next, doneN } the panel's track: a done cluster, `cap` shown, an "N more" cluster (PgProgram)
|
|
7
8
|
* milestoneGroups(st) [{ key, label, items }] Done / Next / Later, the Milestones tab (PgMilestones)
|
|
8
9
|
* mergeClose(milestones, days) [{ first, n, items, label, range }] milestones within `days` of the first merge into one counted diamond (PgTimeline)
|
|
@@ -15,7 +16,9 @@
|
|
|
15
16
|
* · state Shaping while no initiative is past Triage, Closing once every initiative is at Monitor or later, Running otherwise
|
|
16
17
|
* · spread the first and last stage its initiatives are at
|
|
17
18
|
* · products the products its initiatives are in, in the order they first appear
|
|
18
|
-
* · a milestone is ready when every initiative it waits on is past ◆
|
|
19
|
+
* · a milestone is ready when every initiative it waits on is past its own workflow's ◆ stage (D99, Wawan 2026-10-24): Product feature
|
|
20
|
+
* keeps ◆ Deliver; another workflow its first ◆ stage, or the one the charter names for it (`stages: { [initiative]: stageKey }`,
|
|
21
|
+
* the picker lists that initiative's ◆ stages, wf-model.js milestoneStages); "n of m ready" counts them
|
|
19
22
|
* · a milestone that waits on no initiative is a program check: it is done when the PM marked it done (lib/programs.js `check` lines)
|
|
20
23
|
* · span the program's own start and target ("Sep 2026 to Jun 2028"), which can be longer than any initiative
|
|
21
24
|
* A member whose initiative no read row holds is listed as `missing`, never guessed. */
|
|
@@ -28,6 +31,36 @@ const MONITOR = STEPS.findIndex((s) => s.key === 'monitor');
|
|
|
28
31
|
const dayOf = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
|
|
29
32
|
export const shortDay = (iso) => { const d = dayOf(iso); return d ? MON[d.getMonth()] + ' ' + d.getDate() : ''; };
|
|
30
33
|
|
|
34
|
+
const ownWf = (row) => !!(row && row.wf && row.wf.id && row.wf.id !== 'product-feature' && Array.isArray(row.wfStages) && row.wfStage);
|
|
35
|
+
/** The ◆ stage a milestone waits on for one initiative: the charter's pick, else its workflow's first ◆ stage (Product feature: Deliver). */
|
|
36
|
+
export function milestoneStageOf(row, m) {
|
|
37
|
+
const st = (row && row.wfStages) || [];
|
|
38
|
+
const pick = m && m.stages && row ? m.stages[row.id] : null;
|
|
39
|
+
return st.find((s) => s.key === pick && s.milestone) || st.find((s) => s.milestone) || null;
|
|
40
|
+
}
|
|
41
|
+
/** An initiative is past the milestone's ◆ stage: its place in its own workflow is after that stage. A row with no workflow fields reads
|
|
42
|
+
* the lifecycle (past ◆ Deliver). */
|
|
43
|
+
function reached(i, m) {
|
|
44
|
+
const row = i.row;
|
|
45
|
+
if (row && Array.isArray(row.wfStages) && row.wfStages.length && row.wfStage) {
|
|
46
|
+
const s = milestoneStageOf(row, m);
|
|
47
|
+
const k = row.wfStages.indexOf(s);
|
|
48
|
+
return k >= 0 && row.wfStage.n - 1 > k;
|
|
49
|
+
}
|
|
50
|
+
return i.at > DELIVER;
|
|
51
|
+
}
|
|
52
|
+
/** The ◆ stage a program milestone counts for one initiative, and the day it is set for: the ONE place that says it (D99, PM 2026-10-24:
|
|
53
|
+
* each initiative's own workflow names its ◆ stages; Product feature counts ◆ Deliver, another workflow the charter's pick, else its first ◆).
|
|
54
|
+
* The day is the release it rides on, else its plan's end, else none: never guessed. m is the milestone (its `stages` pick), or none.
|
|
55
|
+
* → { key, label, at, date } (`at` is the lifecycle place; -1 on another workflow, where reached() reads the workflow's own order) */
|
|
56
|
+
export function milestoneStep(row, m) {
|
|
57
|
+
const r = row || {};
|
|
58
|
+
const date = String((r.release && r.release.iso) || r.end || '').slice(0, 10);
|
|
59
|
+
const day = /^\d{4}-\d{2}-\d{2}$/.test(date) ? date : '';
|
|
60
|
+
const s = ownWf(r) ? milestoneStageOf(r, m) : null;
|
|
61
|
+
return s ? { key: s.key, label: s.name, at: -1, date: day } : { key: 'deliver', label: 'Deliver', at: DELIVER, date: day };
|
|
62
|
+
}
|
|
63
|
+
|
|
31
64
|
export function programOf(programs, ws, ini) {
|
|
32
65
|
return (programs || []).find((p) => (p.members || []).some((m) => m.initiative === ini && (!m.ws || !ws || m.ws === ws))) || null;
|
|
33
66
|
}
|
|
@@ -44,17 +77,24 @@ export function programState(p, rowsOf, now = Date.now()) {
|
|
|
44
77
|
}
|
|
45
78
|
const idx = inis.map((i) => i.at).filter((i) => i >= 0);
|
|
46
79
|
const lo = idx.length ? Math.min(...idx) : -1, hi = idx.length ? Math.max(...idx) : -1;
|
|
47
|
-
|
|
80
|
+
// D99: an initiative on another workflow counts by its own place: past its first stage, and in a Done stage
|
|
81
|
+
const other = inis.filter((i) => ownWf(i.row));
|
|
82
|
+
const life = inis.filter((i) => !ownWf(i.row) && i.at >= 0);
|
|
83
|
+
const anyPast = (life.length && hi > 0) || other.some((i) => i.row.wfStage.n > 1);
|
|
84
|
+
const allClose = (life.length || other.length) && life.every((i) => i.at >= MONITOR) && other.every((i) => i.row.wfStage.cat === 'done');
|
|
85
|
+
const state = !anyPast ? 'Shaping' : allClose ? 'Closing' : 'Running';
|
|
48
86
|
const spread = idx.length ? { from: STEPS[lo].label, to: STEPS[hi].label, lo, hi } : null;
|
|
49
87
|
const today = new Date(now); today.setHours(0, 0, 0, 0);
|
|
50
88
|
const milestones = ((p && p.milestones) || []).map((m) => {
|
|
51
89
|
const check = !(m.waits || []).length;
|
|
52
90
|
const waits = (m.waits || []).map((id) => inis.find((i) => i.id === id)).filter(Boolean);
|
|
53
|
-
const ready = waits.filter((i) => i
|
|
91
|
+
const ready = waits.filter((i) => reached(i, m)).length;
|
|
54
92
|
// a milestone whose initiatives are all unread is neither a check nor done: it waits on what no row says
|
|
55
93
|
const done = check ? m.done === true : waits.length > 0 && ready === waits.length && waits.length === m.waits.length;
|
|
56
94
|
const d = dayOf(m.date);
|
|
57
|
-
|
|
95
|
+
// the ◆ stage it waits on, named once when every initiative waits on the same one ("reaching Deliver")
|
|
96
|
+
const names = [...new Set(waits.map((i) => { const x = i.row && i.row.wfStages ? milestoneStageOf(i.row, m) : null; return x ? x.name : 'Deliver'; }))];
|
|
97
|
+
return { id: m.id, name: m.name, date: m.date || '', day: shortDay(m.date), reach: names.length === 1 ? names[0] : '', waits: waits.map((i) => i.id), titles: waits.map((i) => i.title), n: waits.length, ready,
|
|
58
98
|
check, done, late: !!(d && d < today && !done) };
|
|
59
99
|
});
|
|
60
100
|
const next = milestones.filter((m) => !m.done).sort((a, b) => String(a.date || '9999').localeCompare(String(b.date || '9999')))[0] || null;
|
|
@@ -162,6 +202,8 @@ export function goalsByPeriod(st, krsOf, now = Date.now()) {
|
|
|
162
202
|
* group per product with the rows no program holds. Each row appears once; there is no "Not in a program" group; a group with no row is left out.
|
|
163
203
|
* o.byProduct: product groups only, a program's row copied with { inProgram: id } (PgBoardProduct's layers icon).
|
|
164
204
|
* o.productOf(row) → the product's name (default row.product, else row.ws, else o.product); o.wsOf(row) → its workspace (default row.ws, else o.ws).
|
|
205
|
+
* o.keepEmpty(program) → true to keep a program with no row here, as a group with no row: a program the PM has just made, or one whose
|
|
206
|
+
* initiatives are all cancelled or archived, still shows, so its panel can be opened to move initiatives into it.
|
|
165
207
|
* Group: { kind: 'program', key: 'g:<id>', program, products: [{ name, rows }], rows } | { kind: 'product', key: 'p:<name>', name, rows }. */
|
|
166
208
|
export function groupRows(rows, programs, o = {}) {
|
|
167
209
|
const productOf = o.productOf || ((r) => r.product || r.ws || o.product || '');
|
|
@@ -187,6 +229,7 @@ export function groupRows(rows, programs, o = {}) {
|
|
|
187
229
|
sub.rows.push(r); g.rows.push(r);
|
|
188
230
|
inProg.set(p.id, g);
|
|
189
231
|
}
|
|
190
|
-
const
|
|
232
|
+
const empty = (p) => !!o.keepEmpty && o.keepEmpty(p);
|
|
233
|
+
const progs = live.map((p) => inProg.get(p.id) || (empty(p) ? { kind: 'program', key: 'g:' + p.id, program: p, products: [], rows: [] } : null)).filter(Boolean);
|
|
191
234
|
return progs.concat(prods.map((name) => ({ kind: 'product', key: 'p:' + name, name, rows: prodRows.get(name) })));
|
|
192
235
|
}
|