feat: Integration von CGI-Platzhaltern für digitale Ausgänge (DASx, DANx)

- Platzhalter in da.js auf neue Struktur (DAS1–DAS4, DAN1–DAN4) umgestellt
- fetchDigitalOutputsService liest Werte dynamisch über da.js vom CPL-Webserver
- Schreibvorgänge via window.location.href mit CGI-Parametern (DASx=, DANx=)
- Umschaltlogik zwischen Entwicklungs- und Produktionsmodus eingebaut
- Modal-Speichern aktualisiert sowohl Status als auch Bezeichnung per CGI
- Unterstützung für lokale Mockdaten über API bleibt bestehen
This commit is contained in:
ISA
2025-05-09 10:59:18 +02:00
parent adb52eb86d
commit d4ba8f5b2e
5 changed files with 73 additions and 31 deletions

View File

@@ -44,25 +44,47 @@ export default function DigitalOutputsModal({
: output
);
try {
const res = await fetch("/api/cpl/updateDigitalOutputs", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ outputs: updatedOutputs }),
});
const isCPL = process.env.NEXT_PUBLIC_NODE_ENV === "production";
if (!res.ok) {
const err = await res.json();
setErrorMsg(err?.error || "Fehler beim Speichern.");
try {
if (isCPL) {
// ✅ Name speichern (DANx=...)
const nameEncoded = encodeURIComponent(label.trim());
const nameUrl = `/CPL?dummy.htm&DAN${selectedOutput.id}=${nameEncoded}`;
// ✅ Status speichern (DASx=...)
const statusUrl = `/CPL?dummy.htm&DAS${selectedOutput.id}=${
status ? 1 : 0
}`;
// 🟢 Beide nacheinander senden (wichtig bei älteren CPL-Versionen)
window.location.href = nameUrl; // Name zuerst (ggf. durch Refresh überschrieben)
setTimeout(() => {
window.location.href = statusUrl;
}, 300); // kleine Verzögerung (optional)
// 💡 Modal wird nicht automatisch geschlossen — da Seite neu lädt.
} else {
console.log(
"✅ Status & Label gespeichert für Ausgang",
selectedOutput.id
);
closeOutputModal();
// 🧪 Lokaler Entwicklungsmodus
const res = await fetch("/api/cpl/updateDigitalOutputs", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ outputs: updatedOutputs }),
});
if (!res.ok) {
const err = await res.json();
setErrorMsg(err?.error || "Fehler beim Speichern.");
} else {
console.log(
"✅ Status & Label gespeichert für Ausgang",
selectedOutput.id
);
closeOutputModal();
}
}
} catch (err) {
setErrorMsg("❌ Netzwerkfehler beim Speichern.");
setErrorMsg("❌ Fehler beim Speichern.");
} finally {
setIsSaving(false);
}