fix: hide Firmware update button if admin not loged in
This commit is contained in:
@@ -6,6 +6,6 @@ NEXT_PUBLIC_USE_MOCK_BACKEND_LOOP_START=false
|
||||
NEXT_PUBLIC_EXPORT_STATIC=false
|
||||
NEXT_PUBLIC_USE_CGI=false
|
||||
# App-Versionsnummer
|
||||
NEXT_PUBLIC_APP_VERSION=1.6.510
|
||||
NEXT_PUBLIC_APP_VERSION=1.6.511
|
||||
NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter)
|
||||
|
||||
|
||||
@@ -5,5 +5,5 @@ NEXT_PUBLIC_CPL_API_PATH=/CPL
|
||||
NEXT_PUBLIC_EXPORT_STATIC=true
|
||||
NEXT_PUBLIC_USE_CGI=true
|
||||
# App-Versionsnummer
|
||||
NEXT_PUBLIC_APP_VERSION=1.6.510
|
||||
NEXT_PUBLIC_APP_VERSION=1.6.511
|
||||
NEXT_PUBLIC_CPL_MODE=production
|
||||
@@ -1,3 +1,8 @@
|
||||
## [1.6.511] – 2025-07-01
|
||||
|
||||
- feat: alle KÜs Firmware update
|
||||
|
||||
---
|
||||
## [1.6.510] – 2025-06-30
|
||||
|
||||
- feat: handleKueFirmwareUpdate
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
// /komponents/main/kabelueberwachung/kue705FO/handlers/firmwareUpdate.ts
|
||||
const firmwareUpdate = (slot: number) => {
|
||||
const url = `${window.location.origin}/CPL?/kabelueberwachung.html&KSU${slot}=1`;
|
||||
const isDev =
|
||||
typeof window !== "undefined" && window.location.hostname === "localhost";
|
||||
const url = isDev
|
||||
? `${window.location.origin}/api/cpl/kueSingleModuleUpdateMock?slot=${
|
||||
slot + 1
|
||||
}`
|
||||
: `${window.location.origin}/CPL?/kabelueberwachung.html&KSU${slot}=1`;
|
||||
|
||||
fetch(url, { method: "GET" })
|
||||
.then((response) => {
|
||||
if (response.ok) {
|
||||
alert(`Update an ${slot + 1} erfolgreich gestartet!`);
|
||||
} else {
|
||||
alert("Fehler beim Update!");
|
||||
}
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
alert(
|
||||
data.message || `Update an Slot ${slot + 1} erfolgreich gestartet!`
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Fehler:", error);
|
||||
alert("Fehler beim Update!");
|
||||
});
|
||||
};
|
||||
|
||||
export default firmwareUpdate;
|
||||
|
||||
@@ -246,7 +246,15 @@ export default function KueEinstellung({
|
||||
<div className="flex justify-end gap-2 p-0 rounded">
|
||||
{isAdminLoggedIn && (
|
||||
<button
|
||||
onClick={() => firmwareUpdate(slot)}
|
||||
onClick={() => {
|
||||
if (
|
||||
window.confirm(
|
||||
"Warnung: Das Firmware-Update kann einige Minuten dauern und das Gerät neu starten.\nMöchten Sie wirklich fortfahren?"
|
||||
)
|
||||
) {
|
||||
firmwareUpdate(slot);
|
||||
}
|
||||
}}
|
||||
className="bg-littwin-blue text-white px-4 py-2 rounded flex items-center"
|
||||
>
|
||||
Firmware Update
|
||||
|
||||
@@ -12,15 +12,15 @@ import { AppDispatch } from "../../../redux/store";
|
||||
import { getSystemSettingsThunk } from "../../../redux/thunks/getSystemSettingsThunk";
|
||||
import handleGeneralSubmit from "./handlers/handleGeneralSubmit";
|
||||
import handleKueFirmwareUpdate from "@/components/main/settingsPageComponents/handlers/handleKueFirmwareUpdate";
|
||||
import { useAdminAuth } from "@/components/main/settingsPageComponents/hooks/useAdminAuth";
|
||||
|
||||
const GeneralSettings: React.FC = () => {
|
||||
const dispatch = useDispatch<AppDispatch>();
|
||||
const systemSettings = useSelector(
|
||||
(state: RootState) => state.systemSettingsSlice
|
||||
);
|
||||
const isAdmin = useSelector(
|
||||
(state: RootState) => state.authSlice?.isAdminLoggedIn
|
||||
);
|
||||
|
||||
const { isAdminLoggedIn } = useAdminAuth(true);
|
||||
|
||||
// const [error, setError] = useState("");
|
||||
|
||||
@@ -196,10 +196,10 @@ const GeneralSettings: React.FC = () => {
|
||||
>
|
||||
Neustart CPL
|
||||
</button>
|
||||
{isAdmin && (
|
||||
{isAdminLoggedIn && (
|
||||
<button
|
||||
type="button"
|
||||
className="bg-red-600 text-white px-4 py-2 h-8 text-xs rounded whitespace-nowrap"
|
||||
className="bg-littwin-blue text-white px-4 py-2 h-8 text-xs rounded whitespace-nowrap"
|
||||
onClick={handleKueFirmwareUpdate}
|
||||
>
|
||||
Firmwareupdate alle KÜ-Module
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"success": true,
|
||||
"message": "Update erfolgreich gestartet für Slot X"
|
||||
}
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "cpl-v4",
|
||||
"version": "1.6.510",
|
||||
"version": "1.6.511",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "cpl-v4",
|
||||
"version": "1.6.510",
|
||||
"version": "1.6.511",
|
||||
"dependencies": {
|
||||
"@fontsource/roboto": "^5.1.0",
|
||||
"@iconify-icons/ri": "^1.2.10",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cpl-v4",
|
||||
"version": "1.6.510",
|
||||
"version": "1.6.511",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
|
||||
25
pages/api/cpl/kueSingleModuleUpdateMock.ts
Normal file
25
pages/api/cpl/kueSingleModuleUpdateMock.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// /pages/api/cpl/kueSingleModuleUpdateMock.ts
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
|
||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/device-cgi-simulator/firmwareUpdate/singleModuleUpdateResponse.json"
|
||||
);
|
||||
|
||||
try {
|
||||
const fileContents = fs.readFileSync(filePath, "utf-8");
|
||||
const responseData = JSON.parse(fileContents);
|
||||
|
||||
// Optional: slot aus query übernehmen
|
||||
const slot = req.query.slot ?? "X";
|
||||
responseData.message = `Update erfolgreich gestartet für Slot ${slot}`;
|
||||
|
||||
res.status(200).json(responseData);
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Lesen der Mock-Datei:", error);
|
||||
res.status(500).json({ error: "Fehler beim Mock-Update" });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user