funktionierender Settings-Dialog

This commit is contained in:
Eric Neuber committed 2025-12-29 17:58:56 +01:00
1 parent bb2bb8d493
commit e74689c70f
10 files changed
+889 -197

No files matched your search

+34 -16
View File
@@ -1,3 +1,18 @@
// Sortiere die Tabelle nach Adresse (addr) beim Laden der Seite
document.addEventListener('DOMContentLoaded', function() {
const tableBody = document.getElementById('tableBody');
if (tableBody) {
// Extrahiere alle Zeilen und deren addr
const rows = Array.from(tableBody.querySelectorAll('tr'));
rows.sort((a, b) => {
const addrA = parseInt(a.querySelector("input[data-field='addr']")?.value || '0', 10);
const addrB = parseInt(b.querySelector("input[data-field='addr']")?.value || '0', 10);
return addrA - addrB;
});
// Füge sortierte Zeilen wieder ein
rows.forEach(row => tableBody.appendChild(row));
}
});
function addRow() {
const tableBody = document.getElementById('tableBody');
const rowCount = tableBody.querySelectorAll('tr').length;
@@ -47,23 +62,26 @@ function updateRowIndices() {
async function saveTable() {
const rows = [];
const tableRows = document.querySelectorAll('#tableBody tr');
tableRows.forEach((row) => {
const bezeichnung = row.querySelector("input[data-field='bezeichnung']").value;
const adresse = row.querySelector("input[data-field='adresse']").value;
const type = row.querySelector("input[data-field='type']").value;
const faktor = row.querySelector("input[data-field='faktor']").value;
const mqtt = row.querySelector("input[data-field='mqtt']").checked;
const influxdb = row.querySelector("input[data-field='influxdb']").checked;
rows.push({
bezeichnung,
adresse,
type,
faktor,
mqtt,
influxdb
});
const key = row.querySelector("input[data-field='bezeichnung']").value.trim();
if (!key) return; // leere Zeilen überspringen
const addr = parseInt(row.querySelector("input[data-field='addr']")?.value || row.querySelector("input[data-field='adresse']")?.value || '0', 10);
const rtype = row.querySelector("input[data-field='type']")?.value || null;
const factor = parseFloat(row.querySelector("input[data-field='factor']")?.value || row.querySelector("input[data-field='faktor']")?.value || '1.0');
const mqtt = row.querySelector("input[data-field='mqtt']")?.checked || false;
const influxdb = row.querySelector("input[data-field='influxdb']")?.checked || false;
const comment = row.querySelector("input[data-field='comment']")?.value || null;
const value = {
addr: addr,
rtype: rtype,
factor: factor,
mqtt: mqtt,
influxdb: influxdb,
comment: comment
};
const obj = {};
obj[key] = value;
rows.push(obj);
});
try {
+44 -13
View File
@@ -1,16 +1,47 @@
async function saveSettings() {
const mqtt_broker = document.getElementById('mqtt_broker').value;
const mqtt_port = document.getElementById('mqtt_port').value;
const influxdb_url = document.getElementById('influxdb_url').value;
const influxdb_token = document.getElementById('influxdb_token').value;
const settings = {
mqtt_broker,
mqtt_port,
influxdb_url,
influxdb_token
// MQTT
const mqtt = {
broker: document.getElementById('mqtt_broker').value,
port: parseInt(document.getElementById('mqtt_port').value, 10),
user: document.getElementById('mqtt_user').value || null,
password: document.getElementById('mqtt_password').value || null,
button_circulation: document.getElementById('mqtt_button_circulation').value || null
};
// InfluxDB
const influxdb = {
url: document.getElementById('influxdb_url').value,
token: document.getElementById('influxdb_token').value,
bucket: document.getElementById('influxdb_bucket').value,
org: document.getElementById('influxdb_org').value,
location: document.getElementById('influxdb_location').value || null,
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,
mqtt,
influxdb,
modbus
};
try {
const response = await fetch('/api/save-settings', {
method: 'POST',
@@ -19,7 +50,7 @@ async function saveSettings() {
},
body: JSON.stringify(settings)
});
const messageDiv = document.getElementById('message');
if (response.ok) {
messageDiv.className = 'message success';
@@ -28,7 +59,7 @@ async function saveSettings() {
messageDiv.className = 'message error';
messageDiv.textContent = '✗ Fehler beim Speichern der Einstellungen!';
}
setTimeout(() => {
messageDiv.style.display = 'none';
}, 3000);