couch-potator 0.0.0-stage → 0.6.1
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/LICENSE +21 -0
- package/README.md +759 -2
- package/dist/assets/app.js +994 -0
- package/dist/assets/index.html +41 -0
- package/dist/assets/style.css +1161 -0
- package/dist/assets/vendor/marked.umd.js +75 -0
- package/dist/assets/vendor/purify.min.js +7 -0
- package/dist/cli.js +5131 -0
- package/package.json +42 -4
|
@@ -0,0 +1,994 @@
|
|
|
1
|
+
(() => {
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const STATUS_ORDER = ["todo", "in-progress", "blocked", "done"];
|
|
5
|
+
const STATUS_LABEL = {
|
|
6
|
+
todo: "Todo",
|
|
7
|
+
"in-progress": "In progress",
|
|
8
|
+
blocked: "Blocked",
|
|
9
|
+
done: "Done",
|
|
10
|
+
};
|
|
11
|
+
const KINDS = ["foundation", "design", "feature", "quality", "release", "fix"];
|
|
12
|
+
|
|
13
|
+
const NODE_W = 204;
|
|
14
|
+
const NODE_H = 78;
|
|
15
|
+
const GAP_X = 74;
|
|
16
|
+
const GAP_Y = 18;
|
|
17
|
+
const PAD = 40;
|
|
18
|
+
|
|
19
|
+
const MAX_DEPTH = 9;
|
|
20
|
+
|
|
21
|
+
const app = {
|
|
22
|
+
data: null,
|
|
23
|
+
projectSlug: null,
|
|
24
|
+
view: "board",
|
|
25
|
+
milestone: null,
|
|
26
|
+
specId: null,
|
|
27
|
+
brief: false,
|
|
28
|
+
graph: { x: 0, y: 0, k: 1, manual: false, width: 0, height: 0 },
|
|
29
|
+
modalSig: "",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const $ = (id) => document.getElementById(id);
|
|
33
|
+
|
|
34
|
+
const esc = (value) =>
|
|
35
|
+
String(value == null ? "" : value).replace(/[&<>"']/g, (char) => {
|
|
36
|
+
switch (char) {
|
|
37
|
+
case "&":
|
|
38
|
+
return "&";
|
|
39
|
+
case "<":
|
|
40
|
+
return "<";
|
|
41
|
+
case ">":
|
|
42
|
+
return ">";
|
|
43
|
+
case '"':
|
|
44
|
+
return """;
|
|
45
|
+
default:
|
|
46
|
+
return "'";
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const kindClass = (kind) => (KINDS.includes(kind) ? kind : "other");
|
|
51
|
+
|
|
52
|
+
const shortId = (id) => String(id).split("-").slice(0, 2).join("-");
|
|
53
|
+
|
|
54
|
+
const currentProject = () =>
|
|
55
|
+
(app.data?.projects || []).find((project) => project.slug === app.projectSlug) || null;
|
|
56
|
+
|
|
57
|
+
// ----------------------------------------------------------- local storage
|
|
58
|
+
|
|
59
|
+
function stored(key) {
|
|
60
|
+
try {
|
|
61
|
+
return window.localStorage.getItem(key);
|
|
62
|
+
} catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function store(key, value) {
|
|
68
|
+
try {
|
|
69
|
+
window.localStorage.setItem(key, value);
|
|
70
|
+
} catch {
|
|
71
|
+
/* file:// origins may refuse storage; the URL hash is the fallback */
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// --------------------------------------------------------------- milestones
|
|
76
|
+
|
|
77
|
+
const milestonesOf = (project) => project?.milestones || [];
|
|
78
|
+
|
|
79
|
+
const milestoneText = (value) => `Milestone ${value}`;
|
|
80
|
+
|
|
81
|
+
function chooseMilestone(project, raw) {
|
|
82
|
+
const milestones = milestonesOf(project);
|
|
83
|
+
if (!milestones.length) return null;
|
|
84
|
+
|
|
85
|
+
const value = String(raw ?? "").trim();
|
|
86
|
+
if (value === "all") return null;
|
|
87
|
+
if (/^\d+$/.test(value)) {
|
|
88
|
+
const digits = Number(value);
|
|
89
|
+
if (milestones.includes(digits)) return digits;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const current = project?.current_milestone;
|
|
93
|
+
return milestones.includes(current) ? current : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function normaliseMilestone(project) {
|
|
97
|
+
const milestones = milestonesOf(project);
|
|
98
|
+
if (!milestones.length) {
|
|
99
|
+
app.milestone = null;
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (app.milestone != null && !milestones.includes(app.milestone)) {
|
|
103
|
+
app.milestone = chooseMilestone(project, null);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function visibleSpecs(project) {
|
|
108
|
+
if (!project) return [];
|
|
109
|
+
if (app.milestone == null) return project.specs;
|
|
110
|
+
return project.specs.filter((spec) => spec.milestone === app.milestone);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Other-milestone specs one hop away from what is shown, so dependencies stay
|
|
114
|
+
// traceable in the graph. They are drawn faded and never counted as cards.
|
|
115
|
+
function contextSpecs(project, visible) {
|
|
116
|
+
if (!project || app.milestone == null) return [];
|
|
117
|
+
|
|
118
|
+
const shown = new Set(visible.map((spec) => spec.id));
|
|
119
|
+
const byId = new Map(project.specs.map((spec) => [spec.id, spec]));
|
|
120
|
+
const context = new Map();
|
|
121
|
+
|
|
122
|
+
for (const spec of visible) {
|
|
123
|
+
for (const dep of spec.depends_on) {
|
|
124
|
+
const target = byId.get(dep);
|
|
125
|
+
if (target && !shown.has(target.id)) context.set(target.id, target);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
for (const spec of project.specs) {
|
|
129
|
+
if (shown.has(spec.id)) continue;
|
|
130
|
+
if (spec.depends_on.some((dep) => shown.has(dep))) context.set(spec.id, spec);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return Array.from(context.values());
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ---------------------------------------------------------------- markdown
|
|
137
|
+
|
|
138
|
+
function configureMarkdown() {
|
|
139
|
+
marked.setOptions({ gfm: true, breaks: false });
|
|
140
|
+
|
|
141
|
+
DOMPurify.addHook("afterSanitizeAttributes", (node) => {
|
|
142
|
+
if (node.tagName === "A") {
|
|
143
|
+
node.setAttribute("target", "_blank");
|
|
144
|
+
node.setAttribute("rel", "noopener noreferrer");
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function renderMarkdown(source) {
|
|
150
|
+
const html = marked.parse(String(source || ""));
|
|
151
|
+
return DOMPurify.sanitize(html, {
|
|
152
|
+
FORBID_TAGS: ["script", "style", "iframe", "form", "object", "embed"],
|
|
153
|
+
FORBID_ATTR: ["style"],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function stripHeading(markdown, needles) {
|
|
158
|
+
const lines = String(markdown || "").split("\n");
|
|
159
|
+
if (lines.length && /^#\s+/.test(lines[0])) {
|
|
160
|
+
const heading = lines[0].replace(/^#\s+/, "");
|
|
161
|
+
const matches =
|
|
162
|
+
!needles.length || needles.some((needle) => needle && heading.includes(needle));
|
|
163
|
+
if (matches) {
|
|
164
|
+
lines.shift();
|
|
165
|
+
while (lines.length && !lines[0].trim()) lines.shift();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return lines.join("\n");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function specBody(spec) {
|
|
172
|
+
return stripHeading(spec.body, [spec.id, spec.title]);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ------------------------------------------------------------------- state
|
|
176
|
+
|
|
177
|
+
function loadData() {
|
|
178
|
+
const node = $("board-data");
|
|
179
|
+
if (!node) {
|
|
180
|
+
app.data = null;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
const parsed = JSON.parse(node.textContent || "{}");
|
|
185
|
+
app.data = parsed && Array.isArray(parsed.projects) ? parsed : null;
|
|
186
|
+
} catch {
|
|
187
|
+
app.data = null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ------------------------------------------------------------------ scroll
|
|
192
|
+
|
|
193
|
+
function captureScroll() {
|
|
194
|
+
const board = document.querySelector(".board");
|
|
195
|
+
return {
|
|
196
|
+
boardLeft: board ? board.scrollLeft : 0,
|
|
197
|
+
columns: Array.from(document.querySelectorAll(".column .cards")).map(
|
|
198
|
+
(column) => column.scrollTop,
|
|
199
|
+
),
|
|
200
|
+
modal: document.querySelector(".modal-body")?.scrollTop ?? 0,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function restoreScroll(scroll) {
|
|
205
|
+
if (!scroll) return;
|
|
206
|
+
const board = document.querySelector(".board");
|
|
207
|
+
if (board) board.scrollLeft = scroll.boardLeft;
|
|
208
|
+
document.querySelectorAll(".column .cards").forEach((column, index) => {
|
|
209
|
+
if (scroll.columns[index] != null) column.scrollTop = scroll.columns[index];
|
|
210
|
+
});
|
|
211
|
+
const modal = document.querySelector(".modal-body");
|
|
212
|
+
if (modal && scroll.modal) modal.scrollTop = scroll.modal;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// ------------------------------------------------------------------ header
|
|
216
|
+
|
|
217
|
+
function renderHeader() {
|
|
218
|
+
const projects = app.data?.projects || [];
|
|
219
|
+
const project = currentProject();
|
|
220
|
+
const slot = $("projectSlot");
|
|
221
|
+
const milestoneSelect = milestoneSelectHtml(project);
|
|
222
|
+
|
|
223
|
+
if (projects.length > 1) {
|
|
224
|
+
slot.innerHTML = `<select id="projectSelect" aria-label="Project">${projects
|
|
225
|
+
.map(
|
|
226
|
+
(item) =>
|
|
227
|
+
`<option value="${esc(item.slug)}"${item.slug === app.projectSlug ? " selected" : ""}>${esc(item.name)}</option>`,
|
|
228
|
+
)
|
|
229
|
+
.join("")}</select>${milestoneSelect}`;
|
|
230
|
+
} else if (project) {
|
|
231
|
+
slot.innerHTML =
|
|
232
|
+
`<span class="project-name">${esc(project.name)}</span>` + milestoneSelect;
|
|
233
|
+
} else {
|
|
234
|
+
slot.innerHTML = "";
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
document.querySelectorAll("[data-view]").forEach((button) => {
|
|
238
|
+
const active = button.dataset.view === app.view;
|
|
239
|
+
button.classList.toggle("active", active);
|
|
240
|
+
button.setAttribute("aria-selected", active ? "true" : "false");
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
const pill = $("readonlyPill");
|
|
244
|
+
if (pill) {
|
|
245
|
+
pill.title = app.data?.generated
|
|
246
|
+
? `Read-only view generated ${app.data.generated}. Re-run couch-potator view after changes.`
|
|
247
|
+
: "Read-only view";
|
|
248
|
+
}
|
|
249
|
+
$("briefBtn").disabled = !project;
|
|
250
|
+
|
|
251
|
+
document.title = project ? `Board · ${project.name}` : "Board";
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function milestoneSelectHtml(project) {
|
|
255
|
+
const milestones = milestonesOf(project);
|
|
256
|
+
if (!milestones.length) return "";
|
|
257
|
+
|
|
258
|
+
const options = [
|
|
259
|
+
`<option value="all"${app.milestone == null ? " selected" : ""}>All milestones</option>`,
|
|
260
|
+
...milestones.map(
|
|
261
|
+
(value) =>
|
|
262
|
+
`<option value="${esc(value)}"${app.milestone === value ? " selected" : ""}>${esc(milestoneText(value))}</option>`,
|
|
263
|
+
),
|
|
264
|
+
];
|
|
265
|
+
|
|
266
|
+
return `<select id="milestoneSelect" aria-label="Milestone">${options.join("")}</select>`;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// ------------------------------------------------------------------- board
|
|
270
|
+
|
|
271
|
+
function renderBoard() {
|
|
272
|
+
const project = currentProject();
|
|
273
|
+
const main = $("main");
|
|
274
|
+
main.className = "board-view";
|
|
275
|
+
|
|
276
|
+
if (!project) {
|
|
277
|
+
main.innerHTML = emptyProjectsHtml();
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (!project.specs.length) {
|
|
281
|
+
main.innerHTML = emptyProjectHtml(project);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const specs = visibleSpecs(project);
|
|
286
|
+
if (!specs.length) {
|
|
287
|
+
main.innerHTML = emptyMilestoneHtml(project);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const columns = STATUS_ORDER.map((status) => {
|
|
292
|
+
const inColumn = specs.filter((spec) => spec.status === status);
|
|
293
|
+
const cards = inColumn.length
|
|
294
|
+
? inColumn.map(cardHtml).join("")
|
|
295
|
+
: `<p class="column-empty">No cards</p>`;
|
|
296
|
+
|
|
297
|
+
return `
|
|
298
|
+
<section class="column" data-status="${status}">
|
|
299
|
+
<header class="column-head">
|
|
300
|
+
<span class="status-dot"></span>
|
|
301
|
+
<h2>${esc(STATUS_LABEL[status])}</h2>
|
|
302
|
+
<span class="count">${inColumn.length}</span>
|
|
303
|
+
</header>
|
|
304
|
+
<div class="cards">${cards}</div>
|
|
305
|
+
</section>`;
|
|
306
|
+
}).join("");
|
|
307
|
+
|
|
308
|
+
const scroll = captureScroll();
|
|
309
|
+
main.innerHTML = `<div class="board">${columns}</div>`;
|
|
310
|
+
restoreScroll(scroll);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function cardHtml(spec) {
|
|
314
|
+
return `<button type="button" class="card kind-${kindClass(spec.kind)}" data-spec="${esc(spec.id)}" title="${esc(spec.title)}">
|
|
315
|
+
<span class="card-title">${esc(spec.title)}</span>
|
|
316
|
+
</button>`;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function emptyProjectsHtml() {
|
|
320
|
+
const workspace = app.data?.workspace || "";
|
|
321
|
+
return `<div class="empty">
|
|
322
|
+
<h1>No board data</h1>
|
|
323
|
+
<p>This page has no embedded board. Regenerate it with <code>couch-potator view</code>.</p>
|
|
324
|
+
${workspace ? `<p class="empty-path">${esc(workspace)}</p>` : ""}
|
|
325
|
+
</div>`;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function emptyProjectHtml(project) {
|
|
329
|
+
return `<div class="empty">
|
|
330
|
+
<h1>${esc(project.name)} has no specs yet</h1>
|
|
331
|
+
<p>Cards appear here as soon as they are written into the board folders. Start with
|
|
332
|
+
<code>couch-potator add "First card"</code>.</p>
|
|
333
|
+
</div>`;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function emptyMilestoneHtml(project) {
|
|
337
|
+
return `<div class="empty">
|
|
338
|
+
<h1>No specs in ${esc(milestoneText(app.milestone))}</h1>
|
|
339
|
+
<p>${esc(project.name)} has ${project.specs.length} specs, but none in this milestone. Choose <b>All milestones</b> in the header to see them.</p>
|
|
340
|
+
</div>`;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// ------------------------------------------------------------------- graph
|
|
344
|
+
|
|
345
|
+
function layoutGraph(specs) {
|
|
346
|
+
const byId = new Map(specs.map((spec) => [spec.id, spec]));
|
|
347
|
+
const depth = new Map();
|
|
348
|
+
const visiting = new Set();
|
|
349
|
+
|
|
350
|
+
const walk = (id) => {
|
|
351
|
+
if (depth.has(id)) return depth.get(id);
|
|
352
|
+
if (visiting.has(id)) return 0;
|
|
353
|
+
visiting.add(id);
|
|
354
|
+
let value = 0;
|
|
355
|
+
const spec = byId.get(id);
|
|
356
|
+
for (const dep of spec?.depends_on || []) {
|
|
357
|
+
if (!byId.has(dep)) continue;
|
|
358
|
+
value = Math.max(value, walk(dep) + 1);
|
|
359
|
+
}
|
|
360
|
+
visiting.delete(id);
|
|
361
|
+
value = Math.min(value, MAX_DEPTH);
|
|
362
|
+
depth.set(id, value);
|
|
363
|
+
return value;
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
for (const spec of specs) walk(spec.id);
|
|
367
|
+
|
|
368
|
+
const maxDepth = Math.max(0, ...specs.map((spec) => depth.get(spec.id) || 0));
|
|
369
|
+
const columns = Array.from({ length: maxDepth + 1 }, () => []);
|
|
370
|
+
for (const spec of specs) columns[depth.get(spec.id) || 0].push(spec);
|
|
371
|
+
for (const column of columns) column.sort((a, b) => a.id.localeCompare(b.id));
|
|
372
|
+
|
|
373
|
+
const heights = columns.map(
|
|
374
|
+
(column) => column.length * NODE_H + Math.max(0, column.length - 1) * GAP_Y,
|
|
375
|
+
);
|
|
376
|
+
const tallest = Math.max(1, ...heights);
|
|
377
|
+
const positions = new Map();
|
|
378
|
+
|
|
379
|
+
columns.forEach((column, columnIndex) => {
|
|
380
|
+
const top = (tallest - heights[columnIndex]) / 2;
|
|
381
|
+
column.forEach((spec, rowIndex) => {
|
|
382
|
+
positions.set(spec.id, {
|
|
383
|
+
x: PAD + columnIndex * (NODE_W + GAP_X),
|
|
384
|
+
y: PAD + top + rowIndex * (NODE_H + GAP_Y),
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
return {
|
|
390
|
+
positions,
|
|
391
|
+
width: PAD * 2 + (maxDepth + 1) * NODE_W + maxDepth * GAP_X,
|
|
392
|
+
height: PAD * 2 + tallest,
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function wrapTitle(title) {
|
|
397
|
+
const words = String(title).split(/\s+/).filter(Boolean);
|
|
398
|
+
const lines = [];
|
|
399
|
+
let line = "";
|
|
400
|
+
|
|
401
|
+
for (const word of words) {
|
|
402
|
+
const candidate = line ? `${line} ${word}` : word;
|
|
403
|
+
if (candidate.length > 25 && line) {
|
|
404
|
+
lines.push(line);
|
|
405
|
+
line = word;
|
|
406
|
+
} else {
|
|
407
|
+
line = candidate;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (line) lines.push(line);
|
|
411
|
+
if (lines.length <= 2) return lines;
|
|
412
|
+
|
|
413
|
+
const second = lines[1].length > 24 ? `${lines[1].slice(0, 23)}…` : `${lines[1]}…`;
|
|
414
|
+
return [lines[0], second];
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function nodeSvg(spec, position, context = false) {
|
|
418
|
+
if (!position) return "";
|
|
419
|
+
const lines = wrapTitle(spec.title);
|
|
420
|
+
const block = 10 + 6 + lines.length * 17;
|
|
421
|
+
const top = (NODE_H - block) / 2;
|
|
422
|
+
const idY = top + 9;
|
|
423
|
+
const titleY = idY + 19;
|
|
424
|
+
const tspans = lines
|
|
425
|
+
.map((line, index) => `<tspan x="16" dy="${index === 0 ? 0 : 17}">${esc(line)}</tspan>`)
|
|
426
|
+
.join("");
|
|
427
|
+
|
|
428
|
+
return `<g class="node kind-${kindClass(spec.kind)} status-${esc(spec.status)}${context ? " is-context" : ""}" data-spec="${esc(spec.id)}" transform="translate(${position.x} ${position.y})">
|
|
429
|
+
<rect class="node-bg" width="${NODE_W}" height="${NODE_H}" rx="10"></rect>
|
|
430
|
+
<rect class="node-stripe" x="0" y="11" width="4" height="${NODE_H - 22}" rx="2"></rect>
|
|
431
|
+
<text class="node-id" x="16" y="${idY}">${esc(shortId(spec.id))}</text>
|
|
432
|
+
<text class="node-title" x="16" y="${titleY}">${tspans}</text>
|
|
433
|
+
</g>`;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function edgePath(from, to, fromId, toId, context = false) {
|
|
437
|
+
const x1 = from.x + NODE_W;
|
|
438
|
+
const y1 = from.y + NODE_H / 2;
|
|
439
|
+
const x2 = to.x;
|
|
440
|
+
const y2 = to.y + NODE_H / 2;
|
|
441
|
+
const bend = Math.max(36, (x2 - x1) * 0.5);
|
|
442
|
+
|
|
443
|
+
return `<path class="edge${context ? " is-context" : ""}" data-from="${esc(fromId)}" data-to="${esc(toId)}"
|
|
444
|
+
d="M ${x1} ${y1} C ${x1 + bend} ${y1}, ${x2 - bend} ${y2}, ${x2 - 7} ${y2}"
|
|
445
|
+
marker-end="url(#arrow)"></path>`;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function legendHtml(hasContext) {
|
|
449
|
+
return (
|
|
450
|
+
STATUS_ORDER.map(
|
|
451
|
+
(status) =>
|
|
452
|
+
`<span class="legend-item"><i class="dot status-${status}"></i>${esc(STATUS_LABEL[status])}</span>`,
|
|
453
|
+
).join("") +
|
|
454
|
+
`<span class="legend-item legend-note"><i class="arrow"></i>arrow points at the dependent spec</span>` +
|
|
455
|
+
(hasContext
|
|
456
|
+
? `<span class="legend-item legend-note"><i class="swatch"></i>faded = another milestone</span>`
|
|
457
|
+
: "")
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function renderGraph() {
|
|
462
|
+
const project = currentProject();
|
|
463
|
+
const main = $("main");
|
|
464
|
+
main.className = "graph-view";
|
|
465
|
+
|
|
466
|
+
if (!project) {
|
|
467
|
+
main.innerHTML = emptyProjectsHtml();
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
if (!project.specs.length) {
|
|
471
|
+
main.innerHTML = emptyProjectHtml(project);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
const visible = visibleSpecs(project);
|
|
476
|
+
if (!visible.length) {
|
|
477
|
+
main.innerHTML = emptyMilestoneHtml(project);
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const context = contextSpecs(project, visible);
|
|
482
|
+
const nodes = visible.concat(context);
|
|
483
|
+
const faded = new Set(context.map((spec) => spec.id));
|
|
484
|
+
|
|
485
|
+
const layout = layoutGraph(nodes);
|
|
486
|
+
const edges = [];
|
|
487
|
+
for (const spec of nodes) {
|
|
488
|
+
const to = layout.positions.get(spec.id);
|
|
489
|
+
if (!to) continue;
|
|
490
|
+
for (const dep of spec.depends_on) {
|
|
491
|
+
const from = layout.positions.get(dep);
|
|
492
|
+
if (!from) continue;
|
|
493
|
+
const isContext = faded.has(spec.id) || faded.has(dep);
|
|
494
|
+
edges.push(edgePath(from, to, dep, spec.id, isContext));
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
const nodeMarkup = nodes
|
|
499
|
+
.map((spec) => nodeSvg(spec, layout.positions.get(spec.id), faded.has(spec.id)))
|
|
500
|
+
.join("");
|
|
501
|
+
|
|
502
|
+
main.innerHTML = `
|
|
503
|
+
<svg class="graph" id="graphSvg" aria-label="Dependency graph">
|
|
504
|
+
<defs>
|
|
505
|
+
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5"
|
|
506
|
+
markerWidth="7" markerHeight="7" orient="auto-start-reverse">
|
|
507
|
+
<path d="M 0 0 L 10 5 L 0 10 z" fill="#bcd2ea"></path>
|
|
508
|
+
</marker>
|
|
509
|
+
</defs>
|
|
510
|
+
<g id="viewport">${edges.join("")}${nodeMarkup}</g>
|
|
511
|
+
</svg>
|
|
512
|
+
<div class="graph-toolbar">
|
|
513
|
+
<button type="button" class="ghost-btn" id="fitBtn">Fit</button>
|
|
514
|
+
</div>
|
|
515
|
+
<div class="graph-hint">drag to pan · scroll to zoom · click a card to read it</div>
|
|
516
|
+
<div class="graph-legend">${legendHtml(context.length > 0)}</div>
|
|
517
|
+
`;
|
|
518
|
+
|
|
519
|
+
const svg = $("graphSvg");
|
|
520
|
+
const rect = svg.getBoundingClientRect();
|
|
521
|
+
app.graph.width = Math.max(rect.width, 320);
|
|
522
|
+
app.graph.height = Math.max(rect.height, 260);
|
|
523
|
+
svg.setAttribute("viewBox", `0 0 ${app.graph.width} ${app.graph.height}`);
|
|
524
|
+
|
|
525
|
+
if (!app.graph.manual) fitGraph(layout);
|
|
526
|
+
applyTransform();
|
|
527
|
+
wireGraph(layout, nodes);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function fitGraph(layout) {
|
|
531
|
+
const { width, height } = app.graph;
|
|
532
|
+
const scale = Math.min((width - 56) / layout.width, (height - 104) / layout.height, 1.1);
|
|
533
|
+
app.graph.k = Math.max(0.18, scale);
|
|
534
|
+
app.graph.x = (width - layout.width * app.graph.k) / 2;
|
|
535
|
+
app.graph.y = (height - layout.height * app.graph.k) / 2;
|
|
536
|
+
app.graph.manual = false;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function applyTransform() {
|
|
540
|
+
const viewport = $("viewport");
|
|
541
|
+
if (!viewport) return;
|
|
542
|
+
viewport.setAttribute(
|
|
543
|
+
"transform",
|
|
544
|
+
`translate(${app.graph.x} ${app.graph.y}) scale(${app.graph.k})`,
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function wireGraph(layout, specs) {
|
|
549
|
+
const svg = $("graphSvg");
|
|
550
|
+
const fitBtn = $("fitBtn");
|
|
551
|
+
|
|
552
|
+
const neighbours = new Map();
|
|
553
|
+
const link = (a, b) => {
|
|
554
|
+
if (!neighbours.has(a)) neighbours.set(a, new Set());
|
|
555
|
+
neighbours.get(a).add(b);
|
|
556
|
+
};
|
|
557
|
+
for (const spec of specs) {
|
|
558
|
+
for (const dep of spec.depends_on) {
|
|
559
|
+
if (!layout.positions.has(dep)) continue;
|
|
560
|
+
link(spec.id, dep);
|
|
561
|
+
link(dep, spec.id);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const clearHighlight = () => {
|
|
566
|
+
svg.classList.remove("has-hover");
|
|
567
|
+
svg.querySelectorAll(".is-near").forEach((node) => node.classList.remove("is-near"));
|
|
568
|
+
svg.querySelectorAll(".is-hot").forEach((edge) => edge.classList.remove("is-hot"));
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
const highlight = (id) => {
|
|
572
|
+
svg.classList.add("has-hover");
|
|
573
|
+
const near = neighbours.get(id) || new Set();
|
|
574
|
+
svg.querySelectorAll(".node").forEach((node) => {
|
|
575
|
+
node.classList.toggle("is-near", node.dataset.spec === id || near.has(node.dataset.spec));
|
|
576
|
+
});
|
|
577
|
+
svg.querySelectorAll(".edge").forEach((edge) => {
|
|
578
|
+
edge.classList.toggle("is-hot", edge.dataset.from === id || edge.dataset.to === id);
|
|
579
|
+
});
|
|
580
|
+
};
|
|
581
|
+
|
|
582
|
+
svg.addEventListener("mouseover", (event) => {
|
|
583
|
+
const node = event.target.closest?.(".node");
|
|
584
|
+
if (!node) return;
|
|
585
|
+
if (event.relatedTarget && node.contains(event.relatedTarget)) return;
|
|
586
|
+
highlight(node.dataset.spec);
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
svg.addEventListener("mouseout", (event) => {
|
|
590
|
+
const node = event.target.closest?.(".node");
|
|
591
|
+
if (!node) return;
|
|
592
|
+
if (event.relatedTarget && node.contains(event.relatedTarget)) return;
|
|
593
|
+
clearHighlight();
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
let drag = null;
|
|
597
|
+
svg.addEventListener("pointerdown", (event) => {
|
|
598
|
+
if (event.target.closest?.(".node")) return;
|
|
599
|
+
drag = { x: event.clientX, y: event.clientY, ox: app.graph.x, oy: app.graph.y };
|
|
600
|
+
svg.classList.add("dragging");
|
|
601
|
+
try {
|
|
602
|
+
svg.setPointerCapture(event.pointerId);
|
|
603
|
+
} catch {
|
|
604
|
+
/* pointer capture is best effort */
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
svg.addEventListener("pointermove", (event) => {
|
|
609
|
+
if (!drag) return;
|
|
610
|
+
app.graph.x = drag.ox + (event.clientX - drag.x);
|
|
611
|
+
app.graph.y = drag.oy + (event.clientY - drag.y);
|
|
612
|
+
app.graph.manual = true;
|
|
613
|
+
applyTransform();
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
const endDrag = () => {
|
|
617
|
+
drag = null;
|
|
618
|
+
svg.classList.remove("dragging");
|
|
619
|
+
};
|
|
620
|
+
svg.addEventListener("pointerup", endDrag);
|
|
621
|
+
svg.addEventListener("pointercancel", endDrag);
|
|
622
|
+
|
|
623
|
+
svg.addEventListener(
|
|
624
|
+
"wheel",
|
|
625
|
+
(event) => {
|
|
626
|
+
event.preventDefault();
|
|
627
|
+
const rect = svg.getBoundingClientRect();
|
|
628
|
+
const mx = event.clientX - rect.left;
|
|
629
|
+
const my = event.clientY - rect.top;
|
|
630
|
+
const factor = Math.exp(-event.deltaY * 0.0016);
|
|
631
|
+
const next = Math.min(2.6, Math.max(0.18, app.graph.k * factor));
|
|
632
|
+
const ratio = next / app.graph.k;
|
|
633
|
+
app.graph.x = mx - (mx - app.graph.x) * ratio;
|
|
634
|
+
app.graph.y = my - (my - app.graph.y) * ratio;
|
|
635
|
+
app.graph.k = next;
|
|
636
|
+
app.graph.manual = true;
|
|
637
|
+
applyTransform();
|
|
638
|
+
},
|
|
639
|
+
{ passive: false },
|
|
640
|
+
);
|
|
641
|
+
|
|
642
|
+
svg.addEventListener("dblclick", () => {
|
|
643
|
+
fitGraph(layout);
|
|
644
|
+
applyTransform();
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
fitBtn?.addEventListener("click", () => {
|
|
648
|
+
fitGraph(layout);
|
|
649
|
+
applyTransform();
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// ------------------------------------------------------------------- modal
|
|
654
|
+
|
|
655
|
+
function renderModal(force = false) {
|
|
656
|
+
const root = $("modalRoot");
|
|
657
|
+
const project = currentProject();
|
|
658
|
+
const spec = app.brief ? null : project?.specs.find((item) => item.id === app.specId);
|
|
659
|
+
|
|
660
|
+
if (!project || (!app.brief && !spec)) {
|
|
661
|
+
if (root.innerHTML) root.innerHTML = "";
|
|
662
|
+
app.modalSig = "";
|
|
663
|
+
document.body.classList.remove("modal-open");
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
const key = app.brief
|
|
668
|
+
? `brief:${project.slug}:${project.brief.length}`
|
|
669
|
+
: `${spec.id}:${spec.status}:${spec.body.length}`;
|
|
670
|
+
|
|
671
|
+
if (!force && key === app.modalSig && root.innerHTML) return;
|
|
672
|
+
app.modalSig = key;
|
|
673
|
+
|
|
674
|
+
const scrollTop = document.querySelector(".modal-body")?.scrollTop ?? 0;
|
|
675
|
+
|
|
676
|
+
if (app.brief) {
|
|
677
|
+
root.innerHTML = `<div class="modal-backdrop">
|
|
678
|
+
<article class="modal" role="dialog" aria-modal="true" aria-label="Project brief">
|
|
679
|
+
<div class="modal-intro">
|
|
680
|
+
${modalHead("Project brief", project.name, "Brief")}
|
|
681
|
+
</div>
|
|
682
|
+
<div class="modal-body markdown">${renderMarkdown(
|
|
683
|
+
stripHeading(project.brief, [project.name]),
|
|
684
|
+
)}</div>
|
|
685
|
+
<div class="modal-foot">
|
|
686
|
+
<span>${esc(project.brief_file || "PROJECT.md")}</span>
|
|
687
|
+
<span class="read-only">read only</span>
|
|
688
|
+
</div>
|
|
689
|
+
</article>
|
|
690
|
+
</div>`;
|
|
691
|
+
} else {
|
|
692
|
+
const links = linkRows(spec, project);
|
|
693
|
+
root.innerHTML = `<div class="modal-backdrop">
|
|
694
|
+
<article class="modal" role="dialog" aria-modal="true" aria-label="${esc(spec.title)}">
|
|
695
|
+
<div class="modal-intro">
|
|
696
|
+
${modalHead(
|
|
697
|
+
`${spec.id} · ${STATUS_LABEL[spec.status] || spec.status}`,
|
|
698
|
+
spec.title,
|
|
699
|
+
"Spec",
|
|
700
|
+
)}
|
|
701
|
+
<div class="modal-meta">${metaChips(spec)}</div>
|
|
702
|
+
${links}
|
|
703
|
+
</div>
|
|
704
|
+
<div class="modal-body markdown">${renderMarkdown(specBody(spec))}</div>
|
|
705
|
+
<div class="modal-foot">
|
|
706
|
+
<span>${esc(spec.file)}</span>
|
|
707
|
+
<span class="read-only">read only</span>
|
|
708
|
+
</div>
|
|
709
|
+
</article>
|
|
710
|
+
</div>`;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
document.body.classList.add("modal-open");
|
|
714
|
+
const body = document.querySelector(".modal-body");
|
|
715
|
+
if (body && scrollTop) body.scrollTop = scrollTop;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function modalHead(eyebrow, title, label) {
|
|
719
|
+
return `<header class="modal-head">
|
|
720
|
+
<div class="modal-eyebrow">${esc(eyebrow)}</div>
|
|
721
|
+
<h1 class="modal-title">${esc(title)}</h1>
|
|
722
|
+
<button type="button" class="modal-close" data-close aria-label="Close ${esc(label)}">×</button>
|
|
723
|
+
</header>`;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function metaChips(spec) {
|
|
727
|
+
const chips = [
|
|
728
|
+
`<span class="chip kind-${kindClass(spec.kind)}">${esc(spec.kind)}</span>`,
|
|
729
|
+
];
|
|
730
|
+
if (spec.priority) chips.push(`<span class="chip">${esc(spec.priority)}</span>`);
|
|
731
|
+
if (spec.milestone != null) {
|
|
732
|
+
chips.push(`<span class="chip">milestone ${esc(spec.milestone)}</span>`);
|
|
733
|
+
}
|
|
734
|
+
chips.push(
|
|
735
|
+
`<span class="chip status-${esc(spec.status)}">${esc(STATUS_LABEL[spec.status] || spec.status)}</span>`,
|
|
736
|
+
);
|
|
737
|
+
if (spec.blocked_reason) {
|
|
738
|
+
chips.push(`<span class="chip chip-warn">blocked: ${esc(spec.blocked_reason)}</span>`);
|
|
739
|
+
}
|
|
740
|
+
if (spec.completed) {
|
|
741
|
+
chips.push(`<span class="chip chip-done">completed ${esc(spec.completed)}</span>`);
|
|
742
|
+
}
|
|
743
|
+
if (spec.resolution) chips.push(`<span class="chip">${esc(spec.resolution)}</span>`);
|
|
744
|
+
return chips.join("");
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
function linkRows(spec, project) {
|
|
748
|
+
const rows = [];
|
|
749
|
+
const addRow = (label, ids) => {
|
|
750
|
+
if (!ids || !ids.length) return;
|
|
751
|
+
const items = ids
|
|
752
|
+
.map((id) => {
|
|
753
|
+
const target = project.specs.find((item) => item.id === id);
|
|
754
|
+
return target
|
|
755
|
+
? `<button type="button" class="chip dep" data-goto="${esc(id)}"><b>${esc(shortId(id))}</b>${esc(target.title)}</button>`
|
|
756
|
+
: `<span class="chip dep missing" title="No spec with this id is on the board"><b>${esc(id)}</b>missing</span>`;
|
|
757
|
+
})
|
|
758
|
+
.join("");
|
|
759
|
+
rows.push(
|
|
760
|
+
`<div class="chip-row"><span class="chip-label">${esc(label)}</span>${items}</div>`,
|
|
761
|
+
);
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
addRow("Depends on", spec.depends_on);
|
|
765
|
+
addRow("Related", spec.related);
|
|
766
|
+
if (spec.surfaces && spec.surfaces.length) {
|
|
767
|
+
const items = spec.surfaces
|
|
768
|
+
.map((surface) => `<span class="chip surface">${esc(surface)}</span>`)
|
|
769
|
+
.join("");
|
|
770
|
+
rows.push(
|
|
771
|
+
`<div class="chip-row"><span class="chip-label">Surfaces</span>${items}</div>`,
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
return rows.join("");
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// ------------------------------------------------------------------ render
|
|
778
|
+
|
|
779
|
+
function render() {
|
|
780
|
+
renderHeader();
|
|
781
|
+
if (!app.data) {
|
|
782
|
+
$("main").className = "board-view";
|
|
783
|
+
$("main").innerHTML = `<div class="empty">
|
|
784
|
+
<h1>Board data missing</h1>
|
|
785
|
+
<p>This page was not generated with a board. Run <code>couch-potator view</code> and open the file it writes.</p>
|
|
786
|
+
</div>`;
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
if (app.view === "graph") renderGraph();
|
|
790
|
+
else renderBoard();
|
|
791
|
+
renderModal();
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// ------------------------------------------------------------------ routes
|
|
795
|
+
|
|
796
|
+
function readRoute() {
|
|
797
|
+
const params = new URLSearchParams(window.location.hash.replace(/^#/, ""));
|
|
798
|
+
const projects = app.data?.projects || [];
|
|
799
|
+
if (!projects.length) {
|
|
800
|
+
app.projectSlug = null;
|
|
801
|
+
app.specId = null;
|
|
802
|
+
app.brief = false;
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
const wanted = params.get("project") || stored("board.project");
|
|
807
|
+
app.projectSlug = projects.some((project) => project.slug === wanted)
|
|
808
|
+
? wanted
|
|
809
|
+
: projects[0].slug;
|
|
810
|
+
app.view = params.get("view") === "graph" ? "graph" : "board";
|
|
811
|
+
|
|
812
|
+
const project = currentProject();
|
|
813
|
+
app.milestone = chooseMilestone(
|
|
814
|
+
project,
|
|
815
|
+
params.get("milestone") ?? stored("board.milestone"),
|
|
816
|
+
);
|
|
817
|
+
|
|
818
|
+
const specId = params.get("spec");
|
|
819
|
+
app.specId =
|
|
820
|
+
specId && visibleSpecs(project).some((spec) => spec.id === specId) ? specId : null;
|
|
821
|
+
app.brief = false;
|
|
822
|
+
app.modalSig = "";
|
|
823
|
+
app.graph.manual = false;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
function writeRoute() {
|
|
827
|
+
const params = new URLSearchParams();
|
|
828
|
+
if (app.projectSlug) params.set("project", app.projectSlug);
|
|
829
|
+
if (app.view === "graph") params.set("view", "graph");
|
|
830
|
+
if (app.milestone != null) params.set("milestone", String(app.milestone));
|
|
831
|
+
if (app.specId) params.set("spec", app.specId);
|
|
832
|
+
|
|
833
|
+
const query = params.toString();
|
|
834
|
+
const url = `${window.location.pathname}${query ? `#${query}` : ""}`;
|
|
835
|
+
try {
|
|
836
|
+
window.history.replaceState(null, "", url);
|
|
837
|
+
} catch {
|
|
838
|
+
if (window.location.hash !== (query ? `#${query}` : "")) {
|
|
839
|
+
window.location.hash = query;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
if (app.projectSlug) {
|
|
844
|
+
store("board.project", app.projectSlug);
|
|
845
|
+
store("board.milestone", app.milestone == null ? "all" : String(app.milestone));
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
function setView(view) {
|
|
850
|
+
if (app.view === view) return;
|
|
851
|
+
app.view = view;
|
|
852
|
+
if (view === "graph") app.graph.manual = false;
|
|
853
|
+
writeRoute();
|
|
854
|
+
render();
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function setProject(slug) {
|
|
858
|
+
if (!slug || slug === app.projectSlug) return;
|
|
859
|
+
app.projectSlug = slug;
|
|
860
|
+
app.milestone = chooseMilestone(currentProject(), null);
|
|
861
|
+
app.specId = null;
|
|
862
|
+
app.brief = false;
|
|
863
|
+
app.modalSig = "";
|
|
864
|
+
app.graph.manual = false;
|
|
865
|
+
writeRoute();
|
|
866
|
+
render();
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
function setMilestone(value) {
|
|
870
|
+
const next = value === "all" ? null : Number(value);
|
|
871
|
+
if (next === app.milestone) return;
|
|
872
|
+
|
|
873
|
+
app.milestone = next;
|
|
874
|
+
const project = currentProject();
|
|
875
|
+
if (app.specId && !visibleSpecs(project).some((spec) => spec.id === app.specId)) {
|
|
876
|
+
app.specId = null;
|
|
877
|
+
app.modalSig = "";
|
|
878
|
+
}
|
|
879
|
+
app.graph.manual = false;
|
|
880
|
+
writeRoute();
|
|
881
|
+
render();
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function openSpec(id) {
|
|
885
|
+
app.specId = id;
|
|
886
|
+
app.brief = false;
|
|
887
|
+
app.modalSig = "";
|
|
888
|
+
writeRoute();
|
|
889
|
+
renderModal(true);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
function openBrief() {
|
|
893
|
+
if (!currentProject()) return;
|
|
894
|
+
app.brief = true;
|
|
895
|
+
app.specId = null;
|
|
896
|
+
app.modalSig = "";
|
|
897
|
+
writeRoute();
|
|
898
|
+
renderModal(true);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
function closeModal() {
|
|
902
|
+
app.specId = null;
|
|
903
|
+
app.brief = false;
|
|
904
|
+
app.modalSig = "";
|
|
905
|
+
writeRoute();
|
|
906
|
+
renderModal(true);
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
// ------------------------------------------------------------------ events
|
|
910
|
+
|
|
911
|
+
function wireEvents() {
|
|
912
|
+
document.addEventListener("click", (event) => {
|
|
913
|
+
const target = event.target;
|
|
914
|
+
if (!(target instanceof Element)) return;
|
|
915
|
+
|
|
916
|
+
if (target.closest("#reloadBtn")) {
|
|
917
|
+
window.location.reload();
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
const goto = target.closest("[data-goto]");
|
|
922
|
+
if (goto) {
|
|
923
|
+
event.preventDefault();
|
|
924
|
+
openSpec(goto.dataset.goto);
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
if (target.closest("[data-close]") || target.classList.contains("modal-backdrop")) {
|
|
929
|
+
closeModal();
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
const viewButton = target.closest("[data-view]");
|
|
934
|
+
if (viewButton) {
|
|
935
|
+
setView(viewButton.dataset.view);
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
if (target.closest("#briefBtn")) {
|
|
940
|
+
openBrief();
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
const card = target.closest("[data-spec]");
|
|
945
|
+
if (card && !card.closest(".modal")) {
|
|
946
|
+
openSpec(card.dataset.spec);
|
|
947
|
+
}
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
document.addEventListener("change", (event) => {
|
|
951
|
+
if (!(event.target instanceof HTMLSelectElement)) return;
|
|
952
|
+
if (event.target.id === "projectSelect") {
|
|
953
|
+
setProject(event.target.value);
|
|
954
|
+
} else if (event.target.id === "milestoneSelect") {
|
|
955
|
+
setMilestone(event.target.value);
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
|
|
959
|
+
document.addEventListener("keydown", (event) => {
|
|
960
|
+
if (event.key === "Escape" && (app.specId || app.brief)) {
|
|
961
|
+
closeModal();
|
|
962
|
+
}
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
window.addEventListener("hashchange", () => {
|
|
966
|
+
readRoute();
|
|
967
|
+
render();
|
|
968
|
+
});
|
|
969
|
+
|
|
970
|
+
let resizeTimer = null;
|
|
971
|
+
window.addEventListener("resize", () => {
|
|
972
|
+
window.clearTimeout(resizeTimer);
|
|
973
|
+
resizeTimer = window.setTimeout(() => {
|
|
974
|
+
if (app.view === "graph") {
|
|
975
|
+
app.graph.manual = false;
|
|
976
|
+
renderGraph();
|
|
977
|
+
}
|
|
978
|
+
}, 120);
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
// -------------------------------------------------------------------- boot
|
|
983
|
+
|
|
984
|
+
function boot() {
|
|
985
|
+
configureMarkdown();
|
|
986
|
+
wireEvents();
|
|
987
|
+
loadData();
|
|
988
|
+
readRoute();
|
|
989
|
+
render();
|
|
990
|
+
writeRoute();
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
boot();
|
|
994
|
+
})();
|