From d14ac5d9af79850ebd91331141fb7a9f90bf5a9e Mon Sep 17 00:00:00 2001 From: elpatron Date: Fri, 21 Mar 2025 12:04:17 +0100 Subject: [PATCH] Feature: CSV-Export der Suchergebnisse --- CHANGELOG.md | 6 ++++ static/js/main.js | 72 ++++++++++++++++++++++++++++++++++++++++++++ templates/index.html | 3 ++ 3 files changed, 81 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89c76d3..ff8e771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ Alle wichtigen Änderungen an diesem Projekt werden in dieser Datei dokumentiert Das Format basiert auf [Keep a Changelog](https://keepachangelog.com/de/1.0.0/), und dieses Projekt adhäriert zu [Semantic Versioning](https://semver.org/lang/de/). +## [Unreleased] +### Hinzugefügt +- CSV-Export-Funktion für Suchergebnisse +- Export-Button in der Benutzeroberfläche +- Automatische Formatierung der CSV-Datei mit allen relevanten Kundendaten + ## [1.2.16] - 2024-03-21 ### Geändert - Verbesserte Darstellung der Suchergebnisse mit rechtsbündigen Aktionen diff --git a/static/js/main.js b/static/js/main.js index 0b15319..0629fb8 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -124,6 +124,78 @@ function updateResultCounts() { document.getElementById('resultCount').textContent = generalCount > 0 ? `${generalCount} Treffer gefunden` : ''; document.getElementById('resultCount').classList.toggle('visible', generalCount > 0); + + // Export-Button anzeigen/verstecken + document.getElementById('exportButton').style.display = generalCount > 0 ? 'inline-block' : 'none'; +} + +function exportToCSV() { + if (!lastResults || lastResults.length === 0) return; + + // CSV-Header definieren + const headers = [ + 'Nummer', + 'Name', + 'Fachrichtung', + 'Straße', + 'PLZ', + 'Ort', + 'Telefon', + 'Mobil', + 'Handy', + 'Telefon Firma', + 'E-Mail', + 'Kontakt 1', + 'Kontakt 2', + 'Kontakt 3', + 'Tags' + ]; + + // CSV-Daten erstellen + const csvRows = [headers]; + + lastResults.forEach(customer => { + const row = [ + customer.nummer, + customer.name, + customer.fachrichtung, + customer.strasse, + customer.plz, + customer.ort, + customer.telefon, + customer.mobil, + customer.handy, + customer.tele_firma, + customer.email, + customer.kontakt1, + customer.kontakt2, + customer.kontakt3, + (customer.tags || []).join(';') + ].map(value => { + // Werte mit Kommas oder Anführungszeichen in Anführungszeichen setzen + if (value && (value.includes(',') || value.includes('"') || value.includes('\n'))) { + return `"${value.replace(/"/g, '""')}"`; + } + return value || ''; + }); + + csvRows.push(row); + }); + + // CSV-String erstellen + const csvContent = csvRows.map(row => row.join(',')).join('\n'); + + // Blob erstellen und Download starten + const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' }); + const link = document.createElement('a'); + const url = URL.createObjectURL(blob); + + link.setAttribute('href', url); + link.setAttribute('download', `kundensuche_${new Date().toISOString().split('T')[0]}.csv`); + link.style.visibility = 'hidden'; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); } function displayResults(results) { diff --git a/templates/index.html b/templates/index.html index 6800938..05c3dc7 100644 --- a/templates/index.html +++ b/templates/index.html @@ -82,6 +82,9 @@
+