diff --git a/admin-dashboard.html b/admin-dashboard.html index 1ccb2ea..92c9448 100644 --- a/admin-dashboard.html +++ b/admin-dashboard.html @@ -4955,6 +4955,92 @@ async function saveReservation(event) { } } +// Function to load and display reservations +function loadReservations() { + fetch('/api/reservations') + .then(response => response.json()) + .then(data => { + const reservations = data.reservations || []; + displayReservations(reservations); + updateVehicleFilter(reservations); + }) + .catch(error => { + console.error('Error loading reservations:', error); + showNotification('Nepodařilo se načíst rezervace', 'error'); + }); +} + +// Function to display reservations +function displayReservations(reservations) { + const reservationsContainer = document.getElementById('reservationsContainer'); + if (!reservationsContainer) return; + + // Clear existing content + reservationsContainer.innerHTML = ''; + + if (reservations.length === 0) { + // Show no reservations message + const noReservations = document.createElement('div'); + noReservations.className = 'text-center py-6 text-gray-500'; + noReservations.innerHTML = 'Zatím nebyly vytvořeny žádné rezervace.'; + reservationsContainer.appendChild(noReservations); + return; + } + + // Sort reservations by date + reservations.sort((a, b) => new Date(a.date) - new Date(b.date)); + + // Add table header + const table = document.createElement('table'); + table.className = 'min-w-full divide-y divide-gray-200'; + const thead = document.createElement('thead'); + thead.className = 'bg-gray-50'; + const headerRow = document.createElement('tr'); + + const headers = ['Datum', 'Čas', 'Vozidlo', 'Jméno', 'Telefon', 'Email', 'Délka', 'Akce']; + headers.forEach(header => { + const th = document.createElement('th'); + th.className = 'px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider'; + th.textContent = header; + headerRow.appendChild(th); + }); + thead.appendChild(headerRow); + table.appendChild(thead); + + // Add table body + const tbody = document.createElement('tbody'); + tbody.className = 'bg-white divide-y divide-gray-200'; + + // Add reservations + reservations.forEach(reservation => { + const row = document.createElement('tr'); + row.className = 'hover:bg-gray-50'; + + // Add cells + const cells = [ + formatDateTime(reservation.date, reservation.time), + reservation.vehicle, + reservation.name, + reservation.phone, + reservation.email, + calculateDuration(reservation), + ' ' + ]; + + cells.forEach(cellContent => { + const cell = document.createElement('td'); + cell.className = 'px-6 py-4 whitespace-nowrap text-sm text-gray-900'; + cell.innerHTML = cellContent; + row.appendChild(cell); + }); + + tbody.appendChild(row); + }); + + table.appendChild(tbody); + reservationsContainer.appendChild(table); +} + // Add event listeners when the page loads document.addEventListener('DOMContentLoaded', function() { // Initialize filters diff --git a/main.go b/main.go index 44c3d23..1c54c42 100644 --- a/main.go +++ b/main.go @@ -50,11 +50,11 @@ type VisitorStats struct { func (v *VisitorStats) init() { if v.UniqueVisitors == nil { v.UniqueVisitors = make(map[string]struct { - FirstVisit time.Time - LastVisit time.Time - Visits int - IP string - UserAgent string + FirstVisit time.Time `json:"first_visit"` + LastVisit time.Time `json:"last_visit"` + Visits int `json:"visits"` + IP string `json:"ip"` + UserAgent string `json:"user_agent"` }) } @@ -72,15 +72,15 @@ func (v *VisitorStats) init() { if len(v.MostActiveHours) == 0 { v.MostActiveHours = make([]struct { - Hour int - Count int + Hour int `json:"hour"` + Count int `json:"count"` }, 24) } if len(v.MostActiveDays) == 0 { v.MostActiveDays = make([]struct { - Day string - Count int + Day string `json:"day"` + Count int `json:"count"` }, 7) } }