feat: Umgebungsspezifisches Laden von Datenquellen implementiert

- Alle fetch-Services (TDM, TDR, analoge/digitale Eingänge/Ausgänge, SystemSettings usw.) angepasst,
  um `NEXT_PUBLIC_NODE_ENV` zu verwenden.
- Entwicklungsumgebung lädt Daten aus /CPLmockData/...
- Produktionsumgebung verwendet echte Endpunkte mit /CPL?/CPL/...
- .env.production und .env.development korrekt berücksichtigt
- loadWindowVariables, WindowVariablesInitializer und verwandte Dateien bereinigt
- Mockdaten erscheinen nicht mehr versehentlich in Produktionsumgebung
This commit is contained in:
ISA
2025-03-27 11:03:23 +01:00
parent 0bec3fb148
commit c55f0e7fe5
21 changed files with 170 additions and 104 deletions

View File

@@ -4,7 +4,7 @@
import { useEffect, useState } from "react";
import { Provider } from "react-redux";
import store, { useAppDispatch } from "../redux/store";
import { checkSession } from "../utils/checkSession";
import { loadWindowVariables } from "../utils/loadWindowVariables";
import Header from "../components/header/Header";
import Navigation from "../components/navigation/Navigation";
import Footer from "../components/footer/Footer";
@@ -23,16 +23,28 @@ function MyApp({ Component, pageProps }: AppProps) {
function AppContent({ Component, pageProps }: AppProps) {
const dispatch = useAppDispatch();
const [sessionExpired, setSessionExpired] = useState(false);
useEffect(() => {
const sessionChecker = async () => {
const ok = await checkSession();
setSessionExpired(!ok);
const loadAndStoreVariables = async () => {
try {
const variables = await loadWindowVariables();
if (!variables) throw new Error("Sitzungsfehler");
//console.log("✅ Window-Variablen geladen:", variables);
const { ...restVariables } = variables;
setSessionExpired(false);
} catch (error) {
console.error("❌ Fehler beim Laden der Sitzung:", error);
setSessionExpired(true);
}
};
if (typeof window !== "undefined") {
sessionChecker();
loadAndStoreVariables();
const intervalId = setInterval(sessionChecker, 10000);
const intervalId = setInterval(loadAndStoreVariables, 10000);
return () => clearInterval(intervalId);
}
}, []);

View File

@@ -5,10 +5,6 @@ import Kue705FO from "../components/main/kabelueberwachung/kue705FO/Kue705FO";
import { useDispatch, useSelector } from "react-redux";
import { AppDispatch } from "../redux/store"; // Adjust the path to your Redux store file
import { RootState } from "../redux/store"; // Adjust the path to your Redux store file
import { fetchAllTDRChartData } from "../redux/thunks/fetchAllTDRChartThunk";
import { fetchAllTDRReferenceChartThunk } from "../redux/thunks/fetchAllTDRReferenceChartThunk";
import { fetchLoopChartDataThunk } from "../redux/thunks/fetchLoopChartDataThunk";
import { fetchAllTDMData } from "../redux/thunks/fetchAllTDMThunk";
function Kabelueberwachung() {
const dispatch: AppDispatch = useDispatch();
@@ -36,15 +32,8 @@ function Kabelueberwachung() {
const tdrData = useSelector((state) => state.tdrChart.data);
const loading = useSelector((state) => state.tdrChart.loading);
const error = useSelector((state) => state.tdrChart.error);
//----------------------------------------------------------------
// Beim Laden der Seite TDR-Daten abrufen
useEffect(() => {
if (!tdrData || tdrData.length === 0) {
// console.log("TDR-Daten abrufen...");
dispatch(fetchAllTDRChartData());
dispatch(fetchAllTDRReferenceChartThunk());
}
}, [dispatch, tdrData]);
//----------------------------------------------------------------
// Alarmstatus basierend auf Redux-Variablen berechnen
const updateAlarmStatus = () => {
@@ -122,35 +111,11 @@ function Kabelueberwachung() {
error: loopError,
} = useSelector((state: RootState) => state.loopChart);
// Daten für alle Kombinationen laden (z.B. Slot 1 als Beispiel)
useEffect(() => {
["DIA0", "DIA1", "DIA2"].forEach((mode) => {
[3, 4].forEach((type) => {
dispatch(
fetchLoopChartDataThunk({
mode: mode as "DIA0" | "DIA1" | "DIA2",
type,
slotNumber: 1,
vonDatum: "2025-03-20",
bisDatum: "2025-03-23",
})
);
});
});
}, [dispatch]);
// Zugriff z.B. auf Schleifenwiderstand von DIA1
const dia1Schleifen = loopData["DIA1"]?.[4];
const dia0Iso = loopData["DIA0"]?.[3];
//------------------------------------------------------------
const tdmData = useSelector((state) => state.tdmChart.data);
useEffect(() => {
if (!tdmData || tdmData.length === 0) {
dispatch(fetchAllTDMData());
}
}, [dispatch, tdmData]);
//----------------------------------------------------------------
return (