fix: Implement correct rack navigation in Kabelueberwachung
- Added logic to read the 'rack' query parameter from the URL using useRouter and URLSearchParams. - Set activeRack state based on the selected rack number from the Dashboard. - Ensured rack selection is correctly handled upon navigation. - Maintained manual rack switching functionality with buttons.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
"use client"; // app/dashboard/page.jsx
|
"use client"; // app/dashboard/page.jsx
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
import "tailwindcss/tailwind.css";
|
import "tailwindcss/tailwind.css";
|
||||||
import "@fontsource/roboto";
|
import "@fontsource/roboto";
|
||||||
import "bootstrap-icons/font/bootstrap-icons.css";
|
import "bootstrap-icons/font/bootstrap-icons.css";
|
||||||
@@ -14,7 +15,7 @@ import { Icon } from "@iconify/react";
|
|||||||
|
|
||||||
function Dashboard() {
|
function Dashboard() {
|
||||||
const [isClient, setIsClient] = useState(false);
|
const [isClient, setIsClient] = useState(false);
|
||||||
|
const router = useRouter(); // Router instanzieren
|
||||||
const [last20Messages, setLast20Messages] = useState([]);
|
const [last20Messages, setLast20Messages] = useState([]);
|
||||||
const [kueOnline, setkueOnline] = useState([]);
|
const [kueOnline, setkueOnline] = useState([]);
|
||||||
const [ip, setIp] = useState("");
|
const [ip, setIp] = useState("");
|
||||||
@@ -152,6 +153,11 @@ function Dashboard() {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleModuleClick = (rackNumber) => {
|
||||||
|
// Navigiere zu /kabelueberwachung und übermittle den rackNumber als Parameter
|
||||||
|
router.push(`/kabelueberwachung?rack=${rackNumber}`);
|
||||||
|
};
|
||||||
|
|
||||||
const renderBaugruppentraeger = () => {
|
const renderBaugruppentraeger = () => {
|
||||||
const baugruppen = [];
|
const baugruppen = [];
|
||||||
const numBaugruppen = Math.ceil(kueOnline.length / 8);
|
const numBaugruppen = Math.ceil(kueOnline.length / 8);
|
||||||
@@ -164,31 +170,31 @@ function Dashboard() {
|
|||||||
<div className="flex gap-1">
|
<div className="flex gap-1">
|
||||||
{slots.map((version, index) => {
|
{slots.map((version, index) => {
|
||||||
const slotNumber = i * 8 + index + 1;
|
const slotNumber = i * 8 + index + 1;
|
||||||
|
|
||||||
const moduleVersion = window.kueVersion
|
const moduleVersion = window.kueVersion
|
||||||
? window.kueVersion[slotNumber - 1]
|
? window.kueVersion[slotNumber - 1]
|
||||||
: version;
|
: version;
|
||||||
|
|
||||||
// Überprüfe die Bedingungen für kueAlarm1, kueAlarm2 und kueCableBreak
|
|
||||||
const hasAlarm1 = kueAlarm1.includes(slotNumber);
|
const hasAlarm1 = kueAlarm1.includes(slotNumber);
|
||||||
const hasAlarm2 = kueAlarm2.includes(slotNumber);
|
const hasAlarm2 = kueAlarm2.includes(slotNumber);
|
||||||
const hasCableBreak = kueCableBreak.includes(slotNumber);
|
const hasCableBreak = kueCableBreak.includes(slotNumber);
|
||||||
|
|
||||||
// Setze die Klasse für rote Färbung, wenn ein Alarm oder Kabelbruch vorhanden ist
|
|
||||||
const alarmClass =
|
const alarmClass =
|
||||||
hasAlarm1 || hasAlarm2 || hasCableBreak
|
hasAlarm1 || hasAlarm2 || hasCableBreak
|
||||||
? "bg-red-500"
|
? "bg-red-500"
|
||||||
: "bg-white";
|
: "bg-white";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<KabelModulStatus
|
<div
|
||||||
key={slotNumber}
|
key={slotNumber}
|
||||||
slot={slotNumber}
|
className={`cursor-pointer ${alarmClass}`} // Sicherstellen, dass cursor-pointer hier verwendet wird
|
||||||
isOnline={version !== 0} // Prüfen, ob ein Modul online ist
|
onClick={() => handleModuleClick(i + 1)} // Bei Klick navigieren
|
||||||
moduleVersion={moduleVersion}
|
>
|
||||||
kueCableBreak={kueCableBreak}
|
<KabelModulStatus
|
||||||
className={alarmClass} // Klasse für die Färbung hinzufügen
|
slot={slotNumber}
|
||||||
/>
|
isOnline={version !== 0} // Prüfen, ob ein Modul online ist
|
||||||
|
moduleVersion={moduleVersion}
|
||||||
|
kueCableBreak={kueCableBreak}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,14 +1,26 @@
|
|||||||
"use client"; // app/kabelueberwachung/page.jsx
|
"use client"; // app/kabelueberwachung/page.jsx
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
import Kue705FO from "../../components/modules/Kue705FO";
|
import Kue705FO from "../../components/modules/Kue705FO";
|
||||||
|
|
||||||
function Kabelueberwachung() {
|
function Kabelueberwachung() {
|
||||||
|
const router = useRouter();
|
||||||
const [activeRack, setActiveRack] = useState(1); // Track the active rack
|
const [activeRack, setActiveRack] = useState(1); // Track the active rack
|
||||||
const [kueIso, setKueIso] = useState([]); // State to store isolation values
|
const [kueIso, setKueIso] = useState([]); // State to store isolation values
|
||||||
const [kueID, setKueID] = useState([]); // State to store the KUE names
|
const [kueID, setKueID] = useState([]); // State to store the KUE names
|
||||||
const [schleifenwiderstand, setSchleifenwiderstand] = useState([]); // State to store the resistance values
|
const [schleifenwiderstand, setSchleifenwiderstand] = useState([]); // State to store the resistance values
|
||||||
const [kueOnline, setKueOnline] = useState([]); // State to store the module status
|
const [kueOnline, setKueOnline] = useState([]); // State to store the module status
|
||||||
|
|
||||||
|
// Verwende den useRouter Hook, um den Rack-Parameter zu extrahieren
|
||||||
|
useEffect(() => {
|
||||||
|
const query = new URLSearchParams(window.location.search);
|
||||||
|
const rackParam = query.get("rack");
|
||||||
|
|
||||||
|
if (rackParam) {
|
||||||
|
setActiveRack(parseInt(rackParam)); // Setze das aktive Rack basierend auf dem URL-Parameter
|
||||||
|
}
|
||||||
|
}, [router.query]);
|
||||||
|
|
||||||
// Load the external JavaScript file and fetch the isolation values
|
// Load the external JavaScript file and fetch the isolation values
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (window.kueIso && Array.isArray(window.kueIso)) {
|
if (window.kueIso && Array.isArray(window.kueIso)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user