Files
nodeMap/utils/openInNewTab.js
ISA 9a2b438eaf feat: basePath-Konfiguration von .env in config.json verschoben
basePath wird jetzt in config.json gepflegt statt als NEXT_PUBLIC_BASE_PATH in .env.*
Alle relevanten Code-Stellen lesen basePath dynamisch aus config.json
Dokumentation und Beispiele in Markdown-Dateien entsprechend angepasst
Erhöhte Flexibilität für Deployments ohne Rebuild
2025-08-20 08:42:24 +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 (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") {
console.log("🟢 Öffne Link:", link);
}
window.open(link, "_blank");
} else {
console.error("❌ Kein gültiger Link gefunden.");
}
}