Files
CPLv4.0/app/dashboard/page.jsx
2024-09-29 10:52:05 +02:00

235 lines
8.8 KiB
JavaScript

"use client"; // app/dashboard/page.jsx
import React, { useEffect, useState } from "react";
import "tailwindcss/tailwind.css";
import "@fontsource/roboto";
import "bootstrap-icons/font/bootstrap-icons.css";
import { loadWindowVariables } from "../../utils/loadWindowVariables";
import CPLStatus from "../../components/modulesStatus/CPLStatus";
import Access1Status from "../../components/modulesStatus/Access1Status";
import Access2Status from "../../components/modulesStatus/Access2Status";
import Kue705_FO from "../../components/modulesStatus/Kue705_FO";
import { Icon } from "@iconify/react";
function Dashboard() {
const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
const [last20Messages, setLast20Messages] = useState([]);
const [ip, setIp] = useState("");
const [subnet, setSubnet] = useState("");
const [gateway, setGateway] = useState("");
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
loadWindowVariables(apiUrl)
.then(() => {
if (window.last20Messages) {
const parsedMessages = parseMessages(window.last20Messages);
setLast20Messages(parsedMessages);
setIp(window.ip);
setSubnet(window.subnet);
setGateway(window.gateway);
} else {
console.error("Konnte last20Messages nicht finden.");
setError("Konnte last20Messages nicht finden.");
}
setLoading(false);
})
.catch((error) => {
console.error("Fehler beim Laden des Skripts:", error);
setError(error);
setLoading(false);
});
}, [apiUrl]);
const parseMessages = (messages) => {
messages = messages
.replace(/<tr>/g, "\n")
.replace(/<\/?td>/g, "")
.replace(/<\/tr>/g, "")
.trim();
const rows = messages.split("\n");
return rows.map((row) => {
const columns = [
row.substring(0, 5), // ID
row.substring(5, 10), // Wert (z.B. Modulnummer)
row.substring(10, 29), // Zeitstempel, Millisekunden entfernt :000
row.substring(33, row.length - 1), // Meldung (ohne letztes Zeichen)
row.substring(row.length - 1), // Status (letztes Zeichen)
];
return columns;
});
};
return (
<div className="bg-gray-100 flex flex-col min-h-screen ">
{/* Letzte Meldungen - Titel und Icon Bereich */}
<div className="flex justify-between items-center pb-2 w-full lg:w-2/3 mt-8">
<div className="flex justify-between gap-1 ">
<Icon
icon="ri:calendar-schedule-line"
className="text-blue-500 text-4xl"
/>
<h1 className="text-xl font-bold text-gray-700">
Letzten 20 Meldungen
</h1>
</div>
<Icon
icon="ph:trash"
className="text-red-500 hover:text-red-600 mr-8 text-3xl cursor-pointer"
/>
</div>
<div className="flex flex-col lg:flex-row gap-8">
{/* Meldungen Liste */}
<div className="bg-white shadow-md rounded-lg w-full lg:w-2/3">
<table className="min-w-full border border-gray-200 text-left">
<thead className="bg-gray-100 border-b border-gray-300">
<tr>
<th className="py-3 px-4 text-gray-700 text-sm font-medium">
ID
</th>
<th className="py-3 px-4 text-gray-700 text-sm font-medium">
Modul
</th>
<th className="py-3 px-4 text-gray-700 text-sm font-medium">
Zeitstempel
</th>
<th className="py-3 px-4 text-gray-700 text-sm font-medium w-2/3">
Meldung
</th>
<th className="py-3 px-4 text-gray-700 text-sm font-medium">
Status
</th>
</tr>
</thead>
<tbody className="text-xs text-gray-600">
{last20Messages.length > 0 ? (
last20Messages.map((columns, index) => (
<tr
key={index}
className="border-b border-gray-200 hover:bg-gray-50"
>
<td className="py-3 px-4 w-1/7">{columns[0]}</td>
<td className="py-3 px-4 w-1/7">{columns[1]}</td>
<td className="py-3 px-4 w-2/7">{columns[2]}</td>
<td className="py-3 px-4 w-2/7">{columns[3]}</td>
<td className="py-3 px-4w-1/7">{columns[4]}</td>
</tr>
))
) : (
<tr>
<td className="py-3 px-4 text-center" colSpan="5">
Keine Meldungen verfügbar.
</td>
</tr>
)}
</tbody>
</table>
</div>
{/* Sidebar mit Informationen */}
<div className="bg-white shadow-md rounded-lg p-4 w-full lg:w-1/3 flex flex-col gap-4">
{/* Versionsinformationen */}
<div className="bg-gray-50 p-4 rounded-lg shadow-sm border border-gray-200">
<h2 className="text-lg font-semibold text-gray-700 mb-2">
Versionsinformationen
</h2>
<p className="text-sm text-gray-600">
<span className="font-bold">Applikationsversion: </span> 5.1.1.8
C-24-KA
</p>
<p className="text-sm text-gray-600">
<span className="font-bold">Webserverversion: </span> 5.3.4.1
</p>
</div>
{/* Beispiel für Geräteanzeige */}
<div className="bg-gray-50 p-4 rounded-lg shadow-sm border border-gray-200 justify-between space-y-1">
<div className="flex flex-row item-center justify-between ">
<CPLStatus />
<Access1Status />
<Access2Status />
</div>
<div className="flex flex-col item-center justify-between gap-1">
<div className="flex flex-row item-center justify-between space-y-0">
<Kue705_FO slot="1" />
<Kue705_FO slot="2" />
<Kue705_FO slot="3" />
<Kue705_FO slot="4" />
<Kue705_FO slot="5" />
<Kue705_FO slot="6" />
<Kue705_FO slot="7" />
<Kue705_FO slot="8" />
</div>
<div className="flex flex-row item-center justify-between space-y-0">
<Kue705_FO slot="9" />
<Kue705_FO slot="10" />
<Kue705_FO slot="11" />
<Kue705_FO slot="12" />
<Kue705_FO slot="13" />
<Kue705_FO slot="14" />
<Kue705_FO slot="15" />
<Kue705_FO slot="16" />
</div>
<div className="flex flex-row item-center justify-between space-y-0">
<Kue705_FO slot="17" />
<Kue705_FO slot="18" />
<Kue705_FO slot="19" />
<Kue705_FO slot="20" />
<Kue705_FO slot="21" />
<Kue705_FO slot="22" />
<Kue705_FO slot="23" />
<Kue705_FO slot="24" />
</div>
<div className="flex flex-row item-center justify-between space-y-0">
<Kue705_FO slot="25" />
<Kue705_FO slot="26" />
<Kue705_FO slot="27" />
<Kue705_FO slot="28" />
<Kue705_FO slot="29" />
<Kue705_FO slot="30" />
<Kue705_FO slot="31" />
<Kue705_FO slot="32" />
</div>
</div>
</div>
</div>
</div>
{/* Footer Informationen */}
<div className="flex justify-between items-center mt-8 bg-white p-4 rounded-lg shadow-md border border-gray-200">
<div className="flex items-center space-x-4">
<img src="/images/IP-icon.svg" alt="IP Address" className="w-6 h-6" />
<div>
<p className="text-xs text-gray-500">IP-Adresse</p>
<p className="text-sm font-medium text-gray-700">{ip}</p>
</div>
</div>
<div className="flex items-center space-x-4">
<img
src="/images/subnet-mask.svg"
alt="subnet mask"
className="w-6 h-6"
/>
<div>
<p className="text-xs text-gray-500">Subnet-Maske</p>
<p className="text-sm font-medium text-gray-700">{subnet}</p>
</div>
</div>
<div className="flex items-center space-x-4">
<img src="/images/gateway.svg" alt="gateway" className="w-6 h-6" />
<div>
<p className="text-xs text-gray-500">Gateway</p>
<p className="text-sm font-medium text-gray-700">{gateway}</p>
</div>
</div>
</div>
</div>
);
}
export default Dashboard;