fix: digital Inputs Modal
This commit is contained in:
@@ -6,5 +6,5 @@ NEXT_PUBLIC_USE_MOCK_BACKEND_LOOP_START=false
|
||||
NEXT_PUBLIC_EXPORT_STATIC=false
|
||||
NEXT_PUBLIC_USE_CGI=false
|
||||
# App-Versionsnummer
|
||||
NEXT_PUBLIC_APP_VERSION=1.6.427
|
||||
NEXT_PUBLIC_APP_VERSION=1.6.428
|
||||
NEXT_PUBLIC_CPL_MODE=jsmock # json (Entwicklungsumgebung) oder jsmock (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter)
|
||||
@@ -5,5 +5,5 @@ NEXT_PUBLIC_CPL_API_PATH=/CPL
|
||||
NEXT_PUBLIC_EXPORT_STATIC=true
|
||||
NEXT_PUBLIC_USE_CGI=true
|
||||
# App-Versionsnummer
|
||||
NEXT_PUBLIC_APP_VERSION=1.6.427
|
||||
NEXT_PUBLIC_APP_VERSION=1.6.428
|
||||
NEXT_PUBLIC_CPL_MODE=production
|
||||
@@ -2,39 +2,51 @@
|
||||
// /components/main/einausgaenge/modals/InputModal.tsx
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { RootState } from "../../../../redux/store";
|
||||
import { RootState } from "@/redux/store";
|
||||
import switchIcon from "@iconify/icons-ion/switch";
|
||||
import {
|
||||
updateInvertierung,
|
||||
updateName,
|
||||
} from "../../../../redux/slices/digitalInputsSlice";
|
||||
import { updateInvert, updateLabel } from "@/redux/slices/digitalInputsSlice";
|
||||
|
||||
export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
type InputModalProps = {
|
||||
selectedInput: {
|
||||
id: number;
|
||||
[key: string]: any;
|
||||
} | null;
|
||||
closeInputModal: () => void;
|
||||
isOpen: boolean;
|
||||
};
|
||||
|
||||
export default function InputModal({
|
||||
selectedInput,
|
||||
closeInputModal,
|
||||
isOpen,
|
||||
}: InputModalProps) {
|
||||
const dispatch = useDispatch();
|
||||
const reduxInput = useSelector((state: RootState) =>
|
||||
state.digitalInputsSlice.inputs.find(
|
||||
(input) => input.id === Number(selectedInput?.id)
|
||||
)
|
||||
);
|
||||
console.log("📦 selectedInput.id:", selectedInput?.id);
|
||||
console.log("📦 reduxInput:", reduxInput);
|
||||
/* console.log("📦 selectedInput.id:", selectedInput?.id);
|
||||
console.log("📦 reduxInput:", reduxInput); */
|
||||
|
||||
const [isInitialLoad, setIsInitialLoad] = useState(true);
|
||||
const [name, setName] = useState("");
|
||||
const [label, setLabel] = useState("");
|
||||
const [invertiert, setInvertiert] = useState(false);
|
||||
const [filterzeit, setFilterzeit] = useState(0);
|
||||
const [gewichtung, setGewichtung] = useState(0);
|
||||
const [timeFilter, setTimeFilter] = useState(0);
|
||||
const [weighting, setWeighting] = useState(0);
|
||||
const [zaehlerAktiv, setZaehlerAktiv] = useState(false);
|
||||
const [eingangOffline, setEingangOffline] = useState(false);
|
||||
const [eingangOffline, setEingangOffline] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (reduxInput && isInitialLoad) {
|
||||
setName(reduxInput.label || "");
|
||||
setInvertiert(reduxInput.invertierung);
|
||||
setFilterzeit(reduxInput.filterzeit);
|
||||
setGewichtung(reduxInput.gewichtung);
|
||||
//reduxInput
|
||||
console.log("📦 reduxInput geladen:", reduxInput);
|
||||
setLabel(reduxInput.label || "");
|
||||
setInvertiert(reduxInput.invert);
|
||||
setTimeFilter(reduxInput.timeFilter);
|
||||
setWeighting(reduxInput.weighting);
|
||||
setZaehlerAktiv(reduxInput.zaehlerAktiv);
|
||||
setEingangOffline(reduxInput.eingangOffline);
|
||||
setEingangOffline(reduxInput.eingangOffline ? 1 : 0);
|
||||
setIsInitialLoad(false);
|
||||
}
|
||||
}, [reduxInput, isInitialLoad]);
|
||||
@@ -58,29 +70,29 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
try {
|
||||
// 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 }));
|
||||
if (label !== reduxInput.label) {
|
||||
await sendCgiUpdate(`DEN${id}=${encodeURIComponent(label)}`);
|
||||
dispatch(updateLabel({ id, label }));
|
||||
hasChange = true;
|
||||
}
|
||||
if (invertiert !== reduxInput.invertierung) {
|
||||
if (invertiert !== reduxInput.invert) {
|
||||
await sendCgiUpdate(`DEI${id}=${invertiert ? 1 : 0}`);
|
||||
dispatch(updateInvertierung({ id, invertierung: invertiert }));
|
||||
dispatch(updateInvert({ id, invert: invertiert }));
|
||||
hasChange = true;
|
||||
}
|
||||
if (filterzeit !== reduxInput.filterzeit) {
|
||||
await sendCgiUpdate(`DEF${id}=${filterzeit}`);
|
||||
if (timeFilter !== reduxInput.timeFilter) {
|
||||
await sendCgiUpdate(`DEF${id}=${timeFilter}`);
|
||||
hasChange = true;
|
||||
}
|
||||
if (gewichtung !== reduxInput.gewichtung) {
|
||||
await sendCgiUpdate(`DEG${id}=${gewichtung}`);
|
||||
if (weighting !== reduxInput.weighting) {
|
||||
await sendCgiUpdate(`DEG${id}=${weighting}`);
|
||||
hasChange = true;
|
||||
}
|
||||
if (zaehlerAktiv !== reduxInput.zaehlerAktiv) {
|
||||
await sendCgiUpdate(`DEZ${id}=${zaehlerAktiv ? 1 : 0}`);
|
||||
hasChange = true;
|
||||
}
|
||||
if (eingangOffline !== reduxInput.eingangOffline) {
|
||||
if (eingangOffline !== (reduxInput.eingangOffline ? 1 : 0)) {
|
||||
await sendCgiUpdate(`DEO${id}=${eingangOffline ? 1 : 0}`);
|
||||
hasChange = true;
|
||||
}
|
||||
@@ -92,22 +104,22 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
} else {
|
||||
// ENTWICKLUNGSUMGEBUNG (lokale API)
|
||||
const updates: any = { id };
|
||||
if (name !== reduxInput.name) {
|
||||
updates.name = name;
|
||||
dispatch(updateName({ id, name }));
|
||||
if (label !== reduxInput.label) {
|
||||
updates.label = label;
|
||||
dispatch(updateLabel({ id, label }));
|
||||
hasChange = true;
|
||||
}
|
||||
if (invertiert !== reduxInput.invertierung) {
|
||||
updates.invertierung = invertiert ? 1 : 0;
|
||||
dispatch(updateInvertierung({ id, invertierung: invertiert }));
|
||||
if (invertiert !== reduxInput.invert) {
|
||||
updates.invert = invertiert ? 1 : 0;
|
||||
dispatch(updateInvert({ id, invert: invertiert }));
|
||||
hasChange = true;
|
||||
}
|
||||
if (filterzeit !== reduxInput.filterzeit) {
|
||||
updates.filterzeit = filterzeit;
|
||||
if (timeFilter !== reduxInput.timeFilter) {
|
||||
updates.timeFilter = timeFilter;
|
||||
hasChange = true;
|
||||
}
|
||||
if (gewichtung !== reduxInput.gewichtung) {
|
||||
updates.gewichtung = gewichtung;
|
||||
if (weighting !== reduxInput.weighting) {
|
||||
updates.weighting = weighting;
|
||||
hasChange = true;
|
||||
}
|
||||
if (zaehlerAktiv !== reduxInput.zaehlerAktiv) {
|
||||
@@ -145,6 +157,11 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
setIsInitialLoad(true);
|
||||
closeInputModal();
|
||||
};
|
||||
useEffect(() => {
|
||||
if (isOpen && selectedInput) {
|
||||
setIsInitialLoad(true);
|
||||
}
|
||||
}, [isOpen, selectedInput]);
|
||||
|
||||
return (
|
||||
<div className="fixed top-0 left-0 w-full h-full bg-black bg-opacity-50 flex justify-center items-center z-50">
|
||||
@@ -169,8 +186,8 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
<div>
|
||||
<input
|
||||
type="text"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
value={label}
|
||||
onChange={(e) => setLabel(e.target.value)}
|
||||
className="border border-gray-300 rounded px-2 py-1 w-full"
|
||||
maxLength={32}
|
||||
/>
|
||||
@@ -206,11 +223,11 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
type="number"
|
||||
min={0}
|
||||
max={2000}
|
||||
value={filterzeit}
|
||||
value={timeFilter}
|
||||
onChange={(e) => {
|
||||
const val = Number(e.target.value);
|
||||
if (val <= 2000) {
|
||||
setFilterzeit(val);
|
||||
setTimeFilter(val);
|
||||
}
|
||||
}}
|
||||
className="border border-gray-300 rounded px-2 py-1 pr-10 w-full text-right"
|
||||
@@ -230,11 +247,11 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
type="number"
|
||||
min={0}
|
||||
max={1000}
|
||||
value={gewichtung}
|
||||
value={weighting}
|
||||
onChange={(e) => {
|
||||
const val = Number(e.target.value);
|
||||
if (val <= 1000) {
|
||||
setGewichtung(val);
|
||||
setWeighting(val);
|
||||
}
|
||||
}}
|
||||
className="border border-gray-300 rounded px-2 py-1 w-full text-right"
|
||||
@@ -250,8 +267,8 @@ export default function InputModal({ selectedInput, closeInputModal, isOpen }) {
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={eingangOffline}
|
||||
onClick={() => setEingangOffline(!eingangOffline)}
|
||||
aria-checked={!!eingangOffline}
|
||||
onClick={() => setEingangOffline(eingangOffline ? 0 : 1)}
|
||||
className={`relative inline-flex h-6 w-11 items-center rounded-full transition-colors duration-200 ${
|
||||
eingangOffline ? "bg-littwin-blue" : "bg-gray-300"
|
||||
}`}
|
||||
|
||||
@@ -1,34 +1,244 @@
|
||||
{
|
||||
"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
|
||||
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
|
||||
],
|
||||
"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
|
||||
0,
|
||||
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
|
||||
],
|
||||
"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
|
||||
],
|
||||
"win_de_time_filter": [
|
||||
1500, 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
|
||||
2,
|
||||
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
|
||||
],
|
||||
"win_de_weighting": [
|
||||
600, 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
|
||||
4,
|
||||
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
|
||||
],
|
||||
"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
|
||||
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
|
||||
],
|
||||
"win_de_offline": [
|
||||
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, 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,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"win_de_label": [
|
||||
"DE112",
|
||||
"DE114",
|
||||
"DE2",
|
||||
"DE3",
|
||||
"DE4",
|
||||
@@ -61,4 +271,4 @@
|
||||
"DE31",
|
||||
"DE32"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,245 @@
|
||||
// @/mocks/device-cgi-simulator/SERVICE/digitalInputsMockData.js
|
||||
|
||||
// auto-generated from update API
|
||||
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,
|
||||
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
|
||||
];
|
||||
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,
|
||||
0,
|
||||
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
|
||||
];
|
||||
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
|
||||
];
|
||||
var win_de_time_filter = [
|
||||
1500, 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,
|
||||
3,
|
||||
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_de_weighting = [
|
||||
600, 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,
|
||||
3,
|
||||
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_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,
|
||||
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_de_offline = [
|
||||
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, 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_de_label = [
|
||||
"DE112",
|
||||
"DE1",
|
||||
"DE2",
|
||||
"DE3",
|
||||
"DE4",
|
||||
@@ -59,5 +270,5 @@ var win_de_label = [
|
||||
"DE29",
|
||||
"DE30",
|
||||
"DE31",
|
||||
"DE32",
|
||||
"DE32"
|
||||
];
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "cpl-v4",
|
||||
"version": "1.6.427",
|
||||
"version": "1.6.428",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cpl-v4",
|
||||
"version": "1.6.427",
|
||||
"version": "1.6.428",
|
||||
"dependencies": {
|
||||
"@fontsource/roboto": "^5.1.0",
|
||||
"@iconify-icons/ri": "^1.2.10",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cpl-v4",
|
||||
"version": "1.6.427",
|
||||
"version": "1.6.428",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
@@ -26,12 +26,13 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
"mocks/device-cgi-simulator/SERVICE/digitalInputsMockData.js"
|
||||
);
|
||||
const fileContent = fs.readFileSync(jsPath, "utf-8");
|
||||
//console.log("📡 JSMOCK-Daten geladen fileContent:", fileContent);
|
||||
|
||||
const extractArray = (name: string) => {
|
||||
const extractArray = (label: string) => {
|
||||
const match = fileContent.match(
|
||||
new RegExp(`var\\s+${name}\\s*=\\s*\\[([\\s\\S]*?)\\];`)
|
||||
new RegExp(`var\\s+${label}\\s*=\\s*\\[([\\s\\S]*?)\\];`)
|
||||
);
|
||||
if (!match) throw new Error(`Feld ${name} nicht gefunden`);
|
||||
if (!match) throw new Error(`Feld ${label} nicht gefunden`);
|
||||
return match[1]
|
||||
.split(",")
|
||||
.map((s) => s.trim().replace(/^["']|["']$/g, ""));
|
||||
@@ -49,7 +50,7 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
win_de_offline: extractArray("win_de_offline").map(Number),
|
||||
win_de_label: extractArray("win_de_label"),
|
||||
};
|
||||
console.log("📡 JSMOCK-Daten geladen:", data);
|
||||
//console.log("📡 JSMOCK-Daten geladen in api in jsmock:", data);
|
||||
|
||||
return res.status(200).json(data);
|
||||
}
|
||||
|
||||
@@ -3,15 +3,36 @@ import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
// WICHTIG: Der Mock-Datenpfad
|
||||
const mockFilePath = path.join(
|
||||
process.cwd(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"digitalInputsMockData.js"
|
||||
);
|
||||
const mode = process.env.NEXT_PUBLIC_CPL_MODE;
|
||||
|
||||
// Funktion zum Parsen des JS-Datei-Inhalts in ein eval-fähiges Objekt
|
||||
// 1️⃣ Variable vorab definieren
|
||||
let mockFilePath: string | null = null;
|
||||
|
||||
if (mode === "json") {
|
||||
mockFilePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks",
|
||||
"api",
|
||||
"SERVICE",
|
||||
"digitalInputsMockData.json"
|
||||
);
|
||||
}
|
||||
if (mode === "jsmock") {
|
||||
mockFilePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks",
|
||||
"device-cgi-simulator",
|
||||
"SERVICE",
|
||||
"digitalInputsMockData.js"
|
||||
);
|
||||
}
|
||||
|
||||
// 2️⃣ Sicherstellen, dass ein Modus aktiv ist
|
||||
if (!mockFilePath) {
|
||||
throw new Error(`❌ Kein gültiger Modus in .env gesetzt: ${mode}`);
|
||||
}
|
||||
|
||||
// Funktion zum Parsen bei jsmock
|
||||
function extractMockData(raw: string) {
|
||||
const context = {};
|
||||
const func = new Function(
|
||||
@@ -44,32 +65,43 @@ export default async function handler(
|
||||
}
|
||||
|
||||
try {
|
||||
const { id, name, invertierung, filterzeit, gewichtung, zaehlerAktiv } =
|
||||
req.body;
|
||||
const {
|
||||
id,
|
||||
label,
|
||||
invert,
|
||||
timeFilter,
|
||||
weighting,
|
||||
zaehlerAktiv,
|
||||
eingangOffline,
|
||||
} = req.body;
|
||||
|
||||
if (typeof id !== "number" || id < 1 || id > 32) {
|
||||
return res.status(400).json({ error: "Ungültige ID (1–32 erlaubt)" });
|
||||
}
|
||||
|
||||
const rawContent = fs.readFileSync(mockFilePath, "utf-8");
|
||||
const data = extractMockData(rawContent);
|
||||
const rawContent = fs.readFileSync(mockFilePath!, "utf-8");
|
||||
|
||||
// Update der Daten
|
||||
if (typeof name === "string") data.win_de_label[id - 1] = name;
|
||||
if (typeof invertierung === "number")
|
||||
data.win_de_invert[id - 1] = invertierung;
|
||||
if (typeof filterzeit === "number")
|
||||
data.win_de_time_filter[id - 1] = filterzeit;
|
||||
if (typeof gewichtung === "number")
|
||||
data.win_de_weighting[id - 1] = gewichtung;
|
||||
// 3️⃣ JSON vs JS Verarbeitung
|
||||
const data =
|
||||
mode === "json" ? JSON.parse(rawContent) : extractMockData(rawContent);
|
||||
|
||||
// 4️⃣ Aktualisieren der Felder
|
||||
if (typeof label === "string") data.win_de_label[id - 1] = label;
|
||||
if (typeof invert === "number") data.win_de_invert[id - 1] = invert;
|
||||
if (typeof timeFilter === "number")
|
||||
data.win_de_time_filter[id - 1] = timeFilter;
|
||||
if (typeof weighting === "number")
|
||||
data.win_de_weighting[id - 1] = weighting;
|
||||
if (typeof zaehlerAktiv === "number")
|
||||
data.win_de_counter_active[id - 1] = zaehlerAktiv;
|
||||
if (typeof eingangOffline === "number")
|
||||
data.win_de_offline[id - 1] = eingangOffline;
|
||||
|
||||
if (typeof invertierung === "number")
|
||||
data.win_de_invert[id - 1] = invertierung;
|
||||
|
||||
// Erzeuge neuen Dateiinhalt
|
||||
const newContent = `
|
||||
// 5️⃣ Speichern
|
||||
if (mode === "json") {
|
||||
fs.writeFileSync(mockFilePath!, JSON.stringify(data, null, 2), "utf-8");
|
||||
} else {
|
||||
const newContent = `
|
||||
// auto-generated from update API
|
||||
var win_de_state = ${JSON.stringify(data.win_de_state, null, 2)};
|
||||
var win_de_invert = ${JSON.stringify(data.win_de_invert, null, 2)};
|
||||
@@ -77,19 +109,25 @@ var win_de_counter = ${JSON.stringify(data.win_de_counter, null, 2)};
|
||||
var win_de_time_filter = ${JSON.stringify(data.win_de_time_filter, null, 2)};
|
||||
var win_de_weighting = ${JSON.stringify(data.win_de_weighting, null, 2)};
|
||||
var win_de_counter_active = ${JSON.stringify(
|
||||
data.win_de_counter_active,
|
||||
null,
|
||||
2
|
||||
)};
|
||||
data.win_de_counter_active,
|
||||
null,
|
||||
2
|
||||
)};
|
||||
var win_de_offline = ${JSON.stringify(data.win_de_offline, null, 2)};
|
||||
var win_de_label = ${JSON.stringify(data.win_de_label, null, 2)};
|
||||
`;
|
||||
fs.writeFileSync(mockFilePath!, newContent, "utf-8");
|
||||
}
|
||||
|
||||
fs.writeFileSync(mockFilePath, newContent, "utf-8");
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
.json({ message: "Update erfolgreich", id, name, invertierung });
|
||||
return res.status(200).json({
|
||||
message: `Update erfolgreich für ID ${id}`,
|
||||
id,
|
||||
label,
|
||||
invert,
|
||||
timeFilter,
|
||||
weighting,
|
||||
eingangOffline,
|
||||
});
|
||||
} catch (err: any) {
|
||||
console.error("Fehler beim Schreiben:", err);
|
||||
return res.status(500).json({ error: "Update fehlgeschlagen" });
|
||||
|
||||
@@ -4,15 +4,14 @@ import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
interface DigitalInput {
|
||||
id: number;
|
||||
label: string;
|
||||
status: boolean;
|
||||
status: number;
|
||||
counter: number;
|
||||
flutter: number;
|
||||
invertierung: boolean;
|
||||
filterzeit: number;
|
||||
gewichtung: number;
|
||||
invert: boolean;
|
||||
timeFilter: number;
|
||||
weighting: number;
|
||||
zaehlerAktiv: boolean;
|
||||
eingangOffline: boolean;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface DigitalInputsState {
|
||||
@@ -40,35 +39,30 @@ const digitalInputsSlice = createSlice({
|
||||
input.status = status;
|
||||
}
|
||||
},
|
||||
updateInvertierung: (
|
||||
updateInvert: (
|
||||
state,
|
||||
action: PayloadAction<{ id: number; invertierung: boolean }>
|
||||
action: PayloadAction<{ id: number; invert: boolean }>
|
||||
) => {
|
||||
const { id, invertierung } = action.payload;
|
||||
const { id, invert } = action.payload;
|
||||
const input = state.inputs.find((input) => input.id === id);
|
||||
if (input) {
|
||||
input.invertierung = invertierung;
|
||||
input.invert = invert;
|
||||
}
|
||||
},
|
||||
updateName: (
|
||||
updateLabel: (
|
||||
state,
|
||||
action: PayloadAction<{ id: number; name: string }>
|
||||
action: PayloadAction<{ id: number; label: string }>
|
||||
) => {
|
||||
const { id, name } = action.payload;
|
||||
const { id, label } = action.payload;
|
||||
const input = state.inputs.find((input) => input.id === id);
|
||||
if (input) {
|
||||
input.name = name;
|
||||
input.label = name; // falls du label mit aktualisieren willst
|
||||
input.label = label; // falls du label mit aktualisieren willst
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
setInputs,
|
||||
updateInputStatus,
|
||||
updateInvertierung,
|
||||
updateName, // <- hinzufügen
|
||||
} = digitalInputsSlice.actions;
|
||||
export const { setInputs, updateInputStatus, updateInvert, updateLabel } =
|
||||
digitalInputsSlice.actions;
|
||||
|
||||
export default digitalInputsSlice.reducer;
|
||||
|
||||
@@ -28,7 +28,7 @@ export const fetchDigitalInputsService = async () => {
|
||||
timeFilter: win.win_de_time_filter[i],
|
||||
weighting: win.win_de_weighting[i],
|
||||
counterActive: !!win.win_de_counter_active[i],
|
||||
offline: !!win.win_de_offline[i],
|
||||
eingangOffline: !!win.win_de_offline[i],
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export const fetchDigitalInputsService = async () => {
|
||||
timeFilter: data.win_de_time_filter[i],
|
||||
weighting: data.win_de_weighting[i],
|
||||
counterActive: !!data.win_de_counter_active[i],
|
||||
offline: !!data.win_de_offline[i],
|
||||
eingangOffline: !!data.win_de_offline[i],
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ export const fetchDigitalInputsService = async () => {
|
||||
throw new Error("❌ Fehler beim Laden der digitalen Eingänge (json)");
|
||||
|
||||
const data = await res.json();
|
||||
//console.log("📡 JSMOCK-Daten geladen in service:", data);
|
||||
|
||||
return data.win_de_state.map((_: any, i: number) => ({
|
||||
id: i + 1,
|
||||
@@ -70,7 +71,7 @@ export const fetchDigitalInputsService = async () => {
|
||||
timeFilter: data.win_de_time_filter[i],
|
||||
weighting: data.win_de_weighting[i],
|
||||
counterActive: !!data.win_de_counter_active[i],
|
||||
offline: !!data.win_de_offline[i],
|
||||
eingangOffline: !!data.win_de_offline[i],
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user