v0.1.0-pre.054
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
// file: kb-app-demo-desktop/frontend/ts/demo_backfill.ts
|
||||
// version: 5
|
||||
// version: 6
|
||||
|
||||
import * as bootstrap from "bootstrap";
|
||||
import "simplebar";
|
||||
import "@andypf/json-viewer";
|
||||
import ResizeObserver from "resize-observer-polyfill";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
@@ -146,7 +147,7 @@ function validationMessage(request: DemoBackfillRequest): string | null {
|
||||
}
|
||||
|
||||
function reportValidationWarning(message: string): void {
|
||||
element<HTMLTextAreaElement>("#backfillSummaryOutput").value = JSON.stringify({ validation: message }, null, 2);
|
||||
renderBackfillSummary({ validation: message });
|
||||
appendLog({ timestamp: new Date().toISOString(), level: "warn", message });
|
||||
frontendDebug("kb-app-demo-desktop.frontend.backfill", `Backfill request rejected locally: ${message}`);
|
||||
}
|
||||
@@ -174,10 +175,10 @@ async function executeBackfill(mode: string): Promise<void> {
|
||||
return;
|
||||
}
|
||||
setRunning(true);
|
||||
element<HTMLTextAreaElement>("#backfillSummaryOutput").value = "Exécution en cours...";
|
||||
renderBackfillSummary({ status: "Exécution en cours" });
|
||||
appendLog({ timestamp: new Date().toISOString(), level: "info", message: `Démarrage du mode ${mode}` });
|
||||
const summary = await invoke<DemoBackfillSummaryPayload>("demo_backfill_execute", { request });
|
||||
element<HTMLTextAreaElement>("#backfillSummaryOutput").value = JSON.stringify(summary, null, 2);
|
||||
renderBackfillSummary(summary);
|
||||
appendLog({
|
||||
timestamp: new Date().toISOString(),
|
||||
level: summary.cancelled ? "warn" : "info",
|
||||
@@ -185,7 +186,7 @@ async function executeBackfill(mode: string): Promise<void> {
|
||||
});
|
||||
} catch (caughtError) {
|
||||
const message = caughtError instanceof Error ? caughtError.message : String(caughtError);
|
||||
element<HTMLTextAreaElement>("#backfillSummaryOutput").value = JSON.stringify({ error: message }, null, 2);
|
||||
renderBackfillSummary({ error: message });
|
||||
appendLog({ timestamp: new Date().toISOString(), level: "error", message });
|
||||
frontendError("kb-app-demo-desktop.frontend.backfill", `Backfill failed: ${message}`);
|
||||
} finally {
|
||||
@@ -232,6 +233,28 @@ async function loadOptions(): Promise<void> {
|
||||
setRunning(options.running);
|
||||
}
|
||||
|
||||
|
||||
function renderBackfillSummary(value: unknown): void {
|
||||
const container = document.querySelector<HTMLElement>("#backfillSummaryOutput");
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
container.textContent = "";
|
||||
const viewer = document.createElement("andypf-json-viewer");
|
||||
viewer.setAttribute("indent", "2");
|
||||
viewer.setAttribute("expanded", "1");
|
||||
viewer.setAttribute("theme", "default-light");
|
||||
viewer.setAttribute("show-data-types", "true");
|
||||
viewer.setAttribute("show-toolbar", "false");
|
||||
viewer.setAttribute("show-copy", "true");
|
||||
viewer.setAttribute("data", JSON.stringify(value ?? { status: "Aucun résultat" }, null, 2));
|
||||
container.appendChild(viewer);
|
||||
}
|
||||
|
||||
async function copyText(value: string): Promise<void> {
|
||||
await navigator.clipboard.writeText(value);
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
installFrontendConsoleBridge("kb-app-demo-desktop.frontend.backfill");
|
||||
frontendDebug("kb-app-demo-desktop.frontend.backfill", "backfill demo window loaded");
|
||||
@@ -264,4 +287,14 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
appendLog({ timestamp: new Date().toISOString(), level: "error", message });
|
||||
frontendError("kb-app-demo-desktop.frontend.backfill", `Options loading failed: ${message}`);
|
||||
});
|
||||
|
||||
document.querySelector<HTMLButtonElement>("#copyBackfillLogButton")?.addEventListener("click", async () => {
|
||||
const value = document.querySelector<HTMLTextAreaElement>("#backfillLogOutput")?.value ?? "";
|
||||
await copyText(value);
|
||||
});
|
||||
document.querySelector<HTMLButtonElement>("#copyBackfillSummaryButton")?.addEventListener("click", async () => {
|
||||
const value = document.querySelector("#backfillSummaryOutput andypf-json-viewer")?.getAttribute("data") ?? "";
|
||||
await copyText(value);
|
||||
});
|
||||
renderBackfillSummary(null);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user