From de1c94a6a22f44844401e10d71caf5ce8c12adf7 Mon Sep 17 00:00:00 2001 From: ISA Date: Fri, 8 Nov 2024 14:56:20 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20URLs=20f=C3=BCr=20Datum=20und=20Uhrzeit?= =?UTF-8?q?=20angepasst=20bei=20Systemzeit=20=C3=BCbernehmen=20Button,=20f?= =?UTF-8?q?=C3=BChrende=20Nullen=20entfernt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Die Funktion `handleSetDateTime` wurde angepasst, um das URL-Format den Anforderungen entsprechend zu gestalten. - Monat, Tag, Stunden, Minuten und Sekunden werden jetzt ohne führende Nullen dargestellt, um eine konsistentere Darstellung zu gewährleisten. - Die URL wird nun korrekt formatiert, z.B. `https://10.10.0.118/CPL?/dashboard.html&CLK00=24-11-8&CLK01=14-3-5` statt `https://10.10.0.118/CPL?/dashboard.html&CLK00=24-11-08&CLK01=14-03-05`. - Implementierung mit `Number()` zur Umwandlung und Entfernung der führenden Nullen. Diese Änderung verbessert die Lesbarkeit und die Kompatibilität des URL-Formats mit dem Zielsystem. --- components/modales/SettingsModal.jsx | 47 ++++++++++++++-------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/components/modales/SettingsModal.jsx b/components/modales/SettingsModal.jsx index a3ef980..57858b1 100644 --- a/components/modales/SettingsModal.jsx +++ b/components/modales/SettingsModal.jsx @@ -131,40 +131,38 @@ function SettingModal({ showModal, onClose }) { const handleSetDateTime = () => { const currentDate = new Date(); - // Format date and time as required by the system: + // 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 = String(currentDate.getMonth() + 1).padStart(2, "0"); // Month (1-12) - const day = String(currentDate.getDate()).padStart(2, "0"); // Day (1-31) + 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 = String(currentDate.getHours()).padStart(2, "0"); // Hours (0-23) - const minutes = String(currentDate.getMinutes()).padStart(2, "0"); // Minutes (0-59) - const seconds = String(currentDate.getSeconds()).padStart(2, "0"); // Seconds (0-59) + 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 command + // Date and Time commands const dateCommand = `CLK00=${year}-${month}-${day}`; - - // Time command const timeCommand = `CLK01=${hours}-${minutes}-${seconds}`; - // Log the URLs to the console - console.log(`/CPL?${dateCommand}`); - console.log(`/CPL?${timeCommand}`); + + // 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(`/CPL?${dateCommand}`, { method: "GET" }) + fetch(url, { method: "GET" }) .then((response) => { if (response.ok) { - alert("Datum erfolgreich gesetzt!"); - return fetch(`/CPL?${timeCommand}`, { method: "GET" }); + alert("Datum und Uhrzeit erfolgreich gesetzt!"); } else { - alert("Fehler beim Setzen des Datums!"); - throw new Error("Date setting failed."); - } - }) - .then((response) => { - if (response.ok) { - alert("Uhrzeit erfolgreich gesetzt!"); - } else { - alert("Fehler beim Setzen der Uhrzeit!"); + alert("Fehler beim Setzen von Datum und Uhrzeit!"); } }) .catch((error) => { @@ -172,6 +170,7 @@ function SettingModal({ showModal, onClose }) { alert("Fehler beim Setzen von Datum und Uhrzeit!"); }); }; + //--------------------------------------------------- // Setze initiale Werte nur beim Öffnen des Modals useEffect(() => {