reqtable 0.1.0__py3-none-any.whl
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.
- reqtable/__init__.py +3 -0
- reqtable/__main__.py +3 -0
- reqtable/baselines.py +920 -0
- reqtable/cli.py +631 -0
- reqtable/comparison.py +63 -0
- reqtable/core.py +1448 -0
- reqtable/drafts.py +166 -0
- reqtable/findings.py +605 -0
- reqtable/gate_checks.py +84 -0
- reqtable/gates.py +348 -0
- reqtable/glossary.py +162 -0
- reqtable/gui.py +952 -0
- reqtable/gui_lookups.py +192 -0
- reqtable/gui_mapping.py +789 -0
- reqtable/gui_page.py +691 -0
- reqtable/gui_page_gates.py +173 -0
- reqtable/gui_page_mapping.py +390 -0
- reqtable/gui_server.py +467 -0
- reqtable/html_report.py +2595 -0
- reqtable/markdown.py +127 -0
- reqtable/package.py +163 -0
- reqtable/quality.py +422 -0
- reqtable/review.py +318 -0
- reqtable/signoff.py +179 -0
- reqtable/traceability.py +1670 -0
- reqtable/values.py +192 -0
- reqtable/waivers.py +109 -0
- reqtable/xlsx.py +1108 -0
- reqtable-0.1.0.dist-info/METADATA +106 -0
- reqtable-0.1.0.dist-info/RECORD +33 -0
- reqtable-0.1.0.dist-info/WHEEL +4 -0
- reqtable-0.1.0.dist-info/entry_points.txt +2 -0
- reqtable-0.1.0.dist-info/licenses/LICENSE +21 -0
reqtable/gui_page.py
ADDED
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
"""The single page the GUI serves. It renders every form from /api/workflows, so field lists live only in reqtable.gui."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
from .gui_page_gates import GATES_JS
|
|
8
|
+
from .gui_page_mapping import MAPPING_JS
|
|
9
|
+
|
|
10
|
+
PAGE = r"""<!doctype html>
|
|
11
|
+
<html lang="en">
|
|
12
|
+
<head>
|
|
13
|
+
<meta charset="utf-8">
|
|
14
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
15
|
+
<title>reqtable</title>
|
|
16
|
+
<style>
|
|
17
|
+
:root {
|
|
18
|
+
--bg: #f5f6f8; --surface: #ffffff; --surface-2: #eef0f4; --text: #1d2330; --muted: #5b6475;
|
|
19
|
+
--line: #d9dde6; --accent: #2457d6; --accent-text: #ffffff; --accent-soft: #e3ebfd;
|
|
20
|
+
--ok: #1a7f4b; --ok-soft: #e1f4ea; --bad: #b42318; --bad-soft: #fde8e6; --warn-soft: #fff4d6;
|
|
21
|
+
--code-bg: #111827; --code-text: #e5e7eb; --radius: 10px;
|
|
22
|
+
}
|
|
23
|
+
@media (prefers-color-scheme: dark) {
|
|
24
|
+
:root {
|
|
25
|
+
--bg: #12151b; --surface: #1a1e27; --surface-2: #232834; --text: #e6e9ef; --muted: #9aa3b5;
|
|
26
|
+
--line: #2f3645; --accent: #7aa2ff; --accent-text: #0c1020; --accent-soft: #212c4a;
|
|
27
|
+
--ok: #5fd39a; --ok-soft: #173326; --bad: #ff8d82; --bad-soft: #3a1c1a; --warn-soft: #3b3217;
|
|
28
|
+
--code-bg: #0b0e14; --code-text: #dfe3ec;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
* { box-sizing: border-box; }
|
|
32
|
+
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
33
|
+
header { padding: 18px 24px 6px; }
|
|
34
|
+
header h1 { margin: 0; font-size: 22px; }
|
|
35
|
+
header p { margin: 2px 0 0; color: var(--muted); }
|
|
36
|
+
.layout { display: grid; grid-template-columns: 270px minmax(0, 1fr) 340px; gap: 20px; padding: 16px 24px 40px; align-items: start; }
|
|
37
|
+
@media (max-width: 1150px) { .layout { grid-template-columns: 250px minmax(0, 1fr); } #panel { grid-column: 1 / -1; } }
|
|
38
|
+
@media (max-width: 760px) { .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 32px; } header { padding: 16px 16px 0; } }
|
|
39
|
+
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
|
|
40
|
+
.card, #nav button.task { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
|
|
41
|
+
.card { padding: 18px; margin-bottom: 16px; }
|
|
42
|
+
#nav { display: flex; flex-direction: column; gap: 8px; }
|
|
43
|
+
#nav button.task { text-align: left; padding: 12px 14px; cursor: pointer; color: var(--text); font: inherit; }
|
|
44
|
+
#nav button.task:hover { border-color: var(--accent); }
|
|
45
|
+
#nav button.task[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
|
|
46
|
+
#nav .title { display: block; font-weight: 600; }
|
|
47
|
+
#nav .when { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
|
|
48
|
+
#nav h3.group { margin: 12px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
|
|
49
|
+
#nav h3.group:first-child { margin-top: 0; }
|
|
50
|
+
.intro ol { margin: 8px 0 0; padding-left: 20px; } .intro li { margin: 4px 0; }
|
|
51
|
+
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
|
|
52
|
+
.cards .opt { position: relative; display: block; margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); cursor: pointer; font-weight: 400; }
|
|
53
|
+
.cards .opt:hover { border-color: var(--accent); }
|
|
54
|
+
.cards .opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
|
|
55
|
+
.cards .opt:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 1px; }
|
|
56
|
+
.cards .opt input { position: absolute; opacity: 0; pointer-events: none; }
|
|
57
|
+
.cards .opt .opt-title { display: block; font-weight: 700; }
|
|
58
|
+
.cards .opt .opt-desc { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
|
|
59
|
+
.preview { margin-top: 8px; font-size: 13px; }
|
|
60
|
+
.preview table, table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
|
|
61
|
+
.preview { overflow-x: auto; }
|
|
62
|
+
.preview th, .preview td, table.grid th, table.grid td { border: 1px solid var(--line); padding: 3px 8px; text-align: left; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
63
|
+
.preview th, table.grid th { background: var(--surface-2); font-weight: 600; }
|
|
64
|
+
.preview .count { color: var(--muted); margin: 0 0 4px; } .preview .count strong { color: var(--text); }
|
|
65
|
+
.check { display: flex; gap: 8px; align-items: baseline; margin: 2px 0; font-weight: 400; }
|
|
66
|
+
.check input { width: auto; }
|
|
67
|
+
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-left: 6px; }
|
|
68
|
+
.badge.strict { background: var(--warn-soft); color: var(--text); }
|
|
69
|
+
.waiver { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(160px, 2fr) auto; gap: 6px; margin: 0 0 6px; }
|
|
70
|
+
ul.plain { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
|
|
71
|
+
.banner.soft { background: var(--warn-soft); }
|
|
72
|
+
.banner.fail { background: var(--bad-soft); white-space: pre-wrap; }
|
|
73
|
+
.waiveoffer { margin-top: 10px; }
|
|
74
|
+
.waiveoffer .actions { margin-top: 6px; }
|
|
75
|
+
.srcrow { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0 0 10px; background: var(--surface); }
|
|
76
|
+
.srcrow .top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(160px, 220px) 120px; gap: 10px; align-items: end; }
|
|
77
|
+
@media (max-width: 760px) { .srcrow .top { grid-template-columns: minmax(0, 1fr); } }
|
|
78
|
+
.srcrow .nm { font-weight: 600; word-break: break-word; } .srcrow .sub { color: var(--muted); font-size: 12px; }
|
|
79
|
+
.srcrow label.mini { font-size: 12px; margin: 0 0 2px; color: var(--muted); font-weight: 500; }
|
|
80
|
+
table.cols { width: 100%; margin-top: 10px; border-collapse: collapse; font-size: 14px; }
|
|
81
|
+
table.cols th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 2px 6px; }
|
|
82
|
+
table.cols td { padding: 3px 6px; vertical-align: middle; border-top: 1px solid var(--line); }
|
|
83
|
+
table.cols td.src { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; word-break: break-word; }
|
|
84
|
+
table.cols select, table.cols input { padding: 4px 6px; }
|
|
85
|
+
pre.json { margin: 0; padding: 12px 14px; background: var(--code-bg); color: var(--code-text); border-radius: 8px; overflow: auto; max-height: 340px; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; user-select: all; }
|
|
86
|
+
.field { margin: 0 0 16px; } .field[hidden] { display: none; }
|
|
87
|
+
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
|
|
88
|
+
.req { font-weight: 500; font-size: 12px; color: var(--accent); margin-left: 6px; }
|
|
89
|
+
.help { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
|
|
90
|
+
.note { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
|
|
91
|
+
input[type=text], input[type=number], select {
|
|
92
|
+
width: 100%; padding: 8px 10px; font: inherit; color: var(--text); background: var(--surface);
|
|
93
|
+
border: 1px solid var(--line); border-radius: 8px;
|
|
94
|
+
}
|
|
95
|
+
.pathrow { display: flex; gap: 8px; } .pathrow input { flex: 1; min-width: 0; }
|
|
96
|
+
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); padding: 8px 14px; }
|
|
97
|
+
button:hover:not(:disabled) { border-color: var(--accent); }
|
|
98
|
+
button:disabled { opacity: .5; cursor: not-allowed; }
|
|
99
|
+
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
|
|
100
|
+
button.small { padding: 3px 9px; font-size: 13px; }
|
|
101
|
+
:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
|
|
102
|
+
details.more { margin: 8px 0 16px; border-top: 1px solid var(--line); padding-top: 12px; }
|
|
103
|
+
details.more > summary { cursor: pointer; font-weight: 600; color: var(--accent); margin-bottom: 12px; }
|
|
104
|
+
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
|
|
105
|
+
.tabs button { border: 0; border-radius: 0; background: var(--surface); padding: 4px 12px; font-size: 13px; }
|
|
106
|
+
.tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
|
|
107
|
+
.commandbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
|
|
108
|
+
pre.command, pre.output { margin: 0; padding: 12px 14px; background: var(--code-bg); color: var(--code-text); border-radius: 8px; overflow-x: auto; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; user-select: all; }
|
|
109
|
+
pre.output { user-select: text; max-height: 320px; overflow: auto; }
|
|
110
|
+
.hint { color: var(--muted); }
|
|
111
|
+
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
|
|
112
|
+
.result { margin-top: 14px; }
|
|
113
|
+
.banner { padding: 12px 14px; border-radius: 8px; margin-bottom: 10px; }
|
|
114
|
+
.banner.ok { background: var(--ok-soft); } .banner.bad { background: var(--bad-soft); }
|
|
115
|
+
.banner strong { display: block; }
|
|
116
|
+
.banner .cli-error { display: block; margin-top: 6px; font: 600 14px ui-monospace, Menlo, Consolas, monospace; color: var(--bad); word-break: break-word; }
|
|
117
|
+
.banner.warn { background: var(--warn-soft); font-size: 14px; }
|
|
118
|
+
.steps { list-style: none; margin: 0 0 12px; padding: 0; }
|
|
119
|
+
.step { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: var(--surface); }
|
|
120
|
+
.step .head { display: flex; align-items: center; gap: 6px; }
|
|
121
|
+
.step .head .name { flex: 1; font-weight: 600; min-width: 0; }
|
|
122
|
+
.step pre { margin: 8px 0 0; padding: 8px 10px; background: var(--code-bg); color: var(--code-text); border-radius: 6px; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; overflow-x: auto; }
|
|
123
|
+
.empty { color: var(--muted); }
|
|
124
|
+
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(640px, 94vw); }
|
|
125
|
+
dialog::backdrop { background: rgba(0,0,0,.45); }
|
|
126
|
+
.dlg { padding: 16px; display: flex; flex-direction: column; gap: 10px; max-height: 80vh; }
|
|
127
|
+
.dlg .where { font: 13px ui-monospace, Menlo, Consolas, monospace; word-break: break-all; color: var(--muted); }
|
|
128
|
+
.dlg .places { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
129
|
+
.dlg ul { list-style: none; margin: 0; padding: 0; overflow: auto; border: 1px solid var(--line); border-radius: 8px; min-height: 120px; flex: 1; }
|
|
130
|
+
.dlg li button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; background: transparent; padding: 8px 12px; }
|
|
131
|
+
.dlg li button:hover { background: var(--accent-soft); }
|
|
132
|
+
.dlg .foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
|
|
133
|
+
.dlg .foot input { flex: 1; min-width: 160px; }
|
|
134
|
+
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
|
|
135
|
+
</style>
|
|
136
|
+
</head>
|
|
137
|
+
<body>
|
|
138
|
+
<header>
|
|
139
|
+
<h1>reqtable</h1>
|
|
140
|
+
<p>Turn requirements spreadsheets into reports. Every step shows the exact command it runs, so you can repeat it later.</p>
|
|
141
|
+
</header>
|
|
142
|
+
<div class="layout">
|
|
143
|
+
<nav aria-label="Tasks"><h2>What do you want to do?</h2><div id="nav"></div></nav>
|
|
144
|
+
<main id="main"></main>
|
|
145
|
+
<aside id="panel" class="card" aria-label="Your workflow"></aside>
|
|
146
|
+
</div>
|
|
147
|
+
<dialog id="picker" aria-label="Choose a file or folder"></dialog>
|
|
148
|
+
<div class="sr" role="status" aria-live="polite" id="live"></div>
|
|
149
|
+
<script>
|
|
150
|
+
const TOKEN = __TOKEN__;
|
|
151
|
+
const $ = (id) => document.getElementById(id);
|
|
152
|
+
const freshLookups = () => ({
|
|
153
|
+
columns: [], rowCount: 0, previewRows: [], tables: [], sheets: [], columnsError: "", idNote: "", tablesError: "", tablesLoaded: false, configMaps: false,
|
|
154
|
+
gates: [], gatesError: "", store: "", baselines: [], baselinesError: "", systems: [],
|
|
155
|
+
});
|
|
156
|
+
const state = { workflows: [], mapping: null, workdir: "", current: null, values: {}, autoId: {}, shell: "sh", steps: [], preview: null, rows: {}, lookups: freshLookups() };
|
|
157
|
+
|
|
158
|
+
function h(tag, attrs, ...kids) {
|
|
159
|
+
const el = document.createElement(tag);
|
|
160
|
+
for (const [k, v] of Object.entries(attrs || {})) {
|
|
161
|
+
if (k === "class") el.className = v;
|
|
162
|
+
else if (k.startsWith("on")) el.addEventListener(k.slice(2), v);
|
|
163
|
+
else if (v === true) el.setAttribute(k, "");
|
|
164
|
+
else if (v !== false && v != null) el.setAttribute(k, v);
|
|
165
|
+
}
|
|
166
|
+
for (const kid of kids.flat()) if (kid != null) el.append(kid);
|
|
167
|
+
return el;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function fill(box, ...kids) { box.replaceChildren(...kids.flat().filter((k) => k != null)); }
|
|
171
|
+
|
|
172
|
+
async function api(path, body) {
|
|
173
|
+
const options = { headers: { "X-Reqtable-Token": TOKEN } };
|
|
174
|
+
if (body !== undefined) { options.method = "POST"; options.headers["Content-Type"] = "application/json"; options.body = JSON.stringify(body); }
|
|
175
|
+
const response = await fetch(path, options);
|
|
176
|
+
const data = await response.json().catch(() => ({ error: "The reqtable server sent something unexpected." }));
|
|
177
|
+
if (!response.ok) throw new Error(data.error || "Request failed");
|
|
178
|
+
return data;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const stepsKey = () => "reqtable.steps:" + state.workdir;
|
|
182
|
+
function remember() {
|
|
183
|
+
try { localStorage.setItem(stepsKey(), JSON.stringify(state.steps)); localStorage.setItem("reqtable.shell", state.shell); } catch (e) {}
|
|
184
|
+
}
|
|
185
|
+
function restore() {
|
|
186
|
+
try {
|
|
187
|
+
const steps = JSON.parse(localStorage.getItem(stepsKey()) || "[]");
|
|
188
|
+
if (Array.isArray(steps)) state.steps = steps.filter((s) => s && s.workflow && s.sh && s.powershell);
|
|
189
|
+
const shell = localStorage.getItem("reqtable.shell");
|
|
190
|
+
if (shell === "sh" || shell === "powershell") state.shell = shell;
|
|
191
|
+
} catch (e) {}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const workflow = () => state.workflows.find((w) => w.id === state.current);
|
|
195
|
+
const shellName = () => (state.shell === "sh" ? "macOS / Linux (sh)" : "Windows (PowerShell)");
|
|
196
|
+
|
|
197
|
+
function announce(text) { $("live").textContent = text; }
|
|
198
|
+
|
|
199
|
+
async function copyText(text, button) {
|
|
200
|
+
let done = false;
|
|
201
|
+
try { await navigator.clipboard.writeText(text); done = true; } catch (e) {}
|
|
202
|
+
if (!done) {
|
|
203
|
+
const area = h("textarea", { class: "sr" }); area.value = text; document.body.append(area); area.select();
|
|
204
|
+
try { done = document.execCommand("copy"); } catch (e) {}
|
|
205
|
+
area.remove();
|
|
206
|
+
}
|
|
207
|
+
const old = button.textContent;
|
|
208
|
+
button.textContent = done ? "Copied" : "Press Ctrl+C to copy";
|
|
209
|
+
setTimeout(() => { button.textContent = old; }, 1800);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function shellTabs(onChange) {
|
|
213
|
+
const tab = (value, label) => h("button", { type: "button", "aria-pressed": String(state.shell === value), onclick: () => { state.shell = value; remember(); onChange(); } }, label);
|
|
214
|
+
return h("div", { class: "tabs", role: "group", "aria-label": "Shell" }, tab("sh", "macOS / Linux"), tab("powershell", "Windows"));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function renderNav() {
|
|
218
|
+
const nav = $("nav"); nav.replaceChildren();
|
|
219
|
+
let group = null;
|
|
220
|
+
for (const w of state.workflows) {
|
|
221
|
+
if (w.group !== group) { group = w.group; nav.append(h("h3", { class: "group" }, group)); }
|
|
222
|
+
nav.append(h("button", { class: "task", type: "button", "aria-current": String(w.id === state.current), onclick: () => choose(w.id) },
|
|
223
|
+
h("span", { class: "title" }, w.title), h("span", { class: "when" }, w.when)));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function renderIntro() {
|
|
228
|
+
$("main").replaceChildren(h("div", { class: "card intro" },
|
|
229
|
+
h("h2", {}, "Welcome"),
|
|
230
|
+
h("p", {}, "Pick a task on the left. You will fill in a short form and press Run. reqtable then does the work on your computer; nothing is uploaded."),
|
|
231
|
+
h("ol", {},
|
|
232
|
+
h("li", {}, "Choose your spreadsheet, and where to save the result."),
|
|
233
|
+
h("li", {}, "Check the command shown under the form. It is exactly what runs, and you can copy it."),
|
|
234
|
+
h("li", {}, "Add steps to your workflow and save them as a script to repeat them later.")),
|
|
235
|
+
h("p", { class: "note" }, "To edit requirements in the browser, choose “Edit requirements (Develop report)”. To keep a frozen record of a review, look under “Gates and sign-off”.")));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function isWorkbook(v) { return /\.xlsx$/i.test(v || ""); }
|
|
239
|
+
function workbookPath() {
|
|
240
|
+
const values = state.values[state.current];
|
|
241
|
+
for (const name of workflow().table_inputs) if (isWorkbook(values[name])) return values[name];
|
|
242
|
+
return "";
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const PANELS = {};
|
|
246
|
+
let panelRefresh = null;
|
|
247
|
+
|
|
248
|
+
async function choose(id) {
|
|
249
|
+
state.current = id;
|
|
250
|
+
const w = workflow();
|
|
251
|
+
renderNav();
|
|
252
|
+
state.rows = {}; state.preview = null; panelRefresh = null;
|
|
253
|
+
if (w.panel !== "form") {
|
|
254
|
+
PANELS[w.panel](w); renderPanel();
|
|
255
|
+
if (window.innerWidth < 760) $("main").scrollIntoView({ behavior: "smooth" });
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (!state.values[id]) {
|
|
259
|
+
state.values[id] = {};
|
|
260
|
+
for (const f of w.fields) if (f.default) state.values[id][f.name] = f.default;
|
|
261
|
+
}
|
|
262
|
+
state.lookups = freshLookups();
|
|
263
|
+
renderForm();
|
|
264
|
+
if (window.innerWidth < 760) $("main").scrollIntoView({ behavior: "smooth" });
|
|
265
|
+
lookupTables(); lookupColumns(); lookupGateData(); refreshPreview();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function renderForm() {
|
|
269
|
+
const w = workflow();
|
|
270
|
+
const main = h("div", {});
|
|
271
|
+
const form = h("div", { class: "card" }, h("h2", {}, w.title), h("p", { class: "hint" }, w.summary));
|
|
272
|
+
if (w.fixed.length) form.append(h("p", { class: "note", style: "margin:6px 0 14px" }, "This card always runs with ", h("code", {}, w.fixed.join(" ")), "."));
|
|
273
|
+
const more = h("details", { class: "more" }, h("summary", {}, "More options"));
|
|
274
|
+
let advanced = 0;
|
|
275
|
+
for (const f of w.fields) {
|
|
276
|
+
const row = buildField(f);
|
|
277
|
+
state.rows[f.name] = row;
|
|
278
|
+
if (f.advanced) { more.append(row.wrap); advanced++; } else form.append(row.wrap);
|
|
279
|
+
}
|
|
280
|
+
if (advanced) form.append(more);
|
|
281
|
+
const commandBox = h("div", { class: "card", id: "commandcard" });
|
|
282
|
+
main.append(form, commandBox, h("div", { id: "result" }));
|
|
283
|
+
$("main").replaceChildren(main);
|
|
284
|
+
syncVisibility(); renderColumns(); renderTableChoices(); renderLookups(); renderPreview();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function setValue(f, value) { state.values[state.current][f.name] = value; onChange(f); }
|
|
288
|
+
|
|
289
|
+
function radioCards(f, id, value, set) {
|
|
290
|
+
const group = h("div", { class: "cards", role: "radiogroup", "aria-labelledby": id + "-label" });
|
|
291
|
+
for (const [v, text] of f.choices) {
|
|
292
|
+
const [title, ...rest] = text.split(": ");
|
|
293
|
+
const input = h("input", { type: "radio", name: id, value: v, onchange: () => set(v) });
|
|
294
|
+
input.checked = value === v;
|
|
295
|
+
group.append(h("label", { class: "opt" }, input, h("span", { class: "opt-title" }, title), rest.length ? h("span", { class: "opt-desc" }, rest.join(": ")) : null));
|
|
296
|
+
}
|
|
297
|
+
return group;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function buildField(f) {
|
|
301
|
+
const id = "f-" + f.name;
|
|
302
|
+
const wrap = h("div", { class: "field" });
|
|
303
|
+
const required = f.required ? h("span", { class: "req" }, "required") : null;
|
|
304
|
+
const label = f.kind === "radio" ? h("div", { class: "lab", id: id + "-label", style: "font-weight:600;margin-bottom:6px" }, f.label, required) : h("label", { for: id }, f.label, required);
|
|
305
|
+
const row = { field: f, wrap, control: null, extra: null, preview: null };
|
|
306
|
+
const set = (value) => setValue(f, value);
|
|
307
|
+
const value = state.values[state.current][f.name] || "";
|
|
308
|
+
if (f.kind === "open" || f.kind === "save") {
|
|
309
|
+
const input = h("input", { type: "text", id, value, spellcheck: "false", oninput: (e) => set(e.target.value), placeholder: f.kind === "open" ? "Choose a file…" : "Choose where to save…" });
|
|
310
|
+
input.value = value;
|
|
311
|
+
row.control = input;
|
|
312
|
+
wrap.append(label, h("div", { class: "pathrow" }, input,
|
|
313
|
+
h("button", { type: "button", onclick: () => pickPath(f, input, set) }, f.kind === "open" ? "Browse…" : "Choose location…")));
|
|
314
|
+
} else if (f.kind === "radio") {
|
|
315
|
+
wrap.append(label, radioCards(f, id, value, set));
|
|
316
|
+
} else if (f.kind === "choice" || f.kind === "flag") {
|
|
317
|
+
const select = h("select", { id, onchange: (e) => set(e.target.value) });
|
|
318
|
+
const options = f.choices.slice();
|
|
319
|
+
if (!f.default && !options.some(([v]) => v === "")) options.unshift(["", "Default"]);
|
|
320
|
+
for (const [v, text] of options) select.append(h("option", { value: v }, text));
|
|
321
|
+
select.value = value;
|
|
322
|
+
row.control = select;
|
|
323
|
+
wrap.append(label, select);
|
|
324
|
+
} else if (f.kind === "column") {
|
|
325
|
+
row.extra = h("div", {}); row.preview = h("div", { class: "preview" });
|
|
326
|
+
wrap.append(label, row.extra);
|
|
327
|
+
} else if (f.kind === "table" || f.kind === "sheet" || LOOKUP_KINDS.has(f.kind)) {
|
|
328
|
+
row.extra = h("div", {});
|
|
329
|
+
wrap.append(label, row.extra);
|
|
330
|
+
} else {
|
|
331
|
+
const input = h("input", { type: f.kind === "number" ? "number" : "text", id, min: f.kind === "number" ? "1" : null, oninput: (e) => set(e.target.value), spellcheck: "false" });
|
|
332
|
+
input.value = value;
|
|
333
|
+
row.control = input;
|
|
334
|
+
wrap.append(label, input);
|
|
335
|
+
}
|
|
336
|
+
wrap.append(h("p", { class: "help" }, f.help));
|
|
337
|
+
row.note = h("p", { class: "note" }); wrap.append(row.note);
|
|
338
|
+
if (row.preview) wrap.append(row.preview);
|
|
339
|
+
return row;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function syncVisibility() {
|
|
343
|
+
const workbook = !!workbookPath();
|
|
344
|
+
const values = state.values[state.current] || {};
|
|
345
|
+
for (const row of Object.values(state.rows)) {
|
|
346
|
+
const f = row.field;
|
|
347
|
+
row.wrap.hidden = (f.xlsx_only && !workbook) || (!!f.requires && !values[f.requires]) || (f.kind === "system" && !systemNeeded());
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
let timers = {};
|
|
352
|
+
function later(name, fn, ms) { clearTimeout(timers[name]); timers[name] = setTimeout(fn, ms); }
|
|
353
|
+
|
|
354
|
+
const LOOKUP_FIELDS = ["input", "new", "table", "sheet", "header_row", "id_column", "config", "traceability", "encoding", "delimiter"];
|
|
355
|
+
|
|
356
|
+
function onChange(f) {
|
|
357
|
+
const values = state.values[state.current];
|
|
358
|
+
if (f.name === "table" && values.table) { values.sheet = ""; values.header_row = ""; }
|
|
359
|
+
if (f.name === "sheet" && values.sheet) values.table = "";
|
|
360
|
+
if (f.name === "sheet" && !values.sheet) values.header_row = "";
|
|
361
|
+
if (f.kind === "gate" && !systemNeeded()) values.system = "";
|
|
362
|
+
syncVisibility();
|
|
363
|
+
if (f.kind === "open") { later("tables", lookupTables, 200); }
|
|
364
|
+
if (f.kind === "open" || ["table", "sheet", "header_row", "encoding", "delimiter", "config"].includes(f.name)) later("columns", lookupColumns, 250);
|
|
365
|
+
if (["table", "sheet", "config"].includes(f.name)) { renderTableChoices(); renderColumns(); }
|
|
366
|
+
if (LOOKUP_FIELDS.includes(f.name)) later("lookups", lookupGateData, 300);
|
|
367
|
+
if (LOOKUP_KINDS.has(f.kind)) renderLookups();
|
|
368
|
+
refreshPreview();
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function textOrSelect(row, name, items, placeholder, blankLabel, emptyLabel) {
|
|
372
|
+
const values = state.values[state.current];
|
|
373
|
+
const holder = row.extra; holder.replaceChildren();
|
|
374
|
+
const id = "f-" + name;
|
|
375
|
+
const set = (v) => setValue(row.field, v);
|
|
376
|
+
if (!items.length && emptyLabel) {
|
|
377
|
+
holder.append(h("select", { id, disabled: true }, h("option", {}, emptyLabel)));
|
|
378
|
+
} else if (items.length) {
|
|
379
|
+
const select = h("select", { id, onchange: (e) => set(e.target.value) }, h("option", { value: "" }, blankLabel));
|
|
380
|
+
for (const [v, label] of items) select.append(h("option", { value: v }, label));
|
|
381
|
+
if (values[name] && !items.some(([v]) => v === values[name])) select.append(h("option", { value: values[name] }, values[name]));
|
|
382
|
+
select.value = values[name] || "";
|
|
383
|
+
holder.append(select);
|
|
384
|
+
} else {
|
|
385
|
+
const input = h("input", { type: "text", id, placeholder, spellcheck: "false", oninput: (e) => set(e.target.value) });
|
|
386
|
+
input.value = values[name] || "";
|
|
387
|
+
holder.append(input);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function tableState() {
|
|
392
|
+
const values = state.values[state.current] || {};
|
|
393
|
+
const L = state.lookups;
|
|
394
|
+
if (!workbookPath() || values.table || values.sheet) return { kind: "chosen" };
|
|
395
|
+
if (L.configMaps) return { kind: "config" };
|
|
396
|
+
if (L.tablesError) return { kind: "unknown" };
|
|
397
|
+
if (!L.tablesLoaded) return { kind: "loading" };
|
|
398
|
+
if (L.tables.length === 1) return { kind: "single", table: L.tables[0].name };
|
|
399
|
+
return { kind: "choose" };
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function renderColumns() {
|
|
403
|
+
const L = state.lookups; const t = tableState();
|
|
404
|
+
for (const row of Object.values(state.rows)) if (row.field.kind === "column") {
|
|
405
|
+
const holder = row.extra;
|
|
406
|
+
if (t.kind === "choose" || t.kind === "loading") {
|
|
407
|
+
holder.replaceChildren(h("select", { id: "f-" + row.field.name, disabled: true }, h("option", {}, t.kind === "choose" ? "Choose a table or sheet first" : "Looking inside the workbook…")));
|
|
408
|
+
row.note.textContent = t.kind === "choose" ? "This workbook has " + (L.tables.length === 0 ? "no tables" : L.tables.length + " tables") + ". Pick one of its tables or sheets above, then the columns appear here." : "";
|
|
409
|
+
row.preview.replaceChildren();
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (t.kind === "config") {
|
|
413
|
+
textOrSelect(row, row.field.name, [], "Leave empty to use the ID column named in your settings file", "");
|
|
414
|
+
row.note.textContent = "Your settings file decides which tables are read, so there is no table to choose here."; row.preview.replaceChildren();
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
textOrSelect(row, row.field.name, L.columns.map((c) => [c, c]), "Type the column name, for example ID", "Choose a column…");
|
|
418
|
+
row.note.textContent = L.columnsError || [L.idNote, t.kind === "single" ? "Reading table “" + t.table + "”, the only table in this workbook." : ""].filter(Boolean).join(" ");
|
|
419
|
+
renderPreviewTable(row);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function renderPreviewTable(row) {
|
|
424
|
+
const L = state.lookups; const box = row.preview; box.replaceChildren();
|
|
425
|
+
if (!L.columns.length) return;
|
|
426
|
+
const rows = L.previewRows || [];
|
|
427
|
+
const table = h("table", {}, h("thead", {}, h("tr", {}, L.columns.map((c) => h("th", {}, c)))),
|
|
428
|
+
h("tbody", {}, rows.map((r) => h("tr", {}, L.columns.map((_, i) => h("td", { title: r[i] || "" }, r[i] || ""))))));
|
|
429
|
+
box.append(h("p", { class: "count" }, h("strong", {}, "Preview: " + L.rowCount + " row" + (L.rowCount === 1 ? "" : "s")), rows.length < L.rowCount ? " (first " + rows.length + " shown)" : ""), table);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function renderTableChoices() {
|
|
433
|
+
for (const row of Object.values(state.rows)) {
|
|
434
|
+
if (row.field.kind === "table") textOrSelect(row, row.field.name, state.lookups.tables.map((t) => [t.name, t.name + " (sheet " + t.sheet + ")"]), "Table name", "Automatic", state.lookups.tablesLoaded ? "This workbook has no tables" : "");
|
|
435
|
+
if (row.field.kind === "sheet") textOrSelect(row, row.field.name, state.lookups.sheets.map((s) => [s.name, s.name]), "Sheet name", "None");
|
|
436
|
+
if (row.field.kind === "table" || row.field.kind === "sheet") row.note.textContent = state.lookups.tablesError;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
let tablesSeq = 0;
|
|
441
|
+
async function lookupTables() {
|
|
442
|
+
const path = workbookPath();
|
|
443
|
+
const id = state.current;
|
|
444
|
+
const L = state.lookups;
|
|
445
|
+
const seq = ++tablesSeq;
|
|
446
|
+
if (!path) { L.tables = []; L.sheets = []; L.tablesError = ""; L.tablesLoaded = false; L.configMaps = false; renderTableChoices(); renderColumns(); return; }
|
|
447
|
+
try {
|
|
448
|
+
const query = new URLSearchParams({ path, config: state.values[id].config || "" });
|
|
449
|
+
const data = await api("/api/tables?" + query);
|
|
450
|
+
if (id !== state.current || seq !== tablesSeq) return;
|
|
451
|
+
L.tables = data.tables; L.sheets = data.sheets; L.tablesError = data.error || ""; L.tablesLoaded = !data.error; L.configMaps = data.config_maps_workbook;
|
|
452
|
+
} catch (e) { if (seq !== tablesSeq) return; L.tablesError = e.message; L.tables = []; L.sheets = []; L.tablesLoaded = false; L.configMaps = false; }
|
|
453
|
+
renderTableChoices(); renderColumns(); lookupColumns();
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
let columnsSeq = 0;
|
|
457
|
+
async function lookupColumns() {
|
|
458
|
+
const w = workflow(); const id = state.current; const values = state.values[id]; const L = state.lookups;
|
|
459
|
+
const path = values[w.column_source];
|
|
460
|
+
const clear = () => { L.columns = []; L.columnsError = ""; L.rowCount = 0; L.previewRows = []; renderColumns(); };
|
|
461
|
+
if (!path || ["choose", "loading", "config"].includes(tableState().kind)) { clear(); return; }
|
|
462
|
+
const query = new URLSearchParams({ path });
|
|
463
|
+
for (const name of ["table", "sheet", "header_row", "encoding", "delimiter", "config"]) if (values[name]) query.set(name, values[name]);
|
|
464
|
+
const seq = ++columnsSeq;
|
|
465
|
+
try {
|
|
466
|
+
const data = await api("/api/columns?" + query);
|
|
467
|
+
if (id !== state.current || seq !== columnsSeq) return;
|
|
468
|
+
L.columns = data.columns; L.rowCount = data.row_count; L.previewRows = data.rows;
|
|
469
|
+
L.columnsError = data.error ? "Could not list the columns yet: " + data.error : "";
|
|
470
|
+
L.idNote = "";
|
|
471
|
+
const idField = w.fields.find((f) => f.kind === "column");
|
|
472
|
+
if (idField && data.columns.length) {
|
|
473
|
+
const current = values[idField.name] || "";
|
|
474
|
+
const guessed = !current || state.autoId[id] === current;
|
|
475
|
+
if (guessed || !data.columns.includes(current)) {
|
|
476
|
+
const next = data.id_guess || "";
|
|
477
|
+
if (!guessed) L.idNote = "“" + current + "” is not a column of this table, so the ID column was " + (next ? "set to “" + next + "”." : "cleared.");
|
|
478
|
+
values[idField.name] = next; state.autoId[id] = next;
|
|
479
|
+
if (next !== current) { refreshPreview(); lookupGateData(); }
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
} catch (e) { if (seq !== columnsSeq) return; L.columns = []; L.columnsError = e.message; }
|
|
483
|
+
renderColumns();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
let previewSeq = 0;
|
|
487
|
+
function refreshPreview() { later("preview", fetchPreview, 120); }
|
|
488
|
+
async function fetchPreview() {
|
|
489
|
+
const seq = ++previewSeq; const id = state.current;
|
|
490
|
+
if (!id || workflow().panel !== "form") return;
|
|
491
|
+
try {
|
|
492
|
+
const data = await api("/api/command", { workflow: id, values: state.values[id] });
|
|
493
|
+
if (seq !== previewSeq) return;
|
|
494
|
+
state.preview = data;
|
|
495
|
+
} catch (e) { if (seq !== previewSeq) return; state.preview = { error: e.message }; }
|
|
496
|
+
renderPreview();
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function renderPreview() {
|
|
500
|
+
const box = $("commandcard"); if (!box) return;
|
|
501
|
+
const p = state.preview;
|
|
502
|
+
const ready = p && !p.error;
|
|
503
|
+
const run = h("button", { class: "primary", type: "button", id: "runbtn", disabled: !ready, onclick: runNow }, "Run");
|
|
504
|
+
const add = h("button", { type: "button", disabled: !ready, onclick: () => addStep(true) }, "Add to workflow");
|
|
505
|
+
const text = ready ? p[state.shell] : "";
|
|
506
|
+
const replaces = ready && p.replaces.length
|
|
507
|
+
? h("div", { class: "banner warn" }, "Run will replace " + p.replaces.map(shownPath).join(", ") + ", which already exists. Choose another name to keep it.")
|
|
508
|
+
: null;
|
|
509
|
+
fill(box,
|
|
510
|
+
h("h2", {}, "The command behind this"),
|
|
511
|
+
h("div", { class: "commandbar" }, shellTabs(renderPreview),
|
|
512
|
+
h("button", { class: "small", type: "button", disabled: !ready, onclick: (e) => copyText(text, e.target) }, "Copy command")),
|
|
513
|
+
ready ? h("pre", { class: "command", tabindex: "0", "aria-label": "Command for " + shellName() }, text)
|
|
514
|
+
: h("p", { class: "hint" }, p && p.error ? p.error : "Fill in the form above to see the command."),
|
|
515
|
+
replaces, h("div", { class: "actions" }, run, add));
|
|
516
|
+
renderPanel();
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function makeStep(w, values, command) {
|
|
520
|
+
return { id: String(Date.now()) + Math.random().toString(16).slice(2), workflow: w.id, title: w.title, records: w.records,
|
|
521
|
+
values, sh: command.sh, powershell: command.powershell, argv: command.argv };
|
|
522
|
+
}
|
|
523
|
+
const stepFromForm = () => makeStep(workflow(), JSON.parse(JSON.stringify(state.values[state.current])), state.preview);
|
|
524
|
+
|
|
525
|
+
function pushStep(step, announceIt) {
|
|
526
|
+
const last = state.steps[state.steps.length - 1];
|
|
527
|
+
if (last && last.workflow === step.workflow && JSON.stringify(last.argv) === JSON.stringify(step.argv)) return false;
|
|
528
|
+
state.steps.push(step); remember(); renderPanel();
|
|
529
|
+
if (announceIt) announce("Added to your workflow: " + step.title);
|
|
530
|
+
return true;
|
|
531
|
+
}
|
|
532
|
+
function addStep(announceIt) { return pushStep(stepFromForm(), announceIt); }
|
|
533
|
+
|
|
534
|
+
async function runNow() {
|
|
535
|
+
const id = state.current; const w = workflow();
|
|
536
|
+
const button = $("runbtn"); button.disabled = true; button.textContent = "Running…";
|
|
537
|
+
$("result").replaceChildren(h("div", { class: "card" }, h("p", { class: "hint" }, "Running. Big spreadsheets can take a moment…")));
|
|
538
|
+
const values = JSON.parse(JSON.stringify(state.values[id]));
|
|
539
|
+
let data;
|
|
540
|
+
try { data = await api("/api/run", { workflow: id, values }); }
|
|
541
|
+
catch (e) { data = { error: e.message }; }
|
|
542
|
+
if (state.current !== id) return;
|
|
543
|
+
button.disabled = false; button.textContent = "Run";
|
|
544
|
+
renderResult(w, data, values);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
const EXIT_WORDS = { 2: "reqtable could not use these settings.", 3: "reqtable could not read an input file.", 4: "reqtable could not write the result file." };
|
|
548
|
+
|
|
549
|
+
function outputTable(w, text) {
|
|
550
|
+
const lines = text.split("\n").filter((l) => l.trim());
|
|
551
|
+
if (!lines.length || !lines.every((l) => l.includes("\t"))) return h("pre", { class: "output" }, text);
|
|
552
|
+
return h("table", { class: "grid" }, h("thead", {}, h("tr", {}, w.table.map((c) => h("th", {}, c)))),
|
|
553
|
+
h("tbody", {}, lines.map((l) => h("tr", {}, l.split("\t").map((c) => h("td", { title: c }, c))))));
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
function renderResult(w, data, values) {
|
|
557
|
+
const box = $("result");
|
|
558
|
+
if (data.error) { box.replaceChildren(h("div", { class: "card" }, h("div", { class: "banner bad" }, h("strong", {}, "That did not run."), h("span", { class: "cli-error" }, data.error)))); return; }
|
|
559
|
+
const stderr = data.stderr || "";
|
|
560
|
+
const errors = stderr.split("\n").filter((l) => /^error:/.test(l));
|
|
561
|
+
const warnings = stderr.split("\n").filter((l) => /^warning:/.test(l));
|
|
562
|
+
const outcome = Object.fromEntries(w.outcomes)[data.exit_code];
|
|
563
|
+
const ok = data.exit_code === 0;
|
|
564
|
+
const answer = !ok && outcome;
|
|
565
|
+
const card = h("div", { class: "card" });
|
|
566
|
+
if (ok) {
|
|
567
|
+
const saved = data.outputs.length ? "Saved: " + data.outputs.map(shownPath).join(", ") : "";
|
|
568
|
+
card.append(h("div", { class: "banner ok", role: "status" }, h("strong", {}, outcome || "Done."), saved, w.recorded ? h("div", {}, w.recorded) : null));
|
|
569
|
+
if (w.records) card.append(h("p", { class: "note" }, "This step was not added to your workflow, because running the script again would record it again. Use “Add to workflow” if you want that."));
|
|
570
|
+
else if (pushStep(makeStep(w, values, data), false)) card.append(h("p", { class: "note" }, "This step was added to your workflow."));
|
|
571
|
+
} else if (answer) {
|
|
572
|
+
card.append(h("div", { class: "banner soft", role: "status" }, h("strong", {}, outcome + "."), h("span", {}, "That is an answer, not a failure. Nothing was recorded and nothing was added to your workflow.")));
|
|
573
|
+
} else {
|
|
574
|
+
const words = data.exit_code === null ? "reqtable stopped because this took too long." : (EXIT_WORDS[data.exit_code] || "Something went wrong.");
|
|
575
|
+
card.append(h("div", { class: "banner bad", role: "alert" }, h("strong", {}, words + " Nothing was added to your workflow."),
|
|
576
|
+
errors.map((e) => h("span", { class: "cli-error" }, e)), errors.length ? null : h("span", {}, "See the details below.")));
|
|
577
|
+
}
|
|
578
|
+
if (warnings.length) card.append(h("div", { class: "banner warn" }, h("strong", {}, "Worth a look"), warnings.map((l) => h("div", {}, l.replace(/^warning:\s*/, "")))));
|
|
579
|
+
const html = data.outputs.find((p) => /\.html$/i.test(p));
|
|
580
|
+
if (ok && html && w.id !== "gate_package") card.append(h("div", { class: "actions" }, h("button", { class: "primary", type: "button", onclick: (e) => openReport(html, e.target) }, "Open report")));
|
|
581
|
+
if (ok && html && w.id === "gate_package") card.append(h("div", { class: "actions" }, h("button", { class: "primary", type: "button", onclick: (e) => openReport(html, e.target) }, "Open package")));
|
|
582
|
+
if (data.stdout.trim()) card.append(h("h2", { style: "margin-top:14px" }, "Result"), w.table.length && ok ? outputTable(w, data.stdout) : h("pre", { class: "output" }, data.stdout));
|
|
583
|
+
const rest = stderr.split("\n").filter((l) => l && !/^(error|warning):/.test(l)).join("\n");
|
|
584
|
+
if (answer && rest) card.append(h("h2", { style: "margin-top:14px" }, "Why"), h("pre", { class: "output" }, rest));
|
|
585
|
+
if (!ok && !answer && rest) card.append(h("details", {}, h("summary", {}, "Technical details"), h("pre", { class: "output" }, rest)));
|
|
586
|
+
if (data.blocked && data.blocked.length) card.append(waiveOffer(w, data.blocked));
|
|
587
|
+
box.replaceChildren(card);
|
|
588
|
+
renderPanel();
|
|
589
|
+
announce(ok ? "Done" : (answer ? outcome : "Failed"));
|
|
590
|
+
refreshPreview();
|
|
591
|
+
if (ok && (w.recorded || w.id === "create_baseline")) lookupGateData();
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
async function openReport(path, button) {
|
|
595
|
+
try { await api("/api/open", { path }); } catch (e) { button.textContent = e.message; }
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function renderPanel() {
|
|
599
|
+
const panel = $("panel");
|
|
600
|
+
const steps = state.steps;
|
|
601
|
+
const list = h("ol", { class: "steps" });
|
|
602
|
+
steps.forEach((s, i) => {
|
|
603
|
+
const move = (d) => { const j = i + d; [steps[i], steps[j]] = [steps[j], steps[i]]; remember(); renderPanel(); };
|
|
604
|
+
list.append(h("li", { class: "step" },
|
|
605
|
+
h("div", { class: "head" }, h("span", { class: "name" }, (i + 1) + ". " + s.title),
|
|
606
|
+
h("button", { class: "small", type: "button", "aria-label": "Move step " + (i + 1) + " up", disabled: i === 0, onclick: () => move(-1) }, "↑"),
|
|
607
|
+
h("button", { class: "small", type: "button", "aria-label": "Move step " + (i + 1) + " down", disabled: i === steps.length - 1, onclick: () => move(1) }, "↓"),
|
|
608
|
+
h("button", { class: "small", type: "button", "aria-label": "Remove step " + (i + 1), onclick: () => { steps.splice(i, 1); remember(); renderPanel(); } }, "✕")),
|
|
609
|
+
s.records ? h("p", { class: "note", style: "margin:4px 0" }, "Running the script again records this again.") : null,
|
|
610
|
+
h("pre", {}, s[state.shell])));
|
|
611
|
+
});
|
|
612
|
+
fill(panel,
|
|
613
|
+
h("h2", {}, "Your workflow"),
|
|
614
|
+
steps.length ? list : h("p", { class: "empty" }, "Steps you run or add show up here. Put them in order, then save them as a script to repeat them any time."),
|
|
615
|
+
h("div", { class: "commandbar" }, shellTabs(() => { renderPreview(); if (panelRefresh) panelRefresh(); })),
|
|
616
|
+
h("div", { class: "actions", style: "margin-top:0" },
|
|
617
|
+
h("button", { type: "button", disabled: !steps.length, onclick: (e) => withScript((s) => copyText(s.script, e.target)) }, "Copy script"),
|
|
618
|
+
h("button", { type: "button", disabled: !steps.length, onclick: () => withScript(saveScript) }, "Save script"),
|
|
619
|
+
h("button", { class: "small", type: "button", disabled: !steps.length, onclick: () => { state.steps = []; remember(); renderPanel(); } }, "Clear")));
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
async function withScript(use) {
|
|
623
|
+
try { use(await api("/api/script", { steps: state.steps.map((s) => ({ workflow: s.workflow, values: s.values, note: s.note || "" })), shell: state.shell })); }
|
|
624
|
+
catch (e) { announce(e.message); alert(e.message); }
|
|
625
|
+
}
|
|
626
|
+
function saveScript(data) {
|
|
627
|
+
const url = URL.createObjectURL(new Blob([data.script], { type: "text/plain" }));
|
|
628
|
+
const link = h("a", { href: url, download: data.filename }); document.body.append(link); link.click(); link.remove();
|
|
629
|
+
setTimeout(() => URL.revokeObjectURL(url), 1000);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
async function pickPath(field, input, set) {
|
|
633
|
+
const dialog = $("picker");
|
|
634
|
+
const startValue = input.value.trim();
|
|
635
|
+
const slash = Math.max(startValue.lastIndexOf("/"), startValue.lastIndexOf("\\"));
|
|
636
|
+
let folder = slash >= 0 ? startValue.slice(0, slash) : "";
|
|
637
|
+
const exts = field.extensions.join(",");
|
|
638
|
+
const choose = (path) => { const shown = shownPath(path); input.value = shown; set(shown); dialog.close(); };
|
|
639
|
+
const load = async (path) => {
|
|
640
|
+
let data;
|
|
641
|
+
try { data = await api("/api/browse?path=" + encodeURIComponent(path) + "&ext=" + encodeURIComponent(exts)); }
|
|
642
|
+
catch (e) { dialog.querySelector(".dlg .err").textContent = e.message; return; }
|
|
643
|
+
const sep = data.path.includes("\\") ? "\\" : "/";
|
|
644
|
+
const name = h("input", { type: "text", "aria-label": "File name", value: field.kind === "save" ? (baseName(input.value) || field.default) : "" });
|
|
645
|
+
const list = h("ul", {});
|
|
646
|
+
if (!data.entries.length) list.append(h("li", { class: "empty", style: "padding:10px 12px" }, "Nothing to show here."));
|
|
647
|
+
for (const e of data.entries) {
|
|
648
|
+
list.append(h("li", {}, h("button", { type: "button", onclick: () => e.dir ? load(e.path) : (field.kind === "open" ? choose(e.path) : (name.value = e.name)) }, (e.dir ? "📁 " : "📄 ") + e.name)));
|
|
649
|
+
}
|
|
650
|
+
const foot = h("div", { class: "foot" });
|
|
651
|
+
if (field.kind === "save") foot.append(name, h("button", { class: "primary", type: "button", onclick: () => name.value.trim() && choose(data.path.replace(/[\\/]$/, "") + sep + name.value.trim()) }, "Save here"));
|
|
652
|
+
foot.append(h("button", { type: "button", onclick: () => dialog.close() }, "Cancel"));
|
|
653
|
+
dialog.replaceChildren(h("div", { class: "dlg" },
|
|
654
|
+
h("strong", {}, field.kind === "open" ? "Choose " + field.label.toLowerCase() : "Choose where to save"),
|
|
655
|
+
h("div", { class: "places" }, data.places.map((p) => h("button", { class: "small", type: "button", onclick: () => load(p.path) }, p.name)),
|
|
656
|
+
h("button", { class: "small", type: "button", disabled: !data.parent, onclick: () => load(data.parent) }, "↑ Up one folder")),
|
|
657
|
+
h("div", { class: "where" }, data.path), h("div", { class: "err note" }), list, foot));
|
|
658
|
+
};
|
|
659
|
+
dialog.replaceChildren(h("div", { class: "dlg" }, h("div", { class: "err note" })));
|
|
660
|
+
dialog.showModal();
|
|
661
|
+
load(folder || state.workdir);
|
|
662
|
+
}
|
|
663
|
+
function baseName(path) { return path.split(/[\\/]/).pop(); }
|
|
664
|
+
function shownPath(path) {
|
|
665
|
+
const root = state.workdir.replace(/[\\/]$/, "");
|
|
666
|
+
return path.startsWith(root) && /^[\\/]/.test(path.slice(root.length)) ? path.slice(root.length + 1) : path;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
async function start() {
|
|
670
|
+
try {
|
|
671
|
+
const data = await api("/api/workflows");
|
|
672
|
+
state.workflows = data.workflows; state.workdir = data.workdir; state.mapping = data.mapping;
|
|
673
|
+
restore();
|
|
674
|
+
} catch (e) {
|
|
675
|
+
$("main").replaceChildren(h("div", { class: "card" }, h("div", { class: "banner bad" }, h("strong", {}, "Could not reach reqtable."), "Close this tab and start it again with --gui.")));
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
renderNav(); renderIntro(); renderPanel();
|
|
679
|
+
}
|
|
680
|
+
__MODULES__
|
|
681
|
+
start();
|
|
682
|
+
</script>
|
|
683
|
+
</body>
|
|
684
|
+
</html>
|
|
685
|
+
"""
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def render_page(token: str) -> str:
|
|
689
|
+
return PAGE.replace("__MODULES__", GATES_JS + MAPPING_JS).replace(
|
|
690
|
+
"__TOKEN__", json.dumps(token)
|
|
691
|
+
)
|