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,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!");
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user