File size: 1,649 Bytes
31e3709
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Global functions and event listeners
document.addEventListener('DOMContentLoaded', function() {
    // Initialize tooltips
    const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
    tooltipTriggerList.map(function (tooltipTriggerEl) {
        return new bootstrap.Tooltip(tooltipTriggerEl);
    });
    
    // Handle dark mode toggle if needed
    const darkModeToggle = document.getElementById('darkModeToggle');
    if(darkModeToggle) {
        darkModeToggle.addEventListener('click', function() {
            document.documentElement.classList.toggle('dark');
        });
    }
});

// API functions
async function fetchAlarms() {
    try {
        const response = await fetch('/api/alarms');
        return await response.json();
    } catch (error) {
        console.error('Error fetching alarms:', error);
        return [];
    }
}

async function fetchCameras() {
    try {
        const response = await fetch('/api/cameras');
        return await response.json();
    } catch (error) {
        console.error('Error fetching cameras:', error);
        return [];
    }
}

// Utility functions
function formatDateTime(dateString) {
    const options = { 
        year: 'numeric', 
        month: 'short', 
        day: 'numeric',
        hour: '2-digit', 
        minute: '2-digit' 
    };
    return new Date(dateString).toLocaleDateString('en-US', options);
}

function getPriorityColor(priority) {
    const colors = {
        'critical': 'red',
        'high': 'orange',
        'medium': 'yellow',
        'low': 'green'
    };
    return colors[priority.toLowerCase()] || 'gray';
}