chore(format): initial formatting

This commit is contained in:
HendrikRauh 2026-03-05 23:05:35 +01:00
parent fa08fcfe65
commit 008c79852b
21 changed files with 1021 additions and 1082 deletions

View file

@ -1,7 +1,7 @@
import {
showLoadingScreen,
showError,
hideLoadingScreen,
showLoadingScreen,
showError,
hideLoadingScreen,
} from "./loading-screen.js";
const form = document.querySelector("form.config");
@ -9,46 +9,46 @@ const form = document.querySelector("form.config");
export let data = {};
export async function loadData(timeout = null) {
const req = await fetch("/config", {
method: "GET",
signal: timeout !== null ? AbortSignal.timeout(timeout) : undefined,
});
if (!req.ok) {
throw new Error(`Response status: ${req.status}`);
}
const req = await fetch("/config", {
method: "GET",
signal: timeout !== null ? AbortSignal.timeout(timeout) : undefined,
});
if (!req.ok) {
throw new Error(`Response status: ${req.status}`);
}
const json = await req.json();
console.log(json);
return json;
const json = await req.json();
console.log(json);
return json;
}
export function writeDataToInput(data) {
console.log("write data");
for (const [key, value] of Object.entries(data)) {
const element = document.querySelector(`[name=${key}]`);
console.log(key, element);
console.log("write data");
for (const [key, value] of Object.entries(data)) {
const element = document.querySelector(`[name=${key}]`);
console.log(key, element);
if (element.type === "checkbox") {
element.checked = value;
} else {
element.value = value;
}
if (element.type === "range") {
// update text next to the slider by sending an event
element.dispatchEvent(new Event("input", { bubbles: true }));
}
if (element.type === "checkbox") {
element.checked = value;
} else {
element.value = value;
}
// send "change" event
form.dispatchEvent(new Event("change", { bubbles: true }));
if (element.type === "range") {
// update text next to the slider by sending an event
element.dispatchEvent(new Event("input", { bubbles: true }));
}
}
// send "change" event
form.dispatchEvent(new Event("change", { bubbles: true }));
}
showLoadingScreen("Konfiguration wird geladen...");
try {
data = await loadData();
hideLoadingScreen();
writeDataToInput(data);
data = await loadData();
hideLoadingScreen();
writeDataToInput(data);
} catch (error) {
console.log(error.message);
showError("Die Konfiguration konnte nicht geladen werden.");
console.log(error.message);
showError("Die Konfiguration konnte nicht geladen werden.");
}