- Alle Schleifen- und Isolationswiderstandsdaten werden zentral in loopChart.data gespeichert - Redux State unterstützt nun strukturierte Speicherung nach mode (DIA0–DIA2) und type (3/4) - Bestehender Thunk fetchLoopChartDataThunk wurde angepasst zur Wiederverwendung - Zugriff aus Komponente via loopData["DIAx"][type] möglich
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
/**
|
|
* Bestimmt die richtige API-URL für digitale Eingänge basierend auf Umgebung.
|
|
*/
|
|
const getApiUrl = () => {
|
|
if (typeof window === "undefined") {
|
|
console.error("❌ `window` ist nicht verfügbar (Server-Side Rendering)");
|
|
return null;
|
|
}
|
|
|
|
return process.env.NODE_ENV === "development"
|
|
? `${window.location.origin}/CPLmockData/SERVICE/de.js`
|
|
: `${window.location.origin}/CPL?/CPL/SERVICE/de.js`;
|
|
};
|
|
|
|
/**
|
|
* Holt die digitalen Eingänge und formatiert die Daten für Redux.
|
|
*/
|
|
export const fetchDigitaleEingaenge = async () => {
|
|
try {
|
|
const apiUrl = getApiUrl();
|
|
if (!apiUrl) return null;
|
|
|
|
// console.log(`📡 API-Request an: ${apiUrl}`);
|
|
const response = await fetch(apiUrl);
|
|
if (!response.ok) {
|
|
throw new Error(`❌ Fehler: ${response.status} ${response.statusText}`);
|
|
}
|
|
|
|
const rawData = await response.text();
|
|
// console.log("✅ Rohdaten erfolgreich geladen:", rawData);
|
|
|
|
// **JavaScript-Variablen als Skript einfügen**
|
|
const script = document.createElement("script");
|
|
script.innerHTML = rawData;
|
|
document.body.appendChild(script);
|
|
|
|
// **Daten ins Redux-Format umwandeln**
|
|
const formattedData = win_de_state.map((status, index) => ({
|
|
id: index + 1,
|
|
label: win_de_label[index] || `DE${index + 1}`,
|
|
status: status === 1,
|
|
counter: win_counter[index] || 0,
|
|
flutter: win_flutter[index] || 0,
|
|
}));
|
|
|
|
// console.log("✅ Formatierte Daten:", formattedData);
|
|
return formattedData;
|
|
} catch (error) {
|
|
console.error("❌ Fehler beim Laden der digitalen Eingänge:", error);
|
|
return null;
|
|
}
|
|
};
|