Fix: Improve owner name mapping and display logic in Manage Owners
Deploy Bürgerwind / deploy (push) Successful in 17s Details

This commit is contained in:
Johannes Baumeister 2026-05-08 13:33:37 +02:00
parent f8874a3e95
commit f26d1f1710
2 changed files with 23 additions and 17 deletions

36
app.js
View File

@ -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 = `
<td><b>${data.last}</b></td>
<td>${data.first}</td>
<td><b>${displayLast}</b></td>
<td>${displayFirst}</td>
<td style="font-size: 0.75rem; opacity: 0.8;">${data.address}</td>
<td>${data.count} Flurstücke</td>
<td>

View File

@ -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",