From 84e1fbd45330abe99f074a9a7a31cb3dba419769 Mon Sep 17 00:00:00 2001 From: ISA Date: Thu, 26 Jun 2025 07:41:53 +0200 Subject: [PATCH] feat: zeige die neuesten 20 Meldungen in Last20MessagesTable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Daten aus API chronologisch absteigend sortiert (neueste zuerst) - Anzeige auf die ersten 20 Einträge begrenzt - Verhalten nun konsistent mit Seite /meldungen --- .env.development | 2 +- .env.production | 2 +- CHANGELOG.md | 5 + .../main/uebersicht/Last20MessagesTable.tsx | 115 ++++++++++-------- package-lock.json | 4 +- package.json | 2 +- pages/meldungen.tsx | 2 +- 7 files changed, 76 insertions(+), 56 deletions(-) diff --git a/.env.development b/.env.development index 333940b..fd5960a 100644 --- a/.env.development +++ b/.env.development @@ -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.449 +NEXT_PUBLIC_APP_VERSION=1.6.450 NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter) diff --git a/.env.production b/.env.production index 9224353..b80fe05 100644 --- a/.env.production +++ b/.env.production @@ -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.449 +NEXT_PUBLIC_APP_VERSION=1.6.450 NEXT_PUBLIC_CPL_MODE=production \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 8583d43..c40e8a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [1.6.450] – 2025-06-26 + +- feat: Filter für Quelle + +--- ## [1.6.449] – 2025-06-25 - refactor: alle Feature-Flags entfernt wegen Aufwand und Zeit diff --git a/components/main/uebersicht/Last20MessagesTable.tsx b/components/main/uebersicht/Last20MessagesTable.tsx index 28dd318..ba21263 100644 --- a/components/main/uebersicht/Last20MessagesTable.tsx +++ b/components/main/uebersicht/Last20MessagesTable.tsx @@ -1,65 +1,76 @@ -"use client"; // /components/main/uebersicht/Last20MessagesTable.tsx -import React, { useEffect } from "react"; -import { useSelector, useDispatch } from "react-redux"; -import { RootState } from "../../../redux/store"; -import { setLast20Messages } from "../../../redux/slices/last20MessagesSlice"; +"use client"; +import React, { useEffect, useState } from "react"; -type Props = { - className?: string; +type Meldung = { + t: string; // Zeitstempel + s: number; // Status + c: string; // Farbe + m: string; // Meldung + i: string; // Modul/Quelle }; -const Last20MessagesTable: React.FC = ({ className }) => { - const dispatch = useDispatch(); - - const rawLast20Messages = useSelector( - (state: RootState) => state.last20MessagesSlice.last20Messages - ); +const Last20MessagesTable: React.FC<{ className?: string }> = ({ + className, +}) => { + const [messages, setMessages] = useState([]); useEffect(() => { - const loadWindowMessages = () => { - if (typeof window !== "undefined" && (window as any).win_last20Messages) { - dispatch(setLast20Messages((window as any).win_last20Messages)); + const fetchLast20Messages = async () => { + const today = new Date(); + const prior30 = new Date(); + prior30.setDate(today.getDate() - 30); + + const format = (d: Date) => + `${d.getFullYear()};${(d.getMonth() + 1) + .toString() + .padStart(2, "0")};${d.getDate().toString().padStart(2, "0")}`; + + const from = format(prior30); + const to = format(today); + + const isDev = + typeof window !== "undefined" && + window.location.hostname === "localhost"; + + const url = isDev + ? `/api/cpl/messages?MSS1=${from};${to};All` + : `/CPL?Service/ae.ACP&MSS1=${from};${to};All`; + + try { + const res = await fetch(url); + const raw = await res.json(); + const data = Array.isArray(raw) ? raw : raw.data; + if (!Array.isArray(data)) return; + + const sorted = [...data].sort( + (a, b) => new Date(b.t).getTime() - new Date(a.t).getTime() + ); + const last20 = sorted.slice(0, 20); // NEUESTE zuerst + + setMessages(last20); + } catch (err) { + console.error("Fehler beim Laden der Meldungen:", err); } }; - loadWindowMessages(); - const interval = setInterval(loadWindowMessages, 1000); - return () => clearInterval(interval); - }, [dispatch]); - - const parseMessages = (messages: string | null) => { - if (!messages) return []; - - return messages - .split("") - .slice(1) - .map((row) => - row - .replace(/<\/tr>/, "") - .split("") - .map((col) => col.replace(/<[^>]+>/g, "")) - ); - }; - - const allMessages = parseMessages(rawLast20Messages); + fetchLast20Messages(); + }, []); return ( -
- {/*

Letzte 20 Meldungen

*/} - +
- - - + + + - {allMessages.length === 0 ? ( + {messages.length === 0 ? ( ) : ( - allMessages.map((msg, index) => ( + messages.map((msg, index) => ( - - - - - - + + + + + )) )} diff --git a/package-lock.json b/package-lock.json index a3a9875..421b765 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cpl-v4", - "version": "1.6.449", + "version": "1.6.450", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cpl-v4", - "version": "1.6.449", + "version": "1.6.450", "dependencies": { "@fontsource/roboto": "^5.1.0", "@iconify-icons/ri": "^1.2.10", diff --git a/package.json b/package.json index 41acd12..a03812b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cpl-v4", - "version": "1.6.449", + "version": "1.6.450", "private": true, "scripts": { "dev": "next dev", diff --git a/pages/meldungen.tsx b/pages/meldungen.tsx index d2195c4..5f30d27 100644 --- a/pages/meldungen.tsx +++ b/pages/meldungen.tsx @@ -41,7 +41,7 @@ export default function Messages() { const isDev = typeof window !== "undefined" && window.location.hostname === "localhost"; - + //http://10.10.0.118/CPL?Service/empty.ACP&MSS1=2025;06;01;2025;06;26;All const url = isDev ? `/api/cpl/messages?MSS1=${fy};${fm};${fd};${ty};${tm};${td};All` : `/CPL?Service/ae.ACP&MSS1=${fy};${fm};${fd};${ty};${tm};${td};All`;
IDModulZeitstempelPrioZeitQuelle Meldung Status
= ({ className }) => {
{msg[0]}{msg[1]}{msg[2]}{msg[3]}{msg[4]} +
+
{msg.t}{msg.i}{msg.m}{msg.s}