refactor: lade OPC UA Daten direkt in NetworkInfo-Komponente statt global in _app.tsx
- Thunk `fetchOpcUaSettingsThunk` wird jetzt nur bei Anzeige von NetworkInfo ausgeführt - Reduzierte Netzwerklast und bessere Trennung von Zuständigkeiten - Entfernt globalen OPC UA-Aufruf aus _app.tsx
This commit is contained in:
@@ -46,7 +46,6 @@ interface OpcUaSettings {
|
||||
export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const requiredVars: string[] = [
|
||||
"win_last20Messages",
|
||||
"win_deviceName",
|
||||
"win_mac1",
|
||||
"win_ip",
|
||||
@@ -86,21 +85,8 @@ export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
"win_kueOverflow",
|
||||
"win_tdrLast",
|
||||
"win_appVersion",
|
||||
"win_analogeEingaenge1",
|
||||
"win_analogeEingaenge2",
|
||||
"win_analogeEingaenge3",
|
||||
"win_analogeEingaenge4",
|
||||
"win_analogeEingaenge5",
|
||||
"win_analogeEingaenge6",
|
||||
"win_analogeEingaenge7",
|
||||
"win_analogeEingaenge8",
|
||||
"win_da_state",
|
||||
"win_da_bezeichnung",
|
||||
"win_opcUaZustand",
|
||||
"win_opcUaActiveClientCount",
|
||||
"win_opcUaNodesetName",
|
||||
"win_opcUaEncryption", // ✅ NEU: Verschlüsselung von OPC-UA
|
||||
"win_opcUaUsers", // ✅ NEU: OPC-UA Benutzerliste
|
||||
];
|
||||
|
||||
const scripts: string[] = [
|
||||
@@ -150,7 +136,6 @@ export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
|
||||
// ✅ Redux mit Systemvariablen aktualisieren
|
||||
loadAndStoreSystemSettings(win);
|
||||
loadAndStoreOpcUaSettings(win);
|
||||
|
||||
resolve(variablesObj);
|
||||
})
|
||||
@@ -180,62 +165,6 @@ const loadAndStoreSystemSettings = (win: CustomWindow) => {
|
||||
store.dispatch(setSystemSettings(settings));
|
||||
};
|
||||
|
||||
// ✅ Funktion zum Speichern von OPC-UA Variablen in Redux
|
||||
const loadAndStoreOpcUaSettings = (win: CustomWindow) => {
|
||||
// ✅ Aktuellen Redux-Status holen
|
||||
const currentState = store.getState().opcuaSettings;
|
||||
|
||||
// ✅ Nur setzen, wenn sich der Zustand geändert hat
|
||||
if (currentState.opcUaZustand !== win.win_opcUaZustand) {
|
||||
store.dispatch(setOpcUaZustand(win.win_opcUaZustand || "Offline"));
|
||||
}
|
||||
|
||||
// ✅ Nur setzen, wenn sich die Verschlüsselung geändert hat
|
||||
if (currentState.encryption !== win.win_opcUaEncryption) {
|
||||
store.dispatch(setOpcUaEncryption(win.win_opcUaEncryption || "None"));
|
||||
}
|
||||
|
||||
// ✅ Nur setzen, wenn sich die Anzahl der aktiven Clients geändert hat
|
||||
if (currentState.opcUaActiveClientCount !== win.win_opcUaActiveClientCount) {
|
||||
store.dispatch(
|
||||
setOpcUaActiveClientCount(win.win_opcUaActiveClientCount || 0)
|
||||
);
|
||||
}
|
||||
|
||||
// ✅ Nur setzen, wenn sich der Nodeset-Name geändert hat
|
||||
if (currentState.opcUaNodesetName !== win.win_opcUaNodesetName) {
|
||||
store.dispatch(
|
||||
setOpcUaNodesetName(win.win_opcUaNodesetName || "DefaultNodeset")
|
||||
);
|
||||
}
|
||||
|
||||
// ✅ Benutzer synchronisieren (aber nicht überschreiben, wenn manuell hinzugefügt)
|
||||
if (Array.isArray(win.win_opcUaUsers) && win.win_opcUaUsers.length > 0) {
|
||||
const newUsers = win.win_opcUaUsers;
|
||||
const currentUsers = currentState.users;
|
||||
|
||||
// ✅ Vorhandene Benutzer entfernen, die nicht mehr in `window` sind
|
||||
currentUsers.forEach((user) => {
|
||||
if (!newUsers.some((newUser) => newUser.username === user.username)) {
|
||||
store.dispatch(removeOpcUaUser(user.id));
|
||||
}
|
||||
});
|
||||
|
||||
// ✅ Nur neue Benutzer hinzufügen, falls sie nicht existieren
|
||||
newUsers.forEach((user) => {
|
||||
if (
|
||||
!currentUsers.some(
|
||||
(existingUser) => existingUser.username === user.username
|
||||
)
|
||||
) {
|
||||
store.dispatch(
|
||||
addOpcUaUser({ username: user.username, password: user.password })
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// ✅ Funktion zum Speichern der digitalen Ausgänge in Redux
|
||||
const loadAndStoreDigitalOutputs = (win: CustomWindow) => {
|
||||
console.log("Prüfe digitale Ausgänge in window:");
|
||||
|
||||
Reference in New Issue
Block a user