From 97eb40e1c60581662126652aacc4b93166a1feca Mon Sep 17 00:00:00 2001 From: ISA Date: Thu, 31 Jul 2025 10:42:06 +0200 Subject: [PATCH] =?UTF-8?q?Feat:=20KVz=20Bereich=20in=20EinstellungsModal?= =?UTF-8?q?=20in=20K=C3=9Cs=20Modal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- .env.production | 2 +- CHANGELOG.md | 5 + .../kabelueberwachung/kue705FO/Kue705FO.tsx | 23 +- .../kue705FO/modals/KvzModalView.tsx | 199 ++++++++++++++++++ .../kue705FO/modals/SettingsModalWrapper.tsx | 17 +- package-lock.json | 4 +- package.json | 2 +- 8 files changed, 235 insertions(+), 19 deletions(-) create mode 100644 components/main/kabelueberwachung/kue705FO/modals/KvzModalView.tsx diff --git a/.env.development b/.env.development index 53add08..ba22d7f 100644 --- a/.env.development +++ b/.env.development @@ -6,6 +6,6 @@ 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.660 +NEXT_PUBLIC_APP_VERSION=1.6.661 NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter) diff --git a/.env.production b/.env.production index 813d111..6550f5d 100644 --- a/.env.production +++ b/.env.production @@ -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.660 +NEXT_PUBLIC_APP_VERSION=1.6.661 NEXT_PUBLIC_CPL_MODE=production \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bf72f1..8efb594 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [1.6.661] – 2025-07-31 + +- feat: TDR starten Button in KÜ Chart + +--- ## [1.6.660] – 2025-07-31 - fix: Schleifenwiderstand (TDR) Messung starten Button auf der Produktion diff --git a/components/main/kabelueberwachung/kue705FO/Kue705FO.tsx b/components/main/kabelueberwachung/kue705FO/Kue705FO.tsx index a86b880..3286323 100644 --- a/components/main/kabelueberwachung/kue705FO/Kue705FO.tsx +++ b/components/main/kabelueberwachung/kue705FO/Kue705FO.tsx @@ -79,6 +79,7 @@ const Kue705FO: React.FC = ({ kueOverflow: kueOverflowRaw, kuePSTmMinus96V, // <- richtig, weil so im State vorhanden tdrActive, // <- TDR aktiv Status hinzugefügt + win_fallSensorsActive, // <- KVz aktiv Status hinzugefügt } = useSelector((state: RootState) => state.kueDataSlice); //--------------------------------------------- @@ -227,6 +228,9 @@ const Kue705FO: React.FC = ({ // TDR aktiv Status für diesen Slot prüfen const isTdrActiveForSlot = tdrActive?.[slotIndex] === 1; + // KVz aktiv Status für diesen Slot prüfen + const isKvzActiveForSlot = win_fallSensorsActive?.[slotIndex] === 1; + // Removed useChartData(loopMeasurementCurveChartData) as the state was unused //--------------------------------- @@ -401,12 +405,15 @@ const Kue705FO: React.FC = ({ TDR )} - + {/* KVz Button - nur anzeigen wenn KVz aktiv ist */} + {isKvzActiveForSlot && ( + + )} {/* Messkurve Button */} @@ -443,8 +450,8 @@ const Kue705FO: React.FC = ({ )} - {/* KVz Panel - Anzeige ganz unten */} - {showKvzPanel && ( + {/* KVz Panel - Anzeige ganz unten, nur wenn KVz aktiv ist */} + {showKvzPanel && isKvzActiveForSlot && (
diff --git a/components/main/kabelueberwachung/kue705FO/modals/KvzModalView.tsx b/components/main/kabelueberwachung/kue705FO/modals/KvzModalView.tsx new file mode 100644 index 0000000..54ab098 --- /dev/null +++ b/components/main/kabelueberwachung/kue705FO/modals/KvzModalView.tsx @@ -0,0 +1,199 @@ +"use client"; + +import React, { useState } from "react"; +import { useSelector, useDispatch } from "react-redux"; +import { RootState } from "../../../../../redux/store"; +import { setKueData } from "../../../../../redux/slices/kueDataSlice"; +import { useAdminAuth } from "../../../settingsPageComponents/hooks/useAdminAuth"; + +type KvzData = { + // Hier können später weitere KVz-spezifische Einstellungen hinzugefügt werden + kvzSettings: string; +}; + +declare global { + interface Window { + __kvzCache?: Record; + } +} + +interface Props { + slot: number; + onClose?: () => void; +} + +export default function KvzModalView({ slot, onClose }: Props) { + const { isAdminLoggedIn } = useAdminAuth(true); + const dispatch = useDispatch(); + const kvzSlice = useSelector((state: RootState) => state.kueDataSlice); + + const cacheKey = `kvz_slot_${slot}`; + if (typeof window !== "undefined") { + window.__kvzCache = window.__kvzCache || {}; + } + const cachedKvz = + typeof window !== "undefined" + ? window.__kvzCache?.[cacheKey] ?? null + : null; + + const [kvzData] = useState( + () => + cachedKvz?.data || { + kvzSettings: "", // Placeholder für zukünftige Einstellungen + } + ); + + const [kvzActive, setKvzActive] = useState( + () => cachedKvz?.kvzActive ?? kvzSlice.win_fallSensorsActive?.[slot] === 1 + ); + + const updateCache = (data: typeof kvzData, active = kvzActive) => { + if (typeof window !== "undefined") { + (window.__kvzCache ??= {})[cacheKey] = { + data, + kvzActive: active, + }; + } + }; + + const handleKvzToggle = () => { + const newState = !kvzActive; + setKvzActive(newState); + updateCache(kvzData, newState); + + // Redux State sofort aktualisieren für UI-Update + const updatedKvzActive = [...(kvzSlice.win_fallSensorsActive || [])]; + updatedKvzActive[slot] = newState ? 1 : 0; + dispatch(setKueData({ win_fallSensorsActive: updatedKvzActive })); + + const isDev = window.location.hostname === "localhost"; + const slotParam = `KVZ${slot}=${newState ? 1 : 0}`; + + const reloadAfterConfirm = () => { + const msg = newState + ? "✅ KVz wurde aktiviert." + : "⚠️ KVz wurde deaktiviert."; + alert(msg); + location.reload(); + }; + + if (isDev) { + const updates = [ + { key: "win_fallSensorsActive", slot, value: newState ? 1 : 0 }, + ]; + + fetch("/api/cpl/updateKvzSettingsDataAPIHandler", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ updates }), + }) + .then((res) => res.json()) + .then(() => { + console.log("KVz-Aktiv-Status gespeichert."); + reloadAfterConfirm(); + }) + .catch((err) => { + console.error("Fehler beim Speichern von KVz aktiv:", err); + }); + } else { + const url = `${window.location.origin}/CPL?/kabelueberwachung.html&${slotParam}`; + fetch(url) + .then((res) => { + if (!res.ok) throw new Error("KVz-Befehl fehlgeschlagen"); + console.log("KVz aktiviert/deaktiviert:", res.status); + reloadAfterConfirm(); + }) + .catch((err) => { + console.error("Fehler beim KVz-Befehl:", err); + alert("Fehler beim Umschalten der KVz-Funktion."); + }); + } + }; + + const handleSave = () => { + const isDev = window.location.hostname === "localhost"; + + if (isDev) { + const updates = [ + { key: "win_fallSensorsActive", slot, value: kvzActive ? 1 : 0 }, + // Hier können später weitere KVz-Einstellungen hinzugefügt werden + ]; + + fetch("/api/cpl/updateKvzSettingsDataAPIHandler", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ updates }), + }) + .then((res) => res.json()) + .then(() => { + alert("KVz-Einstellungen erfolgreich gespeichert."); + if (typeof onClose === "function") onClose(); + }) + .catch((err) => { + console.error("Fehler beim Speichern:", err); + alert("Speichern fehlgeschlagen."); + }); + } else { + // Originaler Webservice-Teil für Produktionsumgebung + alert("KVz-Einstellungen gespeichert."); + if (typeof onClose === "function") onClose(); + } + + updateCache(kvzData, kvzActive); + }; + + return ( +
+ {/* KVz-Funktion */} + {isAdminLoggedIn && ( +
+ KVz-Funktion: +
+ + + {kvzActive ? "aktiviert" : "deaktiviert"} + +
+
+ )} + + {/* Zukünftige KVz-Einstellungen können hier hinzugefügt werden */} + {!isAdminLoggedIn && ( +
+
+

+ Nur Admin-Benutzer können diese Einstellungen ändern. +

+
+
+ )} + + {/* Speichern Button */} + + {/*
+
+ +
+
*/} +
+ ); +} diff --git a/components/main/kabelueberwachung/kue705FO/modals/SettingsModalWrapper.tsx b/components/main/kabelueberwachung/kue705FO/modals/SettingsModalWrapper.tsx index c77dc0d..15b63be 100644 --- a/components/main/kabelueberwachung/kue705FO/modals/SettingsModalWrapper.tsx +++ b/components/main/kabelueberwachung/kue705FO/modals/SettingsModalWrapper.tsx @@ -3,6 +3,7 @@ import { useState, useEffect } from "react"; import ReactModal from "react-modal"; import KueEinstellung from "./KueEinstellung"; import TdrEinstellung from "./TdrEinstellung"; +import KvzModalView from "./KvzModalView"; import Knotenpunkte from "./Knotenpunkte"; interface KueModalProps { @@ -14,18 +15,20 @@ interface KueModalProps { declare global { interface Window { - __lastKueTab?: "kue" | "tdr" | "knoten"; + __lastKueTab?: "kue" | "tdr" | "kvz" | "knoten"; kabelModalOpen?: boolean; } } export default function KueModal({ showModal, onClose, slot }: KueModalProps) { - const [activeTab, setActiveTab] = useState<"kue" | "tdr" | "knoten">(() => { - if (typeof window !== "undefined" && window.__lastKueTab) { - return window.__lastKueTab; + const [activeTab, setActiveTab] = useState<"kue" | "tdr" | "kvz" | "knoten">( + () => { + if (typeof window !== "undefined" && window.__lastKueTab) { + return window.__lastKueTab; + } + return "kue"; } - return "kue"; - }); + ); useEffect(() => { if (typeof window !== "undefined") { @@ -77,6 +80,7 @@ export default function KueModal({ showModal, onClose, slot }: KueModalProps) { {[ { label: "Allgemein", key: "kue" as const }, { label: "TDR ", key: "tdr" as const }, + { label: "KVz", key: "kvz" as const }, { label: "Knotenpunkte", key: "knoten" as const }, ].map(({ label, key }) => (