feat: TDR-Start mit Mock-Backend über Umgebungsvariable steuerbar gemacht

- .env.development mit NEXT_PUBLIC_USE_MOCK_BACKEND_TDR_START ergänzt
- goTDR.ts überarbeitet: Mock-API oder echtes CGI-Interface je nach Modus
- Verbesserte Flexibilität für Entwicklung ohne reale Hardware
This commit is contained in:
Ismail Ali
2025-04-17 23:39:07 +02:00
parent 87422aa665
commit ce32d90ee7
4 changed files with 54 additions and 31 deletions

View File

@@ -1,3 +1,4 @@
NEXT_PUBLIC_NODE_ENV=development NEXT_PUBLIC_NODE_ENV=development
NEXT_PUBLIC_ENCRYPTION_KEY=1 NEXT_PUBLIC_ENCRYPTION_KEY=1
NEXT_PUBLIC_ENCRYPTION_IV=1 NEXT_PUBLIC_ENCRYPTION_IV=1
NEXT_PUBLIC_USE_MOCK_BACKEND_TDR_START=true

View File

@@ -6,5 +6,5 @@
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen). 2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
*/ */
const webVersion = "1.6.242"; const webVersion = "1.6.243";
export default webVersion; export default webVersion;

View File

@@ -0,0 +1,7 @@
// pages/api/cpl/tdrMessungStartenMockHandler.ts
export default function handler(req, res) {
const { slot } = req.query;
setTimeout(() => {
res.status(200).json({ message: `TDR simuliert für Slot ${slot}` });
}, 1000);
}

View File

@@ -1,38 +1,53 @@
export const goTDR = ( // /utils/goTDR.ts
export const goTDR = async (
slotIndex: number, slotIndex: number,
setLoading: (loading: boolean) => void setLoading: (loading: boolean) => void
) => { ) => {
if (slotIndex >= 32) { if (slotIndex >= 32) return;
setLoading(true);
// ✅ ENV-Variable prüfen (funktioniert nur mit NEXT_PUBLIC_)
const isMock = process.env.NEXT_PUBLIC_USE_MOCK_BACKEND_TDR_START === "true";
if (isMock) {
// 🔁 MOCK-MODUS
try {
const response = await fetch(
`/api/cpl/tdrMessungStartenMockHandler?slot=${slotIndex + 1}`
);
const data = await response.json();
alert(`(MOCK) ${data.message}`);
console.log("(MOCK)", data.message);
} catch (error) {
console.error("(MOCK) Fehler:", error);
} finally {
setLoading(false);
}
return; return;
} }
//const slotFormat = slotIndex < 10 ? `${slotIndex}` : `${slotIndex}`; // 🚀 ECHTER Backend-Aufruf über CGI
try {
setLoading(true); const response = await fetch(
//alert(`TDR wird für Slot ${slotIndex + 1} gestartet...`); `${window.location.origin}/CPL?Service/Kabelueberwachung.html&KTT${slotIndex}=1`,
{
fetch( method: "GET",
//`${window.location.origin}/CPL?Service/Kabelueberwachung.html&KTT${slotFormat}=1&slot=${slotIndex}`,
`${window.location.origin}/CPL?Service/Kabelueberwachung.html&KTT${slotIndex}=1`,
{
method: "GET",
}
)
.then((response) => {
if (response.ok) {
alert(
`TDR Messung der KÜ705-FO Strecke ${slotIndex + 1} wurde durchgeführt`
);
/* alert(
`TDR erfolgreich gestartet für Slot format ${Number(slotFormat) + 1}`
); */
console.log("TDR erfolgreich gestartet für Slot", slotIndex + 1);
} else {
console.error("Fehler beim Senden der TDR-Anfrage");
} }
}) );
.catch((error) => {
console.error("Fehler:", error); if (response.ok) {
}) alert(
.finally(() => setLoading(false)); `TDR Messung der KÜ705-FO Strecke ${slotIndex + 1} wurde durchgeführt`
);
console.log("TDR erfolgreich gestartet für Slot", slotIndex + 1);
} else {
console.error("Fehler beim Senden der TDR-Anfrage");
}
} catch (error) {
console.error("Fehler:", error);
} finally {
setLoading(false);
}
}; };