v0.1.4-pre.008
This commit is contained in:
@@ -1,20 +1,140 @@
|
||||
// file: crates/ksp-app-config-desk/frontend/ts/main.ts
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
import "bootstrap";
|
||||
import ResizeObserver from "resize-observer-polyfill";
|
||||
import "simplebar";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import { frontendInfo, installFrontendConsoleBridge } from "./frontend_log";
|
||||
import type { AppSnapshotDto } from "./bindings/ksp_app_config_desk/dto_common/AppSnapshotDto.ts";
|
||||
import { frontendDebug, frontendInfo, frontendTrace, installFrontendConsoleBridge } from "./frontend_log";
|
||||
import { invokeKsp } from "./invoke";
|
||||
|
||||
(window as Window & typeof globalThis & { ResizeObserver?: typeof ResizeObserver }).ResizeObserver = ResizeObserver;
|
||||
installFrontendConsoleBridge("main");
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const windowLabel = getCurrentWindow().label;
|
||||
const status = document.querySelector<HTMLElement>("#shellStatus");
|
||||
if (status) {
|
||||
status.textContent = `Frontend chargé dans la fenêtre '${windowLabel}'.`;
|
||||
type ViewId = "overview" | "documents" | "profiles" | "environment" | "logging";
|
||||
|
||||
const viewCopy: Record<ViewId, { title: string; description: string }> = {
|
||||
overview: {
|
||||
title: "Vue d'ensemble",
|
||||
description: "État sûr du bootstrap Config Desk et du runtime Logging actuellement actif.",
|
||||
},
|
||||
documents: {
|
||||
title: "Documents",
|
||||
description: "Inventaire, diagnostics et réparation des documents Config — surface fonctionnelle prévue en pre.009.",
|
||||
},
|
||||
profiles: {
|
||||
title: "Profils",
|
||||
description: "Sélection et provenance des profils Config — surface fonctionnelle prévue en pre.010.",
|
||||
},
|
||||
environment: {
|
||||
title: "Environnement / .env",
|
||||
description: "Rapports et management des variables KSP/KSPB — surfaces fonctionnelles prévues en pre.011/pre.012.",
|
||||
},
|
||||
logging: {
|
||||
title: "Logging",
|
||||
description: "Édition des profils et hot reload du runtime Logging — surfaces fonctionnelles prévues en pre.014 à pre.017.",
|
||||
},
|
||||
};
|
||||
|
||||
function isViewId(value: string): value is ViewId {
|
||||
return Object.prototype.hasOwnProperty.call(viewCopy, value);
|
||||
}
|
||||
|
||||
function activateView(viewId: ViewId, source: "startup" | "user"): void {
|
||||
if (source === "user") {
|
||||
frontendDebug("main", "Main navigation activated", { viewId });
|
||||
}
|
||||
const copy = viewCopy[viewId];
|
||||
const title = document.querySelector<HTMLElement>("#viewTitle");
|
||||
const description = document.querySelector<HTMLElement>("#viewDescription");
|
||||
if (title) {
|
||||
title.textContent = copy.title;
|
||||
}
|
||||
if (description) {
|
||||
description.textContent = copy.description;
|
||||
}
|
||||
document.querySelectorAll<HTMLButtonElement>("[data-view]").forEach(button => {
|
||||
const active = button.dataset.view === viewId;
|
||||
button.classList.toggle("active", active);
|
||||
button.setAttribute("aria-current", active ? "page" : "false");
|
||||
});
|
||||
const overview = document.querySelector<HTMLElement>("#overviewPanel");
|
||||
if (overview) {
|
||||
overview.hidden = viewId !== "overview";
|
||||
}
|
||||
const placeholder = document.querySelector<HTMLElement>("#placeholderPanel");
|
||||
if (placeholder) {
|
||||
placeholder.hidden = viewId === "overview";
|
||||
}
|
||||
frontendTrace("main", "Main view DOM updated", { viewId, source });
|
||||
}
|
||||
|
||||
function bindNavigation(): void {
|
||||
document.querySelectorAll<HTMLButtonElement>("[data-view]").forEach(button => {
|
||||
button.addEventListener("click", () => {
|
||||
const requestedView = button.dataset.view;
|
||||
if (requestedView && isViewId(requestedView)) {
|
||||
activateView(requestedView, "user");
|
||||
}
|
||||
});
|
||||
});
|
||||
frontendTrace("main", "Main navigation handlers installed");
|
||||
}
|
||||
|
||||
function renderSnapshot(snapshot: AppSnapshotDto): void {
|
||||
const version = document.querySelector<HTMLElement>("#overviewVersion");
|
||||
const documents = document.querySelector<HTMLElement>("#overviewDocuments");
|
||||
const profile = document.querySelector<HTMLElement>("#overviewLoggingProfile");
|
||||
const generation = document.querySelector<HTMLElement>("#overviewLoggingGeneration");
|
||||
const fallback = document.querySelector<HTMLElement>("#overviewLoggingFallback");
|
||||
if (version) {
|
||||
version.textContent = snapshot.applicationVersion;
|
||||
}
|
||||
if (documents) {
|
||||
documents.textContent = snapshot.configDocumentCount.toString();
|
||||
}
|
||||
if (profile) {
|
||||
profile.textContent = snapshot.activeLoggingProfile ?? "fallback transitoire";
|
||||
}
|
||||
if (generation) {
|
||||
generation.textContent = snapshot.loggingGeneration.toString();
|
||||
}
|
||||
if (fallback) {
|
||||
fallback.textContent = snapshot.fallbackLoggingActive ? "oui" : "non";
|
||||
}
|
||||
frontendTrace("main", "Application snapshot rendered", {
|
||||
loggingGeneration: snapshot.loggingGeneration,
|
||||
fallbackLoggingActive: snapshot.fallbackLoggingActive,
|
||||
});
|
||||
}
|
||||
|
||||
async function loadSnapshot(): Promise<void> {
|
||||
const status = document.querySelector<HTMLElement>("#shellStatus");
|
||||
const snapshot = await invokeKsp<AppSnapshotDto>("main", "get_app_snapshot");
|
||||
renderSnapshot(snapshot);
|
||||
if (status) {
|
||||
status.textContent = "Shell principal prêt.";
|
||||
}
|
||||
frontendTrace("main", "Main shell status replaced", { status: "ready" });
|
||||
}
|
||||
|
||||
async function initializeMain(): Promise<void> {
|
||||
const windowLabel = getCurrentWindow().label;
|
||||
frontendInfo("main", "Config Desk main frontend loaded", { windowLabel });
|
||||
bindNavigation();
|
||||
activateView("overview", "startup");
|
||||
try {
|
||||
await loadSnapshot();
|
||||
} catch {
|
||||
const status = document.querySelector<HTMLElement>("#shellStatus");
|
||||
if (status) {
|
||||
status.textContent = "Le snapshot initial n'a pas pu être chargé.";
|
||||
}
|
||||
frontendTrace("main", "Main shell status replaced", { status: "snapshot_error" });
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
void initializeMain();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user