v0.3.8-pre.006
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-store-desk/frontend/ts/main.ts
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
import DataTable from "datatables.net-bs5";
|
||||
import "datatables.net-bs5/css/dataTables.bootstrap5.css";
|
||||
@@ -7,6 +7,7 @@ import "bootstrap";
|
||||
import ResizeObserver from "resize-observer-polyfill";
|
||||
import "simplebar";
|
||||
import type { ShellStatusDto } from "./bindings/ksp_app_store_desk/dto_common/ShellStatusDto.ts";
|
||||
import type { StoreRuntimeStatusDto } from "./bindings/ksp_app_store_desk/dto_common/StoreRuntimeStatusDto.ts";
|
||||
import { frontendDebug, frontendError, frontendInfo, frontendTrace, installFrontendConsoleBridge } from "./frontend_log";
|
||||
import { invokeKsp } from "./invoke";
|
||||
|
||||
@@ -33,6 +34,22 @@ function isViewId(value: string | undefined): value is ViewId {
|
||||
return value === "overview" || value === "transactions" || value === "accounts" || value === "diagnostics";
|
||||
}
|
||||
|
||||
function setText(elementId: string, value: string): void {
|
||||
const element = document.querySelector<HTMLElement>(`#${elementId}`);
|
||||
if (element) {
|
||||
element.textContent = value;
|
||||
}
|
||||
}
|
||||
|
||||
function renderDiagnostic(elementId: string, diagnostic: { domain: string; code: string; message: string } | null): void {
|
||||
const element = document.querySelector<HTMLElement>(`#${elementId}`);
|
||||
if (!element) {
|
||||
return;
|
||||
}
|
||||
element.hidden = diagnostic === null;
|
||||
element.textContent = diagnostic ? `${diagnostic.domain}/${diagnostic.code}: ${diagnostic.message}` : "";
|
||||
}
|
||||
|
||||
function activateView(viewId: ViewId): void {
|
||||
document.querySelectorAll<HTMLElement>("[data-view-panel]").forEach(panel => {
|
||||
panel.hidden = panel.dataset.viewPanel !== viewId;
|
||||
@@ -67,7 +84,7 @@ function initializeEmptyTables(): void {
|
||||
scrollX: true,
|
||||
autoWidth: false,
|
||||
language: {
|
||||
emptyTable: "Aucune donnée Store n'est chargée dans le scaffold pre.002.",
|
||||
emptyTable: "Aucune donnée RAW n'est chargée dans la tranche pre.006.",
|
||||
},
|
||||
};
|
||||
transactionTable = new DataTable("#rawTransactionsTable", commonOptions) as unknown as EmptyDataTable;
|
||||
@@ -76,39 +93,65 @@ function initializeEmptyTables(): void {
|
||||
}
|
||||
|
||||
function renderShellStatus(status: ShellStatusDto): void {
|
||||
const versionBadge = document.querySelector<HTMLElement>("#appVersionBadge");
|
||||
if (versionBadge) {
|
||||
versionBadge.textContent = status.applicationVersion;
|
||||
}
|
||||
const values: Record<string, string> = {
|
||||
runtimeVersion: status.applicationVersion,
|
||||
runtimeShellPhase: status.shellPhase,
|
||||
runtimeConfigDocuments: status.configDocumentCount.toString(),
|
||||
runtimeLoggingProfile: status.activeLoggingProfile ?? "fallback",
|
||||
runtimeLoggingFallback: status.fallbackLoggingActive ? "oui" : "non",
|
||||
};
|
||||
for (const [elementId, value] of Object.entries(values)) {
|
||||
const element = document.querySelector<HTMLElement>(`#${elementId}`);
|
||||
if (element) {
|
||||
element.textContent = value;
|
||||
}
|
||||
}
|
||||
const diagnostic = document.querySelector<HTMLElement>("#runtimeDiagnostic");
|
||||
if (diagnostic) {
|
||||
diagnostic.hidden = status.startupDiagnostic === null;
|
||||
diagnostic.textContent = status.startupDiagnostic ? `${status.startupDiagnostic.domain}/${status.startupDiagnostic.code}: ${status.startupDiagnostic.message}` : "";
|
||||
}
|
||||
setText("appVersionBadge", status.applicationVersion);
|
||||
setText("runtimeVersion", status.applicationVersion);
|
||||
setText("runtimeShellPhase", status.shellPhase);
|
||||
setText("runtimeConfigDocuments", status.configDocumentCount.toString());
|
||||
setText("runtimeLoggingProfile", status.activeLoggingProfile ?? "fallback");
|
||||
setText("runtimeLoggingFallback", status.fallbackLoggingActive ? "oui" : "non");
|
||||
renderDiagnostic("runtimeDiagnostic", status.startupDiagnostic);
|
||||
frontendTrace("main", "Store Desk shell status rendered", {
|
||||
fallbackLoggingActive: status.fallbackLoggingActive,
|
||||
shellPhase: status.shellPhase,
|
||||
});
|
||||
}
|
||||
|
||||
function renderStoreRuntimeStatus(status: StoreRuntimeStatusDto): void {
|
||||
const target = status.backendKind && status.network ? `${status.backendKind} / ${status.network}` : status.network ?? status.backendKind ?? "indisponible";
|
||||
const migration = status.migrationVersionDecimal === null ? `inconnue · ${status.pendingMigrationCount} pending` : `v${status.migrationVersionDecimal} · ${status.pendingMigrationCount} pending`;
|
||||
const pool = `${status.poolAvailable}/${status.poolSize}/${status.poolCapacity} · wait ${status.poolWaiting}`;
|
||||
const profile = status.profileId ?? "indisponible";
|
||||
|
||||
setText("overviewStoreProfile", profile);
|
||||
setText("overviewStoreTarget", target);
|
||||
setText("overviewStoreHealth", status.healthState);
|
||||
setText("overviewStorePool", pool);
|
||||
setText("overviewStoreMigration", migration);
|
||||
renderDiagnostic("overviewStoreDiagnostic", status.diagnostic);
|
||||
|
||||
setText("runtimeStoreProfile", profile);
|
||||
setText("runtimeStoreTarget", target);
|
||||
setText("runtimeStoreHealth", status.healthState);
|
||||
setText("runtimeStoreMigration", migration);
|
||||
setText("runtimeStorePool", pool);
|
||||
renderDiagnostic("runtimeStoreDiagnostic", status.diagnostic);
|
||||
|
||||
frontendTrace("main", "Store Desk Store runtime status rendered", {
|
||||
healthState: status.healthState,
|
||||
pendingMigrationCount: status.pendingMigrationCount,
|
||||
poolCapacity: status.poolCapacity,
|
||||
poolSize: status.poolSize,
|
||||
storeOpen: status.storeOpen,
|
||||
});
|
||||
}
|
||||
|
||||
async function refreshStoreRuntime(): Promise<void> {
|
||||
frontendDebug("main", "Store Desk Store runtime refresh started");
|
||||
try {
|
||||
const status = await invokeKsp<StoreRuntimeStatusDto>("main", "store_runtime_status");
|
||||
renderStoreRuntimeStatus(status);
|
||||
frontendDebug("main", "Store Desk Store runtime refresh completed", { healthState: status.healthState, storeOpen: status.storeOpen });
|
||||
} catch {
|
||||
frontendError("main", "Store Desk Store runtime refresh failed");
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshDiagnostics(): Promise<void> {
|
||||
frontendDebug("main", "Store Desk diagnostics refresh started");
|
||||
try {
|
||||
const status = await invokeKsp<ShellStatusDto>("main", "get_shell_status");
|
||||
renderShellStatus(status);
|
||||
await refreshStoreRuntime();
|
||||
frontendDebug("main", "Store Desk diagnostics refresh completed");
|
||||
} catch {
|
||||
frontendError("main", "Store Desk diagnostics refresh failed");
|
||||
@@ -125,6 +168,11 @@ function installInteractions(): void {
|
||||
}
|
||||
});
|
||||
});
|
||||
const refreshOverview = document.querySelector<HTMLButtonElement>("#refreshOverview");
|
||||
refreshOverview?.addEventListener("click", () => {
|
||||
frontendDebug("main", "Store Desk Overview refresh button clicked");
|
||||
void refreshStoreRuntime();
|
||||
});
|
||||
const refreshButton = document.querySelector<HTMLButtonElement>("#refreshDiagnostics");
|
||||
refreshButton?.addEventListener("click", () => {
|
||||
frontendDebug("main", "Store Desk diagnostics refresh button clicked");
|
||||
@@ -139,7 +187,7 @@ function installInteractions(): void {
|
||||
if (!control) {
|
||||
return;
|
||||
}
|
||||
if (control instanceof HTMLButtonElement && (control.dataset.view || control.id === "refreshDiagnostics")) {
|
||||
if (control instanceof HTMLButtonElement && (control.dataset.view || control.id === "refreshDiagnostics" || control.id === "refreshOverview")) {
|
||||
return;
|
||||
}
|
||||
const controlId = control.id || control.getAttribute("data-bs-target") || control.getAttribute("aria-controls") || "anonymous";
|
||||
|
||||
Reference in New Issue
Block a user