feat: OPC-UA Einstellungen in eigenen Redux Slice ausgelagert
- OPC-UA bezogene Variablen aus `variablesSlice` entfernt und in `opcuaSettingsSlice` ausgelagert
- Neue Redux Actions für:
- `setOpcUaZustand` (OPC-UA Zustand setzen)
- `setOpcUaEncryption` (Verschlüsselung setzen)
- `setOpcUaActiveClientCount` (Anzahl aktiver Clients setzen)
- `setOpcUaNodesetName` (Nodeset-Name setzen)
- `addOpcUaUser` & `removeOpcUaUser` (Benutzerverwaltung)
- `loadWindowVariables.ts` angepasst, um OPC-UA-Daten in `opcuaSettingsSlice` zu speichern
- Benutzerverwaltung optimiert:
- Manuell hinzugefügte Benutzer bleiben erhalten
- Benutzer werden nur aktualisiert, wenn sich `window.win_opcUaUsers` ändert
- Keine automatische Statusumschaltung mehr beim OPC-UA-Server-Button
Jetzt ist die OPC-UA Verwaltung sauber getrennt und stabil! 🚀
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
// /utils/loadWindowVariables.ts
|
||||
import store from "../redux/store";
|
||||
import { setSystemSettings } from "../redux/slices/systemSettingsSlice";
|
||||
import {
|
||||
toggleOpcUaServer,
|
||||
setOpcUaEncryption,
|
||||
setOpcUaZustand,
|
||||
setOpcUaActiveClientCount,
|
||||
setOpcUaNodesetName,
|
||||
addOpcUaUser,
|
||||
removeOpcUaUser,
|
||||
} from "../redux/slices/opcuaSettingsSlice";
|
||||
|
||||
// ✅ Interface für `window`-Objekt zur TypeScript-Sicherheit
|
||||
interface CustomWindow extends Window {
|
||||
@@ -21,6 +31,16 @@ interface SystemSettings {
|
||||
ntpActive: boolean;
|
||||
}
|
||||
|
||||
// ✅ Interface für OPC-UA Einstellungen im Redux-Store
|
||||
interface OpcUaSettings {
|
||||
isEnabled: boolean;
|
||||
encryption: string;
|
||||
opcUaZustand: string;
|
||||
opcUaActiveClientCount: number;
|
||||
opcUaNodesetName: string;
|
||||
users: { id: number; username: string; password: string }[];
|
||||
}
|
||||
|
||||
// ✅ Hauptfunktion zum Laden von `window`-Variablen
|
||||
export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -73,11 +93,13 @@ export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
"win_analogeEingaenge6",
|
||||
"win_analogeEingaenge7",
|
||||
"win_analogeEingaenge8",
|
||||
"win_da_state",
|
||||
"win_da_bezeichnung",
|
||||
"win_opcUaZustand",
|
||||
"win_opcUaActiveClientCount",
|
||||
"win_opcUaNodesetName",
|
||||
"win_da_state",
|
||||
"win_da_bezeichnung",
|
||||
"win_opcUaEncryption", // ✅ NEU: Verschlüsselung von OPC-UA
|
||||
"win_opcUaUsers", // ✅ NEU: OPC-UA Benutzerliste
|
||||
];
|
||||
|
||||
const scripts: string[] = [
|
||||
@@ -127,6 +149,7 @@ export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
|
||||
// ✅ Redux mit Systemvariablen aktualisieren
|
||||
loadAndStoreSystemSettings(win);
|
||||
loadAndStoreOpcUaSettings(win);
|
||||
|
||||
resolve(variablesObj);
|
||||
})
|
||||
@@ -155,3 +178,59 @@ 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 })
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user