File size: 17,278 Bytes
c54f76f
 
 
 
 
 
 
7a5bcd8
 
c54f76f
a04a6df
c54f76f
 
 
 
 
 
 
 
 
 
 
 
 
0c2a304
 
 
 
c54f76f
7a5bcd8
c54f76f
7a5bcd8
 
c54f76f
 
65021b5
 
c54f76f
65021b5
 
 
 
 
 
 
65d2945
65021b5
 
d8bc9c6
 
 
 
 
65021b5
 
 
306400c
65021b5
7a5bcd8
 
65021b5
 
 
 
 
 
0c2a304
65021b5
 
 
0c2a304
65021b5
 
 
0c2a304
65021b5
 
 
c54f76f
65d2945
 
65021b5
306400c
65021b5
7a5bcd8
306400c
 
 
 
 
 
 
e9b5a10
306400c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58cd75e
306400c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e9b5a10
306400c
 
 
 
 
 
 
 
 
7a5bcd8
c54f76f
 
 
 
 
 
 
 
 
 
306400c
a04a6df
eb861b3
306400c
 
 
 
8eed969
50b92fb
8eed969
50b92fb
306400c
5f0e8ab
e9b5a10
306400c
 
5f0e8ab
306400c
 
a04a6df
83d1a1d
306400c
 
 
 
 
5f0e8ab
306400c
 
 
 
 
 
 
 
 
 
 
 
e9b5a10
306400c
 
e9b5a10
306400c
 
a04a6df
83d1a1d
306400c
 
 
 
 
5f0e8ab
306400c
 
 
 
 
 
 
 
 
 
e9b5a10
306400c
 
5f0e8ab
306400c
 
 
e9b5a10
 
02028c4
306400c
02028c4
 
306400c
 
02028c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306400c
02028c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306400c
 
 
 
c54f76f
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WASTE-LESS - Admin Dashboard</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<base target="_blank">
</head>
<body class="bg-gray-100 min-h-screen">
    <div class="container mx-auto px-4 py-8 max-w-6xl">
        <!-- Header with back button -->
        <header class="bg-blue-600 text-white rounded-lg shadow-lg p-6 mb-8">
            <div class="flex items-center justify-between">
                <div class="flex items-center">
                    <a href="index.html" class="text-blue-100 hover:text-white mr-4 text-xl"><i class="fas fa-home"></i></a>
                    <div>
                        <h1 class="text-3xl font-bold">Admin Dashboard</h1>
                        <p class="text-blue-100">Manage food waste and attendance data</p>
                    </div>
                </div>
                <button id="logout-btn" class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg">
                    <i class="fas fa-sign-out-alt mr-2"></i> Logout
                </button>
            </div>
        </header>

        <!-- Admin Controls -->
        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
            <!-- Quick Actions -->
            <div class="bg-white rounded-lg shadow-md p-6">
                <h2 class="text-xl font-semibold mb-4 text-gray-800">Quick Actions</h2>
                <div class="grid grid-cols-2 gap-4">
                    <a href="attendance.html" class="bg-blue-50 hover:bg-blue-100 text-blue-700 p-4 rounded-lg flex flex-col items-center justify-center transition-colors">
                        <i class="fas fa-utensils text-2xl mb-2"></i>
                        <span>Attendance Form A</span>
                    </a>
                    <a href="students-ate.html" class="bg-green-50 hover:bg-green-100 text-green-700 p-4 rounded-lg flex flex-col items-center justify-center transition-colors">
                        <i class="fas fa-check-circle text-2xl mb-2"></i>
                        <span>Attendance Form B</span>
                    </a>
                    <a href="reports.html" class="bg-purple-50 hover:bg-purple-100 text-purple-700 p-4 rounded-lg flex flex-col items-center justify-center transition-colors">
                        <i class="fas fa-chart-bar text-2xl mb-2"></i>
                        <span>View Reports</span>
                    </a>
                    <a href="student-management.html" class="bg-yellow-50 hover:bg-yellow-100 text-yellow-700 p-4 rounded-lg flex flex-col items-center justify-center transition-colors">
                        <i class="fas fa-users-cog text-2xl mb-2"></i>
                        <span>Student Management</span>
                    </a>
                    <a href="#" class="bg-gray-100 hover:bg-gray-200 text-gray-700 p-4 rounded-lg flex flex-col items-center justify-center transition-colors">
                        <i class="fas fa-cog text-2xl mb-2"></i>
                        <span>Settings</span>
                    </a>
                </div>
            </div>

            <!-- System Overview -->
            <div class="bg-white rounded-lg shadow-md p-6">
                <h2 class="text-xl font-semibold mb-4 text-gray-800">System Overview</h2>
                <div class="space-y-4">
                    <div class="flex justify-between items-center p-3 bg-gray-50 rounded-lg">
                        <span>Total Students</span>
                        <span class="font-bold">1200</span>
                    </div>
                    <div class="flex justify-between items-center p-3 bg-gray-50 rounded-lg">
                        <span>Today's Attendance</span>
                        <span class="font-bold">78%</span>
                    </div>
                    <div class="flex justify-between items-center p-3 bg-gray-50 rounded-lg">
                        <span>Food Waste Today</span>
                        <span class="font-bold">15 kg</span>
                    </div>
                    <div class="flex justify-between items-center p-3 bg-gray-50 rounded-lg">
                        <span>Meals Served Today</span>
                        <span class="font-bold">850</span>
                    </div>
                </div>
            </div>
        </div>

        <!-- Attendance Data Tables -->
        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
            <!-- Form A Data -->
            <div class="bg-white rounded-lg shadow-md p-6">
                <div class="flex justify-between items-center mb-4">
                    <h2 class="text-xl font-semibold text-gray-800">Students Who Want To Eat (Form A)</h2>
                    <button id="refresh-formA" class="text-blue-600 hover:text-blue-800">
                        <i class="fas fa-sync-alt mr-1"></i> Refresh
                    </button>
                </div>
                <div class="overflow-x-auto max-h-96 overflow-y-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50 sticky top-0">
                            <tr>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Student</th>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Class</th>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Form</th>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Attendance</th>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Meal</th>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Time</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200" id="formAData">
                            <tr>
                                <td colspan="6" class="px-4 py-4 text-center text-gray-500">Loading data...</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="mt-4 text-sm text-gray-500">
                    <a href="https://github.com/SMSS-Waste-Less/Waste-LessV5/blob/main/Data%20Students%20who%20want%20to%20eat" target="_blank" class="text-blue-600 hover:underline">
                        View full data on GitHub
                    </a>
                </div>
            </div>

            <!-- Form B Data -->
            <div class="bg-white rounded-lg shadow-md p-6">
                <div class="flex justify-between items-center mb-4">
                    <h2 class="text-xl font-semibold text-gray-800">Students Who Have Eaten (Form B)</h2>
                    <button id="refresh-formB" class="text-blue-600 hover:text-blue-800">
                        <i class="fas fa-sync-alt mr-1"></i> Refresh
                    </button>
                </div>
                <div class="overflow-x-auto max-h-96 overflow-y-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50 sticky top-0">
                            <tr>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Student</th>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Class</th>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Form</th>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Meal</th>
                                <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Time</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200" id="formBData">
                            <tr>
                                <td colspan="5" class="px-4 py-4 text-center text-gray-500">Loading data...</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="mt-4 text-sm text-gray-500">
                    <a href="https://github.com/WaffleExecutors/Waste-LessV5/blob/main/data%20who%20has%20ate%20at%20dm" target="_blank" class="text-blue-600 hover:underline">
                        View full data on GitHub
                    </a>
                </div>
            </div>
        </div>

        <!-- Charts -->
        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
            <div class="bg-white rounded-lg shadow-md p-6">
                <h2 class="text-xl font-semibold mb-4 text-gray-800">Attendance Trend</h2>
                <canvas id="attendanceChart" height="250"></canvas>
            </div>
            <div class="bg-white rounded-lg shadow-md p-6">
                <h2 class="text-xl font-semibold mb-4 text-gray-800">Food Waste Breakdown</h2>
                <canvas id="wasteChart" height="250"></canvas>
            </div>
        </div>
    </div>

    <script src="config.js"></script>
    <script>

        // Login check
        if (localStorage.getItem('isAdminLoggedIn') !== 'true') {
            alert('Please login first');
            window.location.href = 'admin-login.html';
            return;
        }

        // Fetch data
        async function fetchAttendanceData() {
            try {
                document.getElementById('formAData').innerHTML = '<tr><td colspan="6" class="text-center py-4"><i class="fas fa-spinner fa-spin"></i> Loading...</td></tr>';
                document.getElementById('formBData').innerHTML = '<tr><td colspan="5" class="text-center py-4"><i class="fas fa-spinner fa-spin"></i> Loading...</td></tr>';

                // Form A
                const aResp = await fetch('https://api.github.com/repos/SMSS-Waste-Less/Waste-LessV5/contents/Data%20Students%20who%20want%20to%20eat', {
                    headers: { 'Authorization': `token ${GITHUB_CONFIG.TOKEN}`, 'Accept': 'application/vnd.github.v3+json' }
                });
                let aRows = '<tr><td colspan="6" class="text-center py-4 text-gray-500">No data</td></tr>';
                if (aResp.ok) {
                    const aFile = await aResp.json();
                    const aContent = atob(aFile.content);
                    aRows = aContent.split('\n').filter(l => l.trim()).reverse().map(l => {
                        try {
                            const r = JSON.parse(l);
                            const t = new Date(r.timestamp).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
                            const att = r.attendance === 'yes' ? 'Will Eat' : 'Will Not Eat';
                            return `<tr class="hover:bg-gray-50">
                                <td class="px-4 py-2 text-sm">${r.studentName}</td>
                                <td class="px-4 py-2 text-sm">${r.class}</td>
                                <td class="px-4 py-2 text-sm">${r.form}</td>
                                <td class="px-4 py-2 text-sm">${att}</td>
                                <td class="px-4 py-2 text-sm">${r.mealTime || '-'}</td>
                                <td class="px-4 py-2 text-sm text-gray-500">${t}</td>
                            </tr>`;
                        } catch { return ''; }
                    }).join('');
                }
                document.getElementById('formAData').innerHTML = aRows;

                // Form B
                const bResp = await fetch('https://api.github.com/repos/WaffleExecutors/Waste-LessV5/contents/data%20who%20has%20ate%20at%20dm', {
                    headers: { 'Authorization': `token ${GITHUB_CONFIG.TOKEN}`, 'Accept': 'application/vnd.github.v3+json' }
                });
                let bRows = '<tr><td colspan="5" class="text-center py-4 text-gray-500">No data</td></tr>';
                if (bResp.ok) {
                    const bFile = await bResp.json();
                    const bContent = atob(bFile.content);
                    bRows = bContent.split('\n').filter(l => l.trim()).reverse().map(l => {
                        try {
                            const r = JSON.parse(l);
                            const t = new Date(r.timestamp).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
                            return `<tr class="hover:bg-gray-50">
                                <td class="px-4 py-2 text-sm">${r.studentName}</td>
                                <td class="px-4 py-2 text-sm">${r.class}</td>
                                <td class="px-4 py-2 text-sm">${r.form}</td>
                                <td class="px-4 py-2 text-sm">${r.mealTime || '-'}</td>
                                <td class="px-4 py-2 text-sm text-gray-500">${t}</td>
                            </tr>`;
                        } catch { return ''; }
                    }).join('');
                }
                document.getElementById('formBData').innerHTML = bRows;

            } catch (err) {
                console.error(err);
                alert('Failed to load data. Check token or connection.');
            }
        }
        // Load data on start and refresh every 30 seconds
        fetchAttendanceData();
        setInterval(fetchAttendanceData, 30000);
// Refresh buttons
        document.getElementById('refresh-formA').onclick = fetchAttendanceData;
        document.getElementById('refresh-formB').onclick = fetchAttendanceData;
        // Initialize charts with empty data
        const attendanceChart = new Chart(document.getElementById('attendanceChart'), { 
            type: 'line', 
            data: { 
                labels: ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'], 
                datasets: [{ 
                    label: 'Attendance Rate (%)', 
                    data: [],
                    borderColor: '#3b82f6',
                    backgroundColor: 'rgba(59, 130, 246, 0.1)',
                    borderWidth: 2,
                    tension: 0.3,
                    fill: true
                }] 
            },
            options: {
                responsive: true,
                plugins: {
                    tooltip: {
                        callbacks: {
                            label: function(context) {
                                return `${context.dataset.label}: ${context.raw}%`;
                            }
                        }
                    }
                },
                scales: {
                    y: {
                        min: 0,
                        max: 100,
                        ticks: {
                            callback: function(value) {
                                return value + '%';
                            }
                        }
                    }
                }
            } 
        });

        const wasteChart = new Chart(document.getElementById('wasteChart'), { 
            type: 'bar', 
            data: { 
                labels: ['Breakfast','Lunch','Dinner','Supper'], 
                datasets: [{ 
                    label: 'Food Waste (kg)', 
                    data: [],
                    backgroundColor: [
                        'rgba(234, 179, 8, 0.7)',
                        'rgba(22, 163, 74, 0.7)',
                        'rgba(99, 102, 241, 0.7)',
                        'rgba(168, 85, 247, 0.7)'
                    ],
                    borderColor: [
                        'rgba(234, 179, 8, 1)',
                        'rgba(22, 163, 74, 1)',
                        'rgba(99, 102, 241, 1)',
                        'rgba(168, 85, 247, 1)'
                    ],
                    borderWidth: 1
                }] 
            },
            options: {
                responsive: true,
                plugins: {
                    tooltip: {
                        callbacks: {
                            label: function(context) {
                                return `${context.dataset.label}: ${context.raw}kg`;
                            }
                        }
                    }
                },
                scales: {
                    y: {
                        beginAtZero: true,
                        title: {
                            display: true,
                            text: 'Kilograms'
                        }
                    }
                }
            } 
        });
// Logout
        document.getElementById('logout-btn').onclick = () => {
            localStorage.clear();
            window.location.href = 'admin-login.html';
        };
    </script>
</body>
</html>