// static/js/ui-channels.js – Kanal-Rendering & Listener
function renderChannels() {
console.log("renderChannels() START");
console.log("→ config.channels existiert?", !!config?.channels);
console.log("→ channels.length:", config?.channels?.length ?? "undefined");
const container = document.getElementById('channels-container');
if (!container) {
console.error("channelsContainer nicht gefunden!");
return;
}
container.innerHTML = '';
if (!config?.channels || config.channels.length === 0) {
container.innerHTML = '
Keine Kanäle definiert.
';
return;
}
config.channels.forEach(channel => {
const col = document.createElement('div');
col.className = 'col-md-6 mb-4';
let html = '';
if (channel.type === 'motor') {
html = `
-100 %
0 %
+100 %
`;
} else {
html = `
`;
}
col.innerHTML = ``;
container.appendChild(col);
});
// Listener hinzufügen (wie bisher)
document.querySelectorAll('.motor-slider').forEach(slider => {
const display = slider.parentElement.querySelector('.value-display');
slider.addEventListener('input', async () => {
const value = parseInt(slider.value) / 100;
if (display) display.textContent = `${slider.value} %`;
await sendControl(slider.dataset.port, value);
});
});
document.querySelectorAll('.stop-channel-btn').forEach(btn => {
btn.addEventListener('click', async () => {
await sendControl(btn.dataset.port, 0);
const slider = document.querySelector(`input[data-port="${btn.dataset.port}"]`);
if (slider) {
slider.value = 0;
const display = slider.parentElement.querySelector('.value-display');
if (display) display.textContent = '0 %';
}
});
});
document.querySelectorAll('.toggle-btn').forEach(btn => {
btn.addEventListener('click', async () => {
const state = btn.dataset.state === 'off' ? 'on' : 'off';
btn.dataset.state = state;
btn.textContent = state === 'on' ? 'EIN' : 'AUS';
btn.classList.toggle('btn-success', state === 'on');
btn.classList.toggle('btn-outline-secondary', state === 'off');
await sendControl(btn.dataset.port, state === 'on' ? 1 : 0);
});
});
}
// Am Ende von ui-channels.js
window.initChannels = renderChannels;