From b0165a27128435e7a5fffdc541a1e347f596c1fd Mon Sep 17 00:00:00 2001 From: Claude Project Manager Date: Thu, 25 Sep 2025 00:12:50 +0200 Subject: [PATCH] Organigramm Zeilenumbruch geht --- backend/src/routes/organizationImport.ts | 45 +++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/backend/src/routes/organizationImport.ts b/backend/src/routes/organizationImport.ts index 2e0c932..276e1cb 100644 --- a/backend/src/routes/organizationImport.ts +++ b/backend/src/routes/organizationImport.ts @@ -29,7 +29,7 @@ const upload = multer({ function parseOrganizationFromText(text: string) { const units: any[] = [] const byCode = new Map() - const lines = text.split('\n').map(line => line.trim()).filter(line => line && line.length > 2) + const rawLines = text.split('\n').map(line => line.trim()).filter(line => line && line.length > 2) const patterns = { direktor: /(Direktor|Director)\s*(LKA)?/i, @@ -45,6 +45,49 @@ function parseOrganizationFromText(text: string) { '1': '#dc2626', '2': '#ea580c', '3': '#0891b2', '4': '#7c3aed', '5': '#0d9488', '6': '#be185d', 'ZA': '#6b7280' } + // Join wrapped description lines to their header lines to avoid losing info across line breaks + // Recognize headers that start a new unit and merge subsequent non-header lines into the previous one + const headerRegex = new RegExp( + '^(?:' + + 'Abteilung\\s+(?:\\d+|Zentralabteilung)' + + '|Zentralabteilung\\b' + + '|ZA\\b' + + '|(?:Dezernat|Dez)\\s+' + + '|SG\\s+' + + '|TD\\s+' + + '|Direktor' + + '|Director' + + '|Leitungsstab' + + '|LStab' + + '|Führungsgruppe' + + '|Personalrat' + + '|Schwerbehindertenvertretung' + + '|Datenschutzbeauftrag' + + '|Gleichstellungsbeauftrag' + + '|Innenrevision' + + '|IUK-Lage' + + ')', + 'i' + ) + const lines: string[] = [] + for (const original of rawLines) { + const line = original.replace(/[–—]/g, '-') + if (lines.length === 0 || headerRegex.test(line)) { + lines.push(line) + } else { + // continuation line: append to previous with spacing; handle hyphenation + const lastIdx = lines.length - 1 + const prev = lines[lastIdx] + if (/[-–—]$/.test(prev)) { + lines[lastIdx] = prev.replace(/[-–—]$/, '') + line + } else if (/[,:;]$/.test(prev)) { + lines[lastIdx] = prev + ' ' + line + } else { + lines[lastIdx] = prev + ' ' + line + } + } + } + const ensure = (u: any) => { const existing = byCode.get(u.code) if (existing) {