Gesamte Mono-Repo des Baukastens (alle apps/clients, examples/tests und packages)
dh_heyart
vor 5 Std. 96438053d50d33b24c946cd290d57356b4a80b73
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import "@dh-software/baukasten-config-ui";
import type { BaukastenConfigurationChangeDetail } from "@dh-software/baukasten-config-ui";
import type { ConfigurationEntry, ConfigurationReference } from "@dh-software/baukasten-types";
 
const picker = document.getElementById("picker") as HTMLElement & {
    available: ConfigurationEntry[];
    selected: ConfigurationReference[];
};
const customerInput = document.getElementById("customer") as HTMLInputElement;
const reloadButton = document.getElementById("reload") as HTMLButtonElement;
const loadButton = document.getElementById("load") as HTMLButtonElement;
const statusEl = document.getElementById("status") as HTMLElement;
const resultsEl = document.getElementById("results") as HTMLElement;
 
let selected: ConfigurationReference[] = [];
 
async function loadCatalog(): Promise<void> {
    const customerNo = customerInput.value.trim();
    statusEl.textContent = "Lade Katalog…";
    const response = await fetch(`/api/catalog?customerNo=${encodeURIComponent(customerNo)}`);
    const entries = (await response.json()) as ConfigurationEntry[];
    picker.available = entries;
    selected = [];
    picker.selected = selected;
    resultsEl.replaceChildren();
    statusEl.textContent = `${entries.length} Konfiguration(en) verfügbar.`;
}
 
picker.addEventListener("configurations-change", (event) => {
    selected = (event as CustomEvent<BaukastenConfigurationChangeDetail>).detail.selected;
});
 
async function loadSelected(): Promise<void> {
    if (selected.length === 0) {
        statusEl.textContent = "Nichts ausgewählt.";
        resultsEl.replaceChildren();
        return;
    }
    statusEl.textContent = "Lese Konfigurationen…";
    const response = await fetch("/api/read", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(selected),
    });
    if (!response.ok) {
        const error = (await response.json().catch(() => ({}))) as { error?: string };
        statusEl.textContent = `Fehler: ${error.error ?? response.status}`;
        return;
    }
    const result = (await response.json()) as Array<{
        reference: ConfigurationReference;
        content: unknown;
    }>;
    resultsEl.replaceChildren(
        ...result.map((item, index) => {
            const wrapper = document.createElement("div");
            wrapper.className = "result";
            const title = document.createElement("h4");
            title.textContent = `${index + 1}. ${item.reference.customerNumber} / ${item.reference.key}`;
            const pre = document.createElement("pre");
            pre.textContent = JSON.stringify(item.content, null, 2);
            wrapper.append(title, pre);
            return wrapper;
        }),
    );
    statusEl.textContent = `${result.length} Konfiguration(en) gelesen (Reihenfolge = Merge-Reihenfolge).`;
}
 
reloadButton.addEventListener("click", () => {
    void loadCatalog();
});
loadButton.addEventListener("click", () => {
    void loadSelected();
});
 
void loadCatalog();