feat(dev): API zum Schreiben von KUE-Mockdaten eingebunden – Entwicklung ohne CPL-Hardware möglich
- Endpunkt /api/cpl/updateKueSettingsDataAPIHandler erstellt - Änderungen werden direkt in apiMockData/SERVICE/kabelueberwachungMockData.js geschrieben - Strings werden korrekt in Anführungszeichen gespeichert - Komma- und Formatierungsfehler im JS-Array beseitigt - Entwicklungsumgebung kann KUE-Einstellungen ohne Embedded-System testen
This commit is contained in:
10
CHANGELOG.md
10
CHANGELOG.md
@@ -4,6 +4,16 @@ Alle Änderungen und Versionen des CPLv4.0 Frontends chronologisch dokumentiert.
|
||||
|
||||
---
|
||||
|
||||
## [1.6.318] – 2025-04-29
|
||||
|
||||
### Fix
|
||||
|
||||
- Anzeige aller KUE-Werte (Grenzwerte, Verzögerung, Intervalle) nach dem Speichern sofort im UI aktualisiert
|
||||
- Lokale Eingabewerte (`formData`) werden direkt nach erfolgreichem Speichern neu gesetzt
|
||||
- Keine Navigation mehr nötig, um gespeicherte Werte zu sehen
|
||||
|
||||
---
|
||||
|
||||
## [1.6.314] – 2025-04-29
|
||||
|
||||
### Verbesserungen
|
||||
|
||||
@@ -57,7 +57,9 @@ Die Benutzeroberfläche ist modular aufgebaut und ermöglicht Zugriff auf digita
|
||||
- Filterzeit setzen
|
||||
- Gewichtung anpassen
|
||||
- Zähler aktivieren/deaktivieren
|
||||
- Speicherung über CGI-Interface oder lokale API
|
||||
- Speicherung über CGI-Interface oder lokale API
|
||||
Echtzeit-Rückmeldung nach Speichern:
|
||||
Änderungen in den KUE-Einstellungen (Bezeichnung, Grenzwerte, Intervalle) werden direkt im UI angezeigt – ohne Neuladen oder Navigation. Die Eingabewerte werden lokal aktualisiert, nachdem die Daten erfolgreich an das CPL gesendet wurden.
|
||||
|
||||
### 🔌 **/digitalOutputs** – Schaltausgänge
|
||||
|
||||
|
||||
@@ -47,9 +47,7 @@ var win_kueIso = [
|
||||
];
|
||||
//Grenzwert (MOhm) für Isolationswiderstand
|
||||
var win_kueLimit1 = [
|
||||
8.9, 9.9, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0,
|
||||
10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0,
|
||||
10.0, 10.0, 10.0, 10.0, 10.0, 10.0,
|
||||
3, 9.9, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0
|
||||
];
|
||||
|
||||
/*
|
||||
@@ -62,9 +60,7 @@ die Filterzeit startet beim nächsten Unterschreiten des Grenzwerts neu. Die Fil
|
||||
kurzfristige Schwankungen oder Störungen fälschlicherweise als Fehler gemeldet werden.
|
||||
*/
|
||||
var win_kueDelay1 = [
|
||||
10, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420,
|
||||
420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420,
|
||||
420,
|
||||
3, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420, 420
|
||||
];
|
||||
//---------------------------------------------------
|
||||
//Schleifenwiderstand in Display (resDisplay) Einheit: KOhm
|
||||
@@ -75,49 +71,15 @@ var win_kueResidence = [
|
||||
];
|
||||
//Schleifenmessung Unterer Grenzwert (KOhm)
|
||||
var win_kueLimit2Low = [
|
||||
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
|
||||
0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1,
|
||||
0.1, 0.1,
|
||||
3, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1
|
||||
];
|
||||
var win_kueLimit2High = [
|
||||
"undefined",
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
|
||||
];
|
||||
|
||||
//Schleifenintervall (h) für Schleifenmessung
|
||||
var win_kueLoopInterval = [
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6,
|
||||
3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6
|
||||
];
|
||||
//---------------------------------------------------
|
||||
//KÜ Modul Version soll /100 und davor V angezeigt werden z.B. 4.19V
|
||||
@@ -129,38 +91,7 @@ var win_kueVersion = [
|
||||
|
||||
//Modulname in Komponente und auf der Anzeige
|
||||
var win_kueID = [
|
||||
"FTZ_5",
|
||||
"B23",
|
||||
"Kabel 3",
|
||||
"Kabel 4",
|
||||
"Kabel 5",
|
||||
"Kabel 6",
|
||||
"FTZ4562",
|
||||
"Kabel 8",
|
||||
"12344",
|
||||
"Kabel 10",
|
||||
"Kabel 11",
|
||||
"Kabel 12",
|
||||
"Kabel 13",
|
||||
"Kabel 14",
|
||||
"Kabel 15",
|
||||
"H56-77",
|
||||
"Kabel 17",
|
||||
"Kabel 18",
|
||||
"Kabel 19",
|
||||
"Kabel 20",
|
||||
"Kabel 21",
|
||||
"Kabel 22",
|
||||
"Kabel 23",
|
||||
"Kabel 24",
|
||||
"Kabel 25",
|
||||
"Kabel 26",
|
||||
"Kabel 27",
|
||||
"Kabel 28",
|
||||
"Kabel 29",
|
||||
"Kabel 30",
|
||||
"Kabel 31",
|
||||
"Kabel 32",
|
||||
"Test3", "B23", "Kabel 3", "Kabel 4", "Kabel 5", "Kabel 6", "FTZ4562", "Kabel 8", "12344", "Kabel 10", "Kabel 11", "Kabel 12", "Kabel 13", "Kabel 14", "Kabel 15", "H56-77", "Kabel 17", "Kabel 18", "Kabel 19", "Kabel 20", "Kabel 21", "Kabel 22", "Kabel 23", "Kabel 24", "Kabel 25", "Kabel 26", "Kabel 27", "Kabel 28", "Kabel 29", "Kabel 30", "Kabel 31", "Kabel 32"
|
||||
];
|
||||
|
||||
//---------------------------------------------------
|
||||
@@ -234,7 +165,6 @@ var win_tdrLast = [
|
||||
//---------------------------------------------------
|
||||
|
||||
var win_memoryInterval = [
|
||||
0, 0, 15, 0, 0, 15, 15, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0,
|
||||
5, 0, 15, 0, 0, 15, 15, 0, 0, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0
|
||||
];
|
||||
//Speicherintervall (Kein, 1 MInute, 5 Minuten, 10 Minuten, 15 Minuten, 30 Minuten, 60 Minuten, 360 Minuten (6h), 720 Minuten (12h)
|
||||
|
||||
@@ -109,23 +109,33 @@ const handleSave = async ({
|
||||
const isProd = !isDev;
|
||||
|
||||
if (isDev) {
|
||||
const keyMap: Record<string, string> = {
|
||||
KID: "win_kueID",
|
||||
KL_: "win_kueLimit1",
|
||||
KD_: "win_kueDelay1",
|
||||
KR_: "win_kueLimit2Low",
|
||||
KRO_: "win_kueLimit2High",
|
||||
KRI: "win_kueLoopInterval",
|
||||
KLO: "win_memoryInterval",
|
||||
};
|
||||
|
||||
for (const [key, value] of Object.entries(changesForFile)) {
|
||||
const mappedKey = keyMap[key] ?? key;
|
||||
|
||||
const params = new URLSearchParams({
|
||||
key: `win_kue${key}`,
|
||||
key: mappedKey,
|
||||
value: String(value),
|
||||
slot: String(slot),
|
||||
});
|
||||
|
||||
const response = await fetch(
|
||||
`/api/cpl/updateKueDataAPIHandler?${params.toString()}`
|
||||
`/api/cpl/updateKueSettingsDataAPIHandler?${params.toString()}`
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
alert(`❌ Fehler beim Schreiben der Datei (${key})`);
|
||||
return;
|
||||
console.error("DEV fetch error:", await response.text());
|
||||
}
|
||||
}
|
||||
|
||||
alert("✅ Daten erfolgreich gespeichert!");
|
||||
}
|
||||
|
||||
if (isProd) {
|
||||
|
||||
@@ -6,5 +6,5 @@
|
||||
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
|
||||
|
||||
*/
|
||||
const webVersion = "1.6.318";
|
||||
const webVersion = "1.6.319";
|
||||
export default webVersion;
|
||||
|
||||
58
pages/api/cpl/updateKueSettingsDataAPIHandler.ts
Normal file
58
pages/api/cpl/updateKueSettingsDataAPIHandler.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
// /pages/api/cpl/updateKueSettingsDataAPIHandler.ts
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const { key, value, slot } = req.query;
|
||||
|
||||
if (!key || slot === undefined) {
|
||||
return res.status(400).json({ error: "Missing key or slot parameter." });
|
||||
}
|
||||
|
||||
const mockFilePath = path.join(
|
||||
process.cwd(),
|
||||
"apiMockData/SERVICE/kabelueberwachungMockData.js"
|
||||
);
|
||||
|
||||
try {
|
||||
const fileContent = await fs.readFile(mockFilePath, "utf-8");
|
||||
|
||||
const regex = new RegExp(`(var\\s+${key}\\s*=\\s*\\[)([^\\]]+)(\\])`);
|
||||
const match = fileContent.match(regex);
|
||||
|
||||
if (!match) {
|
||||
return res
|
||||
.status(404)
|
||||
.json({ error: `Key "${key}" not found in mock data.` });
|
||||
}
|
||||
|
||||
const values = match[2]
|
||||
.split(",")
|
||||
.map((v) => v.trim())
|
||||
.filter((_, i) => i < 32); // Optional: auf maximale Länge beschränken
|
||||
|
||||
const needsQuoting = isNaN(Number(value)) && !/^["'].*["']$/.test(value);
|
||||
values[Number(slot)] = needsQuoting ? `"${value}"` : value;
|
||||
|
||||
// Entferne leere Slots
|
||||
while (values.length > 0 && values[values.length - 1] === "") {
|
||||
values.pop();
|
||||
}
|
||||
|
||||
// Ergänze fehlende Slots mit leerem String
|
||||
while (values.length < 32) {
|
||||
values.push('""'); // Leerstring mit Anführungszeichen
|
||||
}
|
||||
|
||||
const newArray = `var ${key} = [\n ${values.join(", ")}\n]`;
|
||||
|
||||
const updated = fileContent.replace(regex, newArray);
|
||||
|
||||
await fs.writeFile(mockFilePath, updated, "utf-8");
|
||||
|
||||
return res.status(200).json({ success: true, key, slot, value });
|
||||
} catch (error) {
|
||||
console.error("Mock update failed:", error);
|
||||
return res.status(500).json({ error: "Internal server error." });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user