chore: initial import
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Gemeinsamer Baustein „Sicherungen“.
|
||||
*
|
||||
* Jedes schreibende Plugin bekommt damit dieselbe Ansicht: welche Läufe gab
|
||||
* es, was steckt drin, wie weit lässt sich das zurückdrehen. Der Text zur
|
||||
* Rückspielbarkeit kommt aus dem Manifest — die Oberfläche behauptet also
|
||||
* nichts, was das Werkzeug nicht auch kann.
|
||||
*/
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const LEVEL = {
|
||||
voll: { css: "ok", text: "vollständig rückspielbar" },
|
||||
neue_id: { css: "info", text: "rückspielbar, neue ID" },
|
||||
teilweise: { css: "warn", text: "teilweise rückspielbar" },
|
||||
nein: { css: "err", text: "nicht rückspielbar" },
|
||||
};
|
||||
|
||||
function renderRuns(runs, selected) {
|
||||
if (!runs.length) {
|
||||
return `<div class="bt-empty" style="border:none">
|
||||
Noch keine Sicherungen. Es entsteht bei jedem Lauf eine, der wirklich
|
||||
etwas schreibt — Trockenübungen zählen nicht.</div>`;
|
||||
}
|
||||
return runs.map((r) => {
|
||||
const lv = LEVEL[r.restore_level] || LEVEL.nein;
|
||||
const when = r.created_at ? new Date(r.created_at) : null;
|
||||
return `
|
||||
<label class="bt-run ${r.id === selected ? "sel" : ""}">
|
||||
<input type="radio" name="btrun" value="${BT.escape(r.id)}"
|
||||
${r.id === selected ? "checked" : ""}>
|
||||
<span class="bt-run-main">
|
||||
<b>${BT.escape(r.label || r.id)}</b>
|
||||
<span class="bt-run-sub">${when && !isNaN(when) ? when.toLocaleString("de-DE") : BT.escape(r.id)}
|
||||
· ${r.done} von ${r.steps} Schritten geschrieben</span>
|
||||
</span>
|
||||
<span class="bt-run-tags">
|
||||
<span class="bt-badge ${lv.css}">${lv.text}</span>
|
||||
${r.restored ? `<span class="bt-badge">bereits zurückgespielt</span>` : ""}
|
||||
</span>
|
||||
</label>`;
|
||||
}).join("");
|
||||
}
|
||||
|
||||
function renderDetail(detail) {
|
||||
const steps = (detail.manifest?.steps || []).filter((s) => s.status === "done");
|
||||
if (!steps.length) return `<p class="hint">In diesem Lauf wurde nichts geschrieben.</p>`;
|
||||
return `<div class="bt-steps">${steps.map((s) => {
|
||||
const lv = LEVEL[s.restore_level] || LEVEL.nein;
|
||||
let was = "";
|
||||
if (s.action === "properties") {
|
||||
was = `${Object.keys(s.written || {}).length} Werte gesetzt`;
|
||||
} else if (s.action === "merge") {
|
||||
was = `zusammengeführt auf „${BT.escape(s.target_name)}“`
|
||||
+ (s.references?.length ? ` · ${s.references.length} Verweise aufgezeichnet` : "")
|
||||
+ (s.rescued?.length ? ` · ${s.rescued.length} Werte gerettet` : "");
|
||||
} else if (s.action === "delete") {
|
||||
was = "gelöscht";
|
||||
} else if (s.action === "recipe") {
|
||||
was = `${s.step_count} Schritte gesichert`;
|
||||
}
|
||||
return `<div class="bt-step">
|
||||
<span class="bt-badge ${lv.css}">${lv.text}</span>
|
||||
<span><b>${BT.escape(s.food_name || s.source_name || "?")}</b>
|
||||
<span class="bt-muted"> — ${was}</span></span>
|
||||
</div>`;
|
||||
}).join("")}</div>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Baut den Reiter. `mount` ist das Zielelement, `runner` ein BT.Runner,
|
||||
* der auf /api/run/restore zeigt.
|
||||
*/
|
||||
BT.Backups = function (options) {
|
||||
const mount = options.mount;
|
||||
const runner = options.runner;
|
||||
let runs = [];
|
||||
let selected = null;
|
||||
|
||||
async function load() {
|
||||
const data = await BT.api("/api/backups");
|
||||
runs = data.runs || [];
|
||||
if (!runs.some((r) => r.id === selected)) selected = runs[0]?.id || null;
|
||||
draw(data.dir);
|
||||
if (selected) await detail();
|
||||
}
|
||||
|
||||
async function detail() {
|
||||
if (!selected || !options.detail) { paintDetail(""); return; }
|
||||
try {
|
||||
paintDetail(renderDetail(await BT.api(`/api/backups/${encodeURIComponent(selected)}`)));
|
||||
} catch { paintDetail(""); }
|
||||
}
|
||||
|
||||
function paintDetail(html) {
|
||||
const box = mount.querySelector("#btDetail");
|
||||
if (box) box.innerHTML = html;
|
||||
}
|
||||
|
||||
function draw(dir) {
|
||||
const current = runs.find((r) => r.id === selected);
|
||||
const lv = LEVEL[current?.restore_level] || LEVEL.nein;
|
||||
mount.innerHTML = `
|
||||
<div class="bt-card">
|
||||
<div class="bt-row" style="align-items:center;margin-bottom:8px">
|
||||
<h2 style="margin:0;flex:1">Sicherungen</h2>
|
||||
<button class="mini ghost" id="btReload">Neu laden</button>
|
||||
</div>
|
||||
<p class="hint">Jeder Lauf, der wirklich geschrieben hat, liegt unter
|
||||
<code>${BT.escape(dir || "")}</code>. Der Zustand vorher ist dort
|
||||
vollständig festgehalten.</p>
|
||||
<div class="bt-runs">${renderRuns(runs, selected)}</div>
|
||||
</div>
|
||||
|
||||
${runs.length ? `
|
||||
<div class="bt-card">
|
||||
<h2>Was passierte in diesem Lauf</h2>
|
||||
<div id="btDetail"><p class="hint">wird geladen …</p></div>
|
||||
|
||||
<div class="bt-notice ${lv.css === "ok" ? "" : "warn"}" style="margin-top:12px">
|
||||
${options.note || ""}
|
||||
</div>
|
||||
|
||||
<div class="bt-row" style="margin-top:12px;align-items:center">
|
||||
<button id="btDry">Trockenübung</button>
|
||||
<button class="danger" id="btApply">Zurückspielen</button>
|
||||
<span class="bt-spacer"></span>
|
||||
<label class="bt-check">
|
||||
<input type="checkbox" id="btForce">
|
||||
auch wenn seither von Hand geändert wurde
|
||||
</label>
|
||||
</div>
|
||||
<div id="btStatus" class="bt-status">Bereit.</div>
|
||||
<div id="btLog" class="bt-log"></div>
|
||||
</div>` : ""}`;
|
||||
|
||||
mount.querySelectorAll('input[name="btrun"]').forEach((el) =>
|
||||
el.addEventListener("change", () => { selected = el.value; draw(dir); detail(); }));
|
||||
const byId = (id) => mount.querySelector("#" + id);
|
||||
byId("btReload")?.addEventListener("click", load);
|
||||
byId("btDry")?.addEventListener("click", () => go(false));
|
||||
byId("btApply")?.addEventListener("click", () => go(true));
|
||||
|
||||
if (runner) runner.rebind({ log: byId("btLog"), status: byId("btStatus") });
|
||||
}
|
||||
|
||||
function go(apply) {
|
||||
const current = runs.find((r) => r.id === selected);
|
||||
if (!current) return;
|
||||
if (apply && !confirm(
|
||||
`Lauf „${current.label || current.id}“ zurückspielen?\n\n` +
|
||||
`${current.done} Schritte · ${(LEVEL[current.restore_level] || LEVEL.nein).text}\n\n` +
|
||||
(current.restored ? "Achtung: Dieser Lauf wurde bereits zurückgespielt.\n\n" : "") +
|
||||
`Erst die Trockenübung ansehen, wenn du unsicher bist.`)) return;
|
||||
runner.start({ run: selected, apply, force: mount.querySelector("#btForce")?.checked || false });
|
||||
}
|
||||
|
||||
return { load, reload: load };
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,128 @@
|
||||
/* ==========================================================================
|
||||
boehmitools · Runner
|
||||
Gemeinsame Oberflächenlogik für Plugins, die ein Kommandozeilen-Tool
|
||||
kapseln: Lauf starten, Ausgabe live streamen, Status anzeigen, abbrechen.
|
||||
|
||||
const runner = BT.Runner({ log: el, status: el, onFinish: fn });
|
||||
runner.start({ apply: false }); // POST <mount>/api/run
|
||||
runner.attach(jobId); // an laufenden Lauf andocken
|
||||
|
||||
Setzt boehmi.js voraus.
|
||||
========================================================================== */
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const LABEL = {
|
||||
running: ["busy", "läuft …"],
|
||||
done: ["ok", "erfolgreich abgeschlossen"],
|
||||
failed: ["error", "fehlgeschlagen"],
|
||||
cancelled: ["warn", "abgebrochen"],
|
||||
};
|
||||
|
||||
function classify(entry) {
|
||||
if (entry.stream === "meta") return "l-meta";
|
||||
if (entry.stream === "stderr") return "l-err";
|
||||
const t = entry.text;
|
||||
if (/^(FEHLER|Abbruch|Fehlgeschlagen)|✗|Traceback/i.test(t)) return "l-err";
|
||||
if (/^(Warnung|Hinweis)|⚠/i.test(t)) return "l-warn";
|
||||
if (/(erfolgreich|✓|OK\b|angelegt|aktualisiert)/i.test(t)) return "l-ok";
|
||||
return "";
|
||||
}
|
||||
|
||||
function Runner(cfg) {
|
||||
// Nicht const: Oberflächen, die ihre Karten neu zeichnen, hängen den
|
||||
// Runner per rebind() wieder an die frischen Elemente.
|
||||
let logEl = cfg.log;
|
||||
let statusEl = cfg.status;
|
||||
// Plugins mit mehreren Läufen (prüfen / vorschlagen / übernehmen) geben
|
||||
// ihren eigenen Endpunkt an. Vorgabe bleibt der bisherige.
|
||||
const endpoint = cfg.endpoint || "/api/run";
|
||||
let source = null;
|
||||
let job = null;
|
||||
|
||||
function setStatus(kind, text, extra) {
|
||||
if (!statusEl) return;
|
||||
statusEl.className = "bt-status " + (kind || "");
|
||||
statusEl.innerHTML = `<span class="bt-dot"></span><b>${BT.escape(text)}</b>` +
|
||||
(extra ? ` <span class="bt-muted">${BT.escape(extra)}</span>` : "");
|
||||
}
|
||||
|
||||
function clear() {
|
||||
if (logEl) logEl.textContent = "";
|
||||
}
|
||||
|
||||
function append(entry) {
|
||||
if (!logEl) return;
|
||||
const atBottom = logEl.scrollHeight - logEl.scrollTop - logEl.clientHeight < 40;
|
||||
const span = document.createElement("span");
|
||||
const cls = classify(entry);
|
||||
if (cls) span.className = cls;
|
||||
span.textContent = entry.text + "\n";
|
||||
logEl.appendChild(span);
|
||||
if (atBottom) logEl.scrollTop = logEl.scrollHeight;
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (source) { source.close(); source = null; }
|
||||
}
|
||||
|
||||
function attach(id) {
|
||||
close();
|
||||
source = new EventSource(BT.url(`/api/jobs/${id}/events`));
|
||||
setStatus("busy", "läuft …");
|
||||
source.addEventListener("line", (e) => append(JSON.parse(e.data)));
|
||||
source.addEventListener("end", (e) => {
|
||||
const info = JSON.parse(e.data);
|
||||
job = info;
|
||||
const [kind, text] = LABEL[info.status] || ["", info.status];
|
||||
setStatus(kind, text, `${info.duration}s · Exit-Code ${info.returncode}`);
|
||||
close();
|
||||
if (cfg.onFinish) cfg.onFinish(info);
|
||||
});
|
||||
source.onerror = () => {
|
||||
if (source && source.readyState === EventSource.CLOSED) {
|
||||
close();
|
||||
setStatus("warn", "Verbindung zum Protokoll unterbrochen");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function start(body) {
|
||||
clear();
|
||||
setStatus("busy", "wird gestartet …");
|
||||
try {
|
||||
job = await BT.api(endpoint, { method: "POST", body: JSON.stringify(body || {}) });
|
||||
attach(job.id);
|
||||
if (cfg.onStart) cfg.onStart(job);
|
||||
return job;
|
||||
} catch (err) {
|
||||
setStatus("error", "Start fehlgeschlagen", err.message);
|
||||
BT.toast(err.message, "err");
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function cancel() {
|
||||
if (!job) return;
|
||||
try {
|
||||
await BT.api(`/api/jobs/${job.id}/cancel`, { method: "POST" });
|
||||
BT.toast("Abbruch angefordert.");
|
||||
} catch (err) {
|
||||
BT.toast(err.message, "err");
|
||||
}
|
||||
}
|
||||
|
||||
function rebind(next) {
|
||||
if (next.log) logEl = next.log;
|
||||
if (next.status) statusEl = next.status;
|
||||
}
|
||||
|
||||
return {
|
||||
start, attach, cancel, clear, setStatus, rebind,
|
||||
get job() { return job; },
|
||||
get busy() { return Boolean(source); },
|
||||
};
|
||||
}
|
||||
|
||||
window.BT.Runner = Runner;
|
||||
})();
|
||||
@@ -0,0 +1,458 @@
|
||||
/* ==========================================================================
|
||||
boehmitools · gemeinsames Design-System
|
||||
Wird von der Shell UND von jedem Plugin eingebunden.
|
||||
Plugins definieren darüber hinaus nur noch Layout-Spezifisches.
|
||||
========================================================================== */
|
||||
|
||||
:root {
|
||||
/* Farben – hell */
|
||||
--bt-bg: #f7f4ef;
|
||||
--bt-bg-2: #efeae1;
|
||||
--bt-surface: #ffffff;
|
||||
--bt-surface-2: #fbf9f6;
|
||||
--bt-ink: #1c1a17;
|
||||
--bt-ink-soft: #4a453d;
|
||||
--bt-muted: #7a7267;
|
||||
--bt-line: #ddd6ca;
|
||||
--bt-line-soft: #ebe5da;
|
||||
|
||||
--bt-accent: #c2410c;
|
||||
--bt-accent-hi: #9a330a;
|
||||
--bt-accent-soft: #fdf0e8;
|
||||
--bt-accent-ink: #ffffff;
|
||||
|
||||
--bt-teal: #0f766e;
|
||||
--bt-violet: #6d28d9;
|
||||
|
||||
--bt-ok: #15803d;
|
||||
--bt-ok-soft: #eaf6ee;
|
||||
--bt-warn: #a16207;
|
||||
--bt-warn-soft: #fdf5e3;
|
||||
--bt-err: #b3261e;
|
||||
--bt-err-soft: #fbecea;
|
||||
--bt-info: #1d4ed8;
|
||||
--bt-info-soft: #eef2ff;
|
||||
|
||||
/* Form */
|
||||
--bt-r-sm: 6px;
|
||||
--bt-r: 9px;
|
||||
--bt-r-lg: 14px;
|
||||
--bt-shadow: 0 1px 2px rgba(28,26,23,.05), 0 4px 14px rgba(28,26,23,.05);
|
||||
--bt-shadow-lg: 0 12px 40px rgba(28,26,23,.13);
|
||||
--bt-ring: 0 0 0 3px rgba(194,65,12,.18);
|
||||
|
||||
/* Typo */
|
||||
--bt-font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
--bt-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
|
||||
--bt-fs: 14px;
|
||||
|
||||
--bt-appbar-h: 54px;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
[data-bt-theme="dark"] {
|
||||
--bt-bg: #14161a;
|
||||
--bt-bg-2: #1a1d22;
|
||||
--bt-surface: #1e2228;
|
||||
--bt-surface-2: #252a31;
|
||||
--bt-ink: #eceff3;
|
||||
--bt-ink-soft: #c3cad3;
|
||||
--bt-muted: #8d97a3;
|
||||
--bt-line: #333a44;
|
||||
--bt-line-soft: #2a3038;
|
||||
|
||||
--bt-accent: #f2792f;
|
||||
--bt-accent-hi: #ff8f4d;
|
||||
--bt-accent-soft: #2c211a;
|
||||
--bt-accent-ink: #1a1206;
|
||||
|
||||
--bt-teal: #3fc4b4;
|
||||
--bt-violet: #a98bf0;
|
||||
|
||||
--bt-ok: #57cc82;
|
||||
--bt-ok-soft: #17281d;
|
||||
--bt-warn: #e8b654;
|
||||
--bt-warn-soft: #2b2417;
|
||||
--bt-err: #ff8a80;
|
||||
--bt-err-soft: #2d1b1a;
|
||||
--bt-info: #8ec5ff;
|
||||
--bt-info-soft: #17202e;
|
||||
|
||||
--bt-shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.28);
|
||||
--bt-shadow-lg: 0 16px 46px rgba(0,0,0,.45);
|
||||
--bt-ring: 0 0 0 3px rgba(242,121,47,.28);
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ Basis */
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
html, body { height: 100%; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: var(--bt-font);
|
||||
font-size: var(--bt-fs);
|
||||
line-height: 1.45;
|
||||
color: var(--bt-ink);
|
||||
background: var(--bt-bg);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
a { color: var(--bt-accent); text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
|
||||
code, pre, kbd { font-family: var(--bt-mono); font-size: .92em; }
|
||||
|
||||
::selection { background: var(--bt-accent); color: var(--bt-accent-ink); }
|
||||
|
||||
/* ----------------------------------------------------------- App-Bar/Shell */
|
||||
.bt-appbar {
|
||||
position: sticky; top: 0; z-index: 60;
|
||||
height: var(--bt-appbar-h);
|
||||
display: flex; align-items: center; gap: 12px;
|
||||
padding: 0 14px;
|
||||
background: var(--bt-surface);
|
||||
border-bottom: 1px solid var(--bt-line);
|
||||
box-shadow: 0 1px 0 rgba(0,0,0,.02);
|
||||
}
|
||||
|
||||
.bt-brand {
|
||||
display: flex; align-items: center; gap: 9px;
|
||||
font-weight: 800; letter-spacing: -.02em;
|
||||
color: var(--bt-ink); white-space: nowrap;
|
||||
}
|
||||
.bt-brand:hover { text-decoration: none; }
|
||||
.bt-brand-mark {
|
||||
width: 26px; height: 26px; border-radius: 8px; flex: none;
|
||||
display: grid; place-items: center;
|
||||
background: var(--bt-accent); color: var(--bt-accent-ink);
|
||||
font-size: 14px; font-weight: 800;
|
||||
}
|
||||
.bt-brand small {
|
||||
font-weight: 600; color: var(--bt-muted); font-size: 11px;
|
||||
letter-spacing: .06em; text-transform: uppercase;
|
||||
}
|
||||
|
||||
.bt-appbar-sep {
|
||||
width: 1px; height: 22px; background: var(--bt-line); flex: none;
|
||||
}
|
||||
|
||||
.bt-crumb {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
font-weight: 700; color: var(--bt-ink);
|
||||
min-width: 0;
|
||||
}
|
||||
.bt-crumb .bt-crumb-ico { font-size: 15px; }
|
||||
.bt-crumb span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
|
||||
.bt-appbar-spacer { flex: 1 1 auto; }
|
||||
|
||||
.bt-appbar-actions { display: flex; align-items: center; gap: 8px; }
|
||||
|
||||
/* Tool-Umschalter */
|
||||
.bt-switch { position: relative; }
|
||||
.bt-switch-menu {
|
||||
position: absolute; right: 0; top: calc(100% + 8px);
|
||||
width: 320px; max-width: 90vw; padding: 6px;
|
||||
background: var(--bt-surface);
|
||||
border: 1px solid var(--bt-line);
|
||||
border-radius: var(--bt-r-lg);
|
||||
box-shadow: var(--bt-shadow-lg);
|
||||
display: none; z-index: 70;
|
||||
}
|
||||
.bt-switch-menu.open { display: block; }
|
||||
.bt-switch-menu .bt-switch-head {
|
||||
font-size: 11px; font-weight: 700; letter-spacing: .08em;
|
||||
text-transform: uppercase; color: var(--bt-muted);
|
||||
padding: 8px 10px 4px;
|
||||
}
|
||||
.bt-switch-item {
|
||||
display: flex; gap: 10px; align-items: flex-start;
|
||||
padding: 9px 10px; border-radius: var(--bt-r);
|
||||
color: var(--bt-ink);
|
||||
}
|
||||
.bt-switch-item:hover { background: var(--bt-bg-2); text-decoration: none; }
|
||||
.bt-switch-item.active { background: var(--bt-accent-soft); }
|
||||
.bt-switch-item .ico { font-size: 17px; line-height: 1.2; flex: none; }
|
||||
.bt-switch-item b { display: block; font-size: 13px; }
|
||||
.bt-switch-item i {
|
||||
display: block; font-style: normal; font-size: 11.5px;
|
||||
color: var(--bt-muted); line-height: 1.35;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- Container */
|
||||
.bt-main { padding: 18px 16px 60px; max-width: 1140px; margin: 0 auto; }
|
||||
.bt-main.wide { max-width: 1520px; }
|
||||
.bt-main.narrow { max-width: 820px; }
|
||||
|
||||
.bt-pagehead { margin: 0 0 16px; }
|
||||
.bt-pagehead h1 {
|
||||
margin: 0; font-size: 22px; letter-spacing: -.02em; font-weight: 800;
|
||||
}
|
||||
.bt-pagehead p { margin: 5px 0 0; color: var(--bt-muted); }
|
||||
|
||||
/* ------------------------------------------------------------------ Karten */
|
||||
.bt-card {
|
||||
background: var(--bt-surface);
|
||||
border: 1px solid var(--bt-line);
|
||||
border-radius: var(--bt-r-lg);
|
||||
padding: 16px;
|
||||
box-shadow: var(--bt-shadow);
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.bt-card > h2 {
|
||||
margin: 0 0 3px; font-size: 15px; font-weight: 750;
|
||||
letter-spacing: -.01em; color: var(--bt-ink);
|
||||
}
|
||||
.bt-card > h3 {
|
||||
margin: 16px 0 7px; font-size: 11.5px; font-weight: 800;
|
||||
letter-spacing: .09em; text-transform: uppercase; color: var(--bt-teal);
|
||||
}
|
||||
.bt-card > .hint, .bt-hint {
|
||||
margin: 0 0 12px; color: var(--bt-muted); font-size: 12.5px;
|
||||
}
|
||||
.bt-card-flush { padding: 0; overflow: hidden; }
|
||||
|
||||
/* ----------------------------------------------------------------- Buttons */
|
||||
button, .bt-btn {
|
||||
font: inherit; font-weight: 600; cursor: pointer;
|
||||
border: 1px solid var(--bt-line);
|
||||
background: var(--bt-surface);
|
||||
color: var(--bt-ink);
|
||||
border-radius: var(--bt-r);
|
||||
padding: 8px 13px;
|
||||
display: inline-flex; align-items: center; justify-content: center; gap: 7px;
|
||||
transition: background .13s, border-color .13s, color .13s, transform .06s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
button:hover, .bt-btn:hover { background: var(--bt-bg-2); text-decoration: none; }
|
||||
button:active, .bt-btn:active { transform: translateY(1px); }
|
||||
button:focus-visible, .bt-btn:focus-visible,
|
||||
input:focus-visible, select:focus-visible, textarea:focus-visible {
|
||||
outline: none; box-shadow: var(--bt-ring); border-color: var(--bt-accent);
|
||||
}
|
||||
button:disabled, .bt-btn:disabled, button[disabled] {
|
||||
opacity: .5; cursor: not-allowed; transform: none;
|
||||
}
|
||||
|
||||
button.primary, .bt-btn.primary {
|
||||
background: var(--bt-accent); border-color: var(--bt-accent);
|
||||
color: var(--bt-accent-ink); font-weight: 700;
|
||||
}
|
||||
button.primary:hover, .bt-btn.primary:hover {
|
||||
background: var(--bt-accent-hi); border-color: var(--bt-accent-hi);
|
||||
}
|
||||
button.ghost, .bt-btn.ghost {
|
||||
background: transparent; border-color: var(--bt-line); color: var(--bt-muted);
|
||||
}
|
||||
button.ghost:hover, .bt-btn.ghost:hover { color: var(--bt-ink); background: var(--bt-bg-2); }
|
||||
button.danger, .bt-btn.danger { color: var(--bt-err); border-color: var(--bt-err); background: transparent; }
|
||||
button.danger:hover, .bt-btn.danger:hover { background: var(--bt-err-soft); }
|
||||
button.mini, .bt-btn.mini { padding: 4px 9px; font-size: 12px; border-radius: var(--bt-r-sm); }
|
||||
button.icon, .bt-btn.icon { padding: 7px 9px; }
|
||||
|
||||
.bt-btnrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
|
||||
|
||||
/* ---------------------------------------------------------------- Formulare */
|
||||
label, .bt-label {
|
||||
display: block; font-size: 11.5px; font-weight: 700;
|
||||
color: var(--bt-muted); margin: 10px 0 4px;
|
||||
letter-spacing: .02em;
|
||||
}
|
||||
label.bt-inline, .bt-check {
|
||||
display: inline-flex; align-items: center; gap: 7px;
|
||||
font-size: 13px; font-weight: 600; color: var(--bt-ink-soft);
|
||||
margin: 0; text-transform: none; letter-spacing: 0;
|
||||
}
|
||||
.bt-check input { width: auto; }
|
||||
|
||||
input[type=text], input[type=url], input[type=number], input[type=password],
|
||||
input[type=search], textarea, select {
|
||||
width: 100%; font: inherit;
|
||||
padding: 8px 10px;
|
||||
color: var(--bt-ink);
|
||||
background: var(--bt-surface);
|
||||
border: 1px solid var(--bt-line);
|
||||
border-radius: var(--bt-r);
|
||||
transition: border-color .13s, box-shadow .13s;
|
||||
}
|
||||
input::placeholder, textarea::placeholder { color: var(--bt-muted); opacity: .75; }
|
||||
textarea { resize: vertical; min-height: 54px; line-height: 1.5; }
|
||||
select { cursor: pointer; }
|
||||
input[type=color] {
|
||||
width: 36px; height: 34px; padding: 2px; cursor: pointer;
|
||||
border: 1px solid var(--bt-line); border-radius: var(--bt-r-sm);
|
||||
background: var(--bt-surface);
|
||||
}
|
||||
input[type=checkbox], input[type=radio] { accent-color: var(--bt-accent); }
|
||||
|
||||
.bt-row { display: flex; gap: 10px; flex-wrap: wrap; }
|
||||
.bt-row > * { flex: 1; min-width: 130px; }
|
||||
.bt-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
|
||||
.bt-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
|
||||
.bt-grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
|
||||
@media (max-width: 760px) {
|
||||
.bt-grid2, .bt-grid3, .bt-grid4 { grid-template-columns: 1fr; }
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- Tabs */
|
||||
.bt-tabs {
|
||||
display: flex; gap: 3px; flex-wrap: wrap;
|
||||
border-bottom: 1px solid var(--bt-line);
|
||||
padding: 0 2px;
|
||||
}
|
||||
.bt-tab {
|
||||
padding: 8px 13px; font-size: 13px; font-weight: 650;
|
||||
color: var(--bt-muted); background: transparent;
|
||||
border: none; border-bottom: 2px solid transparent;
|
||||
border-radius: var(--bt-r-sm) var(--bt-r-sm) 0 0;
|
||||
margin-bottom: -1px; cursor: pointer;
|
||||
}
|
||||
.bt-tab:hover { color: var(--bt-ink); background: var(--bt-bg-2); }
|
||||
.bt-tab.active { color: var(--bt-accent); border-bottom-color: var(--bt-accent); background: transparent; }
|
||||
|
||||
/* ------------------------------------------------------------------ Badges */
|
||||
.bt-badge {
|
||||
display: inline-flex; align-items: center; gap: 5px;
|
||||
padding: 2px 8px; border-radius: 999px;
|
||||
font-size: 11px; font-weight: 700; letter-spacing: .02em;
|
||||
background: var(--bt-bg-2); color: var(--bt-ink-soft);
|
||||
border: 1px solid var(--bt-line-soft);
|
||||
}
|
||||
.bt-badge.ok { background: var(--bt-ok-soft); color: var(--bt-ok); border-color: transparent; }
|
||||
.bt-badge.warn { background: var(--bt-warn-soft); color: var(--bt-warn); border-color: transparent; }
|
||||
.bt-badge.err { background: var(--bt-err-soft); color: var(--bt-err); border-color: transparent; }
|
||||
.bt-badge.info { background: var(--bt-info-soft); color: var(--bt-info); border-color: transparent; }
|
||||
.bt-badge.accent { background: var(--bt-accent-soft); color: var(--bt-accent); border-color: transparent; }
|
||||
|
||||
.bt-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
|
||||
|
||||
/* ------------------------------------------------------------------ Notice */
|
||||
.bt-notice {
|
||||
border: 1px solid var(--bt-line);
|
||||
border-left: 3px solid var(--bt-muted);
|
||||
background: var(--bt-surface-2);
|
||||
border-radius: 0 var(--bt-r) var(--bt-r) 0;
|
||||
padding: 10px 13px; font-size: 12.5px; color: var(--bt-ink-soft);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.bt-notice.ok { border-left-color: var(--bt-ok); background: var(--bt-ok-soft); }
|
||||
.bt-notice.warn { border-left-color: var(--bt-warn); background: var(--bt-warn-soft); }
|
||||
.bt-notice.err { border-left-color: var(--bt-err); background: var(--bt-err-soft); }
|
||||
.bt-notice.info { border-left-color: var(--bt-info); background: var(--bt-info-soft); }
|
||||
.bt-notice code { background: rgba(128,128,128,.16); padding: 1px 5px; border-radius: 4px; }
|
||||
.bt-notice b { color: var(--bt-ink); }
|
||||
|
||||
/* ------------------------------------------------------------------ Status */
|
||||
.bt-status {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
padding: 9px 13px; border-radius: var(--bt-r);
|
||||
background: var(--bt-surface); border: 1px solid var(--bt-line);
|
||||
font-size: 13px; color: var(--bt-ink-soft); margin: 12px 0;
|
||||
box-shadow: var(--bt-shadow);
|
||||
}
|
||||
.bt-status.ok { border-color: var(--bt-ok); color: var(--bt-ok); }
|
||||
.bt-status.error{ border-color: var(--bt-err); color: var(--bt-err); }
|
||||
.bt-status.warn { border-color: var(--bt-warn); color: var(--bt-warn); }
|
||||
.bt-status.busy { border-color: var(--bt-accent); color: var(--bt-accent); }
|
||||
|
||||
/* -------------------------------------------------------------------- Item */
|
||||
.bt-item {
|
||||
border: 1px solid var(--bt-line);
|
||||
border-radius: var(--bt-r);
|
||||
background: var(--bt-surface-2);
|
||||
padding: 11px 13px; margin: 10px 0;
|
||||
}
|
||||
.bt-item-head {
|
||||
display: flex; align-items: center; gap: 8px; margin-bottom: 7px;
|
||||
}
|
||||
.bt-item-head .n {
|
||||
font-weight: 800; font-size: 11px; color: var(--bt-teal);
|
||||
letter-spacing: .05em;
|
||||
}
|
||||
.bt-item-head .spacer { flex: 1; }
|
||||
|
||||
/* ------------------------------------------------------------------ Tabelle */
|
||||
.bt-table { width: 100%; border-collapse: collapse; font-size: 13px; }
|
||||
.bt-table th {
|
||||
text-align: left; font-size: 11px; font-weight: 800;
|
||||
letter-spacing: .07em; text-transform: uppercase; color: var(--bt-muted);
|
||||
padding: 9px 10px; border-bottom: 1px solid var(--bt-line);
|
||||
background: var(--bt-surface-2);
|
||||
}
|
||||
.bt-table td { padding: 9px 10px; border-bottom: 1px solid var(--bt-line-soft); vertical-align: top; }
|
||||
.bt-table tr:last-child td { border-bottom: none; }
|
||||
.bt-table tbody tr:hover { background: var(--bt-surface-2); }
|
||||
|
||||
/* --------------------------------------------------------------------- Log */
|
||||
.bt-log {
|
||||
font-family: var(--bt-mono); font-size: 12px; line-height: 1.55;
|
||||
background: #0f1115; color: #d7dde6;
|
||||
border: 1px solid var(--bt-line); border-radius: var(--bt-r);
|
||||
padding: 12px 13px; overflow: auto; white-space: pre-wrap;
|
||||
word-break: break-word; min-height: 180px; max-height: 60vh;
|
||||
}
|
||||
.bt-log .l-err { color: #ff9a90; }
|
||||
.bt-log .l-ok { color: #7fdca2; }
|
||||
.bt-log .l-warn { color: #ffd28a; }
|
||||
.bt-log .l-meta { color: #7d8896; }
|
||||
|
||||
/* ------------------------------------------------------------------- Toast */
|
||||
#bt-toaster {
|
||||
position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
|
||||
z-index: 100; display: flex; flex-direction: column; gap: 8px;
|
||||
align-items: center; pointer-events: none;
|
||||
}
|
||||
.bt-toast {
|
||||
background: var(--bt-ink); color: var(--bt-bg);
|
||||
padding: 10px 18px; border-radius: var(--bt-r);
|
||||
font-size: 13px; font-weight: 600; max-width: 92vw;
|
||||
box-shadow: var(--bt-shadow-lg);
|
||||
opacity: 0; transform: translateY(8px);
|
||||
transition: opacity .2s, transform .2s;
|
||||
}
|
||||
.bt-toast.show { opacity: .97; transform: none; }
|
||||
.bt-toast.err { background: var(--bt-err); color: #fff; }
|
||||
.bt-toast.ok { background: var(--bt-ok); color: #fff; }
|
||||
|
||||
/* ------------------------------------------------------------------ Helpers */
|
||||
.bt-muted { color: var(--bt-muted); font-size: 12.5px; }
|
||||
.bt-spacer { flex: 1; }
|
||||
.bt-mono { font-family: var(--bt-mono); }
|
||||
.bt-empty {
|
||||
color: var(--bt-muted); font-size: 13px; text-align: center;
|
||||
padding: 26px 14px; border: 1px dashed var(--bt-line);
|
||||
border-radius: var(--bt-r); background: var(--bt-surface-2);
|
||||
}
|
||||
.bt-scroll { overflow: auto; }
|
||||
.bt-hidden { display: none !important; }
|
||||
|
||||
/* Scrollbars */
|
||||
* { scrollbar-color: var(--bt-line) transparent; scrollbar-width: thin; }
|
||||
::-webkit-scrollbar { width: 10px; height: 10px; }
|
||||
::-webkit-scrollbar-thumb { background: var(--bt-line); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
|
||||
::-webkit-scrollbar-track { background: transparent; }
|
||||
|
||||
/* ---------------------------------------------------------- Sicherungen */
|
||||
.bt-runs{ display: grid; gap: 6px; }
|
||||
.bt-run{
|
||||
display: grid; grid-template-columns: 20px 1fr auto; gap: 10px; align-items: center;
|
||||
padding: 10px 12px; border: 1px solid var(--bt-line); border-radius: var(--bt-r-sm);
|
||||
background: var(--bt-surface); cursor: pointer;
|
||||
}
|
||||
.bt-run:hover{ background: var(--bt-surface-2); }
|
||||
.bt-run.sel{ border-color: var(--bt-accent); background: var(--bt-accent-soft); }
|
||||
.bt-run-main b{ font-size: 13px; }
|
||||
.bt-run-sub{ display: block; font-size: 11.5px; color: var(--bt-muted); margin-top: 1px; }
|
||||
.bt-run-tags{ display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
|
||||
.bt-steps{ display: grid; gap: 5px; max-height: 34vh; overflow: auto; }
|
||||
.bt-step{
|
||||
display: grid; grid-template-columns: auto 1fr; gap: 9px; align-items: baseline;
|
||||
padding: 6px 9px; border-bottom: 1px solid var(--bt-line-soft); font-size: 12.5px;
|
||||
}
|
||||
.bt-step:last-child{ border-bottom: none; }
|
||||
@media (max-width: 700px){
|
||||
.bt-run{ grid-template-columns: 20px 1fr; }
|
||||
.bt-run-tags{ grid-column: 2; justify-content: flex-start; }
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/* ==========================================================================
|
||||
boehmitools · gemeinsame Shell
|
||||
Stellt App-Bar, Tool-Umschalter, Theme und kleine Helfer für alle Plugins.
|
||||
|
||||
Einbindung in einem Plugin (siehe plugins/README.md):
|
||||
<link rel="stylesheet" href="/shared/boehmi.css">
|
||||
<script src="/shared/boehmi.js" defer></script>
|
||||
<body data-bt-title="Mein Tool" data-bt-icon="🔧"> ... </body>
|
||||
|
||||
Der Mount-Pfad wird automatisch aus der URL abgeleitet, ein Plugin muss
|
||||
ihn nicht kennen. API-Aufrufe laufen über BT.api("/api/...").
|
||||
========================================================================== */
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const ROOT_META = document.querySelector('meta[name="bt-root"]');
|
||||
const pathMatch = location.pathname.match(/^(.*?)(\/plugins\/[^/]+)/);
|
||||
|
||||
const BT = {
|
||||
/** Präfix der gesamten Suite (nur bei Reverse-Proxy-Unterpfad gesetzt). */
|
||||
root: ROOT_META ? ROOT_META.content.replace(/\/$/, "") : (pathMatch ? pathMatch[1] : ""),
|
||||
/** Mount-Präfix des aktuellen Plugins, z. B. "/plugins/trainingsplan". */
|
||||
base: pathMatch ? pathMatch[1] + pathMatch[2] : "",
|
||||
/** ID des aktuellen Plugins oder null (Dashboard). */
|
||||
plugin: pathMatch ? pathMatch[2].split("/").pop() : null,
|
||||
plugins: [],
|
||||
};
|
||||
window.BT = BT;
|
||||
|
||||
/* ------------------------------------------------------------- Helfer */
|
||||
|
||||
/** Plugin-eigener Pfad → absolute URL. */
|
||||
BT.url = (path) => BT.base + path;
|
||||
/** Suite-weiter Pfad → absolute URL. */
|
||||
BT.rootUrl = (path) => BT.root + path;
|
||||
|
||||
/** fetch mit JSON-Handling, relativ zum Plugin-Mount. */
|
||||
BT.api = async function (path, options = {}) {
|
||||
const opts = { ...options };
|
||||
if (opts.body !== undefined && !(opts.body instanceof FormData)) {
|
||||
opts.headers = { "Content-Type": "application/json", ...(opts.headers || {}) };
|
||||
}
|
||||
const res = await fetch(BT.url(path), opts);
|
||||
const text = await res.text();
|
||||
let data = {};
|
||||
try { data = text ? JSON.parse(text) : {}; } catch (_) { data = { raw: text }; }
|
||||
if (!res.ok) throw new Error(data.detail || data.error || `HTTP ${res.status}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
BT.toast = function (message, kind = "") {
|
||||
let host = document.getElementById("bt-toaster");
|
||||
if (!host) {
|
||||
host = document.createElement("div");
|
||||
host.id = "bt-toaster";
|
||||
document.body.appendChild(host);
|
||||
}
|
||||
const el = document.createElement("div");
|
||||
el.className = "bt-toast " + kind;
|
||||
el.textContent = message;
|
||||
host.appendChild(el);
|
||||
requestAnimationFrame(() => el.classList.add("show"));
|
||||
setTimeout(() => {
|
||||
el.classList.remove("show");
|
||||
setTimeout(() => el.remove(), 250);
|
||||
}, kind === "err" ? 5200 : 2600);
|
||||
};
|
||||
|
||||
BT.escape = (s) => String(s ?? "").replace(/[&<>"']/g, (c) => (
|
||||
{ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]
|
||||
));
|
||||
|
||||
/* -------------------------------------------------------------- Theme */
|
||||
|
||||
const THEME_KEY = "boehmitools.theme";
|
||||
|
||||
BT.setTheme = function (mode) {
|
||||
const resolved = mode === "auto"
|
||||
? (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light")
|
||||
: mode;
|
||||
document.documentElement.setAttribute("data-bt-theme", resolved);
|
||||
try { localStorage.setItem(THEME_KEY, mode); } catch (_) {}
|
||||
document.querySelectorAll("[data-bt-theme-toggle]").forEach((b) => {
|
||||
b.textContent = resolved === "dark" ? "☀︎" : "☾";
|
||||
b.title = resolved === "dark" ? "Helles Design" : "Dunkles Design";
|
||||
});
|
||||
};
|
||||
|
||||
BT.currentTheme = function () {
|
||||
try { return localStorage.getItem(THEME_KEY) || "auto"; } catch (_) { return "auto"; }
|
||||
};
|
||||
|
||||
// so früh wie möglich anwenden (verhindert Aufblitzen)
|
||||
BT.setTheme(BT.currentTheme());
|
||||
matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
|
||||
if (BT.currentTheme() === "auto") BT.setTheme("auto");
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------ App-Bar */
|
||||
|
||||
function onBody(fn) {
|
||||
if (document.body) fn();
|
||||
else document.addEventListener("DOMContentLoaded", fn, { once: true });
|
||||
}
|
||||
|
||||
function buildAppbar(plugins) {
|
||||
const me = plugins.find((p) => p.id === BT.plugin);
|
||||
const title = document.body.dataset.btTitle || (me ? me.name : "Dashboard");
|
||||
const icon = document.body.dataset.btIcon || (me ? me.icon : "▦");
|
||||
|
||||
const bar = document.createElement("header");
|
||||
bar.className = "bt-appbar";
|
||||
bar.innerHTML = `
|
||||
<a class="bt-brand" href="${BT.rootUrl("/")}" title="Zum Dashboard">
|
||||
<span class="bt-brand-mark">B</span>
|
||||
<span>boehmitools</span>
|
||||
</a>
|
||||
${BT.plugin ? `
|
||||
<span class="bt-appbar-sep"></span>
|
||||
<span class="bt-crumb"><span class="bt-crumb-ico">${BT.escape(icon)}</span>
|
||||
<span>${BT.escape(title)}</span></span>` : ""}
|
||||
<span class="bt-appbar-spacer"></span>
|
||||
<span class="bt-appbar-actions">
|
||||
<span class="bt-switch">
|
||||
<button class="mini ghost" id="bt-switch-btn" aria-haspopup="true" aria-expanded="false">
|
||||
Tools ▾
|
||||
</button>
|
||||
<div class="bt-switch-menu" id="bt-switch-menu" role="menu">
|
||||
<div class="bt-switch-head">Tools</div>
|
||||
${plugins.map((p) => `
|
||||
<a class="bt-switch-item ${p.id === BT.plugin ? "active" : ""}" href="${BT.rootUrl(p.mount)}/">
|
||||
<span class="ico">${BT.escape(p.icon)}</span>
|
||||
<span><b>${BT.escape(p.name)}</b><i>${BT.escape(p.summary || "")}</i></span>
|
||||
</a>`).join("")}
|
||||
<div class="bt-switch-head">Suite</div>
|
||||
<a class="bt-switch-item" href="${BT.rootUrl("/")}"><span class="ico">▦</span>
|
||||
<span><b>Dashboard</b><i>Übersicht aller Tools</i></span></a>
|
||||
<a class="bt-switch-item" href="${BT.rootUrl("/jobs")}"><span class="ico">↻</span>
|
||||
<span><b>Läufe</b><i>Protokolle der Kommandozeilen-Tools</i></span></a>
|
||||
<a class="bt-switch-item" href="${BT.rootUrl("/settings")}"><span class="ico">⚙</span>
|
||||
<span><b>Einstellungen</b><i>Tandoor- und OpenAI-Zugänge</i></span></a>
|
||||
</div>
|
||||
</span>
|
||||
<button class="mini ghost icon" data-bt-theme-toggle title="Design wechseln">☾</button>
|
||||
</span>`;
|
||||
|
||||
const anchor = document.getElementById("bt-appbar") || document.body.firstChild;
|
||||
if (anchor && anchor.id === "bt-appbar") anchor.replaceWith(bar);
|
||||
else document.body.insertBefore(bar, document.body.firstChild);
|
||||
|
||||
const btn = document.getElementById("bt-switch-btn");
|
||||
const menu = document.getElementById("bt-switch-menu");
|
||||
btn.addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
const open = menu.classList.toggle("open");
|
||||
btn.setAttribute("aria-expanded", String(open));
|
||||
});
|
||||
document.addEventListener("click", () => menu.classList.remove("open"));
|
||||
document.addEventListener("keydown", (e) => { if (e.key === "Escape") menu.classList.remove("open"); });
|
||||
|
||||
bar.querySelector("[data-bt-theme-toggle]").addEventListener("click", () => {
|
||||
const now = document.documentElement.getAttribute("data-bt-theme");
|
||||
BT.setTheme(now === "dark" ? "light" : "dark");
|
||||
});
|
||||
BT.setTheme(BT.currentTheme());
|
||||
}
|
||||
|
||||
BT.ready = fetch(BT.rootUrl("/api/plugins"))
|
||||
.then((r) => (r.ok ? r.json() : { plugins: [] }))
|
||||
.catch(() => ({ plugins: [] }))
|
||||
.then((d) => new Promise((resolve) => {
|
||||
BT.plugins = d.plugins || [];
|
||||
onBody(() => {
|
||||
if (document.body.dataset.btShell !== "off") buildAppbar(BT.plugins);
|
||||
document.dispatchEvent(new CustomEvent("bt:ready", { detail: BT }));
|
||||
resolve(BT);
|
||||
});
|
||||
}));
|
||||
})();
|
||||
Reference in New Issue
Block a user