feat: systemSettingsSlice hinzugefügt und Header sowie Einstellungen angepasst
- Neuen Redux Slice `systemSettingsSlice` erstellt, um Systemdaten zentral zu verwalten. - Header-Icon für Systemeinstellungen holt jetzt Daten aus `systemSettingsSlice` statt `variablesSlice`. - Die Einstellungen-Seite (`Allgemeine Einstellungen`) wurde umgestellt und liest nun ebenfalls aus `systemSettingsSlice`. - UI-Optimierungen für die Einstellungen-Seite, um alle Eingabefelder kompakter darzustellen.
This commit is contained in:
@@ -1,9 +1,28 @@
|
||||
// utils/loadWindowVariables.ts
|
||||
interface WindowVariables {
|
||||
[key: string]: any; // Allgemeiner Typ für die Dynamik, kann spezifischer angepasst werden, falls bekannt
|
||||
import store from "../redux/store";
|
||||
import { setSystemSettings } from "../redux/slices/systemSettingsSlice";
|
||||
|
||||
// ✅ Interface für `window`-Objekt zur TypeScript-Sicherheit
|
||||
interface CustomWindow extends Window {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export async function loadWindowVariables(): Promise<WindowVariables> {
|
||||
// ✅ Interface für System-Einstellungen im Redux-Store
|
||||
interface SystemSettings {
|
||||
deviceName: string;
|
||||
mac1: string;
|
||||
ip: string;
|
||||
subnet: string;
|
||||
gateway: string;
|
||||
cplInternalTimestamp: string;
|
||||
ntp1: string;
|
||||
ntp2: string;
|
||||
ntp3: string;
|
||||
ntpTimezone: string;
|
||||
ntpActive: boolean;
|
||||
}
|
||||
|
||||
// ✅ Hauptfunktion zum Laden von `window`-Variablen
|
||||
export async function loadWindowVariables(): Promise<Record<string, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const requiredVars: string[] = [
|
||||
"win_last20Messages",
|
||||
@@ -61,6 +80,16 @@ export async function loadWindowVariables(): Promise<WindowVariables> {
|
||||
"win_da_bezeichnung",
|
||||
];
|
||||
|
||||
const scripts: string[] = [
|
||||
"da.js",
|
||||
"de.js",
|
||||
"ae.js",
|
||||
"kueData.js",
|
||||
"Start.js",
|
||||
"System.js",
|
||||
"opcua.js",
|
||||
];
|
||||
|
||||
const loadScript = (src: string): Promise<void> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
@@ -76,40 +105,29 @@ export async function loadWindowVariables(): Promise<WindowVariables> {
|
||||
});
|
||||
};
|
||||
|
||||
const scripts: string[] = [
|
||||
"da.js",
|
||||
"de.js",
|
||||
"ae.js",
|
||||
"kueData.js",
|
||||
"Start.js",
|
||||
"System.js",
|
||||
"opcua.js",
|
||||
];
|
||||
|
||||
// ✅ Lade alle Skripte nacheinander
|
||||
scripts
|
||||
.reduce(
|
||||
(promise, script) => promise.then(() => loadScript(script)),
|
||||
Promise.resolve()
|
||||
)
|
||||
.then(() => {
|
||||
const variablesObj: WindowVariables = requiredVars.reduce(
|
||||
(acc: WindowVariables, variable: string) => {
|
||||
// Prüfe, ob die Variable auf dem window-Objekt existiert
|
||||
const winVar = (window as any)[variable];
|
||||
if (winVar !== undefined) {
|
||||
// Wenn es sich um kueID handelt, ersetze %20 durch Leerzeichen
|
||||
if (variable === "win_kueID" && Array.isArray(winVar)) {
|
||||
acc[variable.replace("win_", "")] = winVar.map((id: string) =>
|
||||
id.replace(/%20/g, " ")
|
||||
);
|
||||
} else {
|
||||
acc[variable.replace("win_", "")] = winVar;
|
||||
}
|
||||
const win = window as unknown as CustomWindow;
|
||||
|
||||
// ✅ Erstelle ein Objekt mit allen geladenen Variablen
|
||||
const variablesObj: Record<string, any> = requiredVars.reduce(
|
||||
(acc, variable) => {
|
||||
if (win[variable] !== undefined) {
|
||||
acc[variable.replace("win_", "")] = win[variable];
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{}
|
||||
);
|
||||
|
||||
// ✅ Redux mit Systemvariablen aktualisieren
|
||||
loadAndStoreSystemSettings(win);
|
||||
|
||||
resolve(variablesObj);
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -118,3 +136,22 @@ export async function loadWindowVariables(): Promise<WindowVariables> {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// ✅ Funktion zum Speichern von System-Variablen in Redux
|
||||
const loadAndStoreSystemSettings = (win: CustomWindow) => {
|
||||
const settings: SystemSettings = {
|
||||
deviceName: win.win_deviceName || "",
|
||||
mac1: win.win_mac1 || "",
|
||||
ip: win.win_ip || "",
|
||||
subnet: win.win_subnet || "",
|
||||
gateway: win.win_gateway || "",
|
||||
cplInternalTimestamp: win.win_cplInternalTimestamp || "",
|
||||
ntp1: win.win_ntp1 || "",
|
||||
ntp2: win.win_ntp2 || "",
|
||||
ntp3: win.win_ntp3 || "",
|
||||
ntpTimezone: win.win_ntpTimezone || "",
|
||||
ntpActive: win.win_ntpActive || false,
|
||||
};
|
||||
|
||||
store.dispatch(setSystemSettings(settings));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user