DustyP 9 months ago
parent c576b07a66
commit 1bb5f5e640

@ -1314,18 +1314,22 @@ func (s *Server) handleNextHeat() http.HandlerFunc {
}
// Broadcast event to admin page
select {
case s.adminEvents <- "heat-changed":
// Event sent
default:
// Channel full, non-blocking
}
s.broadcastAdminEvent("heat-changed")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
}
}
// broadcastAdminEvent sends an event to all admin clients
func (s *Server) broadcastAdminEvent(event string) {
// Create a simple event message
eventMsg := fmt.Sprintf(`{"event":"%s"}`, event)
// Send to all admin clients
s.adminEvents <- eventMsg
}
// handlePreviousHeat goes back to the previous heat
func (s *Server) handlePreviousHeat() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
@ -1364,12 +1368,7 @@ func (s *Server) handlePreviousHeat() http.HandlerFunc {
}
// Broadcast event to admin page
select {
case s.adminEvents <- "heat-changed":
// Event sent
default:
// Channel full, non-blocking
}
s.broadcastAdminEvent("heat-changed")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
@ -1456,12 +1455,7 @@ func (s *Server) handleRerunHeat() http.HandlerFunc {
}
// Broadcast event to admin page
select {
case s.adminEvents <- "heat-rerun":
// Event sent
default:
// Channel full, non-blocking
}
s.broadcastAdminEvent("heat-rerun")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"status": "success"})
@ -1494,12 +1488,7 @@ func (s *Server) handleSetRacingGroup() http.HandlerFunc {
}
// Broadcast event to admin page
select {
case s.adminEvents <- "group-changed":
// Event sent
default:
// Channel full, non-blocking
}
s.broadcastAdminEvent("group-changed")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"status": "success"})

@ -237,6 +237,23 @@ templ RaceManage(groups []models.Group, currentGroup models.Group, heats []model
}
};
// Add event listener for admin events
eventSource.addEventListener('admin', function(event) {
console.log("Admin event received:", event.data);
try {
const adminData = JSON.parse(event.data);
if (adminData.event === 'heat-changed' ||
adminData.event === 'group-changed' ||
adminData.event === 'heat-rerun') {
// Reload the page when heat or group changes
window.location.reload();
}
} catch (error) {
console.error("Error processing admin event:", error);
}
});
// Function to reset the timer
function resetTimer() {
fetch('/api/reset', { method: 'POST' })

File diff suppressed because one or more lines are too long

@ -121,20 +121,12 @@ templ RacePublic(currentGroup models.Group, heats []models.Heat, racers []models
statusText = 'Ready';
statusClass = 'bg-primary';
// Reset all lanes
// Don't reset times and positions here anymore
// Only reset visual styling
document.querySelectorAll('.lane-card').forEach(lane => {
lane.classList.remove('bg-success-subtle');
});
// Reset all times and positions
document.querySelectorAll('[id^="lane-"][id$="-time"]').forEach(el => {
el.textContent = '--.-';
});
document.querySelectorAll('[id^="lane-"][id$="-position"]').forEach(el => {
el.textContent = '-';
});
} else if (statusData.status === 'running') {
statusText = 'Race Running';
statusClass = 'bg-success';
@ -142,10 +134,8 @@ templ RacePublic(currentGroup models.Group, heats []models.Heat, racers []models
statusText = 'Race Complete';
statusClass = 'bg-info';
// Reload the page after a short delay to show final results
setTimeout(() => {
window.location.reload();
}, 3000);
// Don't reload the page automatically
// Let the race manager control when to move to the next heat
}
const statusIndicator = document.getElementById('status-indicator');

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save