From f26d1f17109913f3c3f8ea44ec79497518cbc906 Mon Sep 17 00:00:00 2001 From: Johannes Baumeister Date: Fri, 8 May 2026 13:33:37 +0200 Subject: [PATCH] Fix: Improve owner name mapping and display logic in Manage Owners --- app.js | 36 +++++++++++++++++++++--------------- server.js | 4 ++-- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app.js b/app.js index faf216f..7a361f0 100644 --- a/app.js +++ b/app.js @@ -9,7 +9,7 @@ document.addEventListener('DOMContentLoaded', async () => { turbines: [], activeVariant: 'A', bakedData: {}, // Cache for standalone persistence - ownerMapping: { firstName: 'VNA', lastName: 'GNA' }, // Default for ALKIS + ownerMapping: { firstName: 'vorname', lastName: 'nachname' }, // Default for ALKIS and modern Shapefiles ownerStatuses: {}, // { "name vorname": { status: "...", notiz: "..." } } showAuxiliary: true }; @@ -1286,8 +1286,8 @@ document.addEventListener('DOMContentLoaded', async () => { const layer = L.geoJSON(geojson, { style: (feature) => { const props = feature.properties; - const firstName = (props.VNA || '').trim(); - const lastName = (props.GNA || '').trim(); + const firstName = (props.vorname || props.VNA || '').trim(); + const lastName = (props.nachname || props.GNA || '').trim(); // Normalisierung des Namens für den Abgleich const normalize = (s) => (s || '').toString().toLowerCase().replace(/[^a-z0-9]/g, '').trim(); @@ -1329,8 +1329,8 @@ document.addEventListener('DOMContentLoaded', async () => { onEachFeature: (feature, layer) => { if (feature.properties) { const props = feature.properties; - const firstName = (props.VNA || '').trim(); - const lastName = (props.GNA || '').trim(); + const firstName = (props.vorname || props.VNA || '').trim(); + const lastName = (props.nachname || props.GNA || '').trim(); const normalize = (s) => (s || '').toString().toLowerCase().replace(/[^a-z0-9]/g, '').trim(); const ownerKey = normalize(firstName + lastName); @@ -1428,12 +1428,16 @@ document.addEventListener('DOMContentLoaded', async () => { } }); const sortedKeys = Array.from(allKeys); - const vnaMatch = sortedKeys.find(k => k.toUpperCase() === 'VNA'); - const gnaMatch = sortedKeys.find(k => k.toUpperCase() === 'GNA' || k.toUpperCase() === 'NBA'); + const vnaMatch = sortedKeys.find(k => k.toUpperCase() === 'VNA' || k.toUpperCase() === 'VORNAME'); + const gnaMatch = sortedKeys.find(k => k.toUpperCase() === 'GNA' || k.toUpperCase() === 'NBA' || k.toUpperCase() === 'NACHNAME' || k.toUpperCase() === 'NAME'); if (vnaMatch && gnaMatch) { state.ownerMapping = { firstName: vnaMatch, lastName: gnaMatch }; console.log("Auto-Mapping erfolgreich:", state.ownerMapping); + } else if (gnaMatch) { + // If only last name/name is found, use it + state.ownerMapping = { firstName: '', lastName: gnaMatch }; + console.log("Partial Auto-Mapping (Last Name only):", state.ownerMapping); } } @@ -1465,10 +1469,9 @@ document.addEventListener('DOMContentLoaded', async () => { selectFirstName.innerHTML = optionsHtml; selectLastName.innerHTML = optionsHtml; - // Smart Defaults: Prefer VNA for First Name and NBA (or GNA/Name) for Last Name - const vnaMatch = sortedKeys.find(k => k.toLowerCase() === 'vna'); - const nbaMatch = sortedKeys.find(k => k.toLowerCase() === 'nba'); - const gnaMatch = sortedKeys.find(k => k.toLowerCase() === 'gna'); + // Smart Defaults + const vnaMatch = sortedKeys.find(k => ['vorname', 'vna', 'first'].includes(k.toLowerCase())); + const gnaMatch = sortedKeys.find(k => ['nachname', 'gna', 'nba', 'name', 'last'].includes(k.toLowerCase())); if (vnaMatch) selectFirstName.value = vnaMatch; else { @@ -1476,8 +1479,7 @@ document.addEventListener('DOMContentLoaded', async () => { if (vMatch) selectFirstName.value = vMatch; } - if (nbaMatch) selectLastName.value = nbaMatch; - else if (gnaMatch) selectLastName.value = gnaMatch; + if (gnaMatch) selectLastName.value = gnaMatch; else { const nMatch = sortedKeys.find(k => k.toLowerCase().startsWith('n')); if (nMatch) selectLastName.value = nMatch; @@ -1553,9 +1555,13 @@ document.addEventListener('DOMContentLoaded', async () => { const notiz = typeof stored === 'object' ? (stored.notiz || '') : ''; const row = document.createElement('tr'); + // If last name is missing but first name has content, show first name in bold + const displayLast = data.last || data.first || 'Unbekannt'; + const displayFirst = data.last ? data.first : ''; + row.innerHTML = ` - ${data.last} - ${data.first} + ${displayLast} + ${displayFirst} ${data.address} ${data.count} Flurstücke diff --git a/server.js b/server.js index 514960b..c4b10ef 100644 --- a/server.js +++ b/server.js @@ -220,8 +220,8 @@ app.get('/api/layers/alkis', async (req, res) => { 'geometry', ST_AsGeoJSON(ST_Transform(geom, 4326))::jsonb, 'properties', jsonb_build_object( 'id', id, - 'VNA', "VNA", - 'GNA', "GNA", + 'vorname', "VNA", + 'nachname', "GNA", 'FSK', "FSK", 'PLZ', "PLZ", 'ORP', "ORP",