From 99d727a925b9a0723665404dba014b47aa26d954 Mon Sep 17 00:00:00 2001 From: Ismail Ali Date: Wed, 26 Mar 2025 21:08:17 +0100 Subject: [PATCH] selectedChartData slice erstellt --- .../kabelueberwachung/kue705FO/Kue705FO.tsx | 3 +- components/main/uebersicht/VersionInfo.tsx | 1 - config/webVersion.ts | 2 +- redux/slices/selectedChartDataSlice.ts | 22 ++++++ redux/store.ts | 2 + services/fetchSystemSettings.ts | 71 +++++++++++-------- 6 files changed, 69 insertions(+), 32 deletions(-) create mode 100644 redux/slices/selectedChartDataSlice.ts diff --git a/components/main/kabelueberwachung/kue705FO/Kue705FO.tsx b/components/main/kabelueberwachung/kue705FO/Kue705FO.tsx index 03256b2..4c08fd3 100644 --- a/components/main/kabelueberwachung/kue705FO/Kue705FO.tsx +++ b/components/main/kabelueberwachung/kue705FO/Kue705FO.tsx @@ -37,8 +37,9 @@ const Kue705FO: React.FC = ({ `Rendering Kue705FO - SlotIndex: ${slotIndex}, ModulName: ${modulName}` ); */ const selectedChartData = useSelector( - (state: RootState) => state.variables.selectedChartData + (state: RootState) => state.selectedChartData.selectedChartData ); + const dispatch = useDispatch(); const chartRef = useRef(null); diff --git a/components/main/uebersicht/VersionInfo.tsx b/components/main/uebersicht/VersionInfo.tsx index 8e96189..19834ba 100644 --- a/components/main/uebersicht/VersionInfo.tsx +++ b/components/main/uebersicht/VersionInfo.tsx @@ -6,7 +6,6 @@ import { RootState } from "../../../redux/store"; const VersionInfo: React.FC = () => { const appVersion = - //useSelector((state: RootState) => state.variables.appVersion) || useSelector((state: RootState) => state.systemSettings.appVersion) || "Unbekannt"; const webVersion = useSelector( diff --git a/config/webVersion.ts b/config/webVersion.ts index b591341..673074b 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.171"; +const webVersion = "1.6.172"; export default webVersion; diff --git a/redux/slices/selectedChartDataSlice.ts b/redux/slices/selectedChartDataSlice.ts new file mode 100644 index 0000000..9b8e7a0 --- /dev/null +++ b/redux/slices/selectedChartDataSlice.ts @@ -0,0 +1,22 @@ +import { createSlice, PayloadAction } from "@reduxjs/toolkit"; + +interface SelectedChartDataState { + selectedChartData: any; +} + +const initialState: SelectedChartDataState = { + selectedChartData: null, +}; + +const selectedChartDataSlice = createSlice({ + name: "selectedChartData", + initialState, + reducers: { + setSelectedChartData(state, action: PayloadAction) { + state.selectedChartData = action.payload; + }, + }, +}); + +export const { setSelectedChartData } = selectedChartDataSlice.actions; +export default selectedChartDataSlice.reducer; diff --git a/redux/store.ts b/redux/store.ts index 5ed7419..21cd12a 100644 --- a/redux/store.ts +++ b/redux/store.ts @@ -19,6 +19,7 @@ import loopChartReducer from "./slices/loopChartSlice"; import tdmChartReducer from "./slices/tdmChartSlice"; import tdrDataByIdReducer from "./slices/tdrDataByIdSlice"; import kueDataReducer from "./slices/kueDataSlice"; +import selectedChartDataReducer from "./slices/selectedChartDataSlice"; const store = configureStore({ reducer: { @@ -40,6 +41,7 @@ const store = configureStore({ tdmChart: tdmChartReducer, tdrDataById: tdrDataByIdReducer, kueData: kueDataReducer, + selectedChartData: selectedChartDataReducer, }, }); diff --git a/services/fetchSystemSettings.ts b/services/fetchSystemSettings.ts index 02151f8..e92fc9c 100644 --- a/services/fetchSystemSettings.ts +++ b/services/fetchSystemSettings.ts @@ -1,36 +1,49 @@ // /services/fetchSystemSettings.ts export const fetchSystemSettings = async () => { - if (typeof window === "undefined") return null; + try { + if (typeof window === "undefined") return null; - // ✅ System.js nur bei Bedarf nachladen (Pfad abhängig von Umgebung) - const scriptSrc = - process.env.NODE_ENV === "production" - ? "/CPL?/CPL/SERVICE/System.js" - : "/CPLmockData/SERVICE/System.js"; + await new Promise((resolve, reject) => { + const script = document.createElement("script"); + script.src = "/CPLmockData/SERVICE/System.js"; // ggf. anpassen + script.async = true; + script.onload = () => resolve(); + script.onerror = () => reject("❌ Fehler beim Laden von System.js"); + document.body.appendChild(script); + }); - await new Promise((resolve, reject) => { - const script = document.createElement("script"); - script.src = scriptSrc; - script.async = true; - script.onload = () => resolve(); - script.onerror = () => reject("❌ Fehler beim Laden von System.js"); - document.body.appendChild(script); - }); + const { + win_deviceName, + win_mac1, + win_ip, + win_subnet, + win_gateway, + win_cplInternalTimestamp, + win_ntp1, + win_ntp2, + win_ntp3, + win_ntpTimezone, + win_ntpActive, + win_appVersion, + } = window as any; - const win = window as any; - - return { - deviceName: win.win_deviceName || "", - mac1: win.win_mac1 || "", - ip: win.win_ip || "", - subnet: win.win_subnet || "", - gateway: win.win_gateway || "", - cplInternalTimestamp: win.win_cplInternalTimestamp || "", - ntp1: win.win_ntp1 || "", - ntp2: win.win_ntp2 || "", - ntp3: win.win_ntp3 || "", - ntpTimezone: win.win_ntpTimezone || "", - ntpActive: win.win_ntpActive || false, - }; + return { + deviceName: win_deviceName, + mac1: win_mac1, + ip: win_ip, + subnet: win_subnet, + gateway: win_gateway, + cplInternalTimestamp: win_cplInternalTimestamp, + ntp1: win_ntp1, + ntp2: win_ntp2, + ntp3: win_ntp3, + ntpTimezone: win_ntpTimezone, + ntpActive: win_ntpActive === "1", + appVersion: win_appVersion, // ✅ jetzt korrekt + }; + } catch (error) { + console.error("❌ Fehler beim Laden der Systemdaten:", error); + return null; + } };