diff --git a/templates/index.html b/templates/index.html index 87d314a..98bb742 100644 --- a/templates/index.html +++ b/templates/index.html @@ -312,59 +312,52 @@ if (query) params.append('q', query); fetch(`/search?${params.toString()}`) - .then(response => { - if (!response.ok) { - return response.json().then(data => { - throw new Error(data.error || 'Ein Fehler ist aufgetreten'); - }); - } - return response.json(); - }) + .then(response => response.json()) .then(data => { - const resultsDiv = document.getElementById('results'); - resultsDiv.innerHTML = ''; - - if (data.length === 0) { - resultsDiv.innerHTML = '
Keine Ergebnisse gefunden.
'; - lastResults = []; - updateResultCounts(); + if (data.error) { + showError(data.error); return; } - - data.forEach(customer => { - const card = document.createElement('div'); - card.className = 'card result-card'; - card.innerHTML = ` -
-
${customer.Vorname} ${customer.Nachname}
-

- Kundennummer: ${customer.Nummer}
- Fachrichtung: ${customer.Fachrichtung || 'N/A'}
- Adresse: ${createAddressLink(customer.Strasse, customer.PLZ, customer.Ort)} - ${customer.weather ? ` - - ${customer.weather.description} - ${customer.weather.temperature}°C - - ` : ''} -
- Telefon: ${createPhoneLink(customer.Tel)}
- E-Mail: ${createEmailLink(customer.mail)} -

-
- + + const resultsContainer = document.getElementById('results'); + resultsContainer.innerHTML = ''; + + if (data.results && data.results.length > 0) { + data.results.forEach(customer => { + const card = document.createElement('div'); + card.className = 'card mb-3'; + card.innerHTML = ` +
+
${customer.Vorname} ${customer.Nachname}
+

+ Kundennummer: ${customer.Nummer}
+ Fachrichtung: ${customer.Fachrichtung || 'N/A'}
+ Adresse: ${createAddressLink(customer.Strasse, customer.PLZ, customer.Ort)} + ${customer.weather ? ` + + ${customer.weather.description} + ${customer.weather.temperature}°C + + ` : ''} +
+ Telefon: ${createPhoneLink(customer.Tel)}
+ E-Mail: ${createEmailLink(customer.mail)} +

-
- `; - resultsDiv.appendChild(card); - }); - - lastResults = data; - updateResultCounts(); + `; + resultsContainer.appendChild(card); + }); + + // Zeige die Anzahl der Treffer an + const totalResults = document.getElementById('total-results'); + if (totalResults) { + totalResults.textContent = `${data.total} Treffer gefunden`; + } + } else { + resultsContainer.innerHTML = '
Keine Ergebnisse gefunden.
'; + } }) .catch(error => { console.error('Fehler:', error);