fix: handleSubmit für SettimgsModal
This commit is contained in:
@@ -5,6 +5,7 @@ import "bootstrap-icons/font/bootstrap-icons.css"; // Import Bootstrap Icons
|
|||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { current } from "@reduxjs/toolkit";
|
import { current } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
|
import handleClearDatabase from "./handlers/handleClearDatabase";
|
||||||
import handleReboot from "./handlers/handleReboot";
|
import handleReboot from "./handlers/handleReboot";
|
||||||
import handleSetDateTime from "./handlers/handleSetDateTime";
|
import handleSetDateTime from "./handlers/handleSetDateTime";
|
||||||
import handleSubmit from "./handlers/handleSubmit";
|
import handleSubmit from "./handlers/handleSubmit";
|
||||||
|
|||||||
@@ -1,67 +1,72 @@
|
|||||||
// components/modales/handlers/handleSubmit.js
|
// components/modales/handlers/handleSubmit.js
|
||||||
|
import handleReboot from "./handleReboot";
|
||||||
const handleSubmit = (originalValues, currentValues) => {
|
const handleSubmit = (originalValues, currentValues) => {
|
||||||
const changes = {};
|
const changes = {};
|
||||||
|
let networkChanges = false;
|
||||||
|
|
||||||
// Überprüfe, welche Werte sich geändert haben
|
// Überprüfe, welche Werte sich geändert haben, wobei Netzwerk- oder Namensänderungen einen Neustart erfordern
|
||||||
if (name !== originalValues.name) {
|
if (currentValues.name !== originalValues.name) {
|
||||||
changes.SNNA = name;
|
changes.SNNA = currentValues.name;
|
||||||
|
networkChanges = true;
|
||||||
}
|
}
|
||||||
if (ip !== originalValues.ip) {
|
if (currentValues.ip !== originalValues.ip) {
|
||||||
changes.SEI01 = ip;
|
changes.SEI01 = currentValues.ip;
|
||||||
|
networkChanges = true;
|
||||||
}
|
}
|
||||||
if (subnet !== originalValues.subnet) {
|
if (currentValues.subnet !== originalValues.subnet) {
|
||||||
changes.SEI02 = subnet;
|
changes.SEI02 = currentValues.subnet;
|
||||||
|
networkChanges = true;
|
||||||
}
|
}
|
||||||
if (gateway !== originalValues.gateway) {
|
if (currentValues.gateway !== originalValues.gateway) {
|
||||||
changes.SEI03 = gateway;
|
changes.SEI03 = currentValues.gateway;
|
||||||
|
networkChanges = true;
|
||||||
}
|
}
|
||||||
if (ntp1 !== originalValues.ntp1) {
|
if (currentValues.ntp1 !== originalValues.ntp1) {
|
||||||
changes.SNIP1 = ntp1;
|
changes.SNIP1 = currentValues.ntp1;
|
||||||
}
|
}
|
||||||
if (ntp2 !== originalValues.ntp2) {
|
if (currentValues.ntp2 !== originalValues.ntp2) {
|
||||||
changes.SNIP2 = ntp2;
|
changes.SNIP2 = currentValues.ntp2;
|
||||||
}
|
}
|
||||||
if (ntp3 !== originalValues.ntp3) {
|
if (currentValues.ntp3 !== originalValues.ntp3) {
|
||||||
changes.SNIP3 = ntp3;
|
changes.SNIP3 = currentValues.ntp3;
|
||||||
}
|
}
|
||||||
if (ntpTimezone !== originalValues.ntpTimezone) {
|
if (currentValues.ntpTimezone !== originalValues.ntpTimezone) {
|
||||||
changes.SNTZ = ntpTimezone;
|
changes.SNTZ = currentValues.ntpTimezone;
|
||||||
}
|
}
|
||||||
if (active !== originalValues.active) {
|
if (currentValues.active !== originalValues.active) {
|
||||||
changes.SNAC = active;
|
changes.SNAC = currentValues.active;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Falls Änderungen vorhanden sind, sende die neuen Daten
|
// Falls Änderungen vorhanden sind, sende die neuen Daten
|
||||||
if (Object.keys(changes).length > 0) {
|
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;
|
let currentPath = window.location.pathname;
|
||||||
if (!currentPath.endsWith(".html")) {
|
if (!currentPath.endsWith(".html")) {
|
||||||
currentPath += ".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}`;
|
let url = `${window.location.origin}/CPL?${currentPath}`;
|
||||||
|
|
||||||
Object.keys(changes).forEach((paramKey) => {
|
Object.keys(changes).forEach((paramKey) => {
|
||||||
url += `&${paramKey}=${encodeURIComponent(changes[paramKey])}`;
|
url += `&${paramKey}=${encodeURIComponent(changes[paramKey])}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log the full URL to the console for debugging
|
// Logge die URL zur Überprüfung
|
||||||
console.log(url);
|
console.log(url);
|
||||||
|
|
||||||
// Send the URL with changes to the server
|
// Sende die URL mit den Änderungen an den Server
|
||||||
fetch(url, { method: "GET" })
|
fetch(url, { method: "GET" });
|
||||||
.then((response) => {
|
|
||||||
if (response.ok) {
|
alert("Daten erfolgreich gesendet!");
|
||||||
alert("Daten erfolgreich gesendet!");
|
|
||||||
} else {
|
// Hinweis und Neustart bei Namens- oder Netzwerkeinstellungen
|
||||||
alert("Fehler beim Senden der Daten!");
|
if (networkChanges) {
|
||||||
}
|
alert(
|
||||||
})
|
"Hinweis: Die Änderungen in CPL-Name und den Netzwerkeinstellungen werden erst nach einem Neustart des CPL wirksam."
|
||||||
.catch((error) => {
|
);
|
||||||
console.error("Fehler:", error);
|
handleReboot(); // handleReboot enthält bereits die Bestätigung
|
||||||
alert("Fehler beim Senden der Daten!");
|
}
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
alert("Keine Änderungen vorgenommen.");
|
alert("Keine Änderungen vorgenommen.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user