feat: Einzelne CGI-Befehle für digitale Eingänge in Produktionsumgebung umgesetzt
- Änderungen (Name, Invertierung, Filterzeit, Gewichtung, Zähler aktiv) werden einzeln erkannt - Pro Änderung wird jeweils ein separater CGI-Request gesendet (z. B. DEN1=..., DEI1=...) - Verbesserte Trennung zwischen Entwicklungs- und Produktionsumgebung
This commit is contained in:
@@ -17,7 +17,6 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
);
|
||||
|
||||
const [isInitialLoad, setIsInitialLoad] = useState(true);
|
||||
|
||||
const [name, setName] = useState("");
|
||||
const [invertiert, setInvertiert] = useState(false);
|
||||
const [filterzeit, setFilterzeit] = useState(0);
|
||||
@@ -37,58 +36,97 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
|
||||
if (!isOpen || !selectedInput || !reduxInput) return null;
|
||||
|
||||
const sendCgiUpdate = async (param: string) => {
|
||||
const url = `/CPL?/eingaenge.html&${param}`;
|
||||
console.log("📡 CGI senden:", url);
|
||||
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Fehler bei CGI-Aufruf: ${param}`);
|
||||
}
|
||||
};
|
||||
|
||||
const handleSpeichern = async () => {
|
||||
const updates: any = { id: reduxInput.id };
|
||||
const id = reduxInput.id;
|
||||
let hasChange = false;
|
||||
|
||||
if (name !== reduxInput.name) {
|
||||
updates.name = name;
|
||||
dispatch(updateName({ id: reduxInput.id, name }));
|
||||
hasChange = true;
|
||||
}
|
||||
|
||||
if (invertiert !== reduxInput.invertierung) {
|
||||
updates.invertierung = invertiert ? 1 : 0;
|
||||
dispatch(
|
||||
updateInvertierung({ id: reduxInput.id, invertierung: invertiert })
|
||||
);
|
||||
hasChange = true;
|
||||
}
|
||||
|
||||
if (filterzeit !== reduxInput.filterzeit) {
|
||||
updates.filterzeit = filterzeit;
|
||||
hasChange = true;
|
||||
}
|
||||
|
||||
if (gewichtung !== reduxInput.gewichtung) {
|
||||
updates.gewichtung = gewichtung;
|
||||
hasChange = true;
|
||||
}
|
||||
|
||||
if (zaehlerAktiv !== reduxInput.zaehlerAktiv) {
|
||||
updates.zaehlerAktiv = zaehlerAktiv ? 1 : 0;
|
||||
hasChange = true;
|
||||
}
|
||||
|
||||
if (!hasChange) {
|
||||
alert("⚠️ Keine Änderungen erkannt.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/cpl/updateDigitaleEingaenge", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(updates),
|
||||
});
|
||||
// PRODUKTIONSUMGEBUNG (CGI-Modus)
|
||||
if (process.env.NEXT_PUBLIC_NODE_ENV === "production") {
|
||||
if (name !== reduxInput.name) {
|
||||
await sendCgiUpdate(`DEN${id}=${encodeURIComponent(name)}`);
|
||||
dispatch(updateName({ id, name }));
|
||||
hasChange = true;
|
||||
}
|
||||
if (invertiert !== reduxInput.invertierung) {
|
||||
await sendCgiUpdate(`DEI${id}=${invertiert ? 1 : 0}`);
|
||||
dispatch(updateInvertierung({ id, invertierung: invertiert }));
|
||||
hasChange = true;
|
||||
}
|
||||
if (filterzeit !== reduxInput.filterzeit) {
|
||||
await sendCgiUpdate(`DEF${id}=${filterzeit}`);
|
||||
hasChange = true;
|
||||
}
|
||||
if (gewichtung !== reduxInput.gewichtung) {
|
||||
await sendCgiUpdate(`DEG${id}=${gewichtung}`);
|
||||
hasChange = true;
|
||||
}
|
||||
if (zaehlerAktiv !== reduxInput.zaehlerAktiv) {
|
||||
await sendCgiUpdate(`DEZ${id}=${zaehlerAktiv ? 1 : 0}`);
|
||||
hasChange = true;
|
||||
}
|
||||
if (!hasChange) {
|
||||
alert("⚠️ Keine Änderungen erkannt.");
|
||||
return;
|
||||
}
|
||||
alert("✅ Daten erfolgreich an die CPL-Hardware gesendet!");
|
||||
} else {
|
||||
// ENTWICKLUNGSUMGEBUNG (lokale API)
|
||||
const updates: any = { id };
|
||||
if (name !== reduxInput.name) {
|
||||
updates.name = name;
|
||||
dispatch(updateName({ id, name }));
|
||||
hasChange = true;
|
||||
}
|
||||
if (invertiert !== reduxInput.invertierung) {
|
||||
updates.invertierung = invertiert ? 1 : 0;
|
||||
dispatch(updateInvertierung({ id, invertierung: invertiert }));
|
||||
hasChange = true;
|
||||
}
|
||||
if (filterzeit !== reduxInput.filterzeit) {
|
||||
updates.filterzeit = filterzeit;
|
||||
hasChange = true;
|
||||
}
|
||||
if (gewichtung !== reduxInput.gewichtung) {
|
||||
updates.gewichtung = gewichtung;
|
||||
hasChange = true;
|
||||
}
|
||||
if (zaehlerAktiv !== reduxInput.zaehlerAktiv) {
|
||||
updates.zaehlerAktiv = zaehlerAktiv ? 1 : 0;
|
||||
hasChange = true;
|
||||
}
|
||||
|
||||
if (!res.ok) {
|
||||
const errData = await res.json();
|
||||
throw new Error(errData.error || "Unbekannter Fehler");
|
||||
if (!hasChange) {
|
||||
alert("⚠️ Keine Änderungen erkannt.");
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await fetch("/api/cpl/updateDigitaleEingaenge", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(updates),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const errData = await res.json();
|
||||
throw new Error(errData.error || "Unbekannter Fehler");
|
||||
}
|
||||
|
||||
alert("✅ Daten lokal gespeichert!");
|
||||
}
|
||||
|
||||
setIsInitialLoad(true); // Reset
|
||||
closeInputModal(); // Modal schließen bei Erfolg
|
||||
setIsInitialLoad(true);
|
||||
closeInputModal();
|
||||
} catch (err: any) {
|
||||
alert("❌ Fehler beim Speichern: " + err.message);
|
||||
}
|
||||
@@ -181,7 +219,7 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
<div>
|
||||
<strong>Gewichtung:</strong>
|
||||
</div>
|
||||
<div className="relative">
|
||||
<div>
|
||||
<input
|
||||
type="number"
|
||||
min={0}
|
||||
@@ -196,11 +234,6 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
className="border border-gray-300 rounded px-2 py-1 w-full"
|
||||
title="Maximal 1000 erlaubt"
|
||||
/>
|
||||
{gewichtung > 1000 && (
|
||||
<div className="text-sm text-red-600 mt-1">
|
||||
Maximalwert 1000 überschritten!
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user