Files
nodeMap/utils/openInNewTab.js
ISA 3896381a8f Debug-Logging zentralisiert: Nutzung von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt und auf getDebugLog() mit config.json umgestellt
- Alle Vorkommen von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt
- Debug-Konfiguration erfolgt jetzt ausschließlich über public/config.json
- getDebugLog()-Utility überall verwendet
- .env-Dateien werden für Debug-Logging nicht mehr benötigt
- Alle betroffenen Komponenten, Services und API
2025-08-22 11:10:40 +02:00

41 lines
1.2 KiB
JavaScript

// utils/openInNewTab.js
export async function openInNewTab(e, target) {
const res = await fetch("/config.json");
const config = await res.json();
const basePath = config.basePath || "";
const url = new URL(window.location.origin);
const originWithoutPort = `${url.protocol}//${url.hostname}`; // ohne Port!
let link;
if (target instanceof L.Marker && target.options.link) {
link = `${originWithoutPort}${basePath}/devices/${target.options.link}`;
} else if (target instanceof L.Polyline) {
const idLD = target.options.idLD;
if (idLD) {
link = `${originWithoutPort}${basePath}/devices/cpl.aspx?id=${idLD}`;
} else {
console.error("Keine gültige 'idLD' für die Linie gefunden.");
return;
}
} else {
const lastElementType = localStorage.getItem("lastElementType");
if (lastElementType === "polyline") {
const savedLink = localStorage.getItem("polylineLink");
if (savedLink) {
link = `${originWithoutPort}${basePath}/devices/${savedLink}`;
}
}
}
if (link) {
if (getDebugLog()) {
console.log("🟢 Öffne Link:", link);
}
window.open(link, "_blank");
} else {
console.error("❌ Kein gültiger Link gefunden.");
}
}