fix: Die Daten (.js) Kabelüberwachungsseite aktualisieren sich zwar alle paar Sekunden aber die Darstellung des BGT bleibt unverändert.
Bei der Kabelüberwachungsseite werden auch die analoge und digitale Eingänge geladen
This commit is contained in:
@@ -8,6 +8,7 @@ import { loadWindowVariables } from "../utils/loadWindowVariables";
|
||||
import Header from "../components/header/Header";
|
||||
import Navigation from "../components/navigation/Navigation";
|
||||
import Footer from "../components/footer/Footer";
|
||||
import { setKueData } from "../redux/slices/kueDataSlice";
|
||||
|
||||
import "../styles/globals.css";
|
||||
import { AppProps } from "next/app";
|
||||
@@ -25,14 +26,17 @@ function AppContent({ Component, pageProps }: AppProps) {
|
||||
const [sessionExpired, setSessionExpired] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
let intervalId: NodeJS.Timeout;
|
||||
|
||||
const loadAndStoreVariables = async () => {
|
||||
try {
|
||||
const variables = await loadWindowVariables();
|
||||
const { variables, kueData } = await loadWindowVariables();
|
||||
if (!variables) throw new Error("Sitzungsfehler");
|
||||
|
||||
//console.log("✅ Window-Variablen geladen:", variables);
|
||||
|
||||
const { ...restVariables } = variables;
|
||||
// Nur auf kabelueberwachung.html Redux aktualisieren
|
||||
if (window.location.pathname.includes("kabelueberwachung")) {
|
||||
dispatch(setKueData(kueData));
|
||||
}
|
||||
|
||||
setSessionExpired(false);
|
||||
} catch (error) {
|
||||
@@ -44,13 +48,15 @@ function AppContent({ Component, pageProps }: AppProps) {
|
||||
if (typeof window !== "undefined") {
|
||||
loadAndStoreVariables();
|
||||
|
||||
const intervalId = setInterval(loadAndStoreVariables, 10000);
|
||||
// Nur auf kabelueberwachung.html regelmäßig aktualisieren
|
||||
if (window.location.pathname.includes("kabelueberwachung")) {
|
||||
intervalId = setInterval(loadAndStoreVariables, 10000);
|
||||
}
|
||||
|
||||
return () => clearInterval(intervalId);
|
||||
}
|
||||
}, []);
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-screen overflow-hidden">
|
||||
<Header />
|
||||
|
||||
@@ -1,38 +1,43 @@
|
||||
// /utils/loadWindowVariables.ts
|
||||
|
||||
// ✅ Interface für `window`-Objekt zur TypeScript-Sicherheit
|
||||
interface CustomWindow extends Window {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
// ✅ Hauptfunktion zum Laden von `window`-Variablen
|
||||
export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
export async function loadWindowVariables(): Promise<{
|
||||
variables: Record<string, any>;
|
||||
kueData?: Record<string, any>;
|
||||
}> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const requiredVars: string[] = ["win_deviceName"];
|
||||
const isDev = window.location.hostname === "localhost";
|
||||
const pathname = window.location.pathname;
|
||||
|
||||
// ✅ Skripte, die geladen werden müssen
|
||||
const scripts: string[] = [
|
||||
isDev ? "analogeEingaengeAPIHandler" : "ae.js",
|
||||
isDev ? "digitaleEingaengeAPIHandler" : "de.js",
|
||||
//isDev ? "digitalOutputsAPIHandler" : "da.js", // das wird Momentan nicht gebraucht
|
||||
isDev ? "kabelueberwachungAPIHandler" : "kueData.js",
|
||||
const scripts: string[] = [];
|
||||
|
||||
if (pathname.includes("kabelueberwachung")) {
|
||||
scripts.push(isDev ? "kabelueberwachungAPIHandler" : "kueData.js");
|
||||
} else if (pathname.includes("digitalInputs")) {
|
||||
scripts.push(isDev ? "digitaleEingaengeAPIHandler" : "de.js");
|
||||
} else if (pathname.includes("digitalOutputs")) {
|
||||
scripts.push(isDev ? "digitalOutputsAPIHandler" : "da.js");
|
||||
} else if (pathname.includes("analogeEingaenge")) {
|
||||
scripts.push(isDev ? "analogeEingaengeAPIHandler" : "ae.js");
|
||||
} else if (pathname.includes("dashboard")) {
|
||||
scripts.push(
|
||||
isDev ? "last20MessagesAPIHandler" : "start.js",
|
||||
isDev ? "opcuaAPIHandler" : "opcua.js",
|
||||
//isDev ? "slotDataAPIHandler" : "slotData.js", // das wird Momentan nicht gebraucht
|
||||
isDev ? "systemAPIHandler" : "system.js",
|
||||
//isDev ? "tdmDataAPIHandler" : "tdmData.js", // das wird Momentan nicht gebraucht
|
||||
//isDev ? "tdrDataAPIHandler" : "tdrData.js", // das wird Momentan nicht gebraucht
|
||||
];
|
||||
isDev ? "opcuaAPIHandler" : "opcua.js"
|
||||
);
|
||||
} else if (pathname.includes("einstellungen")) {
|
||||
scripts.push(isDev ? "opcuaAPIHandler" : "opcua.js");
|
||||
}
|
||||
|
||||
// ✅ Erkenne Umgebung anhand von `window.location.hostname`
|
||||
scripts.push(isDev ? "systemAPIHandler" : "system.js");
|
||||
|
||||
const loadScript = (src: string): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
script.src = isDev
|
||||
? `/api/cpl/${src}` // Entwicklungsumgebung
|
||||
: `/CPL?/CPL/SERVICE/${src}`; // Produktionsumgebung
|
||||
script.src = isDev ? `/api/cpl/${src}` : `/CPL?/CPL/SERVICE/${src}`;
|
||||
script.async = true;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () => reject(new Error(`Script load error: ${src}`));
|
||||
@@ -40,7 +45,6 @@ export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
});
|
||||
};
|
||||
|
||||
// ✅ Lade alle Skripte nacheinander
|
||||
scripts
|
||||
.reduce(
|
||||
(promise, script) => promise.then(() => loadScript(script)),
|
||||
@@ -49,7 +53,6 @@ export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
.then(() => {
|
||||
const win = window as unknown as CustomWindow;
|
||||
|
||||
// ✅ Erstelle ein Objekt mit allen geladenen Variablen
|
||||
const variablesObj: Record<string, any> = requiredVars.reduce(
|
||||
(acc, variable) => {
|
||||
if (win[variable] !== undefined) {
|
||||
@@ -60,7 +63,38 @@ export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
{}
|
||||
);
|
||||
|
||||
resolve(variablesObj);
|
||||
const kueData =
|
||||
pathname.includes("kabelueberwachung") && typeof win === "object"
|
||||
? {
|
||||
kueOnline: win.win_kueOnline || [],
|
||||
kueID: win.win_kueID || [],
|
||||
kuePSTmMinus96V: win.win_kuePSTmMinus96V || [],
|
||||
kueAlarm1: win.win_kueAlarm1 || [],
|
||||
kueAlarm2: win.win_kueAlarm2 || [],
|
||||
kueIso: win.win_kueIso || [],
|
||||
kueResidence: win.win_kueResidence || [],
|
||||
kueCableBreak: win.win_kueCableBreak || [],
|
||||
kueGroundFault: win.win_kueGroundFault || [],
|
||||
kueLimit1: win.win_kueLimit1 || [],
|
||||
kueLimit2Low: win.win_kueLimit2Low || [],
|
||||
kueDelay1: win.win_kueDelay1 || [],
|
||||
kueLoopInterval: win.win_kueLoopInterval || [],
|
||||
kueVersion: win.win_kueVersion || [],
|
||||
kueOverflow: win.win_kueOverflow || [],
|
||||
tdrAtten: win.win_tdrAtten || [],
|
||||
tdrPulse: win.win_tdrPulse || [],
|
||||
tdrSpeed: win.win_tdrSpeed || [],
|
||||
tdrAmp: win.win_tdrAmp || [],
|
||||
tdrTrigger: win.win_tdrTrigger || [],
|
||||
tdrLocation: win.win_tdrLocation || [],
|
||||
tdrActive: win.win_tdrActive || [],
|
||||
tdrLast: win.win_tdrLast || [],
|
||||
tdrOverflow: win.win_kueOverflow || [],
|
||||
memoryInterval: win.win_memoryInterval || [],
|
||||
}
|
||||
: undefined;
|
||||
|
||||
resolve({ variables: variablesObj, kueData });
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("❌ Fehler beim Laden eines Skripts:", error);
|
||||
|
||||
Reference in New Issue
Block a user