diff --git a/components/main/einausgaenge/modals/InputModal.tsx b/components/main/einausgaenge/modals/InputModal.tsx index ed97e01..79f4043 100644 --- a/components/main/einausgaenge/modals/InputModal.tsx +++ b/components/main/einausgaenge/modals/InputModal.tsx @@ -1,108 +1,87 @@ "use client"; import React, { useEffect, useState } from "react"; -import { useSelector } from "react-redux"; +import { useSelector, useDispatch } from "react-redux"; import { RootState } from "../../../../redux/store"; -import { useAppDispatch } from "../../../../redux/store"; -import { updateInvertierung } from "../../../../redux/slices/digitalInputsSlice"; +import { + updateInvertierung, + updateName, +} from "../../../../redux/slices/digitalInputsSlice"; export default function InputModal({ selectedInput, closeInputModal, isOpen }) { - const dispatch = useAppDispatch(); + const [invertiert, setInvertiert] = useState(false); + const [name, setName] = useState(""); + const dispatch = useDispatch(); + const reduxInput = useSelector((state: RootState) => state.digitalInputsSlice.inputs.find( - (input) => input.id === Number(selectedInput.id) + (input) => input.id === Number(selectedInput?.id) ) ); - const [invertiert, setInvertiert] = useState(false); - const isDev = process.env.NODE_ENV === "development"; - - useEffect(() => { - if (selectedInput) { - if (isDev) { - const saved = localStorage.getItem(`invertierung_${selectedInput.id}`); - if (saved !== null) { - setInvertiert(parseInt(saved) === 1); - } else { - setInvertiert(selectedInput.invertierung); - } - } else { - setInvertiert(selectedInput.invertierung); - } - } - }, [selectedInput, isDev]); - - if (!isOpen || !selectedInput) return null; - - const handleInvertierungToggle = async () => { - const neueInvertierung = !invertiert; - - if (process.env.NODE_ENV === "development") { - dispatch( - updateInvertierung({ - id: Number(selectedInput.id), - invertierung: neueInvertierung, - }) - ); - - setInvertiert(neueInvertierung); - } else { - const url = `/CPL?/CPL/SERVICE/empty.acp&DEI${selectedInput.id}=${ - neueInvertierung ? 1 : 0 - }`; - try { - const response = await fetch(url); - if (!response.ok) throw new Error("Fehler beim Senden der Anfrage"); - - dispatch( - updateInvertierung({ - id: Number(selectedInput.id), - invertierung: neueInvertierung, - }) - ); - setInvertiert(neueInvertierung); - } catch (error) { - console.error("Invertierung fehlgeschlagen:", error); - alert("Invertierung konnte nicht geändert werden."); - } - } - }; - //--------------------------------- - useEffect(() => { if (reduxInput) { setInvertiert(reduxInput.invertierung); + setName(reduxInput.name || ""); } }, [reduxInput]); - //--------------------------------- + if (!isOpen || !selectedInput || !reduxInput) return null; + + const handleInvertierungToggle = () => { + const neueInvertierung = !invertiert; + dispatch( + updateInvertierung({ id: reduxInput.id, invertierung: neueInvertierung }) + ); + setInvertiert(neueInvertierung); + }; + + const handleNameSpeichern = () => { + dispatch(updateName({ id: reduxInput.id, name })); + }; + return (
-

- Details für Eingang {selectedInput.id} +

+ Parameter für Eingang {selectedInput.id}

-
-
- Status: -
-
- Status: -
-
- {reduxInput?.status ? "Inaktiv" : "Aktiv"} -
+
- Beschreibung: + Status: +
+
+ {reduxInput.status ? ( + <> + + Inaktiv + + ) : ( + <> + + Aktiv + + )}
-
{selectedInput.description}
Name:
-
{selectedInput.name}
+
+ setName(e.target.value)} + className="border border-gray-300 rounded px-2 py-1 w-full" + maxLength={32} + /> + +
Invertierung: @@ -115,35 +94,35 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
+
+ Zählerstand: +
+
{reduxInput.counter}
+
Filterzeit:
-
{selectedInput.filterzeit} ms
+
{reduxInput.filterzeit} ms
Gewichtung:
-
{selectedInput.gewichtung}
- -
- Zählerstand: -
-
{selectedInput.zaehlerstand}
+
{reduxInput.gewichtung}
Zähler aktiv:
-
{selectedInput.zaehlerAktiv ? "Ja" : "Nein"}
+
{reduxInput.zaehlerAktiv ? "Ja" : "Nein"}
Eingang offline:
-
{selectedInput.eingangOffline ? "Offline" : "Online"}
+
{reduxInput.eingangOffline ? "Offline" : "Online"}
diff --git a/config/webVersion.ts b/config/webVersion.ts index e010e91..be6afe0 100644 --- a/config/webVersion.ts +++ b/config/webVersion.ts @@ -6,5 +6,5 @@ 2: Patch oder Hotfix (Bugfixes oder kleine Änderungen). */ -const webVersion = "1.6.209"; +const webVersion = "1.6.210"; export default webVersion; diff --git a/public/CPLmockData/SERVICE/de.js b/public/CPLmockData/SERVICE/de.js index e29eed4..a46c653 100644 --- a/public/CPLmockData/SERVICE/de.js +++ b/public/CPLmockData/SERVICE/de.js @@ -1,10 +1,12 @@ // public/CPLmockData/SERVICE/de.js + +// Zustand -> DESxx xx =Nr Eingang 1-32 80-83 = BGT 1 bis 4 var win_de_state = [ 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; -// Invertierung -> DEIxx xx = Nr Eingang 1-32 +// Invertierung -> DEIxx xx = Nr Eingang 1-32 var win_de_invert = [ 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -18,6 +20,49 @@ Status Invertierung Anzeige 0 1 ✅ grün 0 0 ✅ grün */ + +//Zählerstand -> DESxx xx =Nr Eingang 1-32 80-83 = BGT 1 bis 4 +var win_de_counter = [ + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, +]; //Zählerstand + +//Filterzeit -> DEFxx xx =Nr Eingang 1-32 80-83 = BGT 1 bis 4 +// Frage: In digitale Eingänge Filterzeit DEFxx (In Lastenheft) und Flatter var flutter DEFxx ist ein und das selbe, welche Begriff soll ich nehmen? +// Antwort: Es ist die Filterzeit. Die Flatterzeit kommt später hinzu. +var win_de_time_filter = [ + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, +]; //Filterzeit + +// Gewichtung -> DEGxx xx = Nr Eingang 1-32 80-83 = BGT 1 bis 4 +var win_de_weighting = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, +]; //Gewichtung + +// Zähler aktiv -> DEZxx xx = Nr Eingang 1-32 80-83 = BGT 1 bis 4 +var win_de_counter_active = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, +]; //Zähler aktiv + +// Eingang offline -> DEAxx xx = Nr Eingang 1-32 80-83 = BGT 1 bis 4 +var win_de_offline = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, +]; //Eingang offline + +// Zähler aktiv -> DEZxx xx = Nr Eingang 1-32 80-83 = BGT 1 bis 4 +var win_counter = [ + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, +]; + +// Name -> DENxx xx =Nr Eingang 1-32 80-83 = BGT 1 bis 4 var win_de_label = [ "DE1", "DE2", @@ -52,12 +97,10 @@ var win_de_label = [ "DE31", "DE32", ]; -var win_counter = [ - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, -]; -var win_flutter = [ + +// Frage: In digitale Eingänge Filterzeit DEFxx (In Lastenheft) und Flatter var flutter DEFxx ist ein und das selbe, welche Begriff soll ich nehmen? +// Antwort: Es ist die Filterzeit. Die Flatterzeit kommt später hinzu. +/* var win_flutter = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -]; +]; */ diff --git a/redux/slices/digitalInputsSlice.ts b/redux/slices/digitalInputsSlice.ts index 4367d9c..5052b7d 100644 --- a/redux/slices/digitalInputsSlice.ts +++ b/redux/slices/digitalInputsSlice.ts @@ -1,4 +1,4 @@ -// slices/digitalInputsSlice.ts +// /redux/slices/digitalInputsSlice.ts import { createSlice, PayloadAction } from "@reduxjs/toolkit"; interface DigitalInput { @@ -8,6 +8,11 @@ interface DigitalInput { counter: number; flutter: number; invertierung: boolean; + filterzeit: number; + gewichtung: number; + zaehlerAktiv: boolean; + eingangOffline: boolean; + name: string; } interface DigitalInputsState { diff --git a/services/fetchDigitaleEingaenge.ts b/services/fetchDigitaleEingaenge.ts index 4c27a3e..dead24b 100644 --- a/services/fetchDigitaleEingaenge.ts +++ b/services/fetchDigitaleEingaenge.ts @@ -26,16 +26,22 @@ export const fetchDigitaleEingaenge = async () => { return []; } - const formattedData = win.win_de_state.map( - (status: number, index: number) => ({ - id: index + 1, - label: win.win_de_label?.[index] || `DE${index + 1}`, - status: status === 1, - counter: win.win_counter?.[index] || 0, - flutter: win.win_flutter?.[index] || 0, - invertierung: win.win_de_invert?.[index] === 1, - }) - ); + const formattedData = win.win_de_state.map((status, index) => ({ + id: index + 1, + label: win.win_de_label?.[index] || `DE${index + 1}`, + name: win.win_de_label?.[index] || "", + + status: status === 1, + counter: win.win_de_counter?.[index] || 0, + flutter: win.win_flutter?.[index] || 0, + invertierung: win.win_de_invert?.[index] === 1, + + // 🔽 NEU: + filterzeit: win.win_de_time_filter?.[index] || 0, + gewichtung: win.win_de_weighting?.[index] || 0, + zaehlerAktiv: win.win_de_counter_active?.[index] === 1, + eingangOffline: win.win_de_offline?.[index] === 1, + })); return formattedData; } catch (error) {