Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
3f69ba6198 | |||
7e812eb835 | |||
ece7f984f7 |
@@ -18,6 +18,7 @@
|
|||||||
.main-content {
|
.main-content {
|
||||||
flex: 1 0 auto;
|
flex: 1 0 auto;
|
||||||
padding: 2rem 0;
|
padding: 2rem 0;
|
||||||
|
margin-bottom: 4rem; /* Platz für die fixierte Fußzeile */
|
||||||
}
|
}
|
||||||
.search-container {
|
.search-container {
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
@@ -75,6 +76,10 @@
|
|||||||
background-color: #f8f9fa;
|
background-color: #f8f9fa;
|
||||||
border-top: 1px solid #dee2e6;
|
border-top: 1px solid #dee2e6;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
z-index: 100;
|
||||||
}
|
}
|
||||||
.share-feedback {
|
.share-feedback {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
@@ -102,6 +107,14 @@
|
|||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
|
background-color: #0d6efd;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
}
|
||||||
|
.share-button:hover {
|
||||||
|
background-color: #0b5ed7;
|
||||||
}
|
}
|
||||||
.search-fields {
|
.search-fields {
|
||||||
display: grid;
|
display: grid;
|
||||||
@@ -139,6 +152,20 @@
|
|||||||
margin-left: 4px;
|
margin-left: 4px;
|
||||||
font-size: 1.2em;
|
font-size: 1.2em;
|
||||||
}
|
}
|
||||||
|
.customer-card {
|
||||||
|
background: white;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 1.5rem;
|
||||||
|
margin-bottom: 1.5rem;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
|
||||||
|
border-bottom: 1px solid #e9ecef;
|
||||||
|
}
|
||||||
|
.customer-card:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
.customer-info {
|
||||||
|
margin-bottom: 1rem;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -211,8 +238,8 @@
|
|||||||
|
|
||||||
function createPhoneLink(phone) {
|
function createPhoneLink(phone) {
|
||||||
if (!phone) return 'N/A';
|
if (!phone) return 'N/A';
|
||||||
const cleaned = phone.replace(/\D/g, '');
|
const cleaned = phone.replace(/[^\d+\s]/g, '');
|
||||||
const telLink = '0' + cleaned;
|
const telLink = cleaned.startsWith('+') ? cleaned : '0' + cleaned.replace(/\s/g, '');
|
||||||
return `<a href="tel:${telLink}" class="phone-link">${phone}</a>`;
|
return `<a href="tel:${telLink}" class="phone-link">${phone}</a>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,11 +248,55 @@
|
|||||||
return `<a href="mailto:${email}" class="email-link">${email}</a>`;
|
return `<a href="mailto:${email}" class="email-link">${email}</a>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function highlightText(text, searchTerms) {
|
||||||
|
// Konvertiere text zu String und prüfe auf null/undefined
|
||||||
|
const textStr = String(text || '');
|
||||||
|
if (!textStr || !searchTerms || searchTerms.length === 0) return textStr;
|
||||||
|
|
||||||
|
// Escapen der Suchbegriffe für reguläre Ausdrücke
|
||||||
|
const escapedTerms = searchTerms.map(term =>
|
||||||
|
String(term || '').replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||||
|
).filter(term => term.length > 0);
|
||||||
|
|
||||||
|
if (escapedTerms.length === 0) return textStr;
|
||||||
|
|
||||||
|
// Erstelle einen temporären div-Element
|
||||||
|
const tempDiv = document.createElement('div');
|
||||||
|
tempDiv.innerHTML = textStr;
|
||||||
|
|
||||||
|
// Funktion zum Hervorheben von Text
|
||||||
|
function highlightNode(node) {
|
||||||
|
if (node.nodeType === 3) { // Text node
|
||||||
|
const text = node.textContent;
|
||||||
|
let newText = text;
|
||||||
|
|
||||||
|
escapedTerms.forEach(term => {
|
||||||
|
const regex = new RegExp(`(${term})`, 'gi');
|
||||||
|
newText = newText.replace(regex, '<mark>$1</mark>');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (newText !== text) {
|
||||||
|
const span = document.createElement('span');
|
||||||
|
span.innerHTML = newText;
|
||||||
|
node.parentNode.replaceChild(span, node);
|
||||||
|
}
|
||||||
|
} else if (node.nodeType === 1) { // Element node
|
||||||
|
// Überspringe mark-Tags und Links
|
||||||
|
if (node.tagName !== 'MARK' && node.tagName !== 'A') {
|
||||||
|
Array.from(node.childNodes).forEach(highlightNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
highlightNode(tempDiv);
|
||||||
|
return tempDiv.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
function createAddressLink(street, plz, city) {
|
function createAddressLink(street, plz, city) {
|
||||||
if (!street || !plz || !city) return 'N/A';
|
if (!street || !plz || !city) return 'N/A';
|
||||||
const address = `${street}, ${plz} ${city}`;
|
const address = `${street}, ${plz} ${city}`;
|
||||||
const searchQuery = encodeURIComponent(address);
|
const searchQuery = encodeURIComponent(address);
|
||||||
return `${address}
|
return `<span class="address-text">${address}</span>
|
||||||
<a href="https://www.google.com/maps/search/?api=1&query=${searchQuery}"
|
<a href="https://www.google.com/maps/search/?api=1&query=${searchQuery}"
|
||||||
class="address-link" target="_blank" rel="noopener noreferrer">
|
class="address-link" target="_blank" rel="noopener noreferrer">
|
||||||
<i class="fa-solid fa-location-pin location-pin"></i>
|
<i class="fa-solid fa-location-pin location-pin"></i>
|
||||||
@@ -268,85 +339,128 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function searchCustomers() {
|
function searchCustomers() {
|
||||||
const name = document.getElementById('nameInput').value;
|
const query = document.getElementById('searchInput').value.trim();
|
||||||
const ort = document.getElementById('ortInput').value;
|
const fachrichtung = document.getElementById('fachrichtungInput').value.trim();
|
||||||
const kundennummer = document.getElementById('kundennummerInput').value;
|
const ort = document.getElementById('ortInput').value.trim();
|
||||||
const fachrichtung = document.getElementById('fachrichtungInput').value;
|
const name = document.getElementById('nameInput').value.trim();
|
||||||
const telefon = document.getElementById('telefonInput').value;
|
const telefon = document.getElementById('telefonInput').value.trim();
|
||||||
const query = document.getElementById('searchInput').value;
|
const kundennummer = document.getElementById('kundennummerInput')?.value.trim() || '';
|
||||||
|
|
||||||
// Prüfe, ob mindestens ein Suchfeld ausgefüllt ist
|
// Sammle alle nicht-leeren Suchbegriffe
|
||||||
if (!name && !ort && !kundennummer && !fachrichtung && !telefon && !query) {
|
const searchTerms = [query, fachrichtung, ort, name, telefon, kundennummer]
|
||||||
document.getElementById('results').innerHTML = '';
|
.filter(term => term && term.length > 0);
|
||||||
lastResults = [];
|
|
||||||
updateResultCounts();
|
// Prüfe, ob alle Suchfelder leer sind
|
||||||
|
if (searchTerms.length === 0) {
|
||||||
|
const resultsDiv = document.getElementById('results');
|
||||||
|
const generalCount = document.getElementById('generalCount');
|
||||||
|
resultsDiv.innerHTML = '';
|
||||||
|
generalCount.textContent = '';
|
||||||
|
generalCount.classList.remove('visible');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lade-Animation anzeigen
|
const resultsDiv = document.getElementById('results');
|
||||||
document.getElementById('loading').style.display = 'block';
|
const loadingDiv = document.getElementById('loading');
|
||||||
document.getElementById('results').innerHTML = '';
|
loadingDiv.style.display = 'block';
|
||||||
|
resultsDiv.innerHTML = '';
|
||||||
// URL-Parameter erstellen
|
|
||||||
const params = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
if (name) params.append('name', name);
|
if (query) searchParams.append('q', query);
|
||||||
if (ort) params.append('ort', ort);
|
if (fachrichtung) searchParams.append('fachrichtung', fachrichtung);
|
||||||
if (kundennummer) params.append('kundennummer', kundennummer);
|
if (ort) searchParams.append('ort', ort);
|
||||||
if (fachrichtung) params.append('fachrichtung', fachrichtung);
|
if (name) searchParams.append('name', name);
|
||||||
if (telefon) params.append('telefon', telefon);
|
if (telefon) searchParams.append('telefon', telefon);
|
||||||
if (query) params.append('q', query);
|
if (kundennummer) searchParams.append('kundennummer', kundennummer);
|
||||||
|
|
||||||
fetch(`/search?${params.toString()}`)
|
fetch(`/search?${searchParams.toString()}`)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data.error) {
|
resultsDiv.innerHTML = '';
|
||||||
showError(data.error);
|
|
||||||
|
// Prüfe, ob data ein Objekt mit results-Array ist
|
||||||
|
if (!data || !data.results || !Array.isArray(data.results)) {
|
||||||
|
console.error('Unerwartetes Datenformat:', data);
|
||||||
|
resultsDiv.innerHTML = '<div class="error">Unerwartetes Datenformat vom Server</div>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const resultsContainer = document.getElementById('results');
|
const results = data.results;
|
||||||
resultsContainer.innerHTML = '';
|
if (results.length === 0) {
|
||||||
|
resultsDiv.innerHTML = '<div class="no-results">Keine Ergebnisse gefunden</div>';
|
||||||
if (data.results && data.results.length > 0) {
|
|
||||||
data.results.forEach(customer => {
|
|
||||||
const card = document.createElement('div');
|
|
||||||
card.className = 'card mb-3';
|
|
||||||
const customerLink = createCustomerLink(customer.Nummer);
|
|
||||||
console.log('Customer:', customer); // Debug-Ausgabe
|
|
||||||
console.log('Customer link:', customerLink); // Debug-Ausgabe
|
|
||||||
card.innerHTML = `
|
|
||||||
<div class="card-body">
|
|
||||||
<h5 class="card-title">${customer.Vorname} ${customer.Nachname}</h5>
|
|
||||||
<p class="card-text">
|
|
||||||
<strong>Kundennummer:</strong> ${customerLink}<br>
|
|
||||||
<strong>Fachrichtung:</strong> ${customer.Fachrichtung || 'N/A'}<br>
|
|
||||||
<strong>Adresse:</strong> ${createAddressLink(customer.Strasse, customer.PLZ, customer.Ort)}<br>
|
|
||||||
<strong>Telefon:</strong> ${createPhoneLink(customer.Tel)}<br>
|
|
||||||
<strong>E-Mail:</strong> ${createEmailLink(customer.mail)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
resultsContainer.appendChild(card);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Zeige die Anzahl der Treffer an
|
|
||||||
const totalResults = document.getElementById('total-results');
|
|
||||||
if (totalResults) {
|
|
||||||
totalResults.textContent = `${data.total} Treffer gefunden`;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
resultsContainer.innerHTML = '<div class="alert alert-info">Keine Ergebnisse gefunden.</div>';
|
results.forEach(customer => {
|
||||||
|
const card = document.createElement('div');
|
||||||
|
card.className = 'customer-card';
|
||||||
|
|
||||||
|
// Debug-Ausgabe für die Kundendaten
|
||||||
|
console.log('Kundendaten:', customer);
|
||||||
|
console.log('Alle verfügbaren Felder:', Object.keys(customer));
|
||||||
|
console.log('Telefon-bezogene Felder:', {
|
||||||
|
Telefon: customer.Telefon,
|
||||||
|
Telefonnummer: customer.Telefonnummer,
|
||||||
|
telefon: customer.telefon,
|
||||||
|
telefonnummer: customer.telefonnummer,
|
||||||
|
phone: customer.phone,
|
||||||
|
'phone.number': customer.phone?.number
|
||||||
|
});
|
||||||
|
|
||||||
|
// Erstelle die Adresse mit Hervorhebung
|
||||||
|
const address = `${customer.Strasse || ''}, ${customer.PLZ || ''} ${customer.Ort || ''}`;
|
||||||
|
const addressLink = createAddressLink(customer.Strasse, customer.PLZ, customer.Ort);
|
||||||
|
const highlightedAddress = highlightText(addressLink, searchTerms);
|
||||||
|
|
||||||
|
// Erstelle die Kundennummer mit Hervorhebung
|
||||||
|
const highlightedNumber = highlightText(customer.Nummer, searchTerms);
|
||||||
|
const customerLink = createCustomerLink(customer.Nummer);
|
||||||
|
|
||||||
|
// Erstelle die Telefonnummern mit Hervorhebung
|
||||||
|
let phoneNumber = '';
|
||||||
|
let companyPhone = '';
|
||||||
|
let mobilePhone = '';
|
||||||
|
|
||||||
|
if (typeof customer === 'object') {
|
||||||
|
phoneNumber = customer.Tel || '';
|
||||||
|
companyPhone = customer['Tele Firma'] || '';
|
||||||
|
mobilePhone = customer.Handy || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
const phoneLink = createPhoneLink(phoneNumber);
|
||||||
|
const companyPhoneLink = createPhoneLink(companyPhone);
|
||||||
|
const mobilePhoneLink = createPhoneLink(mobilePhone);
|
||||||
|
|
||||||
|
const highlightedPhone = highlightText(phoneLink, searchTerms);
|
||||||
|
const highlightedCompanyPhone = highlightText(companyPhoneLink, searchTerms);
|
||||||
|
const highlightedMobilePhone = highlightText(mobilePhoneLink, searchTerms);
|
||||||
|
|
||||||
|
card.innerHTML = `
|
||||||
|
<div class="customer-info">
|
||||||
|
<strong>Kundennummer:</strong> ${customerLink}<br>
|
||||||
|
<strong>Name:</strong> ${highlightText(`${customer.Vorname || ''} ${customer.Nachname || ''}`, searchTerms)}<br>
|
||||||
|
<strong>Fachrichtung:</strong> ${highlightText(customer.Fachrichtung || '', searchTerms)}<br>
|
||||||
|
<strong>Adresse:</strong> ${highlightedAddress}<br>
|
||||||
|
<strong>Telefon:</strong> ${highlightedPhone}<br>
|
||||||
|
<strong>Firma:</strong> ${highlightedCompanyPhone}<br>
|
||||||
|
<strong>Mobil:</strong> ${highlightedMobilePhone}
|
||||||
|
</div>
|
||||||
|
<button class="share-button" onclick="copyCustomerLink('${customer.Nummer}')">
|
||||||
|
<i class="fas fa-share-alt"></i> Teilen
|
||||||
|
</button>
|
||||||
|
`;
|
||||||
|
resultsDiv.appendChild(card);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
// Aktualisiere die Anzahl der Treffer
|
||||||
|
const generalCount = document.getElementById('generalCount');
|
||||||
|
generalCount.textContent = results.length > 0 ? `${results.length} Treffer gefunden` : '';
|
||||||
|
generalCount.classList.toggle('visible', results.length > 0);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('Fehler:', error);
|
console.error('Fehler bei der Suche:', error);
|
||||||
document.getElementById('results').innerHTML =
|
resultsDiv.innerHTML = '<div class="error">Ein Fehler ist aufgetreten</div>';
|
||||||
`<div class="alert alert-danger">${error.message}</div>`;
|
|
||||||
lastResults = [];
|
|
||||||
updateResultCounts();
|
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
document.getElementById('loading').style.display = 'none';
|
loadingDiv.style.display = 'none';
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user