kueConfig.js und kueDetailTdr.js löschen und die Variable in kueData.js einfügen
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"use client"; // components/Header.jsx
|
||||
// components/Header.jsx
|
||||
"use client";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import Image from "next/image";
|
||||
import "bootstrap-icons/font/bootstrap-icons.css";
|
||||
@@ -6,72 +7,68 @@ import { loadWindowVariables } from "../utils/loadWindowVariables";
|
||||
import SettingsModal from "./modales/SettingsModal";
|
||||
|
||||
function Header() {
|
||||
const [isClient, setIsClient] = useState(false);
|
||||
const [stationsname, setStationsname] = useState("Lädt...");
|
||||
const [cplStatus, setCplStatus] = useState("Lädt...");
|
||||
const [showSettingsModal, setShowSettingsModal] = useState(false);
|
||||
const [logOnce, setLogOnce] = useState(false);
|
||||
|
||||
// Flag außerhalb des State-Managements, um die Ausgabe nur einmal zu loggen
|
||||
let variablesLogged = false;
|
||||
|
||||
useEffect(() => {
|
||||
setIsClient(true);
|
||||
}, []);
|
||||
|
||||
const handleSettingsClick = () => {
|
||||
setShowSettingsModal(true);
|
||||
};
|
||||
|
||||
const handleCloseSettingsModal = () => {
|
||||
setShowSettingsModal(false);
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
window.location.href = "/offline.html";
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (isClient && !logOnce) {
|
||||
const environment = process.env.NEXT_PUBLIC_NODE_ENV || "production";
|
||||
const script = document.createElement("script");
|
||||
|
||||
// Laden von nur System.js abhängig von der Umgebung
|
||||
script.src =
|
||||
environment === "production"
|
||||
? `/CPL?/CPL/SERVICE/System.js`
|
||||
: `/CPLmockData/SERVICE/System.js`;
|
||||
|
||||
script.async = true;
|
||||
script.onload = () => {
|
||||
// console.log(`System.js wurde erfolgreich geladen.`);
|
||||
|
||||
// Systemvariablen überprüfen und zuweisen
|
||||
if (window.deviceName) {
|
||||
setStationsname(window.deviceName || "Unbekannt");
|
||||
setCplStatus(window.hardware_version || "Unbekannt");
|
||||
} else {
|
||||
console.error("Systemvariablen sind nicht vollständig verfügbar.");
|
||||
loadWindowVariables()
|
||||
.then(() => {
|
||||
if (!variablesLogged) {
|
||||
console.log("Geladene Systemvariablen:", {
|
||||
deviceName: window.deviceName,
|
||||
ip: window.ip,
|
||||
mac1: window.mac1,
|
||||
mac2: window.mac2,
|
||||
subnet: window.subnet,
|
||||
gateway: window.gateway,
|
||||
datetime: window.datetime,
|
||||
kueOnline: window.kueOnline,
|
||||
kueIso: window.kueIso,
|
||||
kueValid: window.kueValid,
|
||||
kueAlarm1: window.kueAlarm1,
|
||||
kueAlarm2: window.kueAlarm2,
|
||||
kueRes: window.kueRes,
|
||||
kueCableBreak: window.kueCableBreak,
|
||||
kueGroundFault: window.kueGroundFault,
|
||||
kueLimit1: window.kueLimit1,
|
||||
kueLimit2Low: window.kueLimit2Low,
|
||||
kueLimit2High: window.kueLimit2High,
|
||||
kueDelay1: window.kueDelay1,
|
||||
kueLoopInterval: window.kueLoopInterval,
|
||||
kueID: window.kueID,
|
||||
kueName: window.kueName,
|
||||
kueVersion: window.kueVersion,
|
||||
kueOverflow: window.kueOverflow,
|
||||
kue100V: window.kue100V,
|
||||
kueResidence: window.kueResidence,
|
||||
kueBooting: window.kueBooting,
|
||||
tdrAtten: window.tdrAtten,
|
||||
tdrPulse: window.tdrPulse,
|
||||
tdrSpeed: window.tdrSpeed,
|
||||
tdrAmp: window.tdrAmp,
|
||||
tdrTrigger: window.tdrTrigger,
|
||||
tdrLocation: window.tdrLocation,
|
||||
tdrActive: window.tdrActive,
|
||||
tdrLast: window.tdrLast,
|
||||
});
|
||||
variablesLogged = true; // Setze das Flag, um das erneute Loggen zu verhindern
|
||||
}
|
||||
|
||||
console.log(" Header Systemvariablen geladen:", {
|
||||
deviceName: window.deviceName,
|
||||
ip: window.ip,
|
||||
mac1: window.mac1,
|
||||
mac2: window.mac2,
|
||||
subnet: window.subnet,
|
||||
gateway: window.gateway,
|
||||
datetime: window.datetime,
|
||||
});
|
||||
setStationsname(window.deviceName || "Unbekannt");
|
||||
setCplStatus(window.hardware_version || "Unbekannt");
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Fehler beim Laden der Variablen:", error);
|
||||
});
|
||||
}, []);
|
||||
|
||||
setLogOnce(true);
|
||||
};
|
||||
|
||||
script.onerror = (error) =>
|
||||
console.error("Fehler beim Laden von System.js:", error);
|
||||
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
}, [isClient, logOnce]);
|
||||
|
||||
if (!isClient) return null;
|
||||
const handleSettingsClick = () => setShowSettingsModal(true);
|
||||
const handleCloseSettingsModal = () => setShowSettingsModal(false);
|
||||
const handleLogout = () => (window.location.href = "/offline.html");
|
||||
|
||||
return (
|
||||
<header className="bg-gray-300 flex justify-between items-center w-full h-28 relative text-black">
|
||||
@@ -105,7 +102,7 @@ function Header() {
|
||||
<div className="flex items-center justify-end w-full">
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="text bg-littwin-blue text-white px-4 py-2 rounded"
|
||||
className="bg-littwin-blue text-white px-4 py-2 rounded"
|
||||
>
|
||||
Abmelden
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user