diff --git a/app.py b/app.py index b09ddca..a414152 100644 --- a/app.py +++ b/app.py @@ -50,7 +50,8 @@ def init_db(): telefon TEXT, mobil TEXT, email TEXT, - bemerkung TEXT + bemerkung TEXT, + fachrichtung TEXT ) ''') @@ -63,6 +64,7 @@ def init_db(): c.execute('CREATE INDEX IF NOT EXISTS idx_customers_telefon ON customers(telefon)') c.execute('CREATE INDEX IF NOT EXISTS idx_customers_mobil ON customers(mobil)') c.execute('CREATE INDEX IF NOT EXISTS idx_customers_email ON customers(email)') + c.execute('CREATE INDEX IF NOT EXISTS idx_customers_fachrichtung ON customers(fachrichtung)') # Erstelle einen zusammengesetzten Index für die häufigste Suchkombination c.execute('CREATE INDEX IF NOT EXISTS idx_customers_name_ort ON customers(name, ort)') @@ -97,8 +99,8 @@ def import_csv(): # Importiere die Daten for _, row in df.iterrows(): c.execute(''' - INSERT INTO customers (nummer, name, strasse, plz, ort, telefon, mobil, email, bemerkung) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) + INSERT INTO customers (nummer, name, strasse, plz, ort, telefon, mobil, email, bemerkung, fachrichtung) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ''', ( row['Nummer'], row['name'], @@ -108,7 +110,8 @@ def import_csv(): row['Tel'], row['Handy'], row['mail'], - f"Fachrichtung: {row['Fachrichtung']}" + f"Fachrichtung: {row['Fachrichtung']}", + row['Fachrichtung'] )) conn.commit() @@ -132,8 +135,8 @@ def search_customers(search_params): # Allgemeine Suche über alle Felder if search_params.get('q'): search_term = f"%{search_params['q']}%" - query += " AND (name LIKE ? OR ort LIKE ? OR nummer LIKE ? OR telefon LIKE ? OR mobil LIKE ? OR email LIKE ? OR bemerkung LIKE ?)" - params.extend([search_term] * 7) + query += " AND (name LIKE ? OR ort LIKE ? OR nummer LIKE ? OR telefon LIKE ? OR mobil LIKE ? OR email LIKE ? OR bemerkung LIKE ? OR fachrichtung LIKE ?)" + params.extend([search_term] * 8) # Spezifische Suche für einzelne Felder if search_params.get('name'): @@ -169,7 +172,8 @@ def search_customers(search_params): 'telefon': row[6], 'mobil': row[7], 'email': row[8], - 'bemerkung': row[9] + 'bemerkung': row[9], + 'fachrichtung': row[10] } customers.append(customer) @@ -270,7 +274,8 @@ def search(): 'plz': request.args.get('plz', ''), 'telefon': request.args.get('telefon', ''), 'email': request.args.get('email', ''), - 'q': request.args.get('q', '') + 'q': request.args.get('q', ''), + 'fachrichtung': request.args.get('fachrichtung', '') } # Führe die Suche in der Datenbank durch diff --git a/templates/index.html b/templates/index.html index 47df2dd..a87e4b1 100644 --- a/templates/index.html +++ b/templates/index.html @@ -58,6 +58,11 @@ + +
+ + +
@@ -256,6 +261,7 @@ const ort = document.getElementById('ortInput').value; const nummer = document.getElementById('nummerInput').value; const plz = document.getElementById('plzInput').value; + const fachrichtung = document.getElementById('fachrichtungInput').value; // Zeige das Lade-Icon document.getElementById('loading').style.display = 'block'; @@ -267,6 +273,7 @@ if (ort) params.append('ort', ort); if (nummer) params.append('nummer', nummer); if (plz) params.append('plz', plz); + if (fachrichtung) params.append('fachrichtung', fachrichtung); // Führe die Suche durch fetch('/search?' + params.toString()) @@ -323,7 +330,8 @@ document.getElementById('nameInput'), document.getElementById('ortInput'), document.getElementById('nummerInput'), - document.getElementById('plzInput') + document.getElementById('plzInput'), + document.getElementById('fachrichtungInput') ]; const resetIcons = [ @@ -331,7 +339,8 @@ document.querySelector('.reset-icon[onclick="clearInput(\'nameInput\')"]'), document.querySelector('.reset-icon[onclick="clearInput(\'ortInput\')"]'), document.querySelector('.reset-icon[onclick="clearInput(\'nummerInput\')"]'), - document.querySelector('.reset-icon[onclick="clearInput(\'plzInput\')"]') + document.querySelector('.reset-icon[onclick="clearInput(\'plzInput\')"]'), + document.querySelector('.reset-icon[onclick="clearInput(\'fachrichtungInput\')"]') ]; searchInputs.forEach((input, index) => {