Spaces:
Running
Running
Manual changes saved
Browse files- admin-dashboard.html +137 -300
admin-dashboard.html
CHANGED
|
@@ -53,7 +53,7 @@
|
|
| 53 |
<i class="fas fa-cog text-2xl mb-2"></i>
|
| 54 |
<span>Settings</span>
|
| 55 |
</a>
|
| 56 |
-
</div>
|
| 57 |
</div>
|
| 58 |
|
| 59 |
<!-- System Overview -->
|
|
@@ -79,342 +79,179 @@
|
|
| 79 |
</div>
|
| 80 |
</div>
|
| 81 |
</div>
|
|
|
|
| 82 |
<!-- Attendance Data Tables -->
|
| 83 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
</div>
|
| 92 |
-
<div class="overflow-x-auto max-h-96 overflow-y-auto">
|
| 93 |
-
<table class="min-w-full divide-y divide-gray-200">
|
| 94 |
-
<thead class="bg-gray-50 sticky top-0">
|
| 95 |
-
<tr>
|
| 96 |
-
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Student</th>
|
| 97 |
-
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Class</th>
|
| 98 |
-
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Form</th>
|
| 99 |
-
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Meal</th>
|
| 100 |
-
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Time</th>
|
| 101 |
-
</tr>
|
| 102 |
-
</thead>
|
| 103 |
-
<tbody class="bg-white divide-y divide-gray-200" id="formAData">
|
| 104 |
-
<tr>
|
| 105 |
-
<td colspan="5" class="px-4 py-4 text-center text-gray-500">Loading data...</td>
|
| 106 |
-
</tr>
|
| 107 |
-
</tbody>
|
| 108 |
-
</table>
|
| 109 |
-
</div>
|
| 110 |
-
<div class="mt-4 text-sm text-gray-500">
|
| 111 |
-
<a href="https://github.com/SMSS-Waste-Less/Waste-LessV5/blob/main/Data%20Students%20who%20want%20to%20eat"
|
| 112 |
-
target="_blank" class="text-blue-600 hover:underline">
|
| 113 |
-
View full data on GitHub
|
| 114 |
-
</a>
|
| 115 |
-
</div>
|
| 116 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
</div>
|
| 144 |
-
<div class="mt-4 text-sm text-gray-500">
|
| 145 |
-
<a href="https://github.com/WaffleExecutors/Waste-LessV5/blob/main/data%20who%20has%20ate%20at%20dm"
|
| 146 |
-
target="_blank" class="text-blue-600 hover:underline">
|
| 147 |
-
View full data on GitHub
|
| 148 |
-
</a>
|
| 149 |
-
</div>
|
| 150 |
</div>
|
| 151 |
-
<
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
|
| 154 |
-
<!-- Attendance Trend -->
|
| 155 |
<div class="bg-white rounded-lg shadow-md p-6">
|
| 156 |
<h2 class="text-xl font-semibold mb-4 text-gray-800">Attendance Trend</h2>
|
| 157 |
<canvas id="attendanceChart" height="250"></canvas>
|
| 158 |
</div>
|
| 159 |
-
|
| 160 |
-
<!-- Food Waste Breakdown -->
|
| 161 |
<div class="bg-white rounded-lg shadow-md p-6">
|
| 162 |
<h2 class="text-xl font-semibold mb-4 text-gray-800">Food Waste Breakdown</h2>
|
| 163 |
<canvas id="wasteChart" height="250"></canvas>
|
| 164 |
</div>
|
| 165 |
</div>
|
| 166 |
</div>
|
| 167 |
-
|
| 168 |
<script>
|
| 169 |
-
//
|
| 170 |
-
const
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
if (localStorage.getItem('isAdminLoggedIn') !== 'true'
|
| 174 |
-
|
| 175 |
-
(Date.now() - new Date(lastLogin).getTime()) > sessionTimeout) {
|
| 176 |
-
|
| 177 |
-
localStorage.removeItem('isAdminLoggedIn');
|
| 178 |
-
localStorage.removeItem('lastLogin');
|
| 179 |
-
alert('Session expired or not logged in. Please login again.');
|
| 180 |
window.location.href = 'admin-login.html';
|
| 181 |
return;
|
| 182 |
}
|
| 183 |
|
| 184 |
-
//
|
| 185 |
-
localStorage.setItem('lastLogin', new Date().toISOString());
|
| 186 |
-
// Fetch and display attendance data
|
| 187 |
async function fetchAttendanceData() {
|
| 188 |
try {
|
| 189 |
-
|
| 190 |
-
document.getElementById('
|
| 191 |
-
<tr>
|
| 192 |
-
<td colspan="5" class="px-4 py-4 text-center text-gray-500">
|
| 193 |
-
<div class="inline-block animate-spin rounded-full h-6 w-6 border-t-2 border-b-2 border-blue-500 mr-2"></div>
|
| 194 |
-
Loading data...
|
| 195 |
-
</td>
|
| 196 |
-
</tr>
|
| 197 |
-
`;
|
| 198 |
-
document.getElementById('formBData').innerHTML = `
|
| 199 |
-
<tr>
|
| 200 |
-
<td colspan="5" class="px-4 py-4 text-center text-gray-500">
|
| 201 |
-
<div class="inline-block animate-spin rounded-full h-6 w-6 border-t-2 border-b-2 border-blue-500 mr-2"></div>
|
| 202 |
-
Loading data...
|
| 203 |
-
</td>
|
| 204 |
-
</tr>
|
| 205 |
-
`;
|
| 206 |
|
| 207 |
-
//
|
| 208 |
-
const
|
| 209 |
-
headers: {
|
| 210 |
-
'Authorization': ` TOKEN: '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'
|
| 211 |
-
`
|
| 212 |
-
}
|
| 213 |
});
|
| 214 |
-
|
| 215 |
-
if (
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
// Parse and display Form A data
|
| 221 |
-
const formARows = formAContent.split('\n')
|
| 222 |
-
.filter(line => line.trim() !== '')
|
| 223 |
-
.map(line => {
|
| 224 |
try {
|
| 225 |
-
const
|
| 226 |
-
const
|
| 227 |
-
const
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
<
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
`;
|
| 238 |
-
} catch (e) {
|
| 239 |
-
console.error('Error parsing record:', e);
|
| 240 |
-
return '';
|
| 241 |
-
}
|
| 242 |
}).join('');
|
| 243 |
-
|
| 244 |
-
document.getElementById('formAData').innerHTML =
|
| 245 |
-
<tr>
|
| 246 |
-
<td colspan="5" class="px-4 py-4 text-center text-gray-500">No attendance records found</td>
|
| 247 |
-
</tr>
|
| 248 |
-
`;
|
| 249 |
|
| 250 |
-
//
|
| 251 |
-
const
|
| 252 |
-
headers: {
|
| 253 |
-
'Authorization': ` TOKEN: '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'
|
| 254 |
-
`
|
| 255 |
-
}
|
| 256 |
});
|
| 257 |
-
|
| 258 |
-
if (
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
// Parse and display Form B data
|
| 264 |
-
const formBRows = formBContent.split('\n')
|
| 265 |
-
.filter(line => line.trim() !== '')
|
| 266 |
-
.map(line => {
|
| 267 |
try {
|
| 268 |
-
const
|
| 269 |
-
const
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
<
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
<td class="px-4 py-2 whitespace-nowrap text-sm text-gray-500">${timeString}</td>
|
| 279 |
-
</tr>
|
| 280 |
-
`;
|
| 281 |
-
} catch (e) {
|
| 282 |
-
console.error('Error parsing record:', e);
|
| 283 |
-
return '';
|
| 284 |
-
}
|
| 285 |
}).join('');
|
| 286 |
-
|
| 287 |
-
document.getElementById('formBData').innerHTML =
|
| 288 |
-
<tr>
|
| 289 |
-
<td colspan="5" class="px-4 py-4 text-center text-gray-500">No attendance records found</td>
|
| 290 |
-
</tr>
|
| 291 |
-
`;
|
| 292 |
|
| 293 |
-
} catch (
|
| 294 |
-
console.error(
|
| 295 |
-
|
| 296 |
-
<tr>
|
| 297 |
-
<td colspan="5" class="px-4 py-4 text-sm text-red-500">Failed to load data: ${error.message}</td>
|
| 298 |
-
</tr>
|
| 299 |
-
`;
|
| 300 |
-
document.getElementById('formBData').innerHTML = `
|
| 301 |
-
<tr>
|
| 302 |
-
<td colspan="5" class="px-4 py-4 text-sm text-red-500">Failed to load data: ${error.message}</td>
|
| 303 |
-
</tr>
|
| 304 |
-
`;
|
| 305 |
}
|
| 306 |
}
|
| 307 |
-
// Initialize charts and fetch data
|
| 308 |
-
document.addEventListener('DOMContentLoaded', async function() {
|
| 309 |
-
// Fetch attendance data first
|
| 310 |
-
await fetchAttendanceData();
|
| 311 |
-
|
| 312 |
-
// Add refresh button handlers
|
| 313 |
-
document.getElementById('refresh-formA').addEventListener('click', async function() {
|
| 314 |
-
this.innerHTML = '<i class="fas fa-spinner fa-spin mr-1"></i> Refreshing...';
|
| 315 |
-
await fetchAttendanceData();
|
| 316 |
-
this.innerHTML = '<i class="fas fa-sync-alt mr-1"></i> Refresh';
|
| 317 |
-
});
|
| 318 |
-
|
| 319 |
-
document.getElementById('refresh-formB').addEventListener('click', async function() {
|
| 320 |
-
this.innerHTML = '<i class="fas fa-spinner fa-spin mr-1"></i> Refreshing...';
|
| 321 |
-
await fetchAttendanceData();
|
| 322 |
-
this.innerHTML = '<i class="fas fa-sync-alt mr-1"></i> Refresh';
|
| 323 |
-
});
|
| 324 |
-
// Attendance Trend Chart
|
| 325 |
-
const attendanceCtx = document.getElementById('attendanceChart').getContext('2d');
|
| 326 |
-
const attendanceChart = new Chart(attendanceCtx, {
|
| 327 |
-
type: 'line',
|
| 328 |
-
data: {
|
| 329 |
-
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
|
| 330 |
-
datasets: [{
|
| 331 |
-
label: 'Attendance Rate',
|
| 332 |
-
data: [75, 80, 82, 78, 85, 70],
|
| 333 |
-
backgroundColor: 'rgba(59, 130, 246, 0.1)',
|
| 334 |
-
borderColor: 'rgba(59, 130, 246, 1)',
|
| 335 |
-
borderWidth: 2,
|
| 336 |
-
tension: 0.3,
|
| 337 |
-
fill: true
|
| 338 |
-
}]
|
| 339 |
-
},
|
| 340 |
-
options: {
|
| 341 |
-
responsive: true,
|
| 342 |
-
plugins: {
|
| 343 |
-
legend: {
|
| 344 |
-
display: false
|
| 345 |
-
}
|
| 346 |
-
},
|
| 347 |
-
scales: {
|
| 348 |
-
y: {
|
| 349 |
-
beginAtZero: false,
|
| 350 |
-
min: 60,
|
| 351 |
-
max: 100
|
| 352 |
-
}
|
| 353 |
-
}
|
| 354 |
-
}
|
| 355 |
-
});
|
| 356 |
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
const wasteChart = new Chart(wasteCtx, {
|
| 360 |
-
type: 'bar',
|
| 361 |
-
data: {
|
| 362 |
-
labels: ['Breakfast', 'Lunch', 'Dinner', 'Supper'],
|
| 363 |
-
datasets: [{
|
| 364 |
-
label: 'Waste (kg)',
|
| 365 |
-
data: [5, 12, 8, 3],
|
| 366 |
-
backgroundColor: [
|
| 367 |
-
'rgba(234, 179, 8, 0.7)',
|
| 368 |
-
'rgba(22, 163, 74, 0.7)',
|
| 369 |
-
'rgba(99, 102, 241, 0.7)',
|
| 370 |
-
'rgba(168, 85, 247, 0.7)'
|
| 371 |
-
],
|
| 372 |
-
borderColor: [
|
| 373 |
-
'rgba(234, 179, 8, 1)',
|
| 374 |
-
'rgba(22, 163, 74, 1)',
|
| 375 |
-
'rgba(99, 102, 241, 1)',
|
| 376 |
-
'rgba(168, 85, 247, 1)'
|
| 377 |
-
],
|
| 378 |
-
borderWidth: 1
|
| 379 |
-
}]
|
| 380 |
-
},
|
| 381 |
-
options: {
|
| 382 |
-
responsive: true,
|
| 383 |
-
plugins: {
|
| 384 |
-
legend: {
|
| 385 |
-
display: false
|
| 386 |
-
}
|
| 387 |
-
}
|
| 388 |
-
}
|
| 389 |
-
});
|
| 390 |
-
// Logout button
|
| 391 |
-
document.getElementById('logout-btn').addEventListener('click', function() {
|
| 392 |
-
// Clear all session data
|
| 393 |
-
localStorage.removeItem('isAdminLoggedIn');
|
| 394 |
-
localStorage.removeItem('lastLogin');
|
| 395 |
-
localStorage.removeItem('fromLoginPage');
|
| 396 |
-
|
| 397 |
-
// Redirect to login page
|
| 398 |
-
window.location.href = 'admin-login.html';
|
| 399 |
-
});
|
| 400 |
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
alert('You have been logged out due to inactivity.');
|
| 409 |
-
window.location.href = 'admin-login.html';
|
| 410 |
-
}, 30 * 60 * 1000); // 30 minutes of inactivity
|
| 411 |
-
}
|
| 412 |
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
window.
|
| 417 |
-
}
|
| 418 |
</script>
|
| 419 |
</body>
|
| 420 |
</html>
|
|
|
|
| 53 |
<i class="fas fa-cog text-2xl mb-2"></i>
|
| 54 |
<span>Settings</span>
|
| 55 |
</a>
|
| 56 |
+
</div>
|
| 57 |
</div>
|
| 58 |
|
| 59 |
<!-- System Overview -->
|
|
|
|
| 79 |
</div>
|
| 80 |
</div>
|
| 81 |
</div>
|
| 82 |
+
|
| 83 |
<!-- Attendance Data Tables -->
|
| 84 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
|
| 85 |
+
<!-- Form A Data -->
|
| 86 |
+
<div class="bg-white rounded-lg shadow-md p-6">
|
| 87 |
+
<div class="flex justify-between items-center mb-4">
|
| 88 |
+
<h2 class="text-xl font-semibold text-gray-800">Students Who Want To Eat (Form A)</h2>
|
| 89 |
+
<button id="refresh-formA" class="text-blue-600 hover:text-blue-800">
|
| 90 |
+
<i class="fas fa-sync-alt mr-1"></i> Refresh
|
| 91 |
+
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
</div>
|
| 93 |
+
<div class="overflow-x-auto max-h-96 overflow-y-auto">
|
| 94 |
+
<table class="min-w-full divide-y divide-gray-200">
|
| 95 |
+
<thead class="bg-gray-50 sticky top-0">
|
| 96 |
+
<tr>
|
| 97 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Student</th>
|
| 98 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Class</th>
|
| 99 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Form</th>
|
| 100 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Attendance</th>
|
| 101 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Meal</th>
|
| 102 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Time</th>
|
| 103 |
+
</tr>
|
| 104 |
+
</thead>
|
| 105 |
+
<tbody class="bg-white divide-y divide-gray-200" id="formAData">
|
| 106 |
+
<tr>
|
| 107 |
+
<td colspan="6" class="px-4 py-4 text-center text-gray-500">Loading data...</td>
|
| 108 |
+
</tr>
|
| 109 |
+
</tbody>
|
| 110 |
+
</table>
|
| 111 |
+
</div>
|
| 112 |
+
<div class="mt-4 text-sm text-gray-500">
|
| 113 |
+
<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">
|
| 114 |
+
View full data on GitHub
|
| 115 |
+
</a>
|
| 116 |
+
</div>
|
| 117 |
+
</div>
|
| 118 |
|
| 119 |
+
<!-- Form B Data -->
|
| 120 |
+
<div class="bg-white rounded-lg shadow-md p-6">
|
| 121 |
+
<div class="flex justify-between items-center mb-4">
|
| 122 |
+
<h2 class="text-xl font-semibold text-gray-800">Students Who Have Eaten (Form B)</h2>
|
| 123 |
+
<button id="refresh-formB" class="text-blue-600 hover:text-blue-800">
|
| 124 |
+
<i class="fas fa-sync-alt mr-1"></i> Refresh
|
| 125 |
+
</button>
|
| 126 |
+
</div>
|
| 127 |
+
<div class="overflow-x-auto max-h-96 overflow-y-auto">
|
| 128 |
+
<table class="min-w-full divide-y divide-gray-200">
|
| 129 |
+
<thead class="bg-gray-50 sticky top-0">
|
| 130 |
+
<tr>
|
| 131 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Student</th>
|
| 132 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Class</th>
|
| 133 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Form</th>
|
| 134 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Meal</th>
|
| 135 |
+
<th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Time</th>
|
| 136 |
+
</tr>
|
| 137 |
+
</thead>
|
| 138 |
+
<tbody class="bg-white divide-y divide-gray-200" id="formBData">
|
| 139 |
+
<tr>
|
| 140 |
+
<td colspan="5" class="px-4 py-4 text-center text-gray-500">Loading data...</td>
|
| 141 |
+
</tr>
|
| 142 |
+
</tbody>
|
| 143 |
+
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
</div>
|
| 145 |
+
<div class="mt-4 text-sm text-gray-500">
|
| 146 |
+
<a href="https://github.com/WaffleExecutors/Waste-LessV5/blob/main/data%20who%20has%20ate%20at%20dm" target="_blank" class="text-blue-600 hover:underline">
|
| 147 |
+
View full data on GitHub
|
| 148 |
+
</a>
|
| 149 |
+
</div>
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
|
| 153 |
+
<!-- Charts -->
|
| 154 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
|
|
|
|
| 155 |
<div class="bg-white rounded-lg shadow-md p-6">
|
| 156 |
<h2 class="text-xl font-semibold mb-4 text-gray-800">Attendance Trend</h2>
|
| 157 |
<canvas id="attendanceChart" height="250"></canvas>
|
| 158 |
</div>
|
|
|
|
|
|
|
| 159 |
<div class="bg-white rounded-lg shadow-md p-6">
|
| 160 |
<h2 class="text-xl font-semibold mb-4 text-gray-800">Food Waste Breakdown</h2>
|
| 161 |
<canvas id="wasteChart" height="250"></canvas>
|
| 162 |
</div>
|
| 163 |
</div>
|
| 164 |
</div>
|
| 165 |
+
|
| 166 |
<script>
|
| 167 |
+
// Your GitHub token (filled in)
|
| 168 |
+
const GITHUB_TOKEN = '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';
|
| 169 |
+
|
| 170 |
+
// Login check
|
| 171 |
+
if (localStorage.getItem('isAdminLoggedIn') !== 'true') {
|
| 172 |
+
alert('Please login first');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
window.location.href = 'admin-login.html';
|
| 174 |
return;
|
| 175 |
}
|
| 176 |
|
| 177 |
+
// Fetch data
|
|
|
|
|
|
|
| 178 |
async function fetchAttendanceData() {
|
| 179 |
try {
|
| 180 |
+
document.getElementById('formAData').innerHTML = '<tr><td colspan="6" class="text-center py-4"><i class="fas fa-spinner fa-spin"></i> Loading...</td></tr>';
|
| 181 |
+
document.getElementById('formBData').innerHTML = '<tr><td colspan="5" class="text-center py-4"><i class="fas fa-spinner fa-spin"></i> Loading...</td></tr>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
+
// Form A
|
| 184 |
+
const aResp = await fetch('https://api.github.com/repos/SMSS-Waste-Less/Waste-LessV5/contents/Data%20Students%20who%20want%20to%20eat', {
|
| 185 |
+
headers: { 'Authorization': `token ${GITHUB_TOKEN}`, 'Accept': 'application/vnd.github.v3+json' }
|
|
|
|
|
|
|
|
|
|
| 186 |
});
|
| 187 |
+
let aRows = '<tr><td colspan="6" class="text-center py-4 text-gray-500">No data</td></tr>';
|
| 188 |
+
if (aResp.ok) {
|
| 189 |
+
const aFile = await aResp.json();
|
| 190 |
+
const aContent = atob(aFile.content);
|
| 191 |
+
aRows = aContent.split('\n').filter(l => l.trim()).reverse().map(l => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
try {
|
| 193 |
+
const r = JSON.parse(l);
|
| 194 |
+
const t = new Date(r.timestamp).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
|
| 195 |
+
const att = r.attendance === 'yes' ? 'Will Eat' : 'Will Not Eat';
|
| 196 |
+
return `<tr class="hover:bg-gray-50">
|
| 197 |
+
<td class="px-4 py-2 text-sm">${r.studentName}</td>
|
| 198 |
+
<td class="px-4 py-2 text-sm">${r.class}</td>
|
| 199 |
+
<td class="px-4 py-2 text-sm">${r.form}</td>
|
| 200 |
+
<td class="px-4 py-2 text-sm">${att}</td>
|
| 201 |
+
<td class="px-4 py-2 text-sm">${r.mealTime || '-'}</td>
|
| 202 |
+
<td class="px-4 py-2 text-sm text-gray-500">${t}</td>
|
| 203 |
+
</tr>`;
|
| 204 |
+
} catch { return ''; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
}).join('');
|
| 206 |
+
}
|
| 207 |
+
document.getElementById('formAData').innerHTML = aRows;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
+
// Form B
|
| 210 |
+
const bResp = await fetch('https://api.github.com/repos/WaffleExecutors/Waste-LessV5/contents/data%20who%20has%20ate%20at%20dm', {
|
| 211 |
+
headers: { 'Authorization': `token ${GITHUB_TOKEN}`, 'Accept': 'application/vnd.github.v3+json' }
|
|
|
|
|
|
|
|
|
|
| 212 |
});
|
| 213 |
+
let bRows = '<tr><td colspan="5" class="text-center py-4 text-gray-500">No data</td></tr>';
|
| 214 |
+
if (bResp.ok) {
|
| 215 |
+
const bFile = await bResp.json();
|
| 216 |
+
const bContent = atob(bFile.content);
|
| 217 |
+
bRows = bContent.split('\n').filter(l => l.trim()).reverse().map(l => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
try {
|
| 219 |
+
const r = JSON.parse(l);
|
| 220 |
+
const t = new Date(r.timestamp).toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
|
| 221 |
+
return `<tr class="hover:bg-gray-50">
|
| 222 |
+
<td class="px-4 py-2 text-sm">${r.studentName}</td>
|
| 223 |
+
<td class="px-4 py-2 text-sm">${r.class}</td>
|
| 224 |
+
<td class="px-4 py-2 text-sm">${r.form}</td>
|
| 225 |
+
<td class="px-4 py-2 text-sm">${r.mealTime || '-'}</td>
|
| 226 |
+
<td class="px-4 py-2 text-sm text-gray-500">${t}</td>
|
| 227 |
+
</tr>`;
|
| 228 |
+
} catch { return ''; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
}).join('');
|
| 230 |
+
}
|
| 231 |
+
document.getElementById('formBData').innerHTML = bRows;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
+
} catch (err) {
|
| 234 |
+
console.error(err);
|
| 235 |
+
alert('Failed to load data. Check token or connection.');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
}
|
| 237 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
+
// Load on start
|
| 240 |
+
fetchAttendanceData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
+
// Refresh buttons
|
| 243 |
+
document.getElementById('refresh-formA').onclick = fetchAttendanceData;
|
| 244 |
+
document.getElementById('refresh-formB').onclick = fetchAttendanceData;
|
| 245 |
+
|
| 246 |
+
// Charts (placeholder)
|
| 247 |
+
new Chart(document.getElementById('attendanceChart'), { type: 'line', data: { labels: ['Mon','Tue','Wed','Thu','Fri'], datasets: [{ label: 'Attendance', data: [70,75,80,78,85], borderColor: '#3b82f6' }] } });
|
| 248 |
+
new Chart(document.getElementById('wasteChart'), { type: 'bar', data: { labels: ['Breakfast','Lunch','Dinner','Supper'], datasets: [{ label: 'Waste kg', data: [5,12,8,3], backgroundColor: '#f59e0b' }] } });
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
+
// Logout
|
| 251 |
+
document.getElementById('logout-btn').onclick = () => {
|
| 252 |
+
localStorage.clear();
|
| 253 |
+
window.location.href = 'admin-login.html';
|
| 254 |
+
};
|
| 255 |
</script>
|
| 256 |
</body>
|
| 257 |
</html>
|