handleReboot, handleSetDateTime und handleClearDatabase in separate Datei einfügen
This commit is contained in:
@@ -4,6 +4,8 @@ import { ClipLoader } from "react-spinners";
|
||||
import "bootstrap-icons/font/bootstrap-icons.css"; // Import Bootstrap Icons
|
||||
import { useSelector } from "react-redux";
|
||||
import { current } from "@reduxjs/toolkit";
|
||||
import handleReboot from "./handlers/handleReboot";
|
||||
import handleClearDatabase from "./handlers/handleClearDatabase";
|
||||
|
||||
// Definiere das App-Element für ReactModal
|
||||
ReactModal.setAppElement("#__next");
|
||||
@@ -48,60 +50,6 @@ function SettingModal({ showModal, onClose }) {
|
||||
if (!currentPath.endsWith(".html")) {
|
||||
currentPath += ".html";
|
||||
}
|
||||
const handleReboot = () => {
|
||||
if (
|
||||
window.confirm("Sind Sie sicher, dass Sie den CPL neu starten möchten?")
|
||||
) {
|
||||
// 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 reboot command
|
||||
const url = `${window.location.origin}/CPL?${currentPath}&BOOT=1`;
|
||||
|
||||
// Log the full URL to the console for debugging
|
||||
console.log(url);
|
||||
|
||||
// Send the reboot command to the server using fetch and GET method
|
||||
fetch(url, { method: "GET" }).finally(() => {
|
||||
window.location.href = `/wait`; // Redirect to wait page on client side
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
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!");
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
const changes = {};
|
||||
@@ -171,49 +119,6 @@ function SettingModal({ showModal, onClose }) {
|
||||
}
|
||||
};
|
||||
|
||||
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!");
|
||||
});
|
||||
};
|
||||
|
||||
//---------------------------------------------------
|
||||
// Setze initiale Werte nur beim Öffnen des Modals
|
||||
useEffect(() => {
|
||||
|
||||
31
components/modales/handlers/handleClearDatabase.js
Normal file
31
components/modales/handlers/handleClearDatabase.js
Normal file
@@ -0,0 +1,31 @@
|
||||
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/handlers/handleReboot.js
Normal file
19
components/modales/handlers/handleReboot.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// 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;
|
||||
42
components/modales/handlers/handleSetDateTime.js
Normal file
42
components/modales/handlers/handleSetDateTime.js
Normal file
@@ -0,0 +1,42 @@
|
||||
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