refactor: Naming-Konventionen für digitaleEingaenge umgesetzt

- digitaleEingaengeMockData.js = strukturierte Datenbasis für Development
- digitaleEingaengeAPIHandler.ts = API-Endpunkt zur Auslieferung im Dev
- fetchDigitaleEingaengeService.ts = Service zur Umwandlung von window-Variablen
- Naming-Schema sorgt für klare Struktur und gute Lernbarkeit
This commit is contained in:
Ismail Ali
2025-04-15 08:55:50 +02:00
parent fb87e7b3ae
commit f709c2e3b7
22 changed files with 22 additions and 22 deletions

View File

@@ -0,0 +1,37 @@
// ✅ 1. Service: /services/fetchOpcUaSettingsService.ts
export const fetchOpcUaSettings = async () => {
try {
if (typeof window === "undefined") return null;
// ✅ opcua.js nur bei Bedarf nachladen (Pfad abhängig von Umgebung)
const scriptSrc =
process.env.NEXT_PUBLIC_NODE_ENV === "production"
? "/CPL?/CPL/SERVICE/opcua.js"
: "/apiMockData/SERVICE/opcua.js";
await new Promise<void>((resolve, reject) => {
const script = document.createElement("script");
script.src = scriptSrc;
script.async = true;
script.onload = () => resolve();
script.onerror = () => reject("❌ Fehler beim Laden von opcua.js");
document.body.appendChild(script);
});
const win = window as any;
const data = {
zustand: win.win_opcUaZustand || "Offline",
encryption: win.win_opcUaEncryption || "None",
clientCount: win.win_opcUaActiveClientCount || 0,
nodesetName: win.win_opcUaNodesetName || "DefaultNodeset",
users: Array.isArray(win.win_opcUaUsers) ? win.win_opcUaUsers : [],
};
return data;
} catch (error) {
console.error("Fehler beim Laden der OPC UA Daten:", error);
return null;
}
};