feat: fetchKueData mit vollständiger Extraktion aus kueData.js ersetzt loadWindowVariables
- Dynamisches Laden von kueData.js nur bei Bedarf - Alle benötigten Variablen wie kueAlarm1, kueCableBreak etc. extrahiert - Fehleranzeige in KabelModulStatus funktioniert wieder korrekt - loadWindowVariables.ts für KUE vollständig ersetzt
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
"use client"; // components/main/uebersicht/Baugruppentraeger.tsx
|
"use client"; // components/main/uebersicht/Baugruppentraeger.tsx
|
||||||
import React, { useMemo } from "react";
|
import React, { useMemo, useEffect } from "react";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { RootState } from "../../../redux/store";
|
import { RootState, useAppDispatch } from "../../../redux/store";
|
||||||
import KabelModulStatus from "./modulesStatus/KabelModulStatus";
|
import KabelModulStatus from "./modulesStatus/KabelModulStatus";
|
||||||
|
import { fetchKueDataThunk } from "../../../redux/thunks/fetchKueDataThunk";
|
||||||
|
|
||||||
const Baugruppentraeger: React.FC = () => {
|
const Baugruppentraeger: React.FC = () => {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
const router = useRouter(); // useRouter für Navigation hinzufügen
|
const router = useRouter(); // useRouter für Navigation hinzufügen
|
||||||
|
|
||||||
// Redux-Variablen direkt hier abrufen
|
// Redux-Variablen direkt hier abrufen
|
||||||
@@ -16,7 +18,7 @@ const Baugruppentraeger: React.FC = () => {
|
|||||||
kueAlarm1,
|
kueAlarm1,
|
||||||
kueAlarm2,
|
kueAlarm2,
|
||||||
kueGroundFault,
|
kueGroundFault,
|
||||||
} = useSelector((state: RootState) => state.variables);
|
} = useSelector((state: RootState) => state.kueData);
|
||||||
|
|
||||||
// `kueOnline` sicherstellen, dass es nur Zahlen enthält
|
// `kueOnline` sicherstellen, dass es nur Zahlen enthält
|
||||||
const kueOnline = useMemo(
|
const kueOnline = useMemo(
|
||||||
@@ -79,6 +81,11 @@ const Baugruppentraeger: React.FC = () => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
//--------------------------------------------
|
||||||
|
useEffect(() => {
|
||||||
|
dispatch(fetchKueDataThunk());
|
||||||
|
}, [dispatch]);
|
||||||
|
//--------------------------------------------
|
||||||
return <>{baugruppen}</>;
|
return <>{baugruppen}</>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,10 +31,12 @@ const KabelModulStatus: React.FC<KabelModulStatusProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Status nur prüfen, wenn der Slot aktiv ist (kueOnline für den Slot ist 1)
|
// Status nur prüfen, wenn der Slot aktiv ist (kueOnline für den Slot ist 1)
|
||||||
const isCableBreak = kueCableBreak[slot - 1] === 1;
|
const isCableBreak =
|
||||||
const isAlarm1 = kueAlarm1[slot - 1] === 1;
|
Array.isArray(kueCableBreak) && kueCableBreak[slot - 1] === 1;
|
||||||
const isAlarm2 = kueAlarm2[slot - 1] === 1;
|
const isAlarm1 = Array.isArray(kueAlarm1) && kueAlarm1[slot - 1] === 1;
|
||||||
const groundFault = kueGroundFault[slot - 1] === 1;
|
const isAlarm2 = Array.isArray(kueAlarm2) && kueAlarm2[slot - 1] === 1;
|
||||||
|
const groundFault =
|
||||||
|
Array.isArray(kueGroundFault) && kueGroundFault[slot - 1] === 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border border-gray-400 w-10 h-20 flex flex-col scale-100 xl:scale-90">
|
<div className="border border-gray-400 w-10 h-20 flex flex-col scale-100 xl:scale-90">
|
||||||
|
|||||||
@@ -6,5 +6,5 @@
|
|||||||
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
|
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
|
||||||
|
|
||||||
*/
|
*/
|
||||||
const webVersion = "1.6.168";
|
const webVersion = "1.6.169";
|
||||||
export default webVersion;
|
export default webVersion;
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
// hooks/windowvariables/useLoadWindowVariables.ts
|
|
||||||
import { useEffect } from "react";
|
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
import { setDigitalOutputs } from "../../redux/slices/digitalOutputsSlice";
|
|
||||||
|
|
||||||
const requiredVars: string[] = ["win_da_state", "win_da_bezeichnung"];
|
|
||||||
|
|
||||||
const scripts: string[] = [
|
|
||||||
"da.js",
|
|
||||||
"de.js",
|
|
||||||
"ae.js",
|
|
||||||
"kueData.js",
|
|
||||||
"Start.js",
|
|
||||||
"System.js",
|
|
||||||
"opcua.js",
|
|
||||||
];
|
|
||||||
|
|
||||||
const loadScript = (src: string): Promise<void> => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const script = document.createElement("script");
|
|
||||||
const environment = process.env.NEXT_PUBLIC_NODE_ENV || "production";
|
|
||||||
script.src =
|
|
||||||
environment === "production"
|
|
||||||
? `/CPL?/CPL/SERVICE/${src}`
|
|
||||||
: `/CPLmockData/SERVICE/${src}`;
|
|
||||||
script.async = true;
|
|
||||||
script.onload = () => resolve();
|
|
||||||
script.onerror = () => reject(new Error(`Script load error: ${src}`));
|
|
||||||
document.head.appendChild(script);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useLoadWindowVariables = () => {
|
|
||||||
const dispatch = useDispatch();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const loadVariables = async () => {
|
|
||||||
try {
|
|
||||||
await loadScript("da.js"); // Lade `da.js` zuerst
|
|
||||||
for (const script of scripts) {
|
|
||||||
if (script !== "da.js") await loadScript(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("Laden abgeschlossen. Jetzt werden Variablen geprüft.");
|
|
||||||
console.log("win_da_state:", window.win_da_state);
|
|
||||||
console.log("win_da_bezeichnung:", window.win_da_bezeichnung);
|
|
||||||
|
|
||||||
if (window.win_da_state && window.win_da_bezeichnung) {
|
|
||||||
const digitalOutputs = window.win_da_state.map(
|
|
||||||
(status: number, index: number) => ({
|
|
||||||
id: index + 1,
|
|
||||||
label: window.win_da_bezeichnung[index] || `Ausgang ${index + 1}`,
|
|
||||||
status: status === 1,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
console.log("Dispatching digitalOutputs:", digitalOutputs);
|
|
||||||
dispatch(setDigitalOutputs(digitalOutputs));
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Fehler beim Laden der Skripte:", error);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
loadVariables();
|
|
||||||
}, [dispatch]);
|
|
||||||
};
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
|
// /pages/einstellungen.tsx
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { useAppDispatch } from "../redux/store";
|
import { useAppDispatch } from "../redux/store";
|
||||||
import { setSystemSettings } from "../redux/slices/systemSettingsSlice";
|
import { fetchSystemSettingsThunk } from "../redux/thunks/fetchSystemSettingsThunk";
|
||||||
import { loadWindowVariables } from "../utils/loadWindowVariables";
|
|
||||||
import GeneralSettings from "../components/main/settingsPageComponents/GeneralSettings";
|
import GeneralSettings from "../components/main/settingsPageComponents/GeneralSettings";
|
||||||
import OPCUAInterfaceSettings from "../components/main/settingsPageComponents/OPCUAInterfaceSettings";
|
import OPCUAInterfaceSettings from "../components/main/settingsPageComponents/OPCUAInterfaceSettings";
|
||||||
|
|
||||||
@@ -10,42 +10,7 @@ export default function Settings() {
|
|||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const loadSettings = async () => {
|
dispatch(fetchSystemSettingsThunk());
|
||||||
const vars = await loadWindowVariables();
|
|
||||||
if (!vars) return;
|
|
||||||
|
|
||||||
const {
|
|
||||||
deviceName,
|
|
||||||
mac1,
|
|
||||||
ip,
|
|
||||||
subnet,
|
|
||||||
gateway,
|
|
||||||
cplInternalTimestamp,
|
|
||||||
ntp1,
|
|
||||||
ntp2,
|
|
||||||
ntp3,
|
|
||||||
ntpTimezone,
|
|
||||||
ntpActive,
|
|
||||||
} = vars;
|
|
||||||
|
|
||||||
dispatch(
|
|
||||||
setSystemSettings({
|
|
||||||
deviceName,
|
|
||||||
mac1,
|
|
||||||
ip,
|
|
||||||
subnet,
|
|
||||||
gateway,
|
|
||||||
cplInternalTimestamp,
|
|
||||||
ntp1,
|
|
||||||
ntp2,
|
|
||||||
ntp3,
|
|
||||||
ntpTimezone,
|
|
||||||
ntpActive,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
loadSettings();
|
|
||||||
}, [dispatch]);
|
}, [dispatch]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -3,39 +3,39 @@
|
|||||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
interface KueDataState {
|
interface KueDataState {
|
||||||
kueOnline: boolean;
|
kueOnline: number[];
|
||||||
kueID: string | null;
|
kueID: string[];
|
||||||
pstMinus96V: number | null;
|
pstMinus96V: number[];
|
||||||
alarm1: number | null;
|
alarm1: number[];
|
||||||
alarm2: number | null;
|
alarm2: number[];
|
||||||
iso: number | null;
|
iso: number[];
|
||||||
residence: number | null;
|
residence: number[];
|
||||||
cableBreak: number | null;
|
cableBreak: number[];
|
||||||
groundFault: number | null;
|
groundFault: number[];
|
||||||
limit1: number | null;
|
limit1: number[];
|
||||||
limit2Low: number | null;
|
limit2Low: number[];
|
||||||
delay1: number | null;
|
delay1: number[];
|
||||||
loopInterval: number | null;
|
loopInterval: number[];
|
||||||
kueVersion: string | null;
|
kueVersion: number[];
|
||||||
overflow: number | null;
|
overflow: number[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const initialState: KueDataState = {
|
const initialState: KueDataState = {
|
||||||
kueOnline: false,
|
kueOnline: [],
|
||||||
kueID: null,
|
kueID: [],
|
||||||
pstMinus96V: null,
|
pstMinus96V: [],
|
||||||
alarm1: null,
|
alarm1: [],
|
||||||
alarm2: null,
|
alarm2: [],
|
||||||
iso: null,
|
iso: [],
|
||||||
residence: null,
|
residence: [],
|
||||||
cableBreak: null,
|
cableBreak: [],
|
||||||
groundFault: null,
|
groundFault: [],
|
||||||
limit1: null,
|
limit1: [],
|
||||||
limit2Low: null,
|
limit2Low: [],
|
||||||
delay1: null,
|
delay1: [],
|
||||||
loopInterval: null,
|
loopInterval: [],
|
||||||
kueVersion: null,
|
kueVersion: [],
|
||||||
overflow: null,
|
overflow: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const kueDataSlice = createSlice({
|
const kueDataSlice = createSlice({
|
||||||
|
|||||||
@@ -1,40 +1,61 @@
|
|||||||
// ✅ Service: /services/fetchKueData.ts
|
// /services/fetchKueData.ts
|
||||||
|
|
||||||
export const fetchKueData = async () => {
|
export const fetchKueData = async () => {
|
||||||
if (typeof window === "undefined") return null;
|
try {
|
||||||
|
if (typeof window === "undefined") return null;
|
||||||
|
|
||||||
// ✅ kueData.js nur bei Bedarf nachladen (Pfad abhängig von Umgebung)
|
// ✅ Script dynamisch laden
|
||||||
const scriptSrc =
|
await new Promise<void>((resolve, reject) => {
|
||||||
process.env.NODE_ENV === "production"
|
const script = document.createElement("script");
|
||||||
? "/CPL?/CPL/SERVICE/kueData.js"
|
const env = process.env.NEXT_PUBLIC_NODE_ENV;
|
||||||
: "/CPLmockData/SERVICE/kueData.js";
|
script.src =
|
||||||
|
env === "production"
|
||||||
|
? "/CPL?/CPL/SERVICE/kueData.js"
|
||||||
|
: "/CPLmockData/SERVICE/kueData.js";
|
||||||
|
script.async = true;
|
||||||
|
script.onload = () => resolve();
|
||||||
|
script.onerror = () => reject("Fehler beim Laden von kueData.js");
|
||||||
|
document.body.appendChild(script);
|
||||||
|
});
|
||||||
|
|
||||||
await new Promise<void>((resolve, reject) => {
|
const win = window as any;
|
||||||
const script = document.createElement("script");
|
|
||||||
script.src = scriptSrc;
|
|
||||||
script.async = true;
|
|
||||||
script.onload = () => resolve();
|
|
||||||
script.onerror = () => reject("❌ Fehler beim Laden von kueData.js");
|
|
||||||
document.body.appendChild(script);
|
|
||||||
});
|
|
||||||
|
|
||||||
const win = window as any;
|
// ✅ Alle benötigten Variablen extrahieren
|
||||||
|
const keys = [
|
||||||
|
"kueOnline",
|
||||||
|
"kueID",
|
||||||
|
"kuePSTmMinus96V",
|
||||||
|
"kueAlarm1",
|
||||||
|
"kueAlarm2",
|
||||||
|
"kueIso",
|
||||||
|
"kueResidence",
|
||||||
|
"kueCableBreak",
|
||||||
|
"kueGroundFault",
|
||||||
|
"kueLimit1",
|
||||||
|
"kueLimit2Low",
|
||||||
|
"kueDelay1",
|
||||||
|
"kueLoopInterval",
|
||||||
|
"kueVersion",
|
||||||
|
"tdrAtten",
|
||||||
|
"tdrPulse",
|
||||||
|
"tdrSpeed",
|
||||||
|
"tdrAmp",
|
||||||
|
"tdrTrigger",
|
||||||
|
"tdrLocation",
|
||||||
|
"tdrActive",
|
||||||
|
"kueOverflow",
|
||||||
|
"tdrLast",
|
||||||
|
];
|
||||||
|
|
||||||
return {
|
const result: Record<string, any> = {};
|
||||||
kueOnline: win.win_kueOnline ?? false,
|
for (const key of keys) {
|
||||||
kueID: win.win_kueID ?? null,
|
const winKey = `win_${key}`;
|
||||||
pstMinus96V: win.win_kuePSTmMinus96V ?? null,
|
result[key] = win[winKey] ?? [];
|
||||||
alarm1: win.win_kueAlarm1 ?? null,
|
}
|
||||||
alarm2: win.win_kueAlarm2 ?? null,
|
|
||||||
iso: win.win_kueIso ?? null,
|
return result;
|
||||||
residence: win.win_kueResidence ?? null,
|
} catch (error) {
|
||||||
cableBreak: win.win_kueCableBreak ?? null,
|
console.error("❌ Fehler beim Laden der KUE-Daten:", error);
|
||||||
groundFault: win.win_kueGroundFault ?? null,
|
return null;
|
||||||
limit1: win.win_kueLimit1 ?? null,
|
}
|
||||||
limit2Low: win.win_kueLimit2Low ?? null,
|
|
||||||
delay1: win.win_kueDelay1 ?? null,
|
|
||||||
loopInterval: win.win_kueLoopInterval ?? null,
|
|
||||||
kueVersion: win.win_kueVersion ?? null,
|
|
||||||
overflow: win.win_kueOverflow ?? null,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user