From fb68d59da4f53adf5df07b5bad4c1ab35ec9ec0b Mon Sep 17 00:00:00 2001 From: ISA Date: Mon, 21 Jul 2025 13:04:46 +0200 Subject: [PATCH] =?UTF-8?q?feat(service):=20Produktions-URL=20f=C3=BCr=20C?= =?UTF-8?q?PL=20angepasst,=20erkennt=20Umgebung=20und=20baut=20Anfrage=20d?= =?UTF-8?q?ynamisch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 2 +- .env.production | 2 +- CHANGELOG.md | 5 +++ package-lock.json | 4 +- package.json | 2 +- services/fetchAnalogInputsHistoryService.ts | 48 ++++++++++++++++----- 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/.env.development b/.env.development index 440da51..6cac53e 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.614 +NEXT_PUBLIC_APP_VERSION=1.6.615 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 5491cc9..3a3f48f 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.614 +NEXT_PUBLIC_APP_VERSION=1.6.615 NEXT_PUBLIC_CPL_MODE=production \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index bbcd62a..dbcfd7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [1.6.615] – 2025-07-21 + +- feat(chart): Zeitauswahl im Listbox nur lokal speichern, Daten-Fetch erst beim Button-Klick + +--- ## [1.6.614] – 2025-07-21 - feat(ui): Hinweis-Icon und Meldung angezeigt, wenn kein Eingang ausgewählt ist diff --git a/package-lock.json b/package-lock.json index f1a2d86..09978de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cpl-v4", - "version": "1.6.614", + "version": "1.6.615", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cpl-v4", - "version": "1.6.614", + "version": "1.6.615", "dependencies": { "@fontsource/roboto": "^5.1.0", "@headlessui/react": "^2.2.4", diff --git a/package.json b/package.json index 1e485fa..fa051b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cpl-v4", - "version": "1.6.614", + "version": "1.6.615", "private": true, "scripts": { "dev": "next dev", diff --git a/services/fetchAnalogInputsHistoryService.ts b/services/fetchAnalogInputsHistoryService.ts index 425ce3c..fbe91bb 100644 --- a/services/fetchAnalogInputsHistoryService.ts +++ b/services/fetchAnalogInputsHistoryService.ts @@ -8,19 +8,47 @@ export async function fetchAnalogInputsHistory( vonDatum?: string, bisDatum?: string ): Promise<{ daten: AnalogInputsHistoryEntry[] }> { - const url = - `/api/cpl/getAnalogInputsHistory?eingang=${eingang}&zeitraum=${zeitraum}` + - (vonDatum ? `&von=${vonDatum}` : "") + - (bisDatum ? `&bis=${bisDatum}` : ""); + // Umgebung erkennen + const isDev = + window.location.hostname === "localhost" || + window.location.hostname === "127.0.0.1"; - const res = await fetch(url); + if (isDev) { + // Entwicklung: API-Route verwenden + const url = + `/api/cpl/getAnalogInputsHistory?eingang=${eingang}&zeitraum=${zeitraum}` + + (vonDatum ? `&von=${vonDatum}` : "") + + (bisDatum ? `&bis=${bisDatum}` : ""); - if (!res.ok) { - throw new Error("Serverantwort war nicht erfolgreich"); + const res = await fetch(url); + if (!res.ok) { + throw new Error("Serverantwort war nicht erfolgreich"); + } + const json = await res.json(); + return { daten: json.daten }; + } else { + // Produktion: CPL-Webserver direkt abfragen + // Erwartetes Format: /CPL?seite.ACP&DIA1=YYYY;MM;DD;YYYY;MM;DD;Eingang;Zeitraum + // Annahme: vonDatum/bisDatum sind im Format YYYY-MM-DD + if (!vonDatum || !bisDatum) { + throw new Error("vonDatum und bisDatum sind erforderlich in Produktion"); + } + const [vonJahr, vonMonat, vonTag] = vonDatum.split("-"); + const [bisJahr, bisMonat, bisTag] = bisDatum.split("-"); + // CPL-Eingang: 1-8, Zeitraum: 1=Stündlich, 2=Täglich, 0=Alle Messwerte + let cplZeitraum = 1; + if (zeitraum === "DIA2") cplZeitraum = 2; + if (zeitraum === "DIA0") cplZeitraum = 0; + // Beispiel: /CPL?seite.ACP&DIA1=2025;01;01;2025;07;31;2;4 + const url = `${window.location.origin}/CPL?seite.ACP&DIA1=${vonJahr};${vonMonat};${vonTag};${bisJahr};${bisMonat};${bisTag};${eingang};${cplZeitraum}`; + const res = await fetch(url); + if (!res.ok) { + throw new Error("Fehler bei CPL-Server: " + res.status); + } + const json = await res.json(); + // Die Struktur der Antwort kann ggf. angepasst werden + return { daten: json }; } - - const json = await res.json(); - return { daten: json.daten }; // Nur das Feld "daten" extrahieren } /* // ⬇️ PRODUKTION: direkt vom CPL-Webserver holen