🔧 Fix location name logic: User determines name, API only provides coordinates

- Removed automatic API location name usage
- User input from locationSearch field is used as location name
- API search only provides coordinates (latitude/longitude)
- User has full control over location naming
- Search functionality purely for coordinate lookup
This commit is contained in:
2025-09-08 21:44:18 +02:00
parent 7d88ad036d
commit b610d85313

View File

@@ -68,33 +68,33 @@ function toggleTokenFields() {
} }
}, 400); }, 400);
} }
} }
const secret = "542ff224606c61fb3024e22f76ef9ac8"; const secret = "542ff224606c61fb3024e22f76ef9ac8";
function isValidMac(mac) { function isValidMac(mac) {
const pattern = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$|^[0-9A-Fa-f]{12}$/; const pattern = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$|^[0-9A-Fa-f]{12}$/;
return pattern.test(mac); return pattern.test(mac);
} }
function showMessage(elementId, message, isError = false) { function showMessage(elementId, message, isError = false) {
const messageDiv = document.getElementById(elementId); const messageDiv = document.getElementById(elementId);
messageDiv.textContent = message; messageDiv.textContent = message;
messageDiv.classList.add("show"); messageDiv.classList.add("show");
setTimeout(() => { setTimeout(() => {
messageDiv.classList.remove("show"); messageDiv.classList.remove("show");
}, 4000); }, 4000);
} }
function showError(message) { function showError(message) {
showMessage("error", message, true); showMessage("error", message, true);
} }
function showSuccess(message) { function showSuccess(message) {
showMessage("success", message, false); showMessage("success", message, false);
} }
function setLoading(isLoading) { function setLoading(isLoading) {
const btnText = document.getElementById("btn-text"); const btnText = document.getElementById("btn-text");
const btn = document.querySelector(".generate-btn"); const btn = document.querySelector(".generate-btn");
@@ -107,9 +107,9 @@ function toggleTokenFields() {
btn.disabled = false; btn.disabled = false;
btn.style.opacity = '1'; btn.style.opacity = '1';
} }
} }
async function saveToDatabase(token, tier) { async function saveToDatabase(token, tier) {
const description = document.getElementById("description").value.trim(); const description = document.getElementById("description").value.trim();
const standorte = document.getElementById("standorte").value.trim(); const standorte = document.getElementById("standorte").value.trim();
@@ -139,9 +139,9 @@ function toggleTokenFields() {
throw new Error(`Automatisches Speichern fehlgeschlagen. Server nicht erreichbar.\n\nFühren Sie folgenden SQL-Befehl manuell aus:\n${sql}`); throw new Error(`Automatisches Speichern fehlgeschlagen. Server nicht erreichbar.\n\nFühren Sie folgenden SQL-Befehl manuell aus:\n${sql}`);
} }
} }
async function generateLicense() { async function generateLicense() {
const macInput = document.getElementById("mac").value.trim(); const macInput = document.getElementById("mac").value.trim();
const tierInput = document.getElementById("tier").value.trim(); const tierInput = document.getElementById("tier").value.trim();
const resultDiv = document.getElementById("result"); const resultDiv = document.getElementById("result");
@@ -172,7 +172,7 @@ function toggleTokenFields() {
// Standort automatisch speichern, falls vorhanden // Standort automatisch speichern, falls vorhanden
let locationSaved = false; let locationSaved = false;
const locationName = document.getElementById('realLocationName')?.value || document.getElementById('locationSearch')?.value?.trim(); const locationName = document.getElementById('locationSearch')?.value?.trim();
const latitude = document.getElementById('latitude')?.textContent; const latitude = document.getElementById('latitude')?.textContent;
const longitude = document.getElementById('longitude')?.textContent; const longitude = document.getElementById('longitude')?.textContent;
@@ -234,9 +234,9 @@ function toggleTokenFields() {
} finally { } finally {
setLoading(false); setLoading(false);
} }
} }
async function copyToClipboard() { async function copyToClipboard() {
const licenseOutput = document.getElementById("license-output"); const licenseOutput = document.getElementById("license-output");
const copyBtn = document.getElementById("copyButton"); const copyBtn = document.getElementById("copyButton");
@@ -266,30 +266,30 @@ function toggleTokenFields() {
copyBtn.classList.remove("copied"); copyBtn.classList.remove("copied");
}, 2000); }, 2000);
} }
} }
// Enter key support // Enter key support
document.addEventListener('keypress', function(e) { document.addEventListener('keypress', function (e) {
if (e.key === 'Enter') { if (e.key === 'Enter') {
generateLicense(); generateLicense();
} }
}); });
// Input formatting for MAC address // Input formatting for MAC address
document.getElementById('mac').addEventListener('input', function(e) { document.getElementById('mac').addEventListener('input', function (e) {
let value = e.target.value.replace(/[^0-9A-Fa-f]/g, ''); let value = e.target.value.replace(/[^0-9A-Fa-f]/g, '');
if (value.length > 12) value = value.substr(0, 12); if (value.length > 12) value = value.substr(0, 12);
// Add colons every 2 characters // Add colons every 2 characters
value = value.replace(/(.{2})/g, '$1:').replace(/:$/, ''); value = value.replace(/(.{2})/g, '$1:').replace(/:$/, '');
e.target.value = value; e.target.value = value;
}); });
// Input event listener für Lizenzstufe // Input event listener für Lizenzstufe
document.getElementById('tier').addEventListener('input', toggleTokenFields); document.getElementById('tier').addEventListener('input', toggleTokenFields);
// Standortsuche-Funktionalität // Standortsuche-Funktionalität
async function searchLocation(buttonElement) { async function searchLocation(buttonElement) {
const locationInput = document.getElementById('locationSearch').value.trim(); const locationInput = document.getElementById('locationSearch').value.trim();
const coordinatesDiv = document.getElementById('coordinates'); const coordinatesDiv = document.getElementById('coordinates');
const mapContainer = document.getElementById('mapContainer'); const mapContainer = document.getElementById('mapContainer');
@@ -331,18 +331,8 @@ function toggleTokenFields() {
const lat = parseFloat(location.lat); const lat = parseFloat(location.lat);
const lon = parseFloat(location.lon); const lon = parseFloat(location.lon);
// Echten Standortnamen aus der API speichern // Der Name wird vom User bestimmt - nur Koordinaten aus der API verwenden
const realLocationName = location.display_name || location.name || locationInput; // Kein verstecktes Feld nötig, da der User den Namen selbst eingibt
// Verstecktes Feld für echten Standortnamen erstellen/aktualisieren
let locationNameField = document.getElementById('realLocationName');
if (!locationNameField) {
locationNameField = document.createElement('input');
locationNameField.type = 'hidden';
locationNameField.id = 'realLocationName';
document.body.appendChild(locationNameField);
}
locationNameField.value = realLocationName;
// Koordinaten anzeigen // Koordinaten anzeigen
updateCoordinates(lat, lon); updateCoordinates(lat, lon);
@@ -353,7 +343,7 @@ function toggleTokenFields() {
mapContainer.style.display = 'block'; mapContainer.style.display = 'block';
// Erfolgsmeldung // Erfolgsmeldung
showSuccess(`Standort "${realLocationName}" erfolgreich gefunden! Klicken Sie auf die Karte, um den Pin zu verschieben.`); showSuccess(`Koordinaten für "${locationInput}" erfolgreich gefunden! Klicken Sie auf die Karte, um den Pin zu verschieben.`);
} catch (error) { } catch (error) {
showError(`Fehler bei der Standortsuche: ${error.message}`); showError(`Fehler bei der Standortsuche: ${error.message}`);
@@ -366,10 +356,10 @@ function toggleTokenFields() {
searchBtn.disabled = false; searchBtn.disabled = false;
} }
} }
} }
// Koordinaten aktualisieren // Koordinaten aktualisieren
function updateCoordinates(lat, lon) { function updateCoordinates(lat, lon) {
const latitudeSpan = document.getElementById('latitude'); const latitudeSpan = document.getElementById('latitude');
const longitudeSpan = document.getElementById('longitude'); const longitudeSpan = document.getElementById('longitude');
@@ -377,10 +367,10 @@ function toggleTokenFields() {
latitudeSpan.textContent = lat.toFixed(6); latitudeSpan.textContent = lat.toFixed(6);
longitudeSpan.textContent = lon.toFixed(6); longitudeSpan.textContent = lon.toFixed(6);
} }
} }
// Interaktive Karte erstellen // Interaktive Karte erstellen
function createInteractiveMap(initialLat, initialLon) { function createInteractiveMap(initialLat, initialLon) {
const mapFrame = document.getElementById('mapFrame'); const mapFrame = document.getElementById('mapFrame');
// Verwende Leaflet.js für interaktive Karte // Verwende Leaflet.js für interaktive Karte
@@ -397,10 +387,10 @@ function toggleTokenFields() {
// Leaflet.js laden und Karte initialisieren // Leaflet.js laden und Karte initialisieren
loadLeafletAndCreateMap(initialLat, initialLon); loadLeafletAndCreateMap(initialLat, initialLon);
} }
// Leaflet.js laden und Karte erstellen // Leaflet.js laden und Karte erstellen
function loadLeafletAndCreateMap(initialLat, initialLon) { function loadLeafletAndCreateMap(initialLat, initialLon) {
// Prüfe ob Leaflet bereits geladen ist // Prüfe ob Leaflet bereits geladen ist
if (typeof L !== 'undefined') { if (typeof L !== 'undefined') {
createMap(initialLat, initialLon); createMap(initialLat, initialLon);
@@ -418,10 +408,10 @@ function toggleTokenFields() {
leafletScript.src = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js'; leafletScript.src = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js';
leafletScript.onload = () => createMap(initialLat, initialLon); leafletScript.onload = () => createMap(initialLat, initialLon);
document.head.appendChild(leafletScript); document.head.appendChild(leafletScript);
} }
// Karte mit Leaflet erstellen // Karte mit Leaflet erstellen
function createMap(initialLat, initialLon) { function createMap(initialLat, initialLon) {
try { try {
const map = L.map('map').setView([initialLat, initialLon], 15); const map = L.map('map').setView([initialLat, initialLon], 15);
@@ -437,7 +427,7 @@ function toggleTokenFields() {
}).addTo(map); }).addTo(map);
// Marker-Drag Event // Marker-Drag Event
marker.on('dragend', function(event) { marker.on('dragend', function (event) {
const newLat = event.target.getLatLng().lat; const newLat = event.target.getLatLng().lat;
const newLon = event.target.getLatLng().lng; const newLon = event.target.getLatLng().lng;
updateCoordinates(newLat, newLon); updateCoordinates(newLat, newLon);
@@ -445,7 +435,7 @@ function toggleTokenFields() {
}); });
// Klick-Event auf die Karte // Klick-Event auf die Karte
map.on('click', function(event) { map.on('click', function (event) {
const newLat = event.latlng.lat; const newLat = event.latlng.lat;
const newLon = event.latlng.lng; const newLon = event.latlng.lng;
@@ -466,14 +456,14 @@ function toggleTokenFields() {
console.error('Fehler beim Erstellen der Karte:', error); console.error('Fehler beim Erstellen der Karte:', error);
// Fallback zu iframe // Fallback zu iframe
const mapFrame = document.getElementById('mapFrame'); const mapFrame = document.getElementById('mapFrame');
const mapUrl = `https://www.openstreetmap.org/export/embed.html?bbox=${initialLon-0.01},${initialLat-0.01},${initialLon+0.01},${initialLat+0.01}&layer=mapnik&marker=${initialLat},${initialLon}`; const mapUrl = `https://www.openstreetmap.org/export/embed.html?bbox=${initialLon - 0.01},${initialLat - 0.01},${initialLon + 0.01},${initialLat + 0.01}&layer=mapnik&marker=${initialLat},${initialLon}`;
mapFrame.innerHTML = `<iframe src="${mapUrl}" width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" title="Standort auf der Karte"></iframe>`; mapFrame.innerHTML = `<iframe src="${mapUrl}" width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" title="Standort auf der Karte"></iframe>`;
} }
} }
// Standort in Datenbank speichern // Standort in Datenbank speichern
async function saveLocationToDatabase() { async function saveLocationToDatabase() {
const locationName = document.getElementById('realLocationName')?.value || document.getElementById('locationSearch').value.trim(); const locationName = document.getElementById('locationSearch').value.trim();
const latitude = document.getElementById('latitude').textContent; const latitude = document.getElementById('latitude').textContent;
const longitude = document.getElementById('longitude').textContent; const longitude = document.getElementById('longitude').textContent;
const saveBtn = document.getElementById('saveLocationBtn'); const saveBtn = document.getElementById('saveLocationBtn');
@@ -527,15 +517,15 @@ function toggleTokenFields() {
saveBtn.innerHTML = '💾 Standort in Datenbank speichern'; saveBtn.innerHTML = '💾 Standort in Datenbank speichern';
saveBtn.disabled = false; saveBtn.disabled = false;
} }
} }
// Zurück zum Dashboard // Zurück zum Dashboard
function goBackToDashboard() { function goBackToDashboard() {
window.location.href = '/admin-dashboard'; window.location.href = '/admin-dashboard';
} }
// Logout-Funktion // Logout-Funktion
async function logout() { async function logout() {
try { try {
const response = await fetch('/api/v1/public/logout', { const response = await fetch('/api/v1/public/logout', {
method: 'POST', method: 'POST',
@@ -558,13 +548,13 @@ function toggleTokenFields() {
// Bei Fehler trotzdem zur Login-Seite weiterleiten // Bei Fehler trotzdem zur Login-Seite weiterleiten
window.location.href = '/login'; window.location.href = '/login';
} }
} }
// Enter-Taste für Standortsuche // Enter-Taste für Standortsuche
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function () {
const locationSearch = document.getElementById('locationSearch'); const locationSearch = document.getElementById('locationSearch');
if (locationSearch) { if (locationSearch) {
locationSearch.addEventListener('keypress', function(e) { locationSearch.addEventListener('keypress', function (e) {
if (e.key === 'Enter') { if (e.key === 'Enter') {
searchLocation(); searchLocation();
} }
@@ -574,10 +564,10 @@ function toggleTokenFields() {
// Add cookie settings button functionality // Add cookie settings button functionality
const cookieSettingsBtn = document.getElementById('cookie-settings-footer'); const cookieSettingsBtn = document.getElementById('cookie-settings-footer');
if (cookieSettingsBtn) { if (cookieSettingsBtn) {
cookieSettingsBtn.addEventListener('click', function() { cookieSettingsBtn.addEventListener('click', function () {
if (window.cookieConsent) { if (window.cookieConsent) {
window.cookieConsent.resetConsent(); window.cookieConsent.resetConsent();
} }
}); });
} }
}); });