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:
@@ -14,6 +14,7 @@ export default function DigitalOutputsWidget({ openOutputModal }) {
|
||||
const digitalOutputs = useSelector(
|
||||
(state: RootState) => state.digitalOutputsSlice.outputs
|
||||
);
|
||||
const isCPL = process.env.NEXT_PUBLIC_NODE_ENV === "production";
|
||||
|
||||
const handleToggle = async (id: number) => {
|
||||
const updatedOutputs = digitalOutputs.map((output) =>
|
||||
@@ -23,14 +24,21 @@ export default function DigitalOutputsWidget({ openOutputModal }) {
|
||||
dispatch(setDigitalOutputs(updatedOutputs));
|
||||
|
||||
try {
|
||||
await fetch("/api/cpl/updateDigitalOutputs", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ outputs: updatedOutputs }),
|
||||
});
|
||||
console.log("✅ Status gespeichert für Ausgang", id);
|
||||
if (isCPL) {
|
||||
window.location.href = `/CPL?dummy.htm&DAS${id}=${
|
||||
updatedOutputs[id - 1].status ? 1 : 0
|
||||
}`;
|
||||
} else {
|
||||
await fetch("/api/cpl/updateDigitalOutputs", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ outputs: updatedOutputs }),
|
||||
});
|
||||
}
|
||||
|
||||
console.log("✅ Ausgang aktualisiert:", id);
|
||||
} catch (error) {
|
||||
console.error("❌ Fehler beim Speichern:", error);
|
||||
console.error("❌ Fehler beim Schreiben:", error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user