diff --git a/components/main/kabelueberwachung/kue705FO/Charts/ChartSwitcher.tsx b/components/main/kabelueberwachung/kue705FO/Charts/ChartSwitcher.tsx index 1851352..e8611aa 100644 --- a/components/main/kabelueberwachung/kue705FO/Charts/ChartSwitcher.tsx +++ b/components/main/kabelueberwachung/kue705FO/Charts/ChartSwitcher.tsx @@ -19,6 +19,7 @@ import { } from "../../../../../redux/slices/tdrChartSlice"; import { resetBrushRange } from "../../../../../redux/slices/brushSlice"; import { fetchTDMDataBySlotThunk } from "../../../../../redux/thunks/fetchTDMListBySlotThunk"; +import { useLoopChartLoader } from "./LoopMeasurementChart/LoopChartActionBar"; interface ChartSwitcherProps { isOpen: boolean; @@ -75,6 +76,24 @@ const ChartSwitcher: React.FC = ({ }, [dispatch]); */ //------------------------------------- + const { loadLoopChartData } = useLoopChartLoader(); + useEffect(() => { + if (isOpen && activeMode === "Schleife") { + loadLoopChartData(); + } + }, [isOpen, activeMode]); + //------------------------------------- + const slotNumber = useSelector( + (state: RootState) => state.kabelueberwachungChartSlice.slotNumber + ); + + useEffect(() => { + if (isOpen && activeMode === "Schleife" && slotNumber !== null) { + loadLoopChartData(); + } + }, [isOpen, activeMode, slotNumber]); + + //----------------------------------------- return ( { + const dispatch = useDispatch(); + const { vonDatum, bisDatum, selectedMode, selectedSlotType, slotNumber } = + useSelector((state: RootState) => state.kabelueberwachungChartSlice); + const formatDate = (dateString: string) => { + const [year, month, day] = dateString.split("-"); + return `${year};${month};${day}`; + }; + + const getApiUrl = ( + mode: "DIA0" | "DIA1" | "DIA2", + type: number, + slotNumber: number + ) => { + const typeFolder = + type === 3 ? "isolationswiderstand" : "schleifenwiderstand"; + return `${window.location.origin}/CPL?seite.ACP&${mode}=${formatDate( + vonDatum + )};${formatDate(bisDatum)};${slotNumber};${type};`; + }; + + const loadLoopChartData = async () => { + const type = selectedSlotType === "schleifenwiderstand" ? 4 : 3; + if (slotNumber === null) return; + + dispatch(setLoading(true)); + dispatch(setChartOpen(false)); + dispatch(setLoopMeasurementCurveChartData([])); + dispatch(setFullScreen(false)); + + const startTime = Date.now(); + const MIN_LOADING_TIME_MS = 1000; + + try { + const apiUrl = getApiUrl(selectedMode, type, slotNumber); + const response = await fetch(apiUrl); + const data = await response.json(); + + const waitTime = Math.max( + 0, + MIN_LOADING_TIME_MS - (Date.now() - startTime) + ); + await new Promise((res) => setTimeout(res, waitTime)); + + if (Array.isArray(data) && data.length > 0) { + dispatch(setLoopMeasurementCurveChartData(data)); + dispatch(setChartOpen(true)); + } else { + dispatch(setLoopMeasurementCurveChartData([])); + dispatch(setChartOpen(false)); + alert("⚠️ Keine Daten im gewählten Zeitraum."); + } + } catch (err) { + console.error("❌ Fehler beim Laden:", err); + alert("❌ Fehler beim Laden."); + } finally { + dispatch(setLoading(false)); + } + }; + + return { loadLoopChartData }; +}; + +//-----------------------------------------------------------------------------------LoopChartActionBar const LoopChartActionBar: React.FC = () => { const dispatch = useDispatch(); diff --git a/config/webVersion.ts b/config/webVersion.ts index 213abdb..f939ebb 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.212"; +const webVersion = "1.6.213"; export default webVersion;