v0.2.6-pre.004
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-app-wallet-desk/frontend/ts/main.ts
|
||||
// version: 3
|
||||
// version: 4
|
||||
|
||||
import "bootstrap";
|
||||
import DataTable from "datatables.net-bs5";
|
||||
@@ -8,7 +8,10 @@ import ResizeObserver from "resize-observer-polyfill";
|
||||
import "simplebar";
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||
import type { RuntimeStatusDto } from "./bindings/ksp_app_wallet_desk/dto_common/RuntimeStatusDto.ts";
|
||||
import { frontendDebug, frontendInfo, frontendTrace, installFrontendConsoleBridge } from "./frontend_log";
|
||||
import type { LockedWalletDto } from "./bindings/ksp_app_wallet_desk/wallet_inventory/LockedWalletDto.ts";
|
||||
import type { WalletInventoryEntryDto } from "./bindings/ksp_app_wallet_desk/wallet_inventory/WalletInventoryEntryDto.ts";
|
||||
import type { WalletSelectionRequestDto } from "./bindings/ksp_app_wallet_desk/wallet_inventory/WalletSelectionRequestDto.ts";
|
||||
import { frontendDebug, frontendInfo, frontendTrace, frontendWarn, installFrontendConsoleBridge } from "./frontend_log";
|
||||
import { invokeKsp } from "./invoke";
|
||||
import "../sass/main.scss";
|
||||
|
||||
@@ -95,20 +98,169 @@ function bindNavigation(): void {
|
||||
frontendTrace("main", "Wallet Desk navigation handlers installed");
|
||||
}
|
||||
|
||||
function appendIconText(cell: HTMLTableCellElement, iconClass: string, text: string): void {
|
||||
const icon = document.createElement("i");
|
||||
icon.className = `fa-solid ${iconClass} me-2`;
|
||||
icon.setAttribute("aria-hidden", "true");
|
||||
const label = document.createElement("span");
|
||||
label.textContent = text;
|
||||
cell.append(icon, label);
|
||||
}
|
||||
|
||||
function renderWalletInventoryRow(entry: WalletInventoryEntryDto): HTMLTableRowElement {
|
||||
const row = document.createElement("tr");
|
||||
row.dataset.walletId = entry.walletId;
|
||||
row.dataset.walletSelectable = entry.inspectionStatus === "valid" ? "true" : "false";
|
||||
row.dataset.inspectionStatus = entry.inspectionStatus;
|
||||
const state = document.createElement("td");
|
||||
if (entry.state === "locked") {
|
||||
appendIconText(state, "fa-lock", "Locked");
|
||||
} else {
|
||||
appendIconText(state, "fa-triangle-exclamation", "Erreur");
|
||||
}
|
||||
const filename = document.createElement("td");
|
||||
filename.textContent = entry.filename;
|
||||
const format = document.createElement("td");
|
||||
format.textContent = entry.formatVersion === null ? "—" : entry.formatVersion.toString();
|
||||
const view = document.createElement("td");
|
||||
view.textContent = entry.viewEnabled === null ? "—" : entry.viewEnabled ? "enabled" : "disabled";
|
||||
const inspection = document.createElement("td");
|
||||
if (entry.inspectionStatus === "valid") {
|
||||
inspection.textContent = "Valide";
|
||||
} else if (entry.diagnostic) {
|
||||
inspection.textContent = `Invalide — ${entry.diagnostic.domain}.${entry.diagnostic.code}`;
|
||||
inspection.title = entry.diagnostic.message;
|
||||
} else {
|
||||
inspection.textContent = "Invalide";
|
||||
}
|
||||
row.append(state, filename, format, view, inspection);
|
||||
return row;
|
||||
}
|
||||
|
||||
function initializeWalletTable(): void {
|
||||
if (DataTable.isDataTable("#walletInventoryTable")) {
|
||||
new DataTable("#walletInventoryTable").destroy();
|
||||
}
|
||||
new DataTable("#walletInventoryTable", {
|
||||
order: [[1, "asc"]],
|
||||
pageLength: 10,
|
||||
select: {
|
||||
selector: "tbody tr[data-wallet-selectable='true'] td",
|
||||
style: "single",
|
||||
},
|
||||
language: {
|
||||
emptyTable: "L'inventaire Wallet sera branché en pre.004.",
|
||||
emptyTable: "Aucun wallet .kspwallet disponible.",
|
||||
search: "Filtrer :",
|
||||
zeroRecords: "Aucun wallet correspondant.",
|
||||
},
|
||||
});
|
||||
frontendDebug("main", "Wallet inventory DataTable initialized", { phase: "pre.003-config-wallet" });
|
||||
frontendDebug("main", "Wallet inventory DataTable initialized", { phase: "pre.004-wallet-inventory" });
|
||||
}
|
||||
|
||||
function renderWalletInventory(entries: WalletInventoryEntryDto[]): void {
|
||||
if (DataTable.isDataTable("#walletInventoryTable")) {
|
||||
new DataTable("#walletInventoryTable").destroy();
|
||||
}
|
||||
const body = document.querySelector<HTMLTableSectionElement>("#walletInventoryBody");
|
||||
if (body) {
|
||||
body.replaceChildren(...entries.map(entry => renderWalletInventoryRow(entry)));
|
||||
}
|
||||
initializeWalletTable();
|
||||
const invalidCount = entries.filter(entry => entry.inspectionStatus === "invalid").length;
|
||||
frontendDebug("main", "Wallet inventory rendered", { entryCount: entries.length, invalidCount });
|
||||
}
|
||||
|
||||
function clearSelectedWallet(): void {
|
||||
const icon = document.querySelector<HTMLElement>("#currentWalletIcon");
|
||||
const filename = document.querySelector<HTMLElement>("#currentWalletFilename");
|
||||
const state = document.querySelector<HTMLElement>("#currentWalletState");
|
||||
const format = document.querySelector<HTMLElement>("#currentWalletFormat");
|
||||
const view = document.querySelector<HTMLElement>("#currentWalletView");
|
||||
if (icon) {
|
||||
icon.className = "fa-solid fa-lock fa-2x mb-3 text-body-secondary";
|
||||
}
|
||||
if (filename) {
|
||||
filename.textContent = "Aucun wallet sélectionné.";
|
||||
}
|
||||
if (state) {
|
||||
state.textContent = "—";
|
||||
}
|
||||
if (format) {
|
||||
format.textContent = "—";
|
||||
}
|
||||
if (view) {
|
||||
view.textContent = "—";
|
||||
}
|
||||
}
|
||||
|
||||
function renderSelectedWallet(wallet: LockedWalletDto): void {
|
||||
const icon = document.querySelector<HTMLElement>("#currentWalletIcon");
|
||||
const filename = document.querySelector<HTMLElement>("#currentWalletFilename");
|
||||
const state = document.querySelector<HTMLElement>("#currentWalletState");
|
||||
const format = document.querySelector<HTMLElement>("#currentWalletFormat");
|
||||
const view = document.querySelector<HTMLElement>("#currentWalletView");
|
||||
if (icon) {
|
||||
icon.className = "fa-solid fa-lock fa-2x mb-3";
|
||||
}
|
||||
if (filename) {
|
||||
filename.textContent = wallet.filename;
|
||||
}
|
||||
if (state) {
|
||||
state.textContent = "Locked";
|
||||
}
|
||||
if (format) {
|
||||
format.textContent = wallet.formatVersion.toString();
|
||||
}
|
||||
if (view) {
|
||||
view.textContent = wallet.viewEnabled ? "enabled" : "disabled";
|
||||
}
|
||||
frontendDebug("main", "Locked Wallet selection rendered", { walletId: wallet.walletId, formatVersion: wallet.formatVersion, viewEnabled: wallet.viewEnabled });
|
||||
}
|
||||
|
||||
async function selectWallet(walletId: string): Promise<void> {
|
||||
const request: WalletSelectionRequestDto = { walletId };
|
||||
try {
|
||||
const wallet = await invokeKsp<LockedWalletDto>("main", "select_wallet", { request });
|
||||
renderSelectedWallet(wallet);
|
||||
} catch {
|
||||
clearSelectedWallet();
|
||||
frontendWarn("main", "Locked Wallet selection failed", { walletId });
|
||||
}
|
||||
}
|
||||
|
||||
function bindWalletTableSelection(): void {
|
||||
const table = document.querySelector<HTMLTableElement>("#walletInventoryTable");
|
||||
if (!table) {
|
||||
return;
|
||||
}
|
||||
table.addEventListener("click", event => {
|
||||
const source = event.target;
|
||||
if (!(source instanceof Element)) {
|
||||
return;
|
||||
}
|
||||
const row = source.closest<HTMLTableRowElement>("tbody tr[data-wallet-id]");
|
||||
if (!row) {
|
||||
return;
|
||||
}
|
||||
const walletId = row.dataset.walletId;
|
||||
if (!walletId) {
|
||||
return;
|
||||
}
|
||||
if (row.dataset.walletSelectable !== "true") {
|
||||
frontendDebug("main", "Invalid Wallet inventory row selection ignored", { walletId });
|
||||
return;
|
||||
}
|
||||
frontendTrace("main", "Wallet inventory row selected", { walletId });
|
||||
void selectWallet(walletId);
|
||||
});
|
||||
frontendTrace("main", "Wallet inventory row selection handler installed");
|
||||
}
|
||||
|
||||
async function loadWalletInventory(command: "list_wallets" | "refresh_wallets"): Promise<void> {
|
||||
frontendDebug("main", "Wallet inventory load requested", { command });
|
||||
const entries = await invokeKsp<WalletInventoryEntryDto[]>("main", command);
|
||||
clearSelectedWallet();
|
||||
renderWalletInventory(entries);
|
||||
}
|
||||
|
||||
function renderRuntimeStatus(status: RuntimeStatusDto): void {
|
||||
@@ -158,7 +310,7 @@ function renderRuntimeStatus(status: RuntimeStatusDto): void {
|
||||
phase.textContent = status.shellPhase;
|
||||
}
|
||||
if (shellStatus) {
|
||||
shellStatus.textContent = "Config Wallet Desk résolue ; répertoire Wallet prêt.";
|
||||
shellStatus.textContent = "Config résolue ; inventaire Wallet prêt.";
|
||||
}
|
||||
frontendTrace("main", "Wallet Desk runtime status rendered", {
|
||||
compositeProfile: status.activeCompositeProfile,
|
||||
@@ -177,7 +329,13 @@ async function loadRuntimeStatus(): Promise<void> {
|
||||
function bindShellActions(): void {
|
||||
document.querySelectorAll<HTMLButtonElement>("[data-shell-action]").forEach(button => {
|
||||
button.addEventListener("click", () => {
|
||||
frontendDebug("main", "Wallet Desk shell action clicked", { action: button.dataset.shellAction ?? "unknown", enabled: !button.disabled });
|
||||
const action = button.dataset.shellAction ?? "unknown";
|
||||
frontendDebug("main", "Wallet Desk shell action clicked", { action, enabled: !button.disabled });
|
||||
if (action === "refresh-wallets" && !button.disabled) {
|
||||
void loadWalletInventory("refresh_wallets").catch(() => {
|
||||
frontendWarn("main", "Wallet inventory refresh failed");
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
frontendTrace("main", "Wallet Desk shell action handlers installed");
|
||||
@@ -188,17 +346,19 @@ async function initializeMain(): Promise<void> {
|
||||
frontendInfo("main", "Wallet Desk main frontend loaded", { windowLabel });
|
||||
bindFrontendInteractions();
|
||||
bindNavigation();
|
||||
bindWalletTableSelection();
|
||||
bindShellActions();
|
||||
initializeWalletTable();
|
||||
activateView("dashboard", "startup");
|
||||
try {
|
||||
await loadRuntimeStatus();
|
||||
await loadWalletInventory("list_wallets");
|
||||
} catch {
|
||||
renderWalletInventory([]);
|
||||
const shellStatus = document.querySelector<HTMLElement>("#shellStatus");
|
||||
if (shellStatus) {
|
||||
shellStatus.textContent = "Le statut runtime n'a pas pu être chargé.";
|
||||
shellStatus.textContent = "Le statut runtime ou l'inventaire Wallet n'a pas pu être chargé.";
|
||||
}
|
||||
frontendTrace("main", "Wallet Desk shell status replaced", { status: "runtime_error" });
|
||||
frontendWarn("main", "Wallet Desk startup data load failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user