feat: Verwende fetch statt window.location.href für Digitalausgang-Schalteraktionen

This commit is contained in:
ISA
2025-07-08 10:09:46 +02:00
parent 2af99f2740
commit 976f3126f2
8 changed files with 41 additions and 20 deletions

View File

@@ -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.558
NEXT_PUBLIC_APP_VERSION=1.6.559
NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter)

View File

@@ -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.558
NEXT_PUBLIC_APP_VERSION=1.6.559
NEXT_PUBLIC_CPL_MODE=production

View File

@@ -1,3 +1,8 @@
## [1.6.559] 2025-07-08
- circle Button
---
## [1.6.558] 2025-07-08
- feat: ersetzt Einheit-Select durch Listbox mit littwin-blue Design in AnalogInputsSettingsModal

View File

@@ -49,22 +49,22 @@ export default function DigitalOutputsModal({
try {
if (isCPL) {
// ✅ Name speichern (DANx=...)
const nameEncoded = encodeURIComponent(label.trim());
const nameUrl = `/CPL?digitalOutputs.html&DAN0${selectedOutput.id}=${nameEncoded}`;
// ✅ Status speichern (DASx=...)
const statusUrl = `/CPL?digitalOutputs.html&DAS0${selectedOutput.id}=${
status ? 1 : 0
}`;
// 🟢 Beide nacheinander senden (wichtig bei älteren CPL-Versionen)
window.location.href = nameUrl; // Name zuerst (ggf. durch Refresh überschrieben)
setTimeout(() => {
window.location.href = statusUrl;
}, 300); // kleine Verzögerung (optional)
try {
await fetch(nameUrl, { method: "GET" });
await new Promise((res) => setTimeout(res, 300));
await fetch(statusUrl, { method: "GET" });
// 💡 Modal wird nicht automatisch geschlossen — da Seite neu lädt.
closeOutputModal(); // Seite bleibt erhalten
} catch (err) {
console.error("❌ Fehler bei fetch:", err);
setErrorMsg("❌ Fehler beim Speichern.");
}
} else {
// 🧪 Lokaler Entwicklungsmodus
const res = await fetch("/api/cpl/updateDigitalOutputsHandler", {

View File

@@ -32,9 +32,25 @@ export default function DigitalOutputsWidget({
try {
if (isCPL) {
window.location.href = `/CPL?digitalOutputs.html&DAS0${id}=${
updatedOutputs[id - 1].status ? 1 : 0
}`;
// Statt redirect:
// window.location.href = `/CPL?...`;
// Verwende fetch:
fetch(
`/CPL?digitalOutputs.html&DAS0${id}=${
updatedOutputs[id - 1].status ? 1 : 0
}`,
{
method: "GET",
}
)
.then((res) => {
if (!res.ok) throw new Error("Fehler beim Schalten");
// Optional: Feedback anzeigen
})
.catch((err) => {
console.error("CPL Fehler:", err);
});
} else {
await fetch("/api/cpl/updateDigitalOutputsHandler", {
method: "POST",

View File

@@ -1,12 +1,12 @@
{
"win_da_state": [
1,
1,
0,
0,
1,
1
],
"win_da_bezeichnung": [
"Ausgang1",
"DA1",
"Ausgang2",
"Ausgang3",
"Ausgang4"

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "cpl-v4",
"version": "1.6.558",
"version": "1.6.559",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "cpl-v4",
"version": "1.6.558",
"version": "1.6.559",
"dependencies": {
"@fontsource/roboto": "^5.1.0",
"@headlessui/react": "^2.2.4",

View File

@@ -1,6 +1,6 @@
{
"name": "cpl-v4",
"version": "1.6.558",
"version": "1.6.559",
"private": true,
"scripts": {
"dev": "next dev",