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
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""Page script for the gate, baseline, role, system and waiver fields, and the offer to waive a blocked check."""
|
|
2
|
+
|
|
3
|
+
GATES_JS = r"""
|
|
4
|
+
const LOOKUP_KINDS = new Set(["gate", "baseline", "baselines", "role", "system", "waivers"]);
|
|
5
|
+
const gateById = (id) => state.lookups.gates.find((g) => g.id === id);
|
|
6
|
+
const baselineNamed = (name) => state.lookups.baselines.find((b) => b.name === name);
|
|
7
|
+
const kindsOf = (w) => new Set(w.fields.map((f) => f.kind));
|
|
8
|
+
const hasKind = (...names) => { const kinds = kindsOf(workflow()); return names.some((n) => kinds.has(n)); };
|
|
9
|
+
|
|
10
|
+
function systemNeeded() {
|
|
11
|
+
const values = state.values[state.current] || {};
|
|
12
|
+
if (!values.gate) return false;
|
|
13
|
+
const gate = gateById(values.gate);
|
|
14
|
+
return gate ? gate.scope === "system" : true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async function lookupGateData() {
|
|
18
|
+
const w = workflow(); const id = state.current;
|
|
19
|
+
if (!w || w.panel !== "form" || !hasKind(...LOOKUP_KINDS)) return;
|
|
20
|
+
const values = state.values[id]; const L = state.lookups;
|
|
21
|
+
const query = new URLSearchParams();
|
|
22
|
+
if (values[w.lookup_input]) query.set("path", values[w.lookup_input]);
|
|
23
|
+
for (const name of LOOKUP_FIELDS.slice(2)) if (values[name]) query.set(name, values[name]);
|
|
24
|
+
const ask = async (path, apply) => {
|
|
25
|
+
let data;
|
|
26
|
+
try { data = await api(path + "?" + query); } catch (e) { data = { error: e.message }; }
|
|
27
|
+
if (id === state.current) apply(data);
|
|
28
|
+
};
|
|
29
|
+
await Promise.all([
|
|
30
|
+
hasKind("gate", "role", "waivers") ? ask("/api/gates", (d) => { L.gates = d.gates || []; L.gatesError = d.error || ""; }) : null,
|
|
31
|
+
hasKind("baseline", "baselines", "role", "waivers") ? ask("/api/baselines", (d) => { L.baselines = d.baselines || []; L.baselinesError = d.error || ""; L.store = d.store || ""; }) : null,
|
|
32
|
+
hasKind("system") ? ask("/api/systems", (d) => { L.systems = d.systems || []; }) : null,
|
|
33
|
+
]);
|
|
34
|
+
if (id !== state.current) return;
|
|
35
|
+
if (hasKind("system") && !systemNeeded()) values.system = "";
|
|
36
|
+
renderLookups(); refreshPreview();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function renderLookups() {
|
|
40
|
+
for (const row of Object.values(state.rows)) if (LOOKUP_KINDS.has(row.field.kind)) LOOKUP_RENDER[row.field.kind](row);
|
|
41
|
+
syncVisibility();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function gateChecks(gateId) { const g = gateById(gateId); return g ? g.checks : []; }
|
|
45
|
+
|
|
46
|
+
function gitExplanation() {
|
|
47
|
+
const L = state.lookups;
|
|
48
|
+
if (!L.baselinesError) return null;
|
|
49
|
+
const git = L.store === "git" || /git/i.test(L.baselinesError);
|
|
50
|
+
return h("div", { class: "banner fail", role: "alert" },
|
|
51
|
+
h("strong", {}, git ? "Baselines are stored in git, and git cannot be used here." : "The baselines could not be read."),
|
|
52
|
+
git ? h("div", {}, "The requirements file must sit in a git repository and be committed. Otherwise choose a settings file that keeps baselines as plain files, with \"baselines\": {\"store\": \"files\"}.") : null,
|
|
53
|
+
h("span", { class: "cli-error" }, L.baselinesError));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function selectOf(row, options, current, blank, onPick) {
|
|
57
|
+
const select = h("select", { id: "f-" + row.field.name, onchange: (e) => onPick(e.target.value) }, h("option", { value: "" }, blank));
|
|
58
|
+
for (const [v, text] of options) select.append(h("option", { value: v }, text));
|
|
59
|
+
if (current && !options.some(([v]) => v === current)) select.append(h("option", { value: current }, current));
|
|
60
|
+
select.value = current || "";
|
|
61
|
+
return select;
|
|
62
|
+
}
|
|
63
|
+
function textFallback(row, current) {
|
|
64
|
+
return h("input", { type: "text", id: "f-" + row.field.name, spellcheck: "false", value: current || "", oninput: (e) => setValue(row.field, e.target.value) });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function renderGate(row) {
|
|
68
|
+
const L = state.lookups; const values = state.values[state.current]; const f = row.field;
|
|
69
|
+
const holder = row.extra; holder.replaceChildren();
|
|
70
|
+
if (L.gatesError || !L.gates.length) {
|
|
71
|
+
holder.append(textFallback(row, values[f.name]));
|
|
72
|
+
row.note.textContent = L.gatesError ? "Could not list the gates: " + L.gatesError : "";
|
|
73
|
+
} else {
|
|
74
|
+
const options = L.gates.map((g) => [g.id, g.id + " · " + g.name + (g.scope === "system" ? " (covers one system)" : "")]);
|
|
75
|
+
holder.append(selectOf(row, options, values[f.name], "Choose a gate…", (v) => setValue(f, v)));
|
|
76
|
+
row.note.textContent = "";
|
|
77
|
+
const checks = gateChecks(values[f.name]);
|
|
78
|
+
if (checks.length) holder.append(h("details", { class: "more", style: "margin:8px 0 0;padding-top:8px" }, h("summary", { style: "margin-bottom:6px" }, "What this gate checks (" + checks.length + ")"),
|
|
79
|
+
h("ul", { class: "plain" }, checks.map((c) => h("li", {}, h("code", {}, c.id), " " + c.description, h("span", { class: "badge" + (c.enforcement === "strict" ? " strict" : "") }, c.enforcement === "strict" ? "required" : "advisory"))))));
|
|
80
|
+
}
|
|
81
|
+
if (hasKind("waivers") && L.baselinesError) holder.append(gitExplanation());
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function renderBaseline(row) {
|
|
85
|
+
const L = state.lookups; const values = state.values[state.current]; const f = row.field;
|
|
86
|
+
const holder = row.extra; holder.replaceChildren(); row.note.textContent = "";
|
|
87
|
+
if (!values[state.workflows.find((w) => w.id === state.current).lookup_input]) { holder.append(h("select", { id: "f-" + f.name, disabled: true }, h("option", {}, "Choose the requirements file first"))); return; }
|
|
88
|
+
if (L.baselinesError) { holder.append(gitExplanation()); return; }
|
|
89
|
+
if (!L.baselines.length) { holder.append(h("select", { id: "f-" + f.name, disabled: true }, h("option", {}, "No baselines yet. Freeze one first"))); return; }
|
|
90
|
+
const options = L.baselines.map((b) => [b.name, b.name + " · frozen " + b.created.slice(0, 10) + " by " + b.created_by]);
|
|
91
|
+
holder.append(selectOf(row, options, values[f.name], "Choose a baseline…", (v) => { if (hasKind("role")) values.role = ""; setValue(f, v); }));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function rolesOfBaseline(name) {
|
|
95
|
+
const b = baselineNamed(name); const g = b && gateById(b.gate);
|
|
96
|
+
return g ? g.roles : [];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function renderRole(row) {
|
|
100
|
+
const values = state.values[state.current]; const f = row.field;
|
|
101
|
+
const holder = row.extra; holder.replaceChildren(); row.note.textContent = "";
|
|
102
|
+
if (!values.baseline) { holder.append(h("select", { id: "f-" + f.name, disabled: true }, h("option", {}, "Choose a baseline first"))); return; }
|
|
103
|
+
const roles = rolesOfBaseline(values.baseline);
|
|
104
|
+
if (!roles.length) { holder.append(textFallback(row, values[f.name])); row.note.textContent = "Type the role name. reqtable could not find the roles for this baseline's gate."; return; }
|
|
105
|
+
if (!values[f.name] && roles.length === 1) { values[f.name] = roles[0].role; }
|
|
106
|
+
holder.append(selectOf(row, roles.map((r) => [r.role, r.role + " (needs " + r.min + ")"]), values[f.name], "Choose a role…", (v) => setValue(f, v)));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function renderSystem(row) {
|
|
110
|
+
const L = state.lookups; const values = state.values[state.current]; const f = row.field;
|
|
111
|
+
const holder = row.extra; holder.replaceChildren();
|
|
112
|
+
if (!L.systems.length) { holder.append(textFallback(row, values[f.name])); row.note.textContent = "Type the System ID. reqtable could not list the systems yet; choose the table and ID column first."; return; }
|
|
113
|
+
row.note.textContent = "";
|
|
114
|
+
holder.append(selectOf(row, L.systems.map((s) => [s.id, s.id + (s.name ? " · " + s.name : "")]), values[f.name], "Choose a system…", (v) => setValue(f, v)));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function renderBaselinePicks(row) {
|
|
118
|
+
const L = state.lookups; const values = state.values[state.current]; const f = row.field;
|
|
119
|
+
const holder = row.extra; holder.replaceChildren(); row.note.textContent = "";
|
|
120
|
+
if (L.baselinesError) { holder.append(gitExplanation()); return; }
|
|
121
|
+
if (!L.baselines.length) { holder.append(h("p", { class: "note" }, "No baselines to choose from yet.")); return; }
|
|
122
|
+
const chosen = new Set((values[f.name] || "").split(",").filter(Boolean));
|
|
123
|
+
for (const b of L.baselines) {
|
|
124
|
+
const box = h("input", { type: "checkbox", value: b.name, onchange: () => {
|
|
125
|
+
const picked = [...holder.querySelectorAll("input:checked")].map((i) => i.value);
|
|
126
|
+
values[f.name] = picked.join(","); refreshPreview();
|
|
127
|
+
} });
|
|
128
|
+
box.checked = chosen.has(b.name);
|
|
129
|
+
holder.append(h("label", { class: "check" }, box, b.name + " · frozen " + b.created.slice(0, 10)));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function renderWaivers(row) {
|
|
134
|
+
const values = state.values[state.current]; const f = row.field;
|
|
135
|
+
const holder = row.extra; holder.replaceChildren(); row.note.textContent = "";
|
|
136
|
+
const rows = values[f.name] = values[f.name] || [];
|
|
137
|
+
const strict = gateChecks(values.gate).filter((c) => c.enforcement === "strict");
|
|
138
|
+
const known = !!gateById(values.gate);
|
|
139
|
+
rows.forEach((item, i) => {
|
|
140
|
+
const pick = known && strict.length
|
|
141
|
+
? selectOf({ field: { name: "waive-" + i } }, strict.map((c) => [c.id, c.id + " · " + c.description]), item.check, "Choose a check…", (v) => { item.check = v; refreshPreview(); })
|
|
142
|
+
: h("input", { type: "text", placeholder: "Check ID", "aria-label": "Check ID", spellcheck: "false", value: item.check, oninput: (e) => { item.check = e.target.value; refreshPreview(); } });
|
|
143
|
+
pick.setAttribute("aria-label", "Check to waive");
|
|
144
|
+
const reason = h("input", { type: "text", id: "waive-reason-" + i, placeholder: "Why is this check waived?", "aria-label": "Reason for waiving", value: item.reason, oninput: (e) => { item.reason = e.target.value; refreshPreview(); } });
|
|
145
|
+
holder.append(h("div", { class: "waiver" }, pick, reason,
|
|
146
|
+
h("button", { class: "small", type: "button", "aria-label": "Remove waiver " + (i + 1), onclick: () => { rows.splice(i, 1); renderWaivers(row); refreshPreview(); } }, "✕")));
|
|
147
|
+
});
|
|
148
|
+
if (known && !strict.length) row.note.textContent = "This gate has no required checks, so there is nothing to waive.";
|
|
149
|
+
else holder.append(h("button", { class: "small", type: "button", onclick: () => { rows.push({ check: "", reason: "" }); renderWaivers(row); refreshPreview(); } }, "Add a waiver"));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const LOOKUP_RENDER = { gate: renderGate, baseline: renderBaseline, baselines: renderBaselinePicks, role: renderRole, system: renderSystem, waivers: renderWaivers };
|
|
153
|
+
|
|
154
|
+
function waiveOffer(w, blocked) {
|
|
155
|
+
const values = state.values[state.current];
|
|
156
|
+
const box = h("div", { class: "banner soft waiveoffer" },
|
|
157
|
+
h("strong", {}, "To freeze anyway, waive the blocking checks."),
|
|
158
|
+
h("div", { class: "note" }, "A waiver records who skipped a check, and why, inside the baseline. You still have to press Run again."));
|
|
159
|
+
const actions = h("div", { class: "actions" });
|
|
160
|
+
for (const id of blocked) {
|
|
161
|
+
const check = gateChecks(values.gate).find((c) => c.id === id);
|
|
162
|
+
actions.append(h("button", { type: "button", title: check ? check.description : "", onclick: () => {
|
|
163
|
+
const rows = values.waivers = values.waivers || [];
|
|
164
|
+
let at = rows.findIndex((r) => r.check === id);
|
|
165
|
+
if (at < 0) { rows.push({ check: id, reason: "" }); at = rows.length - 1; }
|
|
166
|
+
renderLookups(); refreshPreview();
|
|
167
|
+
const input = $("waive-reason-" + at); if (input) { input.scrollIntoView({ block: "center" }); input.focus(); }
|
|
168
|
+
} }, "Waive “" + id + "”…"));
|
|
169
|
+
}
|
|
170
|
+
box.append(actions);
|
|
171
|
+
return box;
|
|
172
|
+
}
|
|
173
|
+
"""
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
"""Page script for the "Import several tables" card: pick a workbook, say what each table holds, preview, save."""
|
|
2
|
+
|
|
3
|
+
MAPPING_JS = r"""
|
|
4
|
+
const mp = { workbook: "", sources: [], idColumn: "ID", extra: {}, xlsxExtra: {}, notes: [], loadPath: "", savePath: "mapping.json",
|
|
5
|
+
preview: null, saved: "", exists: false, follow: null, bookError: "", busy: false };
|
|
6
|
+
PANELS.mapping = renderMappingPanel;
|
|
7
|
+
|
|
8
|
+
const mappingRoles = () => state.mapping.roles;
|
|
9
|
+
const roleOf = (s) => mappingRoles().find((r) => r.id === s.role);
|
|
10
|
+
let sourceUid = 0;
|
|
11
|
+
const newSource = (kind, name, where) => ({ uid: ++sourceUid, seq: 0, dup: false, kind, name, where, role: "", header_row: "", field: "", id_prefix: "", columns: [], extra: {}, headings: null, raw: null, missing: false, error: "" });
|
|
12
|
+
const hasTarget = (s, column) => s.columns.some((c) => c.action === "map" && c.to === column);
|
|
13
|
+
const mpKey = (s) => s.kind + ":" + s.name;
|
|
14
|
+
|
|
15
|
+
function renderMappingPanel(w) {
|
|
16
|
+
panelRefresh = drawOut;
|
|
17
|
+
$("main").replaceChildren(h("div", {}, h("div", { class: "card", id: "mp-book" }), h("div", { id: "mp-sources" }), h("div", { class: "card", id: "mp-out" })));
|
|
18
|
+
drawBook(); drawSources(); drawOut(); fetchFollow();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function drawBook() {
|
|
22
|
+
const w = workflow();
|
|
23
|
+
const book = h("input", { type: "text", id: "mp-workbook", spellcheck: "false", placeholder: "Choose a workbook…", oninput: (e) => { mp.workbook = e.target.value; later("mp-book", loadBook, 300); } });
|
|
24
|
+
book.value = mp.workbook;
|
|
25
|
+
const loadInput = h("input", { type: "text", id: "mp-load", spellcheck: "false", placeholder: "Choose a mapping file…", oninput: (e) => { mp.loadPath = e.target.value; } });
|
|
26
|
+
loadInput.value = mp.loadPath;
|
|
27
|
+
$("mp-book").replaceChildren(
|
|
28
|
+
h("h2", {}, w.title), h("p", { class: "hint" }, w.summary),
|
|
29
|
+
h("div", { class: "field" }, h("label", { for: "mp-workbook" }, "Excel workbook", h("span", { class: "req" }, "required")),
|
|
30
|
+
h("div", { class: "pathrow" }, book, h("button", { type: "button", onclick: () => pickPath({ kind: "open", label: "Excel workbook", extensions: [".xlsx"], default: "" }, book, (v) => { mp.workbook = v; loadBook(); }) }, "Browse…")),
|
|
31
|
+
h("p", { class: "help" }, "The .xlsx file that holds your requirements and the other tables.")),
|
|
32
|
+
h("details", { class: "more" }, h("summary", {}, "Edit a mapping you saved earlier"),
|
|
33
|
+
h("div", { class: "field" }, h("label", { for: "mp-load" }, "Mapping file"),
|
|
34
|
+
h("div", { class: "pathrow" }, loadInput,
|
|
35
|
+
h("button", { type: "button", onclick: () => pickPath({ kind: "open", label: "mapping file", extensions: [".json"], default: "" }, loadInput, (v) => { mp.loadPath = v; }) }, "Browse…"),
|
|
36
|
+
h("button", { type: "button", onclick: loadSaved }, "Load")),
|
|
37
|
+
h("p", { class: "help" }, "Loads the tables and columns from a mapping.json. Settings this form cannot show are kept untouched."))),
|
|
38
|
+
h("div", { id: "mp-bookmsg" }));
|
|
39
|
+
drawBookMessage();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function drawBookMessage() {
|
|
43
|
+
const box = $("mp-bookmsg"); if (!box) return;
|
|
44
|
+
fill(box,
|
|
45
|
+
mp.bookError ? h("div", { class: "banner bad", role: "alert" }, h("strong", {}, "Could not read the workbook."), h("span", { class: "cli-error" }, mp.bookError)) : null,
|
|
46
|
+
mp.notes.length ? h("div", { class: "banner warn" }, h("strong", {}, "About the loaded mapping"), h("ul", { class: "plain" }, mp.notes.map((n) => h("li", {}, n)))) : null);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let bookSeq = 0;
|
|
50
|
+
async function loadBook() {
|
|
51
|
+
const seq = ++bookSeq;
|
|
52
|
+
mp.bookError = "";
|
|
53
|
+
if (!mp.workbook.trim()) { mp.sources = []; drawBookMessage(); drawSources(); schedulePreview(); return; }
|
|
54
|
+
let data;
|
|
55
|
+
try { data = await api("/api/tables?path=" + encodeURIComponent(mp.workbook)); } catch (e) { data = { error: e.message }; }
|
|
56
|
+
if (seq !== bookSeq) return;
|
|
57
|
+
if (data.error) { mp.bookError = data.error; mp.sources = []; drawBookMessage(); drawSources(); schedulePreview(); return; }
|
|
58
|
+
const onTable = new Set(data.tables.map((t) => t.sheet));
|
|
59
|
+
const found = [
|
|
60
|
+
...data.tables.map((t) => newSource("table", t.name, "table on sheet " + t.sheet)),
|
|
61
|
+
...data.sheets.filter((s) => !onTable.has(s.name)).map((s) => newSource("sheet", s.name, s.state === "visible" ? "sheet" : s.state + " sheet")),
|
|
62
|
+
];
|
|
63
|
+
const before = new Map();
|
|
64
|
+
for (const s of mp.sources) before.set(mpKey(s), [...(before.get(mpKey(s)) || []), s]);
|
|
65
|
+
const refetch = [];
|
|
66
|
+
const kept = found.flatMap((fresh) => (before.get(mpKey(fresh)) || [fresh]).map((s) => {
|
|
67
|
+
if (s !== fresh && s.missing) { s.missing = false; s.where = fresh.where; if (s.role) refetch.push(s); }
|
|
68
|
+
return s;
|
|
69
|
+
}));
|
|
70
|
+
const foundKeys = new Set(found.map(mpKey));
|
|
71
|
+
const lost = mp.sources.filter((s) => (s.role || s.raw) && !foundKeys.has(mpKey(s)));
|
|
72
|
+
for (const s of lost) { s.missing = true; s.where = "not in this workbook"; }
|
|
73
|
+
mp.sources = [...kept, ...lost];
|
|
74
|
+
drawBookMessage(); drawSources(); schedulePreview(); fetchFollow();
|
|
75
|
+
for (const s of refetch) fetchColumns(s, false);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function loadSaved() {
|
|
79
|
+
let data;
|
|
80
|
+
try { data = await api("/api/mapping/load?path=" + encodeURIComponent(mp.loadPath)); } catch (e) { data = { error: e.message }; }
|
|
81
|
+
if (data.error) { mp.bookError = data.error; mp.notes = []; drawBookMessage(); return; }
|
|
82
|
+
mp.bookError = ""; mp.notes = data.notes;
|
|
83
|
+
const form = data.form;
|
|
84
|
+
mp.idColumn = form.id_column; mp.extra = form.extra; mp.xlsxExtra = form.xlsx_extra;
|
|
85
|
+
const wanted = new Set(form.sources.map((fs) => fs.kind + ":" + fs.name));
|
|
86
|
+
mp.sources = mp.sources.filter((s) => !s.dup);
|
|
87
|
+
for (const s of mp.sources) if (!wanted.has(mpKey(s))) { s.role = ""; s.columns = []; s.raw = null; s.headings = null; }
|
|
88
|
+
const used = new Set();
|
|
89
|
+
for (const fs of form.sources) {
|
|
90
|
+
let s = mp.sources.find((x) => x.kind === fs.kind && x.name === fs.name && !used.has(x));
|
|
91
|
+
if (!s) {
|
|
92
|
+
const siblings = mp.sources.filter((x) => x.kind === fs.kind && x.name === fs.name);
|
|
93
|
+
s = newSource(fs.kind, fs.name, siblings.length ? siblings[0].where : "not in this workbook");
|
|
94
|
+
s.missing = !siblings.length; s.dup = siblings.length > 0;
|
|
95
|
+
mp.sources.splice(siblings.length ? mp.sources.indexOf(siblings[siblings.length - 1]) + 1 : mp.sources.length, 0, s);
|
|
96
|
+
}
|
|
97
|
+
used.add(s);
|
|
98
|
+
if (fs.raw) { s.raw = fs.raw; s.role = ""; continue; }
|
|
99
|
+
Object.assign(s, { raw: null, role: fs.role, header_row: fs.header_row == null ? "" : String(fs.header_row), field: fs.field, id_prefix: fs.id_prefix, columns: fs.columns.map((c) => ({ ...c })), extra: fs.extra,
|
|
100
|
+
headings: fs.headings ? { column: fs.headings.column, values: fs.headings.values.join(", "), text: fs.headings.text || "", into: fs.headings.into, auto: "" } : null });
|
|
101
|
+
}
|
|
102
|
+
drawBookMessage(); drawSources(); schedulePreview();
|
|
103
|
+
for (const s of mp.sources) if (s.role && !s.missing) fetchColumns(s, false);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
async function fetchColumns(s, fresh) {
|
|
107
|
+
const seq = ++s.seq;
|
|
108
|
+
const query = new URLSearchParams({ path: mp.workbook, role: s.role });
|
|
109
|
+
query.set(s.kind, s.name);
|
|
110
|
+
if (s.kind === "sheet" && s.header_row) query.set("header_row", s.header_row);
|
|
111
|
+
let data;
|
|
112
|
+
try { data = await api("/api/mapping/suggest?" + query); } catch (e) { data = { error: e.message }; }
|
|
113
|
+
if (seq !== s.seq) return;
|
|
114
|
+
if (data.error) { s.error = data.error; if (fresh) s.columns = []; drawSources(); schedulePreview(); return; }
|
|
115
|
+
s.error = "";
|
|
116
|
+
if (fresh) { s.columns = data.columns; s.id_prefix = data.id_prefix; }
|
|
117
|
+
else {
|
|
118
|
+
const have = new Map(s.columns.map(({ missing, ...c }) => [c.header, c]));
|
|
119
|
+
const headers = data.columns.map((c) => c.header);
|
|
120
|
+
const taken = new Set([...have.values()].filter((c) => headers.includes(c.header) && c.action === "map").map((c) => c.to));
|
|
121
|
+
const unmatched = roleOf(s).merge ? "exclude" : "keep";
|
|
122
|
+
s.columns = data.columns.map((c) => have.get(c.header) || (c.action === "map" && taken.has(c.to) ? { ...c, action: unmatched, to: "", separator: "" } : c));
|
|
123
|
+
for (const c of have.values()) if (!headers.includes(c.header)) s.columns.push({ ...c, missing: true });
|
|
124
|
+
}
|
|
125
|
+
drawSources(); schedulePreview();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function setRole(s, roleId) {
|
|
129
|
+
s.seq++;
|
|
130
|
+
s.role = roleId; s.columns = []; s.field = ""; s.id_prefix = ""; s.error = ""; s.headings = null;
|
|
131
|
+
if (!roleId) { drawSources(); schedulePreview(); return; }
|
|
132
|
+
drawSources();
|
|
133
|
+
fetchColumns(s, true);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const MARKER_GUESS = /^(requirement type|req\.? type|type)$/i;
|
|
137
|
+
const markerChoices = (s) => s.columns.filter((c) => !c.missing).map((c) => c.header);
|
|
138
|
+
const columnNamed = (s, header) => s.columns.find((c) => c.header === header);
|
|
139
|
+
|
|
140
|
+
function restoreMarker(s) {
|
|
141
|
+
const h = s.headings; if (!h || !h.auto) return;
|
|
142
|
+
const c = columnNamed(s, h.auto);
|
|
143
|
+
if (c && c.action === "exclude") { c.action = "keep"; c.to = ""; c.separator = ""; }
|
|
144
|
+
h.auto = "";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function leaveMarkerOut(s) {
|
|
148
|
+
const h = s.headings; const c = h.column && columnNamed(s, h.column);
|
|
149
|
+
if (c && c.action === "keep") { c.action = "exclude"; h.auto = c.header; }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function enableHeadings(s) {
|
|
153
|
+
const headers = markerChoices(s);
|
|
154
|
+
const text = s.columns.find((c) => c.action === "map" && c.to === "Requirement");
|
|
155
|
+
s.headings = { column: headers.find((x) => MARKER_GUESS.test(x.trim())) || "", values: "Heading", text: text ? text.header : "", into: "Category", auto: "" };
|
|
156
|
+
leaveMarkerOut(s);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function setMarker(s, header) {
|
|
160
|
+
restoreMarker(s); s.headings.column = header; leaveMarkerOut(s);
|
|
161
|
+
drawSources(); schedulePreview();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function toggleHeadings(s, on) {
|
|
165
|
+
if (on) enableHeadings(s); else { restoreMarker(s); s.headings = null; }
|
|
166
|
+
drawSources(); schedulePreview();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function headerSelect(s, id, label, value, empty, onpick) {
|
|
170
|
+
const headers = markerChoices(s);
|
|
171
|
+
const options = [h("option", { value: "" }, empty), ...headers.map((x) => h("option", { value: x }, x))];
|
|
172
|
+
if (value && !headers.includes(value)) options.push(h("option", { value }, value + " (not in this table)"));
|
|
173
|
+
const select = h("select", { id, "aria-label": label, onchange: (e) => onpick(e.target.value) }, options);
|
|
174
|
+
select.value = value;
|
|
175
|
+
return select;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function headingsSection(s, i) {
|
|
179
|
+
const hd = s.headings;
|
|
180
|
+
const on = h("input", { type: "checkbox", id: "hd-on-" + i, checked: !!hd, onchange: (e) => toggleHeadings(s, e.target.checked) });
|
|
181
|
+
const box = h("div", { class: "headings", style: "margin-top:12px" },
|
|
182
|
+
h("label", { for: on.id, style: "display:flex;gap:8px;align-items:center;font-weight:600" }, on, "This table has heading rows that group requirements into categories"));
|
|
183
|
+
if (!hd) return box;
|
|
184
|
+
const values = h("input", { type: "text", id: "hd-values-" + i, spellcheck: "false", style: "max-width:240px", oninput: (e) => { hd.values = e.target.value; schedulePreview(); } });
|
|
185
|
+
values.value = hd.values;
|
|
186
|
+
const into = h("input", { type: "text", id: "hd-into-" + i, spellcheck: "false", style: "max-width:240px", oninput: (e) => { hd.into = e.target.value; schedulePreview(); } });
|
|
187
|
+
into.value = hd.into;
|
|
188
|
+
const field = (label, id, control, help) => h("div", { class: "field", style: "margin-top:10px" }, h("label", { class: "mini", for: id }, label), control, help ? h("p", { class: "help" }, help) : null);
|
|
189
|
+
box.append(
|
|
190
|
+
h("p", { class: "help" }, "Rows whose marker column says Heading become category names. Every requirement below a heading, up to the next one, gets that category."),
|
|
191
|
+
field("Which column marks a heading row?", "hd-col-" + i, headerSelect(s, "hd-col-" + i, "Which column marks a heading row?", hd.column, "Choose a column…", (v) => setMarker(s, v)),
|
|
192
|
+
"The marker column is left out of the table by default, because every row that stays is a requirement. Change it back in the table above to keep it."),
|
|
193
|
+
field("Marker value(s)", "hd-values-" + i, values, "The words that mark a heading row. Separate several with commas. Capital letters and spaces do not matter."),
|
|
194
|
+
field("Which column holds the heading text?", "hd-text-" + i, headerSelect(s, "hd-text-" + i, "Which column holds the heading text?", hd.text, "First non-empty cell", (v) => { hd.text = v; schedulePreview(); })),
|
|
195
|
+
field("Put the category in", "hd-into-" + i, into, "A column of this name is added to the table when it is missing. A row that already has a value there keeps it."));
|
|
196
|
+
return box;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function headingsForm(s) {
|
|
200
|
+
const hd = s.headings;
|
|
201
|
+
if (!hd) return null;
|
|
202
|
+
return { column: hd.column, values: hd.values.split(",").map((v) => v.trim()).filter(Boolean), text: hd.text, into: hd.into.trim() };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function targetValue(c) { return c.action === "map" ? "map:" + c.to : c.action; }
|
|
206
|
+
|
|
207
|
+
function setTarget(s, c, value) {
|
|
208
|
+
const role = roleOf(s); const hadId = hasTarget(s, "ID");
|
|
209
|
+
if (value.startsWith("map:")) { c.action = "map"; c.to = value.slice(4); } else { c.action = value; c.to = ""; }
|
|
210
|
+
const target = role.targets.find((t) => t.column === c.to);
|
|
211
|
+
c.separator = c.action !== "exclude" && target && target.list_separator ? (c.separator || ",") : "";
|
|
212
|
+
const hasId = hasTarget(s, "ID");
|
|
213
|
+
if (hasId && !hadId && s.id_prefix === role.id_prefix) s.id_prefix = "";
|
|
214
|
+
if (!hasId && hadId && !s.id_prefix) s.id_prefix = role.id_prefix;
|
|
215
|
+
if (hasTarget(s, "Field")) s.field = "";
|
|
216
|
+
drawSources(); schedulePreview();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function columnTable(s) {
|
|
220
|
+
const role = roleOf(s);
|
|
221
|
+
const rows = s.columns.map((c) => {
|
|
222
|
+
const options = [h("option", { value: "keep" }, "Keep as is"),
|
|
223
|
+
...role.targets.map((t) => h("option", { value: "map:" + t.column }, t.label + (t.label === t.column ? "" : " (" + t.column + ")"))),
|
|
224
|
+
h("option", { value: "exclude" }, "Leave out")];
|
|
225
|
+
if (c.action === "map" && !role.targets.some((t) => t.column === c.to)) options.push(h("option", { value: "map:" + c.to }, c.to));
|
|
226
|
+
const pick = h("select", { "aria-label": "Where " + c.header + " goes", onchange: (e) => setTarget(s, c, e.target.value) }, options);
|
|
227
|
+
pick.value = targetValue(c);
|
|
228
|
+
const sep = c.separator || (c.action === "map" && (role.targets.find((t) => t.column === c.to) || {}).list_separator);
|
|
229
|
+
const separator = sep ? h("select", { "aria-label": "Separator in " + c.header, onchange: (e) => { c.separator = e.target.value; schedulePreview(); } },
|
|
230
|
+
state.mapping.separators.map((x) => h("option", { value: x.value }, x.label))) : null;
|
|
231
|
+
if (separator) separator.value = c.separator || ",";
|
|
232
|
+
return h("tr", {}, h("td", { class: "src" }, c.header, c.missing ? h("span", { class: "badge" }, "not in this table") : null), h("td", {}, pick), h("td", {}, separator ? ["Split on ", separator] : null));
|
|
233
|
+
});
|
|
234
|
+
return h("table", { class: "cols" }, h("thead", {}, h("tr", {}, h("th", {}, "Column in the workbook"), h("th", {}, "Goes into"), h("th", {}, "If it holds a list"))), h("tbody", {}, rows));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function fieldPicker(s) {
|
|
238
|
+
const fields = state.mapping.fields;
|
|
239
|
+
const custom = !!s.field && !fields.some((f) => f.value === s.field);
|
|
240
|
+
const select = h("select", { id: "field-" + s.uid, "aria-label": "Which column are these values for?", onchange: (e) => { s.field = e.target.value === "__other" ? " " : e.target.value; drawSources(); schedulePreview(); } },
|
|
241
|
+
h("option", { value: "" }, "Choose a column…"), fields.map((f) => h("option", { value: f.value }, f.label)), h("option", { value: "__other" }, "Another column…"));
|
|
242
|
+
select.value = custom ? "__other" : s.field;
|
|
243
|
+
const other = custom ? h("input", { type: "text", "aria-label": "Column name", placeholder: "Column name", spellcheck: "false", style: "margin-top:6px", onchange: (e) => { s.field = e.target.value.trim(); schedulePreview(); } }) : null;
|
|
244
|
+
if (other) other.value = s.field.trim();
|
|
245
|
+
return h("div", { style: "margin-top:10px;max-width:340px" }, h("label", { class: "mini", for: select.id }, "Which column are these values for?"), select, other);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function drawSource(s, i) {
|
|
249
|
+
const role = roleOf(s);
|
|
250
|
+
const title = h("div", {}, h("div", { class: "nm" }, s.name), h("div", { class: "sub" }, s.where));
|
|
251
|
+
if (s.raw) {
|
|
252
|
+
return h("div", { class: "srcrow" }, h("div", { class: "top" }, title, h("p", { class: "note", style: "grid-column: span 2" }, "Kept exactly as it is in the file, because this form cannot edit it."),
|
|
253
|
+
), h("div", { class: "actions" }, h("button", { class: "small", type: "button", onclick: () => { s.raw = null; drawSources(); schedulePreview(); } }, "Stop importing this")));
|
|
254
|
+
}
|
|
255
|
+
const pick = h("select", { id: "role-" + i, "aria-label": "What does " + s.name + " hold?", onchange: (e) => setRole(s, e.target.value) },
|
|
256
|
+
h("option", { value: "" }, "Don't import"), mappingRoles().map((r) => h("option", { value: r.id }, r.label)));
|
|
257
|
+
pick.value = s.role;
|
|
258
|
+
const row = h("div", { class: "srcrow" }, h("div", { class: "top" }, title,
|
|
259
|
+
h("div", {}, h("label", { class: "mini", for: pick.id }, "What is it?"), pick),
|
|
260
|
+
s.kind === "sheet" ? h("div", {}, h("label", { class: "mini", for: "hr-" + i }, "Header row"),
|
|
261
|
+
h("input", { type: "number", id: "hr-" + i, min: "1", placeholder: "first", value: s.header_row, onchange: (e) => { s.header_row = e.target.value; if (s.role) fetchColumns(s, false); } })) : h("div", {})));
|
|
262
|
+
const again = h("div", { class: "actions", style: "margin-top:8px" },
|
|
263
|
+
h("button", { class: "small", type: "button", onclick: () => { const c = newSource(s.kind, s.name, s.where); c.dup = true; mp.sources.splice(i + 1, 0, c); drawSources(); } }, "Add this table again with another role"),
|
|
264
|
+
s.dup ? h("button", { class: "small", type: "button", onclick: () => { mp.sources.splice(i, 1); drawSources(); schedulePreview(); } }, "Remove this extra row") : null);
|
|
265
|
+
if (!role) { row.append(again); return row; }
|
|
266
|
+
row.append(h("p", { class: "note" }, role.help));
|
|
267
|
+
if (s.error) row.append(h("div", { class: "banner bad" }, s.error));
|
|
268
|
+
if (role.needs_field && !hasTarget(s, "Field")) row.append(fieldPicker(s));
|
|
269
|
+
else if (role.needs_field) row.append(h("p", { class: "note" }, "The column you sent to Field says which column each value is for."));
|
|
270
|
+
if (s.columns.length) row.append(columnTable(s));
|
|
271
|
+
if (role.headings && s.columns.length) row.append(headingsSection(s, i));
|
|
272
|
+
if (!role.merge && !hasTarget(s, "ID") && (role.id_prefix || s.id_prefix)) {
|
|
273
|
+
const prefix = h("input", { type: "text", id: "prefix-" + i, spellcheck: "false", style: "max-width:160px", onchange: (e) => { s.id_prefix = e.target.value.trim(); schedulePreview(); } });
|
|
274
|
+
prefix.value = s.id_prefix;
|
|
275
|
+
row.append(h("div", { style: "margin-top:10px" }, h("label", { class: "mini", for: prefix.id }, "No ID column here, so reqtable makes IDs that start with"), prefix));
|
|
276
|
+
}
|
|
277
|
+
row.append(again);
|
|
278
|
+
return row;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function drawSources() {
|
|
282
|
+
const box = $("mp-sources"); if (!box) return;
|
|
283
|
+
if (!mp.workbook.trim() || mp.bookError) { box.replaceChildren(); return; }
|
|
284
|
+
box.replaceChildren(h("div", { class: "card" }, h("h2", {}, "What is in each table?"),
|
|
285
|
+
h("p", { class: "hint" }, "Say what each table or sheet holds. Leave the ones you do not need on “Don't import”. reqtable fills in the column choices from the headers; change any that are wrong."),
|
|
286
|
+
mp.sources.length ? mp.sources.map(drawSource) : h("p", { class: "empty" }, "Nothing found in this workbook.")));
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function buildForm() {
|
|
290
|
+
return {
|
|
291
|
+
id_column: mp.idColumn, extra: mp.extra, xlsx_extra: mp.xlsxExtra,
|
|
292
|
+
sources: mp.sources.filter((s) => s.raw || s.role).map((s) => s.raw ? { kind: s.kind, name: s.name, raw: s.raw } : {
|
|
293
|
+
kind: s.kind, name: s.name, role: s.role, header_row: s.header_row === "" ? null : Number(s.header_row), field: s.field, id_prefix: s.id_prefix, extra: s.extra, headings: headingsForm(s),
|
|
294
|
+
columns: s.columns.map((c) => ({ header: c.header, action: c.action, to: c.to, separator: c.separator })),
|
|
295
|
+
}),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
let mapPreviewSeq = 0;
|
|
300
|
+
function schedulePreview() { mp.saved = ""; mp.exists = false; later("mp-preview", fetchMapPreview, 300); }
|
|
301
|
+
async function fetchMapPreview() {
|
|
302
|
+
const seq = ++mapPreviewSeq;
|
|
303
|
+
if (!mp.workbook.trim() || mp.bookError) { mp.preview = null; drawOut(); return; }
|
|
304
|
+
let data;
|
|
305
|
+
try { data = await api("/api/mapping/preview", { path: mp.workbook, form: buildForm() }); } catch (e) { data = { error: e.message }; }
|
|
306
|
+
if (seq !== mapPreviewSeq) return;
|
|
307
|
+
mp.preview = data; drawOut();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const followValues = () => ({ input: mp.workbook, config: mp.savePath, traceability: "on", output: "requirements-report.html", document_mode: "review" });
|
|
311
|
+
async function fetchFollow() {
|
|
312
|
+
if (!mp.workbook.trim() || !mp.savePath.trim()) { mp.follow = null; drawOut(); return; }
|
|
313
|
+
try { mp.follow = await api("/api/command", { workflow: "report", values: followValues() }); } catch (e) { mp.follow = { error: e.message }; }
|
|
314
|
+
drawOut();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async function saveMapping(overwrite) {
|
|
318
|
+
let data;
|
|
319
|
+
try { data = await api("/api/mapping/save", { path: mp.savePath, form: buildForm(), overwrite }); } catch (e) { data = { error: e.message }; }
|
|
320
|
+
if (data.error) { mp.preview = { ...(mp.preview || {}), error: data.error }; mp.saved = ""; drawOut(); return; }
|
|
321
|
+
mp.exists = !!data.exists;
|
|
322
|
+
mp.saved = data.saved ? mp.savePath : "";
|
|
323
|
+
if (data.saved) {
|
|
324
|
+
await fetchFollow();
|
|
325
|
+
if (mp.follow && !mp.follow.error) {
|
|
326
|
+
const base = baseName(mp.savePath);
|
|
327
|
+
const added = pushStep({ id: String(Date.now()), workflow: "report", title: "Make a report with " + base, note: "needs " + base + ", saved by “Import several tables”",
|
|
328
|
+
values: followValues(), sh: mp.follow.sh, powershell: mp.follow.powershell, argv: mp.follow.argv }, true);
|
|
329
|
+
mp.stepAdded = added;
|
|
330
|
+
}
|
|
331
|
+
announce("Saved " + mp.savePath);
|
|
332
|
+
}
|
|
333
|
+
drawOut();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function reportWithMapping() {
|
|
337
|
+
const report = state.workflows.find((w) => w.id === "report");
|
|
338
|
+
const values = {};
|
|
339
|
+
for (const f of report.fields) if (f.default) values[f.name] = f.default;
|
|
340
|
+
state.values.report = { ...values, ...followValues() };
|
|
341
|
+
choose("report");
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function headingSummary(src) {
|
|
345
|
+
const hd = src.headings;
|
|
346
|
+
if (hd.warning) return h("div", { class: "banner warn", style: "margin-top:8px", role: "status" }, src.name + ": " + hd.warning);
|
|
347
|
+
const named = hd.categories.map((c) => c.name + " (" + c.count + ")");
|
|
348
|
+
if (hd.uncategorised) named.push("No category (" + hd.uncategorised + ")");
|
|
349
|
+
return h("div", { style: "margin-top:6px" }, h("strong", {}, "Categories" + (mp.sources.filter((x) => x.headings).length > 1 ? " in " + src.name : "") + ": "),
|
|
350
|
+
named.length ? named.join(", ") : "none yet",
|
|
351
|
+
". " + hd.removed + " heading row" + (hd.removed === 1 ? " is" : "s are") + " removed.");
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function drawOut() {
|
|
355
|
+
const box = $("mp-out"); if (!box) return;
|
|
356
|
+
const p = mp.preview;
|
|
357
|
+
const pathInput = h("input", { type: "text", id: "mp-save", spellcheck: "false", onchange: (e) => { mp.savePath = e.target.value.trim(); mp.saved = ""; mp.exists = false; fetchFollow(); } });
|
|
358
|
+
pathInput.value = mp.savePath;
|
|
359
|
+
const ready = p && p.mapping && !p.error;
|
|
360
|
+
const status = !p ? h("p", { class: "hint" }, "Choose a workbook and say what each table holds. A preview of the import appears here.")
|
|
361
|
+
: p.error ? h("div", { class: p.mapping ? "banner fail" : "banner soft", role: "status" }, h("strong", {}, p.mapping ? "This mapping does not import yet." : "Not ready yet."), h("span", { class: p.mapping ? "cli-error" : "" }, p.error))
|
|
362
|
+
: h("div", { class: "banner ok", role: "status" }, h("strong", {}, p.total + " row" + (p.total === 1 ? "" : "s") + " would be imported."),
|
|
363
|
+
h("table", { class: "grid", style: "margin-top:8px;background:var(--surface)" }, h("thead", {}, h("tr", {}, h("th", {}, "Table"), h("th", {}, "Rows"))),
|
|
364
|
+
h("tbody", {}, p.sources.map((s) => h("tr", {}, h("td", {}, s.name), h("td", {}, s.rows == null ? "fills in existing rows" : String(s.rows)))))),
|
|
365
|
+
h("div", { style: "margin-top:6px" }, "Record types: " + Object.entries(p.types).map(([k, v]) => k + " " + v).join(", ")),
|
|
366
|
+
p.sources.filter((x) => x.headings).map(headingSummary));
|
|
367
|
+
const warnings = p && p.warnings && p.warnings.length ? h("div", { class: "banner warn" }, h("strong", {}, "Worth a look"), p.warnings.map((x) => h("div", {}, x))) : null;
|
|
368
|
+
const json = p && p.mapping ? JSON.stringify(p.mapping, null, 2) : "";
|
|
369
|
+
const f = mp.follow;
|
|
370
|
+
const confirm = mp.exists ? h("div", { class: "banner warn", role: "alert" }, h("strong", {}, baseName(mp.savePath) + " already exists."), "Replacing it throws away what is in it now.",
|
|
371
|
+
h("div", { class: "actions" }, h("button", { type: "button", onclick: () => saveMapping(true) }, "Replace it"), h("button", { type: "button", onclick: () => { mp.exists = false; drawOut(); $("mp-save").focus(); } }, "Choose another name"))) : null;
|
|
372
|
+
const saved = mp.saved ? h("div", { class: "banner ok", role: "status" }, h("strong", {}, "Saved " + mp.saved + "."),
|
|
373
|
+
mp.stepAdded ? "The report command below was added to your workflow, with a note that it needs " + baseName(mp.saved) + "." : "",
|
|
374
|
+
h("div", { class: "actions" }, h("button", { class: "primary", type: "button", onclick: reportWithMapping }, "Make a report with this mapping"))) : null;
|
|
375
|
+
fill(box,
|
|
376
|
+
h("h2", {}, "The mapping"), status, warnings,
|
|
377
|
+
json ? h("div", {}, h("div", { class: "commandbar" }, h("strong", {}, "mapping.json"), h("button", { class: "small", type: "button", onclick: (e) => copyText(json, e.target) }, "Copy JSON")),
|
|
378
|
+
h("pre", { class: "json", tabindex: "0", "aria-label": "Mapping JSON" }, json)) : null,
|
|
379
|
+
h("div", { class: "field", style: "margin-top:14px" }, h("label", { for: "mp-save" }, "Save the mapping as"),
|
|
380
|
+
h("div", { class: "pathrow" }, pathInput, h("button", { type: "button", onclick: () => pickPath({ kind: "save", label: "mapping", extensions: [".json"], default: "mapping.json" }, pathInput, (v) => { mp.savePath = v; mp.saved = ""; mp.exists = false; fetchFollow(); }) }, "Choose location…")),
|
|
381
|
+
h("p", { class: "help" }, "Saving never replaces an existing file without asking.")),
|
|
382
|
+
confirm, saved,
|
|
383
|
+
h("div", { class: "actions" }, h("button", { class: "primary", id: "mp-savebtn", type: "button", disabled: !ready, onclick: () => saveMapping(false) }, "Save mapping")),
|
|
384
|
+
h("h2", { style: "margin-top:18px" }, "Then make the report"),
|
|
385
|
+
h("div", { class: "commandbar" }, shellTabs(drawOut), f && !f.error ? h("button", { class: "small", type: "button", onclick: (e) => copyText(f[state.shell], e.target) }, "Copy command") : null),
|
|
386
|
+
f && !f.error ? h("pre", { class: "command", tabindex: "0", "aria-label": "Command for " + shellName() }, f[state.shell]) : h("p", { class: "hint" }, f && f.error ? f.error : "Choose a workbook to see the command."),
|
|
387
|
+
h("p", { class: "note" }, "Run this after the mapping is saved. It needs " + baseName(mp.savePath || "mapping.json") + " in the same folder."));
|
|
388
|
+
renderPanel();
|
|
389
|
+
}
|
|
390
|
+
"""
|