diff --git a/admin-dashboard.html b/admin-dashboard.html index e062761..f5aec1f 100644 --- a/admin-dashboard.html +++ b/admin-dashboard.html @@ -1130,48 +1130,6 @@ - -
-

Správa rezervací

- -
-
- - - -
- -
- -
- - - - - - - - - - - - - - - - -
ŘidičVozidloOdDoÚčelAkce
- Načítám data o rezervacích... -
-
-
-

Správa aplikací

@@ -1186,7 +1144,49 @@

Přednastavené aplikace

- + +
+

Rezervace vozidel

+
+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+ + + + + + + + + + + + + + +
Jméno řidičeVozidloOdDoÚčelAkce
+
+
+
Načítám přednastavené aplikace...
@@ -4599,13 +4599,25 @@ async function loadReservations() { const tbody = document.querySelector('#reservationsTable tbody'); try { const response = await fetch('/api/reservations'); - if (!response.ok) throw new Error('Failed to load reservations'); + if (!response.ok) { + throw new Error('Failed to load reservations'); + } const reservations = await response.json(); - window.allReservations = reservations; // Store for filtering + // Transform data to match frontend format + const transformedReservations = reservations.map(res => ({ + id: res.ID, + driverName: res.DriverName, + vehicle: res.Vehicle, + start: new Date(res.StartDate + 'T' + res.StartTime).toISOString(), + end: new Date(res.EndDate + 'T' + res.EndTime).toISOString(), + purpose: res.Purpose + })); - displayReservations(reservations); - updateVehicleFilter(reservations); + window.allReservations = transformedReservations; // Store for filtering + + displayReservations(transformedReservations); + updateVehicleFilter(transformedReservations); } catch (error) { console.error('Error loading reservations:', error); tbody.innerHTML = ` @@ -5123,7 +5135,10 @@ document.addEventListener('DOMContentLoaded', function() { loadReservations(); }); - +// Load reservations when page loads +document.addEventListener('DOMContentLoaded', () => { + loadReservations(); +}); \ No newline at end of file diff --git a/main.go b/main.go index 9296c4d..ff7bd53 100644 --- a/main.go +++ b/main.go @@ -145,8 +145,20 @@ func trackVisit(w http.ResponseWriter, r *http.Request) { stats.TodayVisits++ } - // Get visitor ID (using IP and User-Agent) - visitorID := fmt.Sprintf("%s-%s", r.RemoteAddr, r.UserAgent()) + // Extract IP address (remove port) + ip := r.RemoteAddr + if strings.Contains(ip, ":") { + // Split at the last colon to remove port + parts := strings.Split(ip, ":") + ip = strings.Join(parts[:len(parts)-1], ":") + // Remove IPv6 brackets if present + if strings.HasPrefix(ip, "[") && strings.HasSuffix(ip, "]") { + ip = ip[1 : len(ip)-1] + } + } + + // Get visitor ID (using cleaned IP and User-Agent) + visitorID := fmt.Sprintf("%s-%s", ip, r.UserAgent()) // Update or create visitor stats if visitor, exists := stats.UniqueVisitors[visitorID]; exists { @@ -357,6 +369,36 @@ type Reservation struct { Purpose string `json:"purpose,omitempty"` } +func getReservations(w http.ResponseWriter, r *http.Request) { + // Load reservations from JSON file + data, err := os.ReadFile("data/reservations.json") + if err != nil { + if os.IsNotExist(err) { + // Return empty array if file doesn't exist + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + w.Write([]byte("[]")) + return + } + log.Printf("Error reading reservations: %v", err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + var reservations []Reservation + if err := json.Unmarshal(data, &reservations); err != nil { + log.Printf("Error unmarshaling reservations: %v", err) + w.WriteHeader(http.StatusInternalServerError) + return + } + + w.Header().Set("Content-Type", "application/json") + if err := json.NewEncoder(w).Encode(reservations); err != nil { + log.Printf("Error encoding reservations: %v", err) + w.WriteHeader(http.StatusInternalServerError) + } +} + func main() { log.SetFlags(log.LstdFlags | log.Lshortfile) @@ -373,6 +415,9 @@ func main() { // Visitor tracking endpoints r.HandleFunc("/api/track-visit", trackVisit).Methods("GET") r.HandleFunc("/api/visitor-stats", getVisitorStats).Methods("GET") + + // Reservations endpoints + r.HandleFunc("/api/reservations", getReservations).Methods("GET") // Set up reverse proxy to kontakt service kontaktURL, _ := url.Parse("http://webportal:8080")