feat: handleSave Funktion ausgelagert und KueModal strukturiert
- handleSave in separate Datei handle-save.js ausgelagert, um KueModal-Komponente modularer und wartbarer zu gestalten - handleSaveWrapper in KueModal hinzugefügt, um Parameter an handleSave zu übergeben - KueModal umgestaltet, um Funktionen und Redux-Dispatch klarer zu organisieren - Konsistente Verwendung von Parametern und State-Updates für sauberen Codefluss
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
// components/modales/handlers/handleClearDatabase.js
|
||||
const handleClearDatabase = async () => {
|
||||
const confirmClear = window.confirm(
|
||||
"Sind Sie sicher, dass Sie die Datenbank leeren möchten?"
|
||||
);
|
||||
if (!confirmClear) return;
|
||||
|
||||
// Get the current path and ensure it ends with ".html"
|
||||
let currentPath = window.location.pathname;
|
||||
if (!currentPath.endsWith(".html")) {
|
||||
currentPath += ".html";
|
||||
}
|
||||
|
||||
// Full URL with host, current path, and clear database command
|
||||
const url = `${window.location.origin}/CPL?${currentPath}&DEDB=1`;
|
||||
|
||||
// Log the full URL to the console for debugging
|
||||
console.log(url);
|
||||
|
||||
// Send the clear database command to the server using fetch and GET method
|
||||
try {
|
||||
const response = await fetch(url, { method: "GET" });
|
||||
if (response.ok) {
|
||||
alert("Datenbank erfolgreich geleert!");
|
||||
} else {
|
||||
alert("Fehler beim Leeren der Datenbank!");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler:", error);
|
||||
alert("Fehler beim Leeren der Datenbank!");
|
||||
}
|
||||
};
|
||||
19
components/modales/settingsModal/handlers/handleReboot.js
Normal file
19
components/modales/settingsModal/handlers/handleReboot.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// components/modales/handlers/handleReboot.js
|
||||
const handleReboot = () => {
|
||||
if (
|
||||
window.confirm("Sind Sie sicher, dass Sie den CPL neu starten möchten?")
|
||||
) {
|
||||
let currentPath = window.location.pathname;
|
||||
if (!currentPath.endsWith(".html")) {
|
||||
currentPath += ".html";
|
||||
}
|
||||
|
||||
const url = `${window.location.origin}/CPL?${currentPath}&BOOT=1`;
|
||||
console.log(url);
|
||||
fetch(url, { method: "GET" }).finally(() => {
|
||||
window.location.href = `/wait`;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default handleReboot;
|
||||
@@ -0,0 +1,43 @@
|
||||
//components/modales/handlers/handleSetDateTime.js
|
||||
const handleSetDateTime = () => {
|
||||
const currentDate = new Date();
|
||||
|
||||
// Format date and time as required by the system without leading zeros:
|
||||
const year = currentDate.getFullYear().toString().slice(-2); // Last two digits of the year
|
||||
const month = Number(currentDate.getMonth() + 1); // Convert to Number to remove leading zero
|
||||
const day = Number(currentDate.getDate()); // Convert to Number to remove leading zero
|
||||
|
||||
const hours = Number(currentDate.getHours()); // Convert to Number to remove leading zero
|
||||
const minutes = Number(currentDate.getMinutes()); // Convert to Number to remove leading zero
|
||||
const seconds = Number(currentDate.getSeconds()); // Convert to Number to remove leading zero
|
||||
|
||||
// Date and Time commands
|
||||
const dateCommand = `CLK00=${year}-${month}-${day}`;
|
||||
const timeCommand = `CLK01=${hours}-${minutes}-${seconds}`;
|
||||
|
||||
// Get the current path and ensure it ends with ".html"
|
||||
let currentPath = window.location.pathname;
|
||||
if (!currentPath.endsWith(".html")) {
|
||||
currentPath += ".html";
|
||||
}
|
||||
|
||||
// Full URL with host, current path, date, and time commands
|
||||
const url = `${window.location.origin}/CPL?${currentPath}&${dateCommand}&${timeCommand}`;
|
||||
|
||||
// Log the full URL to the console
|
||||
console.log(url);
|
||||
|
||||
// Send the commands to the server using fetch and GET method
|
||||
fetch(url, { method: "GET" })
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
alert("Datum und Uhrzeit erfolgreich gesetzt!");
|
||||
} else {
|
||||
alert("Fehler beim Setzen von Datum und Uhrzeit!");
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Fehler:", error);
|
||||
alert("Fehler beim Setzen von Datum und Uhrzeit!");
|
||||
});
|
||||
};
|
||||
68
components/modales/settingsModal/handlers/handleSubmit.js
Normal file
68
components/modales/settingsModal/handlers/handleSubmit.js
Normal file
@@ -0,0 +1,68 @@
|
||||
// components/modales/handlers/handleSubmit.js
|
||||
const handleSubmit = (originalValues, currentValues) => {
|
||||
const changes = {};
|
||||
|
||||
// Überprüfe, welche Werte sich geändert haben
|
||||
if (name !== originalValues.name) {
|
||||
changes.SNNA = name;
|
||||
}
|
||||
if (ip !== originalValues.ip) {
|
||||
changes.SEI01 = ip;
|
||||
}
|
||||
if (subnet !== originalValues.subnet) {
|
||||
changes.SEI02 = subnet;
|
||||
}
|
||||
if (gateway !== originalValues.gateway) {
|
||||
changes.SEI03 = gateway;
|
||||
}
|
||||
if (ntp1 !== originalValues.ntp1) {
|
||||
changes.SNIP1 = ntp1;
|
||||
}
|
||||
if (ntp2 !== originalValues.ntp2) {
|
||||
changes.SNIP2 = ntp2;
|
||||
}
|
||||
if (ntp3 !== originalValues.ntp3) {
|
||||
changes.SNIP3 = ntp3;
|
||||
}
|
||||
if (ntpTimezone !== originalValues.ntpTimezone) {
|
||||
changes.SNTZ = ntpTimezone;
|
||||
}
|
||||
if (active !== originalValues.active) {
|
||||
changes.SNAC = 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"
|
||||
let currentPath = window.location.pathname;
|
||||
if (!currentPath.endsWith(".html")) {
|
||||
currentPath += ".html";
|
||||
}
|
||||
|
||||
// Full URL with host, current path, and all change parameters
|
||||
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
|
||||
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!");
|
||||
});
|
||||
} else {
|
||||
alert("Keine Änderungen vorgenommen.");
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user