feat: Datenquelle auf statische JSON-Dateien in public umgestellt
- Fetch-API in `LoopChartActionBar.tsx` angepasst, um Mock-Daten aus `/public/CPLmockData/kuesChartData/` zu laden. - Mock-Daten als statische JSON-Dateien (`DIA0.json`, `DIA1.json`, `DIA2.json`) hinzugefügt. - `LoopMeasurementChart.tsx` angepasst, um die Daten aus dem Redux-Store zu verwenden. - Debugging-Logs entfernt und Fehlerbehandlung für fehlgeschlagene API-Requests verbessert. Mock-Daten können jetzt ohne API-Server geladen werden.
This commit is contained in:
@@ -30,37 +30,33 @@ const LoopChartActionBar: React.FC = () => {
|
||||
* @param mode - DIA0, DIA1 oder DIA2
|
||||
* @param slotIndex - Slot für die Abfrage
|
||||
*/
|
||||
const getApiUrl = (mode: "DIA0" | "DIA1" | "DIA2", slotIndex: number) => {
|
||||
const baseUrl =
|
||||
process.env.NODE_ENV === "development"
|
||||
? `/api/mockChartData?${mode}=true`
|
||||
: `/CPL?seite.ACP&${mode}=${vonDatum};${bisDatum};${slotIndex}`;
|
||||
|
||||
return baseUrl;
|
||||
const getApiUrl = (mode: "DIA0" | "DIA1" | "DIA2") => {
|
||||
return process.env.NODE_ENV === "development"
|
||||
? `/CPLmockData/kuesChartData/${mode}.json`
|
||||
: `/CPL?seite.ACP&${mode}=${vonDatum};${bisDatum};${slotIndex}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Funktion zum Laden der Messwerte
|
||||
*/
|
||||
const handleFetchData = async () => {
|
||||
const slotIndex =
|
||||
selectedSlotType === "schleifenwiderstand"
|
||||
? schleifenwiderstand
|
||||
: isolationswiderstand;
|
||||
|
||||
try {
|
||||
const apiUrl = getApiUrl(selectedMode, slotIndex);
|
||||
const response = await fetch(apiUrl);
|
||||
const data = await response.json();
|
||||
const apiUrl = getApiUrl(selectedMode);
|
||||
console.log("Mock JSON laden von:", apiUrl);
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
console.log("Daten geladen:", data);
|
||||
dispatch(setChartData(data));
|
||||
const response = await fetch(apiUrl);
|
||||
if (!response.ok) throw new Error(`Fehler: ${response.status}`);
|
||||
|
||||
const jsonData = await response.json();
|
||||
console.log("Geladene Daten:", jsonData);
|
||||
|
||||
if (Array.isArray(jsonData)) {
|
||||
dispatch(setChartData(jsonData));
|
||||
} else {
|
||||
console.error("Erwartetes Array, aber erhalten:", data);
|
||||
console.error("Erwartetes Array, aber erhalten:", jsonData);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Daten:", error);
|
||||
console.error("Fehler beim Laden der Mock-Daten:", error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// components/main/kabelueberwachung/kue705FO/Charts/LoopMeasurementChart/LoopMeasurementChart.tsx
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import Chart from "chart.js/auto";
|
||||
|
||||
@@ -6,5 +6,5 @@
|
||||
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
|
||||
|
||||
*/
|
||||
const webVersion = "1.6.65";
|
||||
const webVersion = "1.6.66";
|
||||
export default webVersion;
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
// Feste Mock-Daten für DIA0, DIA1, DIA2
|
||||
const mockDataDIA0 = [
|
||||
{ t: "2025-02-14 12:33:00", m: 11.0, v: 1, i: 11.0, a: 11.0 },
|
||||
{ t: "2025-02-14 12:30:00", m: 11.2, v: 1, i: 11.0, a: 11.4 },
|
||||
{ t: "2025-02-14 12:27:00", m: 10.8, v: 1, i: 10.5, a: 11.2 },
|
||||
];
|
||||
|
||||
const mockDataDIA1 = [
|
||||
{ t: "2025-02-14 12:00:00", i: 10.5, a: 11.0, g: 10.8 },
|
||||
{ t: "2025-02-14 11:00:00", i: 10.0, a: 10.8, g: 10.4 },
|
||||
{ t: "2025-02-14 10:00:00", i: 9.5, a: 10.2, g: 9.8 },
|
||||
];
|
||||
|
||||
const mockDataDIA2 = [
|
||||
{ t: "2025-02-14 00:00:00", i: 10.3, a: 10.9, g: 10.6 },
|
||||
{ t: "2025-02-13 00:00:00", i: 9.8, a: 10.4, g: 10.1 },
|
||||
];
|
||||
|
||||
// API-Handler für Mock-Daten
|
||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { DIA0, DIA1, DIA2 } = req.query;
|
||||
|
||||
let responseData = [];
|
||||
|
||||
if (DIA0) {
|
||||
responseData = mockDataDIA0;
|
||||
} else if (DIA1) {
|
||||
responseData = mockDataDIA1;
|
||||
} else if (DIA2) {
|
||||
responseData = mockDataDIA2;
|
||||
} else {
|
||||
return res
|
||||
.status(400)
|
||||
.json({
|
||||
error:
|
||||
"Kein gültiger Parameter übergeben. Verwende DIA0, DIA1 oder DIA2.",
|
||||
});
|
||||
}
|
||||
|
||||
res.status(200).json(responseData);
|
||||
}
|
||||
5
public/CPLmockData/kuesChartData/DIA0.json
Normal file
5
public/CPLmockData/kuesChartData/DIA0.json
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
{ "t": "2025-02-14 12:33:00", "m": 11.0, "v": 1, "i": 11.0, "a": 11.0 },
|
||||
{ "t": "2025-02-14 12:30:00", "m": 11.2, "v": 1, "i": 11.0, "a": 11.4 },
|
||||
{ "t": "2025-02-14 12:27:00", "m": 10.8, "v": 1, "i": 10.5, "a": 11.2 }
|
||||
]
|
||||
5
public/CPLmockData/kuesChartData/DIA1.json
Normal file
5
public/CPLmockData/kuesChartData/DIA1.json
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
{ "t": "2025-02-14 12:00:00", "i": 10.5, "a": 11.0, "g": 10.8 },
|
||||
{ "t": "2025-02-14 11:00:00", "i": 10.0, "a": 10.8, "g": 10.4 },
|
||||
{ "t": "2025-02-14 10:00:00", "i": 9.5, "a": 10.2, "g": 9.8 }
|
||||
]
|
||||
4
public/CPLmockData/kuesChartData/DIA2.json
Normal file
4
public/CPLmockData/kuesChartData/DIA2.json
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
{ "t": "2025-02-14 00:00:00", "i": 10.3, "a": 10.9, "g": 10.6 },
|
||||
{ "t": "2025-02-13 00:00:00", "i": 9.8, "a": 10.4, "g": 10.1 }
|
||||
]
|
||||
Reference in New Issue
Block a user