Compare commits
5 Commits
v1.2.14
...
d14ac5d9af
Author | SHA1 | Date | |
---|---|---|---|
d14ac5d9af | |||
b4939147c4 | |||
2a33fc45de | |||
3a317de8f0 | |||
f626cd52fd |
18
CHANGELOG.md
18
CHANGELOG.md
@@ -5,6 +5,24 @@ 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/),
|
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/).
|
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
|
||||||
|
- Optimierte CSS-Styles für bessere Lesbarkeit und Layout
|
||||||
|
- JavaScript-Code in separate Datei ausgelagert für bessere Wartbarkeit
|
||||||
|
|
||||||
|
## [1.2.15] - 2024-03-20
|
||||||
|
### Hinzugefügt
|
||||||
|
- Autovervollständigung für das Ort-Feld
|
||||||
|
- Neue API-Route für Ortsvorschläge
|
||||||
|
- Optimierte SQL-Abfragen für die Ortssuche
|
||||||
|
|
||||||
## [1.2.14] - 2024-03-20
|
## [1.2.14] - 2024-03-20
|
||||||
### Hinzugefügt
|
### Hinzugefügt
|
||||||
- Autovervollständigung für das Fachrichtungsfeld
|
- Autovervollständigung für das Fachrichtungsfeld
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
# Medi-Customers
|
# medisoftware Kundensuche
|
||||||
|
|
||||||
Eine moderne Webanwendung zur Suche und Verwaltung von Kundendaten, die MEDISOFT und MEDICONSULT Daten kombiniert.
|
Eine einfache und effiziente Kundensuche für medisoftware Kunden.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ Eine moderne Webanwendung zur Suche und Verwaltung von Kundendaten, die MEDISOFT
|
|||||||
|
|
||||||
## Version
|
## Version
|
||||||
|
|
||||||
Aktuelle Version: 1.2.14
|
Aktuelle Version: 1.2.16
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
40
app.py
40
app.py
@@ -13,13 +13,12 @@ import sqlite3
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
app = Flask(__name__, static_folder='static')
|
app = Flask(__name__, static_folder='static')
|
||||||
app.secret_key = os.getenv('SECRET_KEY', 'default-secret-key')
|
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'dev')
|
||||||
|
app.config['ALLOWED_IP_RANGES'] = os.getenv('ALLOWED_IP_RANGES', '192.168.0.0/16,10.0.0.0/8').split(',')
|
||||||
|
app.config['VERSION'] = '1.2.16'
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Version der Anwendung
|
|
||||||
VERSION = "1.2.14"
|
|
||||||
|
|
||||||
# Pfad zur Datenbank
|
# Pfad zur Datenbank
|
||||||
DB_FILE = 'data/customers.db'
|
DB_FILE = 'data/customers.db'
|
||||||
|
|
||||||
@@ -28,7 +27,6 @@ load_dotenv()
|
|||||||
|
|
||||||
# Statisches Passwort aus der .env Datei
|
# Statisches Passwort aus der .env Datei
|
||||||
STATIC_PASSWORD = os.getenv('LOGIN_PASSWORD', 'default-password')
|
STATIC_PASSWORD = os.getenv('LOGIN_PASSWORD', 'default-password')
|
||||||
ALLOWED_IP_RANGES = os.getenv('ALLOWED_IP_RANGES', '').split(',')
|
|
||||||
|
|
||||||
def isIPInSubnet(ip, subnet):
|
def isIPInSubnet(ip, subnet):
|
||||||
"""Überprüft, ob eine IP-Adresse in einem Subnetz liegt."""
|
"""Überprüft, ob eine IP-Adresse in einem Subnetz liegt."""
|
||||||
@@ -184,7 +182,7 @@ def login():
|
|||||||
client_ip = request.headers.get('X-Forwarded-For', request.remote_addr)
|
client_ip = request.headers.get('X-Forwarded-For', request.remote_addr)
|
||||||
|
|
||||||
# Überprüfe, ob die Client-IP in einem der erlaubten Bereichen liegt
|
# Überprüfe, ob die Client-IP in einem der erlaubten Bereichen liegt
|
||||||
is_allowed = any(isIPInSubnet(client_ip, range.strip()) for range in ALLOWED_IP_RANGES if range.strip())
|
is_allowed = any(isIPInSubnet(client_ip, range.strip()) for range in app.config['ALLOWED_IP_RANGES'] if range.strip())
|
||||||
|
|
||||||
if is_allowed:
|
if is_allowed:
|
||||||
logger.info(f"Client-IP {client_ip} ist in einem erlaubten Bereich, automatischer Login")
|
logger.info(f"Client-IP {client_ip} ist in einem erlaubten Bereich, automatischer Login")
|
||||||
@@ -213,8 +211,8 @@ def index():
|
|||||||
|
|
||||||
client_ip = request.headers.get('X-Forwarded-For', request.remote_addr)
|
client_ip = request.headers.get('X-Forwarded-For', request.remote_addr)
|
||||||
logger.info(f"Client-IP: {client_ip}")
|
logger.info(f"Client-IP: {client_ip}")
|
||||||
logger.info(f"Erlaubte IP-Bereiche: {ALLOWED_IP_RANGES}")
|
logger.info(f"Erlaubte IP-Bereiche: {app.config['ALLOWED_IP_RANGES']}")
|
||||||
return render_template('index.html', allowed_ip_ranges=','.join(ALLOWED_IP_RANGES), version=VERSION)
|
return render_template('index.html', allowed_ip_ranges=','.join(app.config['ALLOWED_IP_RANGES']), version=app.config['VERSION'])
|
||||||
|
|
||||||
@app.route('/search', methods=['GET', 'POST'])
|
@app.route('/search', methods=['GET', 'POST'])
|
||||||
def search():
|
def search():
|
||||||
@@ -374,6 +372,32 @@ def get_fachrichtungen():
|
|||||||
logger.error(f"Fehler beim Abrufen der Fachrichtungen: {str(e)}")
|
logger.error(f"Fehler beim Abrufen der Fachrichtungen: {str(e)}")
|
||||||
return jsonify([])
|
return jsonify([])
|
||||||
|
|
||||||
|
@app.route('/api/orte')
|
||||||
|
def get_orte():
|
||||||
|
try:
|
||||||
|
search_term = request.args.get('q', '').lower()
|
||||||
|
conn = get_db_connection()
|
||||||
|
c = conn.cursor()
|
||||||
|
|
||||||
|
# Hole alle eindeutigen Orte, die mit dem Suchbegriff übereinstimmen
|
||||||
|
c.execute('''
|
||||||
|
SELECT DISTINCT ort
|
||||||
|
FROM customers
|
||||||
|
WHERE ort IS NOT NULL
|
||||||
|
AND ort != ''
|
||||||
|
AND LOWER(ort) LIKE ?
|
||||||
|
ORDER BY ort
|
||||||
|
LIMIT 10
|
||||||
|
''', (f'%{search_term}%',))
|
||||||
|
|
||||||
|
orte = [row[0] for row in c.fetchall()]
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return jsonify(orte)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Fehler beim Abrufen der Orte: {str(e)}")
|
||||||
|
return jsonify([])
|
||||||
|
|
||||||
def init_app(app):
|
def init_app(app):
|
||||||
"""Initialisiert die Anwendung mit allen notwendigen Einstellungen."""
|
"""Initialisiert die Anwendung mit allen notwendigen Einstellungen."""
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
|
@@ -1,24 +0,0 @@
|
|||||||
.result-header {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.result-tag {
|
|
||||||
padding: 4px 8px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 0.9em;
|
|
||||||
font-weight: 500;
|
|
||||||
text-transform: uppercase;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag-medisoft {
|
|
||||||
background-color: #e3f2fd;
|
|
||||||
color: #1976d2;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag-mediconsult {
|
|
||||||
background-color: #f3e5f5;
|
|
||||||
color: #7b1fa2;
|
|
||||||
}
|
|
@@ -182,18 +182,78 @@ body {
|
|||||||
.customer-card {
|
.customer-card {
|
||||||
background: white;
|
background: white;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
padding: 1.5rem;
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||||
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;
|
margin-bottom: 1rem;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-start;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-name {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-details {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-details p {
|
||||||
|
margin: 0.25rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customer-details strong {
|
||||||
|
color: #333;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phone-link, .email-link, .customer-link {
|
||||||
|
color: #007bff;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.phone-link:hover, .email-link:hover, .customer-link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.address-text {
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.address-link, .route-link {
|
||||||
|
color: #6c757d;
|
||||||
|
text-decoration: none;
|
||||||
|
margin-left: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.address-link:hover, .route-link:hover {
|
||||||
|
color: #343a40;
|
||||||
|
}
|
||||||
|
|
||||||
|
.location-pin, .route-pin {
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
padding: 0.35em 0.65em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-sm {
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer-content {
|
.footer-content {
|
||||||
@@ -272,22 +332,26 @@ body {
|
|||||||
background-color: #ff9800;
|
background-color: #ff9800;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Adress-Links */
|
.autocomplete-items {
|
||||||
.address-text {
|
position: absolute;
|
||||||
margin-right: 5px;
|
border: 1px solid #d4d4d4;
|
||||||
|
border-top: none;
|
||||||
|
z-index: 99;
|
||||||
|
top: 100%;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
background-color: white;
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.address-link, .route-link {
|
.autocomplete-items div {
|
||||||
color: #666;
|
padding: 8px 12px;
|
||||||
text-decoration: none;
|
cursor: pointer;
|
||||||
margin-left: 5px;
|
background-color: white;
|
||||||
transition: color 0.2s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.address-link:hover, .route-link:hover {
|
.autocomplete-items div:hover {
|
||||||
color: #0d6efd;
|
background-color: #f8f9fa;
|
||||||
}
|
|
||||||
|
|
||||||
.location-pin, .route-pin {
|
|
||||||
font-size: 1.1em;
|
|
||||||
}
|
}
|
445
static/js/main.js
Normal file
445
static/js/main.js
Normal file
@@ -0,0 +1,445 @@
|
|||||||
|
let searchTimeout;
|
||||||
|
let lastResults = [];
|
||||||
|
let fachrichtungTimeout;
|
||||||
|
let ortTimeout;
|
||||||
|
|
||||||
|
function createPhoneLink(phone) {
|
||||||
|
if (!phone) return '';
|
||||||
|
|
||||||
|
const clientIP = document.querySelector('meta[name="client-ip"]').content;
|
||||||
|
const allowedIPRanges = document.querySelector('meta[name="allowed-ip-ranges"]').content.split(',');
|
||||||
|
|
||||||
|
// Überprüfen, ob die Client-IP in einem der erlaubten Bereiche liegt
|
||||||
|
const isAllowed = allowedIPRanges.some(range => isIPInSubnet(clientIP, range.trim()));
|
||||||
|
|
||||||
|
// Entferne alle nicht-numerischen Zeichen
|
||||||
|
let cleanNumber = phone.replace(/\D/g, '');
|
||||||
|
|
||||||
|
// Formatiere die Nummer
|
||||||
|
let formattedNumber = cleanNumber;
|
||||||
|
if (cleanNumber.length === 11) {
|
||||||
|
formattedNumber = cleanNumber.replace(/(\d{4})(\d{7})/, '$1-$2');
|
||||||
|
} else if (cleanNumber.length === 10) {
|
||||||
|
formattedNumber = cleanNumber.replace(/(\d{3})(\d{7})/, '$1-$2');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Erstelle den Link
|
||||||
|
return `<a href="tel:${cleanNumber}" class="phone-link">${formattedNumber}</a>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function createEmailLink(email) {
|
||||||
|
if (!email) return '';
|
||||||
|
return `<a href="mailto:${email}" class="email-link">${email}</a>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function highlightText(text, searchTerm) {
|
||||||
|
if (!searchTerm || !text) return text;
|
||||||
|
// Escapen von Sonderzeichen im Suchbegriff
|
||||||
|
const escapedSearchTerm = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||||
|
// Erstelle einen regulären Ausdruck ohne Wortgrenzen
|
||||||
|
const regex = new RegExp(escapedSearchTerm, 'gi');
|
||||||
|
return text.replace(regex, '<mark>$&</mark>');
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAddressLink(street, plz, city) {
|
||||||
|
if (!street || !plz || !city) return '';
|
||||||
|
const address = `${street}, ${plz} ${city}`;
|
||||||
|
const searchQuery = encodeURIComponent(address);
|
||||||
|
const routeQuery = encodeURIComponent(address);
|
||||||
|
return `<span class="address-text">${address}</span>
|
||||||
|
<a href="https://www.google.com/maps/search/?api=1&query=${searchQuery}"
|
||||||
|
class="address-link" target="_blank" rel="noopener noreferrer">
|
||||||
|
<i class="fa-solid fa-location-dot location-pin"></i>
|
||||||
|
</a>
|
||||||
|
<a href="https://www.google.com/maps/dir/?api=1&destination=${routeQuery}"
|
||||||
|
class="route-link" target="_blank" rel="noopener noreferrer">
|
||||||
|
<i class="fa-solid fa-route route-pin"></i>
|
||||||
|
</a>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function adjustCustomerNumber(number) {
|
||||||
|
return number - 12000;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isIPInSubnet(ip, subnet) {
|
||||||
|
// Teile die IP und das Subnetz in ihre Komponenten
|
||||||
|
const [subnetIP, bits] = subnet.split('/');
|
||||||
|
const ipParts = ip.split('.').map(Number);
|
||||||
|
const subnetParts = subnetIP.split('.').map(Number);
|
||||||
|
|
||||||
|
// Konvertiere IPs in 32-bit Zahlen
|
||||||
|
const ipNum = (ipParts[0] << 24) | (ipParts[1] << 16) | (ipParts[2] << 8) | ipParts[3];
|
||||||
|
const subnetNum = (subnetParts[0] << 24) | (subnetParts[1] << 16) | (subnetParts[2] << 8) | subnetParts[3];
|
||||||
|
|
||||||
|
// Erstelle die Subnetzmaske
|
||||||
|
const mask = ~((1 << (32 - bits)) - 1);
|
||||||
|
|
||||||
|
// Prüfe, ob die IP im Subnetz liegt
|
||||||
|
return (ipNum & mask) === (subnetNum & mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createCustomerLink(nummer) {
|
||||||
|
const clientIP = document.querySelector('meta[name="client-ip"]').content;
|
||||||
|
const allowedIPRanges = document.querySelector('meta[name="allowed-ip-ranges"]').content.split(',');
|
||||||
|
|
||||||
|
// Überprüfe, ob die Client-IP in einem der erlaubten Bereiche liegt
|
||||||
|
const isAllowed = allowedIPRanges.some(range => {
|
||||||
|
const trimmedRange = range.trim();
|
||||||
|
return isIPInSubnet(clientIP, trimmedRange);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isAllowed) {
|
||||||
|
const adjustedNumber = adjustCustomerNumber(nummer);
|
||||||
|
return `<a href="medisw:openkkbefe/P${adjustedNumber}?NetGrp=4" class="customer-link">${nummer}</a>`;
|
||||||
|
} else {
|
||||||
|
return nummer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showCopyFeedback() {
|
||||||
|
const feedback = document.getElementById('shareFeedback');
|
||||||
|
feedback.style.display = 'block';
|
||||||
|
feedback.style.opacity = '1';
|
||||||
|
|
||||||
|
feedback.addEventListener('animationend', () => {
|
||||||
|
feedback.style.display = 'none';
|
||||||
|
}, { once: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyCustomerLink(customerNumber) {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
|
url.searchParams.set('kundennummer', customerNumber);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(url.toString());
|
||||||
|
showCopyFeedback();
|
||||||
|
} catch (err) {
|
||||||
|
// Fehlerbehandlung ohne console.log
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateResultCounts() {
|
||||||
|
// Nur Gesamtzahl anzeigen
|
||||||
|
const generalCount = lastResults.length;
|
||||||
|
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) {
|
||||||
|
const resultsDiv = document.getElementById('results');
|
||||||
|
const resultCount = document.getElementById('resultCount');
|
||||||
|
const generalSearchTerm = document.getElementById('q').value;
|
||||||
|
const nameSearchTerm = document.getElementById('nameInput').value;
|
||||||
|
const fachrichtungSearchTerm = document.getElementById('fachrichtungInput').value;
|
||||||
|
|
||||||
|
if (!results || results.length === 0) {
|
||||||
|
resultsDiv.innerHTML = '<p>Keine Ergebnisse gefunden.</p>';
|
||||||
|
resultCount.textContent = '0 Ergebnisse';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
resultCount.textContent = `${results.length} Ergebnisse`;
|
||||||
|
lastResults = results;
|
||||||
|
|
||||||
|
const resultsHTML = results.map(customer => {
|
||||||
|
const highlightedName = highlightText(customer.name, nameSearchTerm);
|
||||||
|
const highlightedFachrichtung = highlightText(customer.fachrichtung, fachrichtungSearchTerm);
|
||||||
|
const highlightedGeneral = highlightText(customer.name, generalSearchTerm) ||
|
||||||
|
highlightText(customer.fachrichtung, generalSearchTerm) ||
|
||||||
|
highlightText(customer.ort, generalSearchTerm);
|
||||||
|
|
||||||
|
// Hilfsfunktion zum Erstellen von Feldern nur wenn sie Werte haben
|
||||||
|
const createFieldIfValue = (label, value, formatter = (v) => v) => {
|
||||||
|
if (!value || value === 'N/A' || value === 'n/a' || value === 'N/a' || (typeof value === 'string' && value.trim() === '')) return '';
|
||||||
|
const formattedValue = formatter(value);
|
||||||
|
return `<p class="mb-1"><strong>${label}:</strong> ${formattedValue}</p>`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class="customer-card">
|
||||||
|
<div class="customer-header">
|
||||||
|
<h3 class="customer-name">${highlightedName || highlightedGeneral}</h3>
|
||||||
|
<div class="customer-actions">
|
||||||
|
<span class="badge ${(customer.tag || 'medisoft') === 'medisoft' ? 'bg-primary' : 'bg-warning text-dark'}">${(customer.tag || 'medisoft').toUpperCase()}</span>
|
||||||
|
<button class="btn btn-sm btn-outline-primary" onclick="copyCustomerLink('${customer.nummer}')">
|
||||||
|
<i class="fas fa-link"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="customer-details">
|
||||||
|
${createFieldIfValue('Nummer', highlightText(customer.nummer, generalSearchTerm), createCustomerLink)}
|
||||||
|
${createFieldIfValue('Adresse', (customer.strasse && customer.plz && customer.ort) ? true : false,
|
||||||
|
() => createAddressLink(
|
||||||
|
highlightText(customer.strasse, generalSearchTerm),
|
||||||
|
highlightText(customer.plz, generalSearchTerm),
|
||||||
|
highlightText(customer.ort, generalSearchTerm)
|
||||||
|
))}
|
||||||
|
${createFieldIfValue('Telefon', highlightText(customer.telefon, generalSearchTerm), createPhoneLink)}
|
||||||
|
${createFieldIfValue('Mobil', highlightText(customer.mobil, generalSearchTerm), createPhoneLink)}
|
||||||
|
${createFieldIfValue('Handy', highlightText(customer.handy, generalSearchTerm), createPhoneLink)}
|
||||||
|
${createFieldIfValue('Telefon Firma', highlightText(customer.tele_firma, generalSearchTerm), createPhoneLink)}
|
||||||
|
${createFieldIfValue('E-Mail', highlightText(customer.email, generalSearchTerm), createEmailLink)}
|
||||||
|
${createFieldIfValue('Fachrichtung', highlightText(customer.fachrichtung, generalSearchTerm || fachrichtungSearchTerm))}
|
||||||
|
${createFieldIfValue('Kontakt 1', highlightText(customer.kontakt1, generalSearchTerm), createPhoneLink)}
|
||||||
|
${createFieldIfValue('Kontakt 2', highlightText(customer.kontakt2, generalSearchTerm), createPhoneLink)}
|
||||||
|
${createFieldIfValue('Kontakt 3', highlightText(customer.kontakt3, generalSearchTerm), createPhoneLink)}
|
||||||
|
${customer.tags && customer.tags.length > 0 ? `
|
||||||
|
<p class="mb-0"><strong>Tags:</strong>
|
||||||
|
${customer.tags.map(tag => `<span class="badge bg-primary me-1">${tag}</span>`).join('')}
|
||||||
|
</p>
|
||||||
|
` : ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}).join('');
|
||||||
|
|
||||||
|
resultsDiv.innerHTML = resultsHTML;
|
||||||
|
updateResultCounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearInput(inputId) {
|
||||||
|
document.getElementById(inputId).value = '';
|
||||||
|
searchCustomers();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function searchCustomers() {
|
||||||
|
const loading = document.getElementById('loading');
|
||||||
|
const results = document.getElementById('results');
|
||||||
|
const generalSearch = document.getElementById('q').value;
|
||||||
|
const nameSearch = document.getElementById('nameInput').value;
|
||||||
|
const ortSearch = document.getElementById('ortInput').value;
|
||||||
|
const nummerSearch = document.getElementById('nummerInput').value;
|
||||||
|
const plzSearch = document.getElementById('plzInput').value;
|
||||||
|
const fachrichtungSearch = document.getElementById('fachrichtungInput').value;
|
||||||
|
const tagFilter = document.getElementById('tagFilter').value;
|
||||||
|
|
||||||
|
// Zeige Ladeanimation
|
||||||
|
loading.style.display = 'block';
|
||||||
|
results.innerHTML = '';
|
||||||
|
|
||||||
|
// Setze Timeout zurück
|
||||||
|
clearTimeout(searchTimeout);
|
||||||
|
|
||||||
|
// Verzögerte Suche
|
||||||
|
searchTimeout = setTimeout(async () => {
|
||||||
|
try {
|
||||||
|
// Baue die Suchanfrage
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (generalSearch) params.append('q', generalSearch);
|
||||||
|
if (nameSearch) params.append('name', nameSearch);
|
||||||
|
if (ortSearch) params.append('ort', ortSearch);
|
||||||
|
if (nummerSearch) params.append('nummer', nummerSearch);
|
||||||
|
if (plzSearch) params.append('plz', plzSearch);
|
||||||
|
if (fachrichtungSearch) params.append('fachrichtung', fachrichtungSearch);
|
||||||
|
if (tagFilter) params.append('tag', tagFilter);
|
||||||
|
|
||||||
|
const response = await fetch('/search?' + params.toString());
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Netzwerkantwort war nicht ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
displayResults(data);
|
||||||
|
} catch (error) {
|
||||||
|
results.innerHTML = '<p>Ein Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.</p>';
|
||||||
|
} finally {
|
||||||
|
loading.style.display = 'none';
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupFachrichtungAutocomplete() {
|
||||||
|
const fachrichtungInput = document.getElementById('fachrichtungInput');
|
||||||
|
const autocompleteList = document.createElement('div');
|
||||||
|
autocompleteList.className = 'autocomplete-items';
|
||||||
|
fachrichtungInput.parentNode.appendChild(autocompleteList);
|
||||||
|
|
||||||
|
fachrichtungInput.addEventListener('input', function() {
|
||||||
|
clearTimeout(fachrichtungTimeout);
|
||||||
|
const searchTerm = this.value;
|
||||||
|
|
||||||
|
if (searchTerm.length < 2) {
|
||||||
|
autocompleteList.style.display = 'none';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fachrichtungTimeout = setTimeout(() => {
|
||||||
|
fetch(`/api/fachrichtungen?q=${encodeURIComponent(searchTerm)}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
autocompleteList.innerHTML = '';
|
||||||
|
if (data.length > 0) {
|
||||||
|
data.forEach(item => {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.textContent = item;
|
||||||
|
div.addEventListener('click', () => {
|
||||||
|
fachrichtungInput.value = item;
|
||||||
|
autocompleteList.style.display = 'none';
|
||||||
|
searchCustomers();
|
||||||
|
});
|
||||||
|
autocompleteList.appendChild(div);
|
||||||
|
});
|
||||||
|
autocompleteList.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
autocompleteList.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('click', function(e) {
|
||||||
|
if (!fachrichtungInput.contains(e.target) && !autocompleteList.contains(e.target)) {
|
||||||
|
autocompleteList.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupOrtAutocomplete() {
|
||||||
|
const ortInput = document.getElementById('ortInput');
|
||||||
|
const autocompleteList = document.createElement('div');
|
||||||
|
autocompleteList.className = 'autocomplete-items';
|
||||||
|
ortInput.parentNode.appendChild(autocompleteList);
|
||||||
|
|
||||||
|
ortInput.addEventListener('input', function() {
|
||||||
|
clearTimeout(ortTimeout);
|
||||||
|
const searchTerm = this.value;
|
||||||
|
|
||||||
|
if (searchTerm.length < 2) {
|
||||||
|
autocompleteList.style.display = 'none';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ortTimeout = setTimeout(() => {
|
||||||
|
fetch(`/api/orte?q=${encodeURIComponent(searchTerm)}`)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
autocompleteList.innerHTML = '';
|
||||||
|
if (data.length > 0) {
|
||||||
|
data.forEach(item => {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.textContent = item;
|
||||||
|
div.addEventListener('click', () => {
|
||||||
|
ortInput.value = item;
|
||||||
|
autocompleteList.style.display = 'none';
|
||||||
|
searchCustomers();
|
||||||
|
});
|
||||||
|
autocompleteList.appendChild(div);
|
||||||
|
});
|
||||||
|
autocompleteList.style.display = 'block';
|
||||||
|
} else {
|
||||||
|
autocompleteList.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
|
||||||
|
document.addEventListener('click', function(e) {
|
||||||
|
if (!ortInput.contains(e.target) && !autocompleteList.contains(e.target)) {
|
||||||
|
autocompleteList.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Event-Listener für die URL-Parameter und Autocomplete-Setup
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
const kundennummer = urlParams.get('kundennummer');
|
||||||
|
const name = urlParams.get('name');
|
||||||
|
const ort = urlParams.get('ort');
|
||||||
|
const plz = urlParams.get('plz');
|
||||||
|
|
||||||
|
if (kundennummer) {
|
||||||
|
document.getElementById('nummerInput').value = kundennummer;
|
||||||
|
searchCustomers();
|
||||||
|
}
|
||||||
|
if (name) {
|
||||||
|
document.getElementById('nameInput').value = name;
|
||||||
|
searchCustomers();
|
||||||
|
}
|
||||||
|
if (ort) {
|
||||||
|
document.getElementById('ortInput').value = ort;
|
||||||
|
searchCustomers();
|
||||||
|
}
|
||||||
|
if (plz) {
|
||||||
|
document.getElementById('plzInput').value = plz;
|
||||||
|
searchCustomers();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup Autocomplete
|
||||||
|
setupFachrichtungAutocomplete();
|
||||||
|
setupOrtAutocomplete();
|
||||||
|
});
|
@@ -3,6 +3,8 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta name="client-ip" content="{{ request.headers.get('X-Forwarded-For', request.remote_addr) }}">
|
||||||
|
<meta name="allowed-ip-ranges" content="{{ allowed_ip_ranges }}">
|
||||||
<title>medisoftware Kundensuche</title>
|
<title>medisoftware Kundensuche</title>
|
||||||
<link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='favicon.ico') }}">
|
<link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='favicon.ico') }}">
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
@@ -80,6 +82,9 @@
|
|||||||
|
|
||||||
<div class="result-counts">
|
<div class="result-counts">
|
||||||
<span id="resultCount" class="result-count"></span>
|
<span id="resultCount" class="result-count"></span>
|
||||||
|
<button id="exportButton" class="btn btn-sm btn-outline-success ms-2" onclick="exportToCSV()" style="display: none;">
|
||||||
|
<i class="fas fa-file-csv"></i> CSV Export
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="loading" class="loading">
|
<div id="loading" class="loading">
|
||||||
@@ -104,309 +109,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
<script>
|
<script src="{{ url_for('static', filename='js/main.js') }}"></script>
|
||||||
let searchTimeout;
|
|
||||||
let lastResults = [];
|
|
||||||
|
|
||||||
function createPhoneLink(phone) {
|
|
||||||
if (!phone) return '';
|
|
||||||
|
|
||||||
const clientIP = '{{ request.headers.get("X-Forwarded-For", request.remote_addr) }}';
|
|
||||||
const allowedIPRanges = '{{ allowed_ip_ranges }}'.split(',');
|
|
||||||
|
|
||||||
// Überprüfen, ob die Client-IP in einem der erlaubten Bereiche liegt
|
|
||||||
const isAllowed = allowedIPRanges.some(range => isIPInSubnet(clientIP, range.trim()));
|
|
||||||
|
|
||||||
// Entferne alle nicht-numerischen Zeichen
|
|
||||||
let cleanNumber = phone.replace(/\D/g, '');
|
|
||||||
|
|
||||||
// Formatiere die Nummer
|
|
||||||
let formattedNumber = cleanNumber;
|
|
||||||
if (cleanNumber.length === 11) {
|
|
||||||
formattedNumber = cleanNumber.replace(/(\d{4})(\d{7})/, '$1-$2');
|
|
||||||
} else if (cleanNumber.length === 10) {
|
|
||||||
formattedNumber = cleanNumber.replace(/(\d{3})(\d{7})/, '$1-$2');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Erstelle den Link
|
|
||||||
return `<a href="tel:${cleanNumber}" class="phone-link">${formattedNumber}</a>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createEmailLink(email) {
|
|
||||||
if (!email) return '';
|
|
||||||
return `<a href="mailto:${email}" class="email-link">${email}</a>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function highlightText(text, searchTerm) {
|
|
||||||
if (!searchTerm || !text) return text;
|
|
||||||
// Escapen von Sonderzeichen im Suchbegriff
|
|
||||||
const escapedSearchTerm = searchTerm.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
||||||
// Erstelle einen regulären Ausdruck ohne Wortgrenzen
|
|
||||||
const regex = new RegExp(escapedSearchTerm, 'gi');
|
|
||||||
return text.replace(regex, '<mark>$&</mark>');
|
|
||||||
}
|
|
||||||
|
|
||||||
function createAddressLink(street, plz, city) {
|
|
||||||
if (!street || !plz || !city) return '';
|
|
||||||
const address = `${street}, ${plz} ${city}`;
|
|
||||||
const searchQuery = encodeURIComponent(address);
|
|
||||||
const routeQuery = encodeURIComponent(address);
|
|
||||||
const clientIP = '{{ request.headers.get("X-Forwarded-For", request.remote_addr) }}';
|
|
||||||
return `<span class="address-text">${address}</span>
|
|
||||||
<a href="https://www.google.com/maps/search/?api=1&query=${searchQuery}"
|
|
||||||
class="address-link" target="_blank" rel="noopener noreferrer">
|
|
||||||
<i class="fa-solid fa-location-dot location-pin"></i>
|
|
||||||
</a>
|
|
||||||
<a href="https://www.google.com/maps/dir/?api=1&destination=${routeQuery}"
|
|
||||||
class="route-link" target="_blank" rel="noopener noreferrer">
|
|
||||||
<i class="fa-solid fa-route route-pin"></i>
|
|
||||||
</a>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function adjustCustomerNumber(number) {
|
|
||||||
return number - 12000;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isIPInSubnet(ip, subnet) {
|
|
||||||
// Teile die IP und das Subnetz in ihre Komponenten
|
|
||||||
const [subnetIP, bits] = subnet.split('/');
|
|
||||||
const ipParts = ip.split('.').map(Number);
|
|
||||||
const subnetParts = subnetIP.split('.').map(Number);
|
|
||||||
|
|
||||||
// Konvertiere IPs in 32-bit Zahlen
|
|
||||||
const ipNum = (ipParts[0] << 24) | (ipParts[1] << 16) | (ipParts[2] << 8) | ipParts[3];
|
|
||||||
const subnetNum = (subnetParts[0] << 24) | (subnetParts[1] << 16) | (subnetParts[2] << 8) | subnetParts[3];
|
|
||||||
|
|
||||||
// Erstelle die Subnetzmaske
|
|
||||||
const mask = ~((1 << (32 - bits)) - 1);
|
|
||||||
|
|
||||||
// Prüfe, ob die IP im Subnetz liegt
|
|
||||||
return (ipNum & mask) === (subnetNum & mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createCustomerLink(nummer) {
|
|
||||||
const clientIP = '{{ request.headers.get("X-Forwarded-For", request.remote_addr) }}';
|
|
||||||
const allowedIPRanges = '{{ allowed_ip_ranges }}'.split(',');
|
|
||||||
|
|
||||||
// Überprüfe, ob die Client-IP in einem der erlaubten Bereiche liegt
|
|
||||||
const isAllowed = allowedIPRanges.some(range => {
|
|
||||||
const trimmedRange = range.trim();
|
|
||||||
return isIPInSubnet(clientIP, trimmedRange);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isAllowed) {
|
|
||||||
const adjustedNumber = adjustCustomerNumber(nummer);
|
|
||||||
return `<a href="medisw:openkkbefe/P${adjustedNumber}?NetGrp=4" class="customer-link">${nummer}</a>`;
|
|
||||||
} else {
|
|
||||||
return nummer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function showCopyFeedback() {
|
|
||||||
const feedback = document.getElementById('shareFeedback');
|
|
||||||
feedback.style.display = 'block';
|
|
||||||
feedback.style.opacity = '1';
|
|
||||||
|
|
||||||
feedback.addEventListener('animationend', () => {
|
|
||||||
feedback.style.display = 'none';
|
|
||||||
}, { once: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
async function copyCustomerLink(customerNumber) {
|
|
||||||
const url = new URL(window.location.href);
|
|
||||||
url.searchParams.set('kundennummer', customerNumber);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await navigator.clipboard.writeText(url.toString());
|
|
||||||
showCopyFeedback();
|
|
||||||
} catch (err) {
|
|
||||||
// Fehlerbehandlung ohne console.log
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateResultCounts() {
|
|
||||||
// Nur Gesamtzahl anzeigen
|
|
||||||
const generalCount = lastResults.length;
|
|
||||||
document.getElementById('resultCount').textContent =
|
|
||||||
generalCount > 0 ? `${generalCount} Treffer gefunden` : '';
|
|
||||||
document.getElementById('resultCount').classList.toggle('visible', generalCount > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function displayResults(results) {
|
|
||||||
const resultsDiv = document.getElementById('results');
|
|
||||||
const resultCount = document.getElementById('resultCount');
|
|
||||||
const generalSearchTerm = document.getElementById('q').value;
|
|
||||||
const nameSearchTerm = document.getElementById('nameInput').value;
|
|
||||||
const fachrichtungSearchTerm = document.getElementById('fachrichtungInput').value;
|
|
||||||
|
|
||||||
if (!results || results.length === 0) {
|
|
||||||
resultsDiv.innerHTML = '<p>Keine Ergebnisse gefunden.</p>';
|
|
||||||
resultCount.textContent = '0 Ergebnisse';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
resultCount.textContent = `${results.length} Ergebnisse`;
|
|
||||||
|
|
||||||
const resultsList = results.map(customer => {
|
|
||||||
// Hilfsfunktion zum Erstellen von Feldern nur wenn sie Werte haben
|
|
||||||
const createFieldIfValue = (label, value, formatter = (v) => v) => {
|
|
||||||
if (!value || value === 'N/A' || value === 'n/a' || value === 'N/a' || (typeof value === 'string' && value.trim() === '')) return '';
|
|
||||||
const formattedValue = formatter(value);
|
|
||||||
return `<p class="mb-1"><strong>${label}:</strong> ${formattedValue}</p>`;
|
|
||||||
};
|
|
||||||
|
|
||||||
return `
|
|
||||||
<div class="card mb-1">
|
|
||||||
<div class="card-body py-1">
|
|
||||||
<div class="d-flex justify-content-between align-items-start">
|
|
||||||
<h5 class="card-title mb-1">${highlightText(customer.name, generalSearchTerm || nameSearchTerm)}</h5>
|
|
||||||
<div class="d-flex align-items-center gap-2">
|
|
||||||
<span class="badge ${(customer.tag || 'medisoft') === 'medisoft' ? 'bg-primary' : 'bg-warning text-dark'}">${(customer.tag || 'medisoft').toUpperCase()}</span>
|
|
||||||
<button class="btn btn-sm btn-outline-primary" onclick="copyCustomerLink('${customer.nummer}')">
|
|
||||||
<i class="fas fa-share-alt"></i> Teilen
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="card-text">
|
|
||||||
${createFieldIfValue('Nummer', highlightText(customer.nummer, generalSearchTerm), createCustomerLink)}
|
|
||||||
${createFieldIfValue('Adresse', (customer.strasse && customer.plz && customer.ort) ? true : false,
|
|
||||||
() => createAddressLink(
|
|
||||||
highlightText(customer.strasse, generalSearchTerm),
|
|
||||||
highlightText(customer.plz, generalSearchTerm),
|
|
||||||
highlightText(customer.ort, generalSearchTerm)
|
|
||||||
))}
|
|
||||||
${createFieldIfValue('Telefon', highlightText(customer.telefon, generalSearchTerm), createPhoneLink)}
|
|
||||||
${createFieldIfValue('Mobil', highlightText(customer.mobil, generalSearchTerm), createPhoneLink)}
|
|
||||||
${createFieldIfValue('Handy', highlightText(customer.handy, generalSearchTerm), createPhoneLink)}
|
|
||||||
${createFieldIfValue('Telefon Firma', highlightText(customer.tele_firma, generalSearchTerm), createPhoneLink)}
|
|
||||||
${createFieldIfValue('E-Mail', highlightText(customer.email, generalSearchTerm), createEmailLink)}
|
|
||||||
${createFieldIfValue('Fachrichtung', highlightText(customer.fachrichtung, generalSearchTerm || fachrichtungSearchTerm))}
|
|
||||||
${createFieldIfValue('Kontakt 1', highlightText(customer.kontakt1, generalSearchTerm), createPhoneLink)}
|
|
||||||
${createFieldIfValue('Kontakt 2', highlightText(customer.kontakt2, generalSearchTerm), createPhoneLink)}
|
|
||||||
${createFieldIfValue('Kontakt 3', highlightText(customer.kontakt3, generalSearchTerm), createPhoneLink)}
|
|
||||||
${customer.tags && customer.tags.length > 0 ? `
|
|
||||||
<p class="mb-0"><strong>Tags:</strong>
|
|
||||||
${customer.tags.map(tag => `<span class="badge bg-primary me-1">${tag}</span>`).join('')}
|
|
||||||
</p>
|
|
||||||
` : ''}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`}).join('');
|
|
||||||
|
|
||||||
resultsDiv.innerHTML = resultsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
function searchCustomers() {
|
|
||||||
const q = document.getElementById('q').value;
|
|
||||||
const name = document.getElementById('nameInput').value;
|
|
||||||
const ort = document.getElementById('ortInput').value;
|
|
||||||
const nummer = document.getElementById('nummerInput').value;
|
|
||||||
const plz = document.getElementById('plzInput').value;
|
|
||||||
const fachrichtung = document.getElementById('fachrichtungInput').value;
|
|
||||||
const selectedTag = document.getElementById('tagFilter').value;
|
|
||||||
|
|
||||||
// Prüfe, ob mindestens ein Suchfeld einen Wert hat
|
|
||||||
if (!q && !name && !ort && !nummer && !plz && !fachrichtung) {
|
|
||||||
document.getElementById('results').innerHTML = '';
|
|
||||||
document.getElementById('resultCount').textContent = '';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zeige das Lade-Icon
|
|
||||||
document.getElementById('loading').style.display = 'block';
|
|
||||||
|
|
||||||
// Baue die Suchanfrage
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
if (q) params.append('q', q);
|
|
||||||
if (name) params.append('name', name);
|
|
||||||
if (ort) params.append('ort', ort);
|
|
||||||
if (nummer) params.append('nummer', nummer);
|
|
||||||
if (plz) params.append('plz', plz);
|
|
||||||
if (fachrichtung) params.append('fachrichtung', fachrichtung);
|
|
||||||
if (selectedTag) params.append('tag', selectedTag);
|
|
||||||
|
|
||||||
// Führe die Suche durch
|
|
||||||
fetch('/search?' + params.toString())
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error('Netzwerk-Antwort war nicht ok');
|
|
||||||
}
|
|
||||||
return response.json();
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
// Verstecke das Lade-Icon
|
|
||||||
document.getElementById('loading').style.display = 'none';
|
|
||||||
|
|
||||||
if (data.error) {
|
|
||||||
console.error('Fehler bei der Suche:', data.error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastResults = data;
|
|
||||||
updateResultCounts();
|
|
||||||
displayResults(data);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
document.getElementById('loading').style.display = 'none';
|
|
||||||
console.error('Fehler bei der Suche:', error);
|
|
||||||
document.getElementById('results').innerHTML = '<p>Ein Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.</p>';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Event-Listener für die Live-Suche
|
|
||||||
const searchInputs = [
|
|
||||||
document.getElementById('q'),
|
|
||||||
document.getElementById('nameInput'),
|
|
||||||
document.getElementById('ortInput'),
|
|
||||||
document.getElementById('nummerInput'),
|
|
||||||
document.getElementById('plzInput'),
|
|
||||||
document.getElementById('fachrichtungInput')
|
|
||||||
];
|
|
||||||
|
|
||||||
const resetIcons = [
|
|
||||||
document.querySelector('.reset-icon[onclick="clearInput(\'q\')"]'),
|
|
||||||
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(\'fachrichtungInput\')"]')
|
|
||||||
];
|
|
||||||
|
|
||||||
searchInputs.forEach((input, index) => {
|
|
||||||
input.addEventListener('input', function() {
|
|
||||||
clearTimeout(searchTimeout);
|
|
||||||
// Erhöhe das Debounce-Intervall auf 500ms
|
|
||||||
searchTimeout = setTimeout(searchCustomers, 500);
|
|
||||||
|
|
||||||
// Reset-Icon anzeigen/verstecken
|
|
||||||
resetIcons[index].classList.toggle('visible', this.value.length > 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Reset-Funktionalität
|
|
||||||
resetIcons[index].addEventListener('click', function() {
|
|
||||||
searchInputs[index].value = '';
|
|
||||||
searchCustomers();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// URL-Parameter beim Laden der Seite prüfen
|
|
||||||
window.addEventListener('load', function() {
|
|
||||||
const urlParams = new URLSearchParams(window.location.search);
|
|
||||||
const name = urlParams.get('name');
|
|
||||||
const ort = urlParams.get('ort');
|
|
||||||
const kundennummer = urlParams.get('kundennummer');
|
|
||||||
const plz = urlParams.get('plz');
|
|
||||||
|
|
||||||
if (name) document.getElementById('nameInput').value = name;
|
|
||||||
if (ort) document.getElementById('ortInput').value = ort;
|
|
||||||
if (kundennummer) document.getElementById('nummerInput').value = kundennummer;
|
|
||||||
if (plz) document.getElementById('plzInput').value = plz;
|
|
||||||
|
|
||||||
if (name || ort || kundennummer || plz) {
|
|
||||||
searchCustomers();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Reference in New Issue
Block a user