diff --git a/components/modales/settingsModal/SettingsModal.jsx b/components/modales/settingsModal/SettingsModal.jsx index c3118e1..6420ddb 100644 --- a/components/modales/settingsModal/SettingsModal.jsx +++ b/components/modales/settingsModal/SettingsModal.jsx @@ -5,6 +5,7 @@ import "bootstrap-icons/font/bootstrap-icons.css"; // Import Bootstrap Icons import { useSelector } from "react-redux"; import { current } from "@reduxjs/toolkit"; +import handleClearDatabase from "./handlers/handleClearDatabase"; import handleReboot from "./handlers/handleReboot"; import handleSetDateTime from "./handlers/handleSetDateTime"; import handleSubmit from "./handlers/handleSubmit"; diff --git a/components/modales/settingsModal/handlers/handleSubmit.js b/components/modales/settingsModal/handlers/handleSubmit.js index eb95289..ab3d049 100644 --- a/components/modales/settingsModal/handlers/handleSubmit.js +++ b/components/modales/settingsModal/handlers/handleSubmit.js @@ -1,67 +1,72 @@ // components/modales/handlers/handleSubmit.js +import handleReboot from "./handleReboot"; const handleSubmit = (originalValues, currentValues) => { const changes = {}; + let networkChanges = false; - // Überprüfe, welche Werte sich geändert haben - if (name !== originalValues.name) { - changes.SNNA = name; + // Überprüfe, welche Werte sich geändert haben, wobei Netzwerk- oder Namensänderungen einen Neustart erfordern + if (currentValues.name !== originalValues.name) { + changes.SNNA = currentValues.name; + networkChanges = true; } - if (ip !== originalValues.ip) { - changes.SEI01 = ip; + if (currentValues.ip !== originalValues.ip) { + changes.SEI01 = currentValues.ip; + networkChanges = true; } - if (subnet !== originalValues.subnet) { - changes.SEI02 = subnet; + if (currentValues.subnet !== originalValues.subnet) { + changes.SEI02 = currentValues.subnet; + networkChanges = true; } - if (gateway !== originalValues.gateway) { - changes.SEI03 = gateway; + if (currentValues.gateway !== originalValues.gateway) { + changes.SEI03 = currentValues.gateway; + networkChanges = true; } - if (ntp1 !== originalValues.ntp1) { - changes.SNIP1 = ntp1; + if (currentValues.ntp1 !== originalValues.ntp1) { + changes.SNIP1 = currentValues.ntp1; } - if (ntp2 !== originalValues.ntp2) { - changes.SNIP2 = ntp2; + if (currentValues.ntp2 !== originalValues.ntp2) { + changes.SNIP2 = currentValues.ntp2; } - if (ntp3 !== originalValues.ntp3) { - changes.SNIP3 = ntp3; + if (currentValues.ntp3 !== originalValues.ntp3) { + changes.SNIP3 = currentValues.ntp3; } - if (ntpTimezone !== originalValues.ntpTimezone) { - changes.SNTZ = ntpTimezone; + if (currentValues.ntpTimezone !== originalValues.ntpTimezone) { + changes.SNTZ = currentValues.ntpTimezone; } - if (active !== originalValues.active) { - changes.SNAC = active; + if (currentValues.active !== originalValues.active) { + changes.SNAC = currentValues.active; } // Falls Änderungen vorhanden sind, sende die neuen Daten if (Object.keys(changes).length > 0) { - // Get the current path and ensure it ends with ".html" + // Pfad anpassen, um sicherzustellen, dass er auf ".html" endet let currentPath = window.location.pathname; if (!currentPath.endsWith(".html")) { currentPath += ".html"; } - // Full URL with host, current path, and all change parameters + // Erstelle die vollständige URL mit Host, Pfad und Parametern let url = `${window.location.origin}/CPL?${currentPath}`; Object.keys(changes).forEach((paramKey) => { url += `&${paramKey}=${encodeURIComponent(changes[paramKey])}`; }); - // Log the full URL to the console for debugging + // Logge die URL zur Überprüfung console.log(url); - // Send the URL with changes to the server - fetch(url, { method: "GET" }) - .then((response) => { - if (response.ok) { - alert("Daten erfolgreich gesendet!"); - } else { - alert("Fehler beim Senden der Daten!"); - } - }) - .catch((error) => { - console.error("Fehler:", error); - alert("Fehler beim Senden der Daten!"); - }); + // Sende die URL mit den Änderungen an den Server + fetch(url, { method: "GET" }); + + alert("Daten erfolgreich gesendet!"); + + // Hinweis und Neustart bei Namens- oder Netzwerkeinstellungen + if (networkChanges) { + alert( + "Hinweis: Die Änderungen in CPL-Name und den Netzwerkeinstellungen werden erst nach einem Neustart des CPL wirksam." + ); + handleReboot(); // handleReboot enthält bereits die Bestätigung + } } else { alert("Keine Änderungen vorgenommen."); }