Files
PPve/contact-scrape-test/index.html
T
Tomáš Dvořák 3c41a8378c Add files via upload
2025-05-22 09:00:19 +02:00

374 lines
18 KiB
HTML

<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kontakty</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
.contact-card {
transition: all 0.2s ease-in-out;
}
.contact-card:hover {
transform: translateY(-2px);
}
.search-highlight {
background-color: #fef3c7;
padding: 1px 2px;
border-radius: 2px;
}
</style>
</head>
<body class="bg-gradient-to-br from-blue-50 to-indigo-100 min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-7xl">
<div class="bg-white rounded-xl shadow-xl p-6 md:p-8">
<!-- Header -->
<div class="flex flex-col sm:flex-row justify-between items-start sm:items-center mb-8 gap-4">
<div>
<h1 class="text-4xl font-bold text-gray-800 mb-2">📞 Kontakty</h1>
<p class="text-gray-600">Firemní telefonní seznam</p>
</div>
<button onclick="reloadContacts()" id="reloadBtn"
class="bg-blue-500 hover:bg-blue-600 text-white px-6 py-3 rounded-lg transition-all duration-200 shadow-md hover:shadow-lg flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
Obnovit
</button>
</div>
<!-- Search Bar -->
<div class="mb-6">
<div class="relative">
<input type="text" id="searchInput" placeholder="Hledat podle jména, pozice nebo telefonu..."
class="w-full px-4 py-3 pl-12 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent shadow-sm text-lg"
onkeyup="filterContacts()">
<svg class="absolute left-4 top-1/2 transform -translate-y-1/2 w-5 h-5 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
</svg>
</div>
</div>
<!-- Filter Buttons -->
<div class="mb-6 flex flex-wrap gap-2">
<button onclick="filterByTable('all')" class="filter-btn active" data-filter="all">
Všechny kontakty
</button>
<button onclick="filterByTable(1)" class="filter-btn" data-filter="1">
Tabulka 1
</button>
<button onclick="filterByTable(2)" class="filter-btn" data-filter="2">
Tabulka 2
</button>
</div>
<!-- Loading State -->
<div id="loading" class="text-center py-16">
<div class="inline-block animate-spin rounded-full h-12 w-12 border-b-2 border-blue-500 mb-4"></div>
<p class="text-gray-600 text-lg">Načítání kontaktů...</p>
</div>
<!-- Main Content -->
<div id="contactsList" class="hidden">
<!-- Stats -->
<div id="stats" class="mb-6 p-4 bg-gray-50 rounded-lg border text-sm text-gray-700"></div>
<!-- Contacts Grid -->
<div id="contacts" class="grid gap-6 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"></div>
<!-- No Results -->
<div id="noResults" class="hidden text-center py-16">
<div class="text-6xl mb-4">🔍</div>
<h3 class="text-xl font-semibold text-gray-700 mb-2">Žádné výsledky</h3>
<p class="text-gray-500">Zkuste změnit hledaný výraz</p>
</div>
</div>
<!-- Error State -->
<div id="error" class="hidden text-center py-16">
<div class="text-6xl mb-4">⚠️</div>
<h3 class="text-xl font-semibold text-red-600 mb-2">Chyba při načítání</h3>
<p class="text-gray-600 mb-4">Nepodařilo se načíst kontakty</p>
<button onclick="loadContacts()" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg transition-colors">
Zkusit znovu
</button>
</div>
</div>
</div>
<script>
let allContacts = [];
let filteredContacts = [];
let currentTableFilter = 'all';
async function loadContacts() {
try {
showLoading();
const response = await fetch('/contacts');
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json();
allContacts = data.contacts || [];
hideLoading();
showContactsList();
updateStats(data);
filterContacts();
} catch (error) {
console.error('Error loading contacts:', error);
hideLoading();
showError('Chyba při načítání kontaktů: ' + error.message);
}
}
function showLoading() {
document.getElementById('loading').classList.remove('hidden');
document.getElementById('contactsList').classList.add('hidden');
document.getElementById('error').classList.add('hidden');
}
function hideLoading() {
document.getElementById('loading').classList.add('hidden');
}
function showContactsList() {
document.getElementById('contactsList').classList.remove('hidden');
document.getElementById('error').classList.add('hidden');
}
function showError(message) {
document.getElementById('error').classList.remove('hidden');
document.getElementById('error').querySelector('p').textContent = message;
document.getElementById('contactsList').classList.add('hidden');
}
function updateStats(data) {
const lastUpdated = new Date(data.last_updated).toLocaleString('cs-CZ');
const table1Count = allContacts.filter(c => c.table === 1).length;
const table2Count = allContacts.filter(c => c.table === 2).length;
document.getElementById('stats').innerHTML = `
<div class="flex flex-wrap items-center gap-4 text-sm">
<div class="flex items-center gap-2">
<span class="w-2 h-2 bg-green-500 rounded-full"></span>
<span><strong>Celkem:</strong> ${allContacts.length} kontaktů</span>
</div>
<div class="flex items-center gap-2">
<span class="w-2 h-2 bg-blue-500 rounded-full"></span>
<span><strong>Tabulka 1:</strong> ${table1Count}</span>
</div>
<div class="flex items-center gap-2">
<span class="w-2 h-2 bg-purple-500 rounded-full"></span>
<span><strong>Tabulka 2:</strong> ${table2Count}</span>
</div>
<div class="flex items-center gap-2">
<span class="w-2 h-2 bg-gray-400 rounded-full"></span>
<span><strong>Poslední aktualizace:</strong> ${lastUpdated}</span>
</div>
</div>
`;
}
function filterByTable(tableNum) {
currentTableFilter = tableNum;
// Update filter buttons
document.querySelectorAll('.filter-btn').forEach(btn => {
btn.classList.remove('active');
if (btn.dataset.filter == tableNum) {
btn.classList.add('active');
}
});
filterContacts();
}
function filterContacts() {
const query = document.getElementById('searchInput').value.toLowerCase().trim();
// Apply table filter
let contacts = allContacts;
if (currentTableFilter !== 'all') {
contacts = contacts.filter(contact => contact.table == currentTableFilter);
}
// Apply search filter
if (query) {
contacts = contacts.filter(contact =>
(contact.name && contact.name.toLowerCase().includes(query)) ||
(contact.position && contact.position.toLowerCase().includes(query)) ||
(contact.phone && contact.phone.replace(/\s/g, '').includes(query.replace(/\s/g, ''))) ||
(contact.service_phone && contact.service_phone.replace(/\s/g, '').includes(query.replace(/\s/g, '')))
);
}
filteredContacts = contacts;
displayContacts(filteredContacts, query);
}
function highlightText(text, query) {
if (!query || !text) return text;
const regex = new RegExp(`(${query})`, 'gi');
return text.replace(regex, '<span class="search-highlight">$1</span>');
}
function displayContacts(contacts, searchQuery = '') {
const container = document.getElementById('contacts');
const noResults = document.getElementById('noResults');
if (contacts.length === 0) {
container.innerHTML = '';
noResults.classList.remove('hidden');
return;
}
noResults.classList.add('hidden');
container.innerHTML = '';
contacts.forEach(contact => {
const contactCard = document.createElement('div');
contactCard.className = 'contact-card bg-white p-6 rounded-lg border border-gray-200 hover:shadow-lg transition-all duration-200';
const name = contact.name || 'Bez jména';
const position = contact.position || '';
const tableColor = contact.table === 1 ? 'bg-blue-100 text-blue-800' : 'bg-purple-100 text-purple-800';
contactCard.innerHTML = `
<div class="flex items-start justify-between mb-3">
<h3 class="font-bold text-gray-800 text-lg leading-tight">${highlightText(name, searchQuery)}</h3>
<span class="text-xs ${tableColor} px-2 py-1 rounded-full font-medium flex-shrink-0 ml-2">T${contact.table}</span>
</div>
${position ? `<p class="text-gray-600 mb-4 text-sm leading-relaxed">${highlightText(position, searchQuery)}</p>` : ''}
<div class="space-y-2">
${contact.phone ? `
<div class="flex items-center text-sm group">
<svg class="w-4 h-4 text-gray-400 mr-3 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path>
</svg>
<span class="font-medium text-gray-700 mr-2">Tel:</span>
<a href="tel:${contact.phone}" class="text-blue-600 hover:text-blue-800 hover:underline transition-colors">
${highlightText(contact.phone, searchQuery)}
</a>
</div>
` : ''}
${contact.service_phone ? `
<div class="flex items-center text-sm group">
<svg class="w-4 h-4 text-gray-400 mr-3 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 13.255A23.931 23.931 0 0112 15c-3.183 0-6.22-.62-9-1.745M16 6V4a2 2 0 00-2-2h-4a2 2 0 00-2-2v2m8 0V6a2 2 0 012 2v6a2 2 0 01-2 2H6a2 2 0 01-2-2V8a2 2 0 012-2V6"></path>
</svg>
<span class="font-medium text-gray-700 mr-2">Služební:</span>
<a href="tel:${contact.service_phone}" class="text-blue-600 hover:text-blue-800 hover:underline transition-colors">
${highlightText(contact.service_phone, searchQuery)}
</a>
</div>
` : ''}
${!contact.phone && !contact.service_phone ? '<p class="text-gray-400 text-sm italic">Bez telefonu</p>' : ''}
</div>
`;
container.appendChild(contactCard);
});
}
async function reloadContacts() {
const btn = document.getElementById('reloadBtn');
const originalText = btn.innerHTML;
btn.disabled = true;
btn.innerHTML = `
<svg class="w-4 h-4 animate-spin" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
</svg>
Načítání...
`;
try {
const response = await fetch('/reload', { method: 'POST' });
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
// Small delay to show the loading state
await new Promise(resolve => setTimeout(resolve, 500));
await loadContacts();
// Show success feedback
btn.innerHTML = `
<svg class="w-4 h-4 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path>
</svg>
Obnoveno
`;
setTimeout(() => {
btn.innerHTML = originalText;
}, 2000);
} catch (error) {
console.error('Error reloading:', error);
btn.innerHTML = `
<svg class="w-4 h-4 text-red-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
</svg>
Chyba
`;
setTimeout(() => {
btn.innerHTML = originalText;
}, 2000);
alert('Chyba při obnovování: ' + error.message);
} finally {
btn.disabled = false;
}
}
// Initialize filter button styles
document.addEventListener('DOMContentLoaded', function() {
const style = document.createElement('style');
style.textContent = `
.filter-btn {
@apply px-4 py-2 rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 transition-all duration-200 text-sm font-medium;
}
.filter-btn.active {
@apply bg-blue-500 text-white border-blue-500 shadow-md;
}
.filter-btn:hover:not(.active) {
@apply bg-gray-100 border-gray-400;
}
`;
document.head.appendChild(style);
});
// Load contacts on page load
document.addEventListener('DOMContentLoaded', loadContacts);
// Add keyboard shortcuts
document.addEventListener('keydown', function(e) {
// Ctrl/Cmd + K to focus search
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
document.getElementById('searchInput').focus();
}
// Escape to clear search
if (e.key === 'Escape') {
document.getElementById('searchInput').value = '';
filterContacts();
}
});
// Add search input focus ring and animations
document.getElementById('searchInput').addEventListener('focus', function() {
this.parentElement.classList.add('ring-2', 'ring-blue-500');
});
document.getElementById('searchInput').addEventListener('blur', function() {
this.parentElement.classList.remove('ring-2', 'ring-blue-500');
});
</script>
</body>
</html>