diff --git a/.env.development b/.env.development index 06de1fc..4221072 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.503 +NEXT_PUBLIC_APP_VERSION=1.6.506 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 7debfe4..a14fc2d 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.503 +NEXT_PUBLIC_APP_VERSION=1.6.506 NEXT_PUBLIC_CPL_MODE=production \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cee2dc..6655e65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +## [1.6.506] – 2025-06-30 + +- feat: Redux-Integration für Meldungen, Anzeige von 'v' statt 's' in UI + +--- +## [1.6.505] – 2025-06-30 + +- feat: Redux-Integration für Meldungen, Anzeige von 'v' statt 's' in UI + +--- +## [1.6.504] – 2025-06-30 + +- feat: Redux-Integration für Meldungen, Anzeige von 'v' statt 's' in UI + +--- ## [1.6.503] – 2025-06-30 - feat: Redux-Integration für Meldungen, Anzeige von 'v' statt 's' in UI diff --git a/components/main/dashboard/Last20MessagesTable.tsx b/components/main/dashboard/Last20MessagesTable.tsx index d24b912..8bab080 100644 --- a/components/main/dashboard/Last20MessagesTable.tsx +++ b/components/main/dashboard/Last20MessagesTable.tsx @@ -1,86 +1,71 @@ "use client"; -import React, { useEffect, useState } from "react"; +// @/components/main/dashboard/Last20MessagesTable.tsx + +import React, { useState, useEffect } from "react"; +import { useSelector, useDispatch } from "react-redux"; +import { getMessagesThunk } from "@/redux/thunks/getMessagesThunk"; +import type { AppDispatch } from "@/redux/store"; type Meldung = { - t: string; // Zeitstempel - s: number; // Status - c: string; // Farbe - m: string; // Meldung - i: string; // Modul/Quelle + t: string; + s: number; + c: string; + m: string; + i: string; + v: string; }; +export default function Last20MessagesTable() { + const dispatch = useDispatch(); + type RootState = { + messages: { + data: Meldung[]; + }; + // add other slices if needed + }; + const { data: messages } = useSelector((state: RootState) => state.messages); -const Last20MessagesTable: React.FC<{ className?: string }> = ({ - className, -}) => { - const [messages, setMessages] = useState([]); + const [sourceFilter, setSourceFilter] = useState("Alle"); + + // Datum initialisieren: von = heute - 30 Tage, bis = heute + const today = new Date(); + const prior30 = new Date(); + prior30.setDate(today.getDate() - 30); + + const formatDate = (d: Date) => d.toISOString().split("T")[0]; + + const [fromDate, setFromDate] = useState(formatDate(prior30)); + const [toDate, setToDate] = useState(formatDate(today)); useEffect(() => { - const fetchLast20Messages = async () => { - const today = new Date(); - const prior30 = new Date(); - prior30.setDate(today.getDate() - 30); + dispatch(getMessagesThunk({ fromDate, toDate })); + }, [dispatch, fromDate, toDate]); - 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/last20MessagesAPIHandler` - : `/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); - } - }; - - fetchLast20Messages(); - }, []); + const filteredMessages = + sourceFilter === "Alle" + ? messages + : messages.filter((m: Meldung) => m.i === sourceFilter); return ( -
-
+
+

+ +
+ +
- + - {messages.length === 0 ? ( - - - - ) : ( - messages.map((msg, index) => ( + {filteredMessages + .slice(0, 20) + .map((msg: Meldung, index: number) => ( - + - + {/* NEU */} - )) - )} + ))}
PrioZeitZeitstempel Quelle Meldung Status
- Keine Meldungen verfügbar. -
= ({ style={{ backgroundColor: msg.c }} >
{msg.t}{msg.t} {msg.i} {msg.m}{msg.s}{msg.v}
+ {messages.length === 0 && ( +
+ Keine Meldungen im gewählten Zeitraum vorhanden. +
+ )}
); -}; - -export default Last20MessagesTable; +} diff --git a/package-lock.json b/package-lock.json index 3b2a59c..2f8eb98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cpl-v4", - "version": "1.6.503", + "version": "1.6.506", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cpl-v4", - "version": "1.6.503", + "version": "1.6.506", "dependencies": { "@fontsource/roboto": "^5.1.0", "@iconify-icons/ri": "^1.2.10", diff --git a/package.json b/package.json index b657c72..ad419b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cpl-v4", - "version": "1.6.503", + "version": "1.6.506", "private": true, "scripts": { "dev": "next dev", diff --git a/redux/thunks/getLast20MessagesThunk.ts b/redux/thunks/getLast20MessagesThunk.ts index 1b9f156..75cf90b 100644 --- a/redux/thunks/getLast20MessagesThunk.ts +++ b/redux/thunks/getLast20MessagesThunk.ts @@ -1,13 +1,21 @@ -// /redux/thunks/getLast20MessagesThunk.ts +// redux/thunks/getLast20MessagesThunk.ts import { createAsyncThunk } from "@reduxjs/toolkit"; -import { fetchLast20MessagesFromWindow } from "../../services/fetchLast20MessagesService"; -import { setLast20Messages } from "../slices/last20MessagesSlice"; +import { fetchMessagesService } from "@/services/fetchMessagesService"; export const getLast20MessagesThunk = createAsyncThunk( - "last20Messages/fetchLast20Messages", - async (_, { dispatch }) => { - const messages = await fetchLast20MessagesFromWindow(); - dispatch(setLast20Messages(messages)); - return messages; + "last20Messages/fetch", + async () => { + const toDate = new Date(); + const fromDate = new Date(); + fromDate.setDate(toDate.getDate() - 30); // z.B. letzte 30 Tage + + const allMessages = await fetchMessagesService( + fromDate.toISOString().split("T")[0], + toDate.toISOString().split("T")[0] + ); + + const last20 = allMessages.slice(-20); + console.log("Last 20 messages in thunk:", last20); + return last20; } );