get_config realisiert, damti der darkmode aus der yaml geladen wird
This commit is contained in:
1 parent
3fb6051e4a
commit
49bd17d52b
6 files changed
+105
-86
No files matched your search
+10
-6
@@ -1,11 +1,15 @@
|
||||
// Sortiere die Tabelle nach Adresse (addr) beim Laden der Seite
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Darkmode-Status aus localStorage übernehmen
|
||||
if (localStorage.getItem('darkmode') === 'true') {
|
||||
document.body.classList.add('darkmode');
|
||||
} else {
|
||||
document.body.classList.remove('darkmode');
|
||||
}
|
||||
// Darkmode-Status aus Konfiguration übernehmen
|
||||
fetch('/api/config')
|
||||
.then(response => response.json())
|
||||
.then(config => {
|
||||
if (config && config.default && config.default.darkmode === true) {
|
||||
document.body.classList.add('darkmode');
|
||||
} else {
|
||||
document.body.classList.remove('darkmode');
|
||||
}
|
||||
});
|
||||
const tableBody = document.getElementById('tableBody');
|
||||
if (tableBody) {
|
||||
// Extrahiere alle Zeilen und deren addr
|
||||
|
||||
+42
-32
@@ -1,4 +1,44 @@
|
||||
// Setze den Wert des Darkmode-Schalters beim Laden der Seite, sobald das Element existiert
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
fetch('/api/config')
|
||||
.then(response => response.json())
|
||||
.then(config => {
|
||||
function setSwitch() {
|
||||
const el = document.getElementById('darkmode_switch');
|
||||
if (el) {
|
||||
if (config && config.default && (config.default.darkmode === true || config.default.darkmode === 'true')) {
|
||||
el.checked = true;
|
||||
} else {
|
||||
el.checked = false;
|
||||
}
|
||||
} else {
|
||||
// Falls das Element noch nicht existiert, erneut versuchen
|
||||
setTimeout(setSwitch, 50);
|
||||
}
|
||||
}
|
||||
setSwitch();
|
||||
});
|
||||
});
|
||||
async function saveSettings() {
|
||||
// Default (für [default])
|
||||
const darkmode = document.getElementById('darkmode_switch')?.checked ?? null;
|
||||
const defaultConfig = {
|
||||
loglevel: document.getElementById('loglevel')?.value || null,
|
||||
darkmode: darkmode
|
||||
};
|
||||
|
||||
// Modbus
|
||||
const modbus = {
|
||||
host: document.getElementById('modbus_host').value,
|
||||
port: parseInt(document.getElementById('modbus_port').value, 10),
|
||||
max_coils_addr: parseInt(document.getElementById('modbus_max_coils_addr').value, 10) || null,
|
||||
max_input_addr: parseInt(document.getElementById('modbus_max_input_addr').value, 10) || null,
|
||||
max_holding_addr: parseInt(document.getElementById('modbus_max_holding_addr').value, 10) || null,
|
||||
modbus_coils: null,
|
||||
modbus_input_register: null,
|
||||
modbus_holding_register: null
|
||||
};
|
||||
|
||||
// MQTT
|
||||
const mqtt = {
|
||||
broker: document.getElementById('mqtt_broker').value,
|
||||
@@ -18,28 +58,11 @@ async function saveSettings() {
|
||||
measurement: document.getElementById('influxdb_measurement').value || null
|
||||
};
|
||||
|
||||
// Modbus
|
||||
const modbus = {
|
||||
host: document.getElementById('modbus_host').value,
|
||||
port: parseInt(document.getElementById('modbus_port').value, 10),
|
||||
max_coils_addr: parseInt(document.getElementById('modbus_max_coils_addr').value, 10) || null,
|
||||
max_input_addr: parseInt(document.getElementById('modbus_max_input_addr').value, 10) || null,
|
||||
max_holding_addr: parseInt(document.getElementById('modbus_max_holding_addr').value, 10) || null,
|
||||
modbus_coils: null,
|
||||
modbus_input_register: null,
|
||||
modbus_holding_register: null
|
||||
};
|
||||
|
||||
// Default (für [default])
|
||||
const defaultConfig = {
|
||||
loglevel: document.getElementById('loglevel')?.value || null
|
||||
};
|
||||
|
||||
const settings = {
|
||||
default: defaultConfig,
|
||||
modbus,
|
||||
mqtt,
|
||||
influxdb,
|
||||
modbus
|
||||
influxdb
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -70,16 +93,3 @@ async function saveSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
// Darkmode Toggle
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const btn = document.getElementById('darkmode-toggle');
|
||||
if (!btn) return;
|
||||
// Initialer Zustand aus LocalStorage
|
||||
if (localStorage.getItem('darkmode') === 'true') {
|
||||
document.body.classList.add('darkmode');
|
||||
}
|
||||
btn.addEventListener('click', function() {
|
||||
document.body.classList.toggle('darkmode');
|
||||
localStorage.setItem('darkmode', document.body.classList.contains('darkmode'));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user