feat(analogeEingaenge): CGI-Unterstützung für Produktion – Einstellungen werden je nach Umgebung per API oder per CPL-Link gespeichert
This commit is contained in:
@@ -31,40 +31,48 @@ export default function AnalogInputsSettingsModal({
|
||||
|
||||
const handleSave = async () => {
|
||||
setIsSaving(true);
|
||||
|
||||
const slot = selectedInput.id;
|
||||
const isDev = window.location.hostname === "localhost";
|
||||
|
||||
const acn = encodeURIComponent(name);
|
||||
const offsetParam = offset.toString().replace(",", ".");
|
||||
const factorParam = factor.toString().replace(",", ".");
|
||||
const loggerParam = loggerInterval.toString();
|
||||
|
||||
const url = `/CPL?/Service/ae.ACP&ACN${slot}=${acn}&ACO${slot}=${offsetParam}&ACF${slot}=${factorParam}&ACL${slot}=${loggerParam}`;
|
||||
|
||||
try {
|
||||
await fetch("/api/cpl/updateAnalogInputsSettingsAPIHandler", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
updates: [
|
||||
{
|
||||
key: "win_analogInputsNames",
|
||||
index: selectedInput.id - 1,
|
||||
value: name,
|
||||
},
|
||||
{
|
||||
key: "win_analogInputsOffset",
|
||||
index: selectedInput.id - 1,
|
||||
value: parseFloat(offset.toString()),
|
||||
},
|
||||
{
|
||||
key: "win_analogInputsFactor",
|
||||
index: selectedInput.id - 1,
|
||||
value: parseFloat(factor.toString()),
|
||||
},
|
||||
{
|
||||
key: "win_analogInputsloggerIntervall",
|
||||
index: selectedInput.id - 1,
|
||||
value: parseInt(loggerInterval.toString()),
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
alert("Einstellungen gespeichert.");
|
||||
if (isDev) {
|
||||
// Entwicklung: lokale Mock-API
|
||||
await fetch("/api/cpl/updateAnalogInputsSettingsAPIHandler", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
updates: [
|
||||
{ key: "win_analogInputsNames", index: slot - 1, value: name },
|
||||
{ key: "win_analogInputsOffset", index: slot - 1, value: offset },
|
||||
{ key: "win_analogInputsFactor", index: slot - 1, value: factor },
|
||||
{
|
||||
key: "win_analogInputsloggerIntervall",
|
||||
index: slot - 1,
|
||||
value: loggerInterval,
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
alert("Mockdaten gespeichert.");
|
||||
} else {
|
||||
// Produktion: direkter CGI-Befehl
|
||||
const result = await fetch(url);
|
||||
if (!result.ok) throw new Error("Fehler bei CGI-Aufruf");
|
||||
alert("Einstellungen gespeichert (Produktion).");
|
||||
}
|
||||
|
||||
onClose();
|
||||
location.reload();
|
||||
} catch (err) {
|
||||
alert("Fehler beim Speichern der Einstellungen.");
|
||||
alert("Fehler beim Speichern.");
|
||||
console.error(err);
|
||||
} finally {
|
||||
setIsSaving(false);
|
||||
|
||||
Reference in New Issue
Block a user