Update config, web GUI, and add debug features
This commit is contained in:
1 parent
4492b77d67
commit
7eb72bd00e
6 files changed
+140
-9
No files matched your search
@@ -0,0 +1,68 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Debug WebGUI</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Debug WebGUI Config Loading</h1>
|
||||
<div id="output"></div>
|
||||
|
||||
<script>
|
||||
const output = document.getElementById('output');
|
||||
|
||||
async function apiGet(path) {
|
||||
const res = await fetch(path, { cache: "no-store" });
|
||||
if (!res.ok) throw new Error(await res.text());
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
function getConfigBoundElements() {
|
||||
return Array.from(document.querySelectorAll("[data-key]"));
|
||||
}
|
||||
|
||||
async function testConfig() {
|
||||
try {
|
||||
output.innerHTML += '<p>Testing API...</p>';
|
||||
const cfg = await apiGet("/api/config");
|
||||
output.innerHTML += `<p>Config loaded: ${Object.keys(cfg).length} keys</p>`;
|
||||
|
||||
// Test getConfigBoundElements
|
||||
const elements = getConfigBoundElements();
|
||||
output.innerHTML += `<p>Found ${elements.length} config-bound elements</p>`;
|
||||
|
||||
if (elements.length > 0) {
|
||||
output.innerHTML += '<p>Sample elements:</p><ul>';
|
||||
for (let i = 0; i < Math.min(5, elements.length); i++) {
|
||||
const el = elements[i];
|
||||
output.innerHTML += `<li>${el.id || el.name || 'unnamed'}: data-key="${el.dataset.key}"</li>`;
|
||||
}
|
||||
output.innerHTML += '</ul>';
|
||||
}
|
||||
|
||||
// Test DEFAULTS
|
||||
const DEFAULTS = {
|
||||
min_prize_value_yuan: 0,
|
||||
min_participants: 0,
|
||||
skip_if_countdown_lt_seconds: 15,
|
||||
};
|
||||
|
||||
output.innerHTML += '<p>Testing applyConfigToUI logic...</p>';
|
||||
|
||||
for (const key of Object.keys(DEFAULTS)) {
|
||||
const val = cfg ? cfg[key] : undefined;
|
||||
const hasVal = !(typeof val === "undefined" || val === null);
|
||||
const useVal = hasVal ? val : (Object.prototype.hasOwnProperty.call(DEFAULTS, key) ? DEFAULTS[key] : undefined);
|
||||
|
||||
output.innerHTML += `<p>${key}: config=${val}, hasVal=${hasVal}, useVal=${useVal}</p>`;
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
output.innerHTML += `<p>Error: ${e.message}</p>`;
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
testConfig();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user