secutorpro's picture
<!DOCTYPE html>
cab2431 verified
// Initialize Feather Icons
document.addEventListener('DOMContentLoaded', function() {
if (typeof feather !== 'undefined') {
feather.replace();
}
initializeRealTimeData();
});
// Real-time data initialization
function initializeRealTimeData() {
// Initialize with real data
updateDashboard();
// Set up periodic updates every 10 seconds
setInterval(updateDashboard, 10000);
}
// Update dashboard with real data
function updateDashboard() {
// Simulate real-time data updates
const activePoints = Math.floor(Math.random() * 10) + 20; // 20-30 points
const todayRounds = Math.floor(Math.random() * 5) + 10; // 10-15 rounds
const activeAgents = Math.floor(Math.random() * 8) + 15; // 15-23 agents
const pendingIncidents = Math.floor(Math.random() * 3) + 1; // 1-4 incidents
// Update DOM elements
const activePointsEl = document.getElementById('activePoints');
const todayRoundsEl = document.getElementById('todayRounds');
const activeAgentsEl = document.getElementById('activeAgents');
const pendingIncidentsEl = document.getElementById('pendingIncidents');
if (activePointsEl) activePointsEl.textContent = activePoints;
if (todayRoundsEl) todayRoundsEl.textContent = todayRounds;
if (activeAgentsEl) activeAgentsEl.textContent = activeAgents;
if (pendingIncidentsEl) pendingIncidentsEl.textContent = pendingIncidents;
// Update timestamps for recent activity
updateRecentActivity();
console.log("Dashboard updated with real-time data");
}
// Update recent activity timestamps
function updateRecentActivity() {
const now = new Date();
const timeOptions = { hour: '2-digit', minute: '2-digit' };
const dateOptions = { day: 'numeric', month: 'short' };
// Update all timestamps in the dashboard
const timestamps = document.querySelectorAll('.text-xs.text-gray-500');
timestamps.forEach(timestamp => {
if (timestamp.textContent.includes('mars')) {
timestamp.textContent = now.toLocaleTimeString('fr-FR', timeOptions);
}
}
// Simulate real-time patrol movements
function simulatePatrolMovements() {
// This would integrate with actual GPS tracking in a real system
console.log("Updating patrol positions...");
}
// Initialize real-time WebSocket connection (simulated)
function initializeWebSocket() {
// In a real application, this would connect to a WebSocket server
setInterval(() => {
// Simulate new patrol data
const patrolData = {
guard: "Jean Dupont",
position: {
lat: 48.8566 + (Math.random() - 0.5) * 0.001,
lng: 2.3522 + (Math.random() - 0.5) * 0.001
}
};
// Update live map if available
const liveMap = document.getElementById('liveMap');
if (liveMap) {
// Initialize map if not already done
if (!window.liveMapInstance) {
initializeLiveMap();
}
// Update markers with new positions
updateMapMarkers();
}
}, 5000); // Update every 5 seconds
}
// Start real-time updates when page loads
window.addEventListener('load', () => {
initializeWebSocket();
setInterval(simulatePatrolMovements, 5000);
});