Spaces:
Running
Running
Promote version 323005e to main
Browse filesPromoted commit 323005efe4ba56500274bc64022c087afc2563fa to main branch
- attendance.html +37 -68
- student-management.html +338 -233
- students-ate.html +97 -106
attendance.html
CHANGED
|
@@ -108,9 +108,15 @@
|
|
| 108 |
|
| 109 |
<div id="eating-details" class="space-y-4">
|
| 110 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
<div>
|
| 112 |
<label for="form" class="block text-gray-700 font-medium mb-2">Form</label>
|
| 113 |
-
<select id="form" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" onchange="
|
| 114 |
<option value="">Select Form</option>
|
| 115 |
<option value="1">Form 1</option>
|
| 116 |
<option value="2">Form 2</option>
|
|
@@ -119,18 +125,11 @@
|
|
| 119 |
<option value="5">Form 5</option>
|
| 120 |
</select>
|
| 121 |
</div>
|
| 122 |
-
<div>
|
| 123 |
-
<label for="class" class="block text-gray-700 font-medium mb-2">Class</label>
|
| 124 |
-
<select id="class" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" onchange="loadStudents()" disabled>
|
| 125 |
-
<option value="">Select Form First</option>
|
| 126 |
-
</select>
|
| 127 |
-
</div>
|
| 128 |
</div>
|
| 129 |
-
|
| 130 |
<div id="student-container" class="mt-4 hidden">
|
| 131 |
<label for="student" class="block text-gray-700 font-medium mb-2">Student Name</label>
|
| 132 |
<select id="student" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" disabled>
|
| 133 |
-
<option value="">
|
| 134 |
</select>
|
| 135 |
</div>
|
| 136 |
</div>
|
|
@@ -167,6 +166,7 @@
|
|
| 167 |
<script>
|
| 168 |
// Dynamic student list
|
| 169 |
let students = {};
|
|
|
|
| 170 |
|
| 171 |
async function loadStudentList() {
|
| 172 |
try {
|
|
@@ -176,64 +176,41 @@
|
|
| 176 |
'Accept': 'application/vnd.github.v3+json'
|
| 177 |
}
|
| 178 |
});
|
| 179 |
-
|
| 180 |
if (response.status === 404) {
|
| 181 |
students = {};
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
} else {
|
| 186 |
-
throw new Error('Failed to load student list');
|
| 187 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
} catch (error) {
|
| 189 |
console.error('Error loading student list:', error);
|
| 190 |
alert('Could not load student list. Using empty list.');
|
| 191 |
students = {};
|
|
|
|
|
|
|
| 192 |
}
|
| 193 |
-
|
| 194 |
-
// Reset class dropdown until form is selected
|
| 195 |
-
document.getElementById('class').disabled = true;
|
| 196 |
-
document.getElementById('class').innerHTML = '<option value="">Select Form First</option>';
|
| 197 |
}
|
| 198 |
|
| 199 |
-
|
| 200 |
-
function updateClassesForForm() {
|
| 201 |
-
const formVal = document.getElementById('form').value;
|
| 202 |
const classSelect = document.getElementById('class');
|
| 203 |
-
|
| 204 |
classSelect.innerHTML = '<option value="">Select Class</option>';
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
}
|
| 212 |
-
|
| 213 |
-
const classesForForm = new Set();
|
| 214 |
-
for (const key in students) {
|
| 215 |
-
const [cls, form] = key.split('-');
|
| 216 |
-
if (form === formVal) {
|
| 217 |
-
classesForForm.add(cls);
|
| 218 |
-
}
|
| 219 |
-
}
|
| 220 |
-
|
| 221 |
-
if (classesForForm.size === 0) {
|
| 222 |
-
classSelect.innerHTML = '<option value="">No classes in this form</option>';
|
| 223 |
-
} else {
|
| 224 |
-
classesForForm.forEach(cls => {
|
| 225 |
-
const opt = document.createElement('option');
|
| 226 |
-
opt.value = cls;
|
| 227 |
-
opt.textContent = cls;
|
| 228 |
-
classSelect.appendChild(opt);
|
| 229 |
-
});
|
| 230 |
-
classSelect.disabled = false;
|
| 231 |
-
}
|
| 232 |
-
|
| 233 |
-
clearStudents();
|
| 234 |
-
loadStudents();
|
| 235 |
}
|
| 236 |
|
|
|
|
| 237 |
function loadStudents() {
|
| 238 |
const classVal = document.getElementById('class').value;
|
| 239 |
const formVal = document.getElementById('form').value;
|
|
@@ -261,22 +238,15 @@
|
|
| 261 |
}
|
| 262 |
}
|
| 263 |
|
| 264 |
-
|
| 265 |
-
const studentSelect = document.getElementById('student');
|
| 266 |
-
const studentContainer = document.getElementById('student-container');
|
| 267 |
-
studentSelect.innerHTML = '<option value="">Select Student</option>';
|
| 268 |
-
studentSelect.disabled = true;
|
| 269 |
-
studentContainer.classList.add('hidden');
|
| 270 |
-
}
|
| 271 |
-
|
| 272 |
-
// Re-check student list when Yes/No changes
|
| 273 |
document.querySelectorAll('input[name="attendance"]').forEach(radio => {
|
| 274 |
radio.addEventListener('change', loadStudents);
|
| 275 |
});
|
| 276 |
|
|
|
|
| 277 |
window.addEventListener('load', loadStudentList);
|
| 278 |
|
| 279 |
-
// ===
|
| 280 |
function updateDateTime() {
|
| 281 |
const now = new Date();
|
| 282 |
document.getElementById('current-time').textContent = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
@@ -418,9 +388,9 @@
|
|
| 418 |
this.innerHTML = '<i class="fas fa-paper-plane mr-2"></i> Submit Attendance';
|
| 419 |
}
|
| 420 |
});
|
| 421 |
-
|
| 422 |
async function sendDataToGitHub(data) {
|
| 423 |
try {
|
|
|
|
| 424 |
let currentContent = '';
|
| 425 |
let sha = '';
|
| 426 |
const filePath = 'Data%20Students%20who%20want%20to%20eat';
|
|
@@ -441,9 +411,11 @@
|
|
| 441 |
throw new Error('Failed to fetch existing data');
|
| 442 |
}
|
| 443 |
|
|
|
|
| 444 |
const record = JSON.stringify(data);
|
| 445 |
const newContent = currentContent + record + '\n';
|
| 446 |
|
|
|
|
| 447 |
const response = await fetch(repoUrl, {
|
| 448 |
method: 'PUT',
|
| 449 |
headers: {
|
|
@@ -469,12 +441,9 @@
|
|
| 469 |
throw new Error('Failed to submit attendance: ' + error.message);
|
| 470 |
}
|
| 471 |
}
|
| 472 |
-
|
| 473 |
-
function resetForm() {
|
| 474 |
document.getElementById('class').value = '';
|
| 475 |
document.getElementById('form').value = '';
|
| 476 |
-
document.getElementById('class').disabled = true;
|
| 477 |
-
document.getElementById('class').innerHTML = '<option value="">Select Form First</option>';
|
| 478 |
document.getElementById('student').innerHTML = '<option value="">Select Student</option>';
|
| 479 |
document.getElementById('student').disabled = true;
|
| 480 |
document.getElementById('student-container').classList.add('hidden');
|
|
|
|
| 108 |
|
| 109 |
<div id="eating-details" class="space-y-4">
|
| 110 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 111 |
+
<div>
|
| 112 |
+
<label for="class" class="block text-gray-700 font-medium mb-2">Class</label>
|
| 113 |
+
<select id="class" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" onchange="loadStudents()">
|
| 114 |
+
<option value="">Select Class</option>
|
| 115 |
+
</select>
|
| 116 |
+
</div>
|
| 117 |
<div>
|
| 118 |
<label for="form" class="block text-gray-700 font-medium mb-2">Form</label>
|
| 119 |
+
<select id="form" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" onchange="loadStudents()">
|
| 120 |
<option value="">Select Form</option>
|
| 121 |
<option value="1">Form 1</option>
|
| 122 |
<option value="2">Form 2</option>
|
|
|
|
| 125 |
<option value="5">Form 5</option>
|
| 126 |
</select>
|
| 127 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
</div>
|
|
|
|
| 129 |
<div id="student-container" class="mt-4 hidden">
|
| 130 |
<label for="student" class="block text-gray-700 font-medium mb-2">Student Name</label>
|
| 131 |
<select id="student" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" disabled>
|
| 132 |
+
<option value="">Please select Class and Form first</option>
|
| 133 |
</select>
|
| 134 |
</div>
|
| 135 |
</div>
|
|
|
|
| 166 |
<script>
|
| 167 |
// Dynamic student list
|
| 168 |
let students = {};
|
| 169 |
+
let availableClasses = [];
|
| 170 |
|
| 171 |
async function loadStudentList() {
|
| 172 |
try {
|
|
|
|
| 176 |
'Accept': 'application/vnd.github.v3+json'
|
| 177 |
}
|
| 178 |
});
|
|
|
|
| 179 |
if (response.status === 404) {
|
| 180 |
students = {};
|
| 181 |
+
availableClasses = [];
|
| 182 |
+
updateClassDropdown();
|
| 183 |
+
return;
|
|
|
|
|
|
|
| 184 |
}
|
| 185 |
+
if (!response.ok) throw new Error('Failed to load student list');
|
| 186 |
+
const data = await response.json();
|
| 187 |
+
students = JSON.parse(atob(data.content));
|
| 188 |
+
|
| 189 |
+
// Extract unique classes
|
| 190 |
+
availableClasses = [...new Set(Object.keys(students).map(key => key.split('-')[0]))].sort();
|
| 191 |
+
updateClassDropdown();
|
| 192 |
} catch (error) {
|
| 193 |
console.error('Error loading student list:', error);
|
| 194 |
alert('Could not load student list. Using empty list.');
|
| 195 |
students = {};
|
| 196 |
+
availableClasses = [];
|
| 197 |
+
updateClassDropdown();
|
| 198 |
}
|
| 199 |
+
loadStudents(); // Initial load
|
|
|
|
|
|
|
|
|
|
| 200 |
}
|
| 201 |
|
| 202 |
+
function updateClassDropdown() {
|
|
|
|
|
|
|
| 203 |
const classSelect = document.getElementById('class');
|
|
|
|
| 204 |
classSelect.innerHTML = '<option value="">Select Class</option>';
|
| 205 |
+
availableClasses.forEach(cls => {
|
| 206 |
+
const opt = document.createElement('option');
|
| 207 |
+
opt.value = cls;
|
| 208 |
+
opt.textContent = cls;
|
| 209 |
+
classSelect.appendChild(opt);
|
| 210 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
}
|
| 212 |
|
| 213 |
+
// Load students based on selected class and form
|
| 214 |
function loadStudents() {
|
| 215 |
const classVal = document.getElementById('class').value;
|
| 216 |
const formVal = document.getElementById('form').value;
|
|
|
|
| 238 |
}
|
| 239 |
}
|
| 240 |
|
| 241 |
+
// Always show student dropdown when class/form selected
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
document.querySelectorAll('input[name="attendance"]').forEach(radio => {
|
| 243 |
radio.addEventListener('change', loadStudents);
|
| 244 |
});
|
| 245 |
|
| 246 |
+
// Load student list on page load
|
| 247 |
window.addEventListener('load', loadStudentList);
|
| 248 |
|
| 249 |
+
// === Rest of your existing code (time, meal menu, submission, etc.) unchanged ===
|
| 250 |
function updateDateTime() {
|
| 251 |
const now = new Date();
|
| 252 |
document.getElementById('current-time').textContent = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
|
|
| 388 |
this.innerHTML = '<i class="fas fa-paper-plane mr-2"></i> Submit Attendance';
|
| 389 |
}
|
| 390 |
});
|
|
|
|
| 391 |
async function sendDataToGitHub(data) {
|
| 392 |
try {
|
| 393 |
+
// First check if file exists and get current content
|
| 394 |
let currentContent = '';
|
| 395 |
let sha = '';
|
| 396 |
const filePath = 'Data%20Students%20who%20want%20to%20eat';
|
|
|
|
| 411 |
throw new Error('Failed to fetch existing data');
|
| 412 |
}
|
| 413 |
|
| 414 |
+
// Prepare new content
|
| 415 |
const record = JSON.stringify(data);
|
| 416 |
const newContent = currentContent + record + '\n';
|
| 417 |
|
| 418 |
+
// Create or update file
|
| 419 |
const response = await fetch(repoUrl, {
|
| 420 |
method: 'PUT',
|
| 421 |
headers: {
|
|
|
|
| 441 |
throw new Error('Failed to submit attendance: ' + error.message);
|
| 442 |
}
|
| 443 |
}
|
| 444 |
+
function resetForm() {
|
|
|
|
| 445 |
document.getElementById('class').value = '';
|
| 446 |
document.getElementById('form').value = '';
|
|
|
|
|
|
|
| 447 |
document.getElementById('student').innerHTML = '<option value="">Select Student</option>';
|
| 448 |
document.getElementById('student').disabled = true;
|
| 449 |
document.getElementById('student-container').classList.add('hidden');
|
student-management.html
CHANGED
|
@@ -10,7 +10,7 @@
|
|
| 10 |
</head>
|
| 11 |
<body class="bg-gray-100 min-h-screen">
|
| 12 |
<div class="container mx-auto px-4 py-8 max-w-4xl">
|
| 13 |
-
<!-- Header -->
|
| 14 |
<header class="bg-blue-600 text-white rounded-lg shadow-lg p-6 mb-8">
|
| 15 |
<div class="flex items-center">
|
| 16 |
<a href="admin-dashboard.html" class="text-blue-100 hover:text-white mr-4 text-xl"><i class="fas fa-arrow-left"></i></a>
|
|
@@ -20,8 +20,7 @@
|
|
| 20 |
</div>
|
| 21 |
</div>
|
| 22 |
</header>
|
| 23 |
-
|
| 24 |
-
<!-- Tabs -->
|
| 25 |
<div class="bg-white rounded-lg shadow-md p-6 mb-8">
|
| 26 |
<div class="flex border-b border-gray-200 mb-6 overflow-x-auto">
|
| 27 |
<button id="add-tab" class="px-4 py-2 font-medium text-blue-600 border-b-2 border-blue-600 whitespace-nowrap">
|
|
@@ -37,14 +36,14 @@
|
|
| 37 |
<i class="fas fa-file-import mr-2"></i> Import/Export
|
| 38 |
</button>
|
| 39 |
</div>
|
| 40 |
-
|
| 41 |
-
<!-- Add Student -->
|
| 42 |
<div id="add-form" class="space-y-4">
|
| 43 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 44 |
<div>
|
| 45 |
<label for="add-class" class="block text-gray-700 font-medium mb-2">Class</label>
|
| 46 |
<select id="add-class" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
|
| 47 |
<option value="">Select Class</option>
|
|
|
|
| 48 |
</select>
|
| 49 |
</div>
|
| 50 |
<div>
|
|
@@ -68,18 +67,21 @@
|
|
| 68 |
<div id="add-success" class="hidden bg-green-50 border border-green-200 text-green-700 p-4 rounded-lg">
|
| 69 |
<div class="flex items-center">
|
| 70 |
<i class="fas fa-check-circle text-green-500 text-xl mr-3"></i>
|
| 71 |
-
<div>
|
|
|
|
|
|
|
|
|
|
| 72 |
</div>
|
| 73 |
</div>
|
| 74 |
</div>
|
| 75 |
-
|
| 76 |
-
<!-- Remove Student -->
|
| 77 |
<div id="remove-form" class="space-y-4 hidden">
|
| 78 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 79 |
<div>
|
| 80 |
<label for="remove-class" class="block text-gray-700 font-medium mb-2">Class</label>
|
| 81 |
<select id="remove-class" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
|
| 82 |
<option value="">Select Class</option>
|
|
|
|
| 83 |
</select>
|
| 84 |
</div>
|
| 85 |
<div>
|
|
@@ -106,23 +108,24 @@
|
|
| 106 |
<div id="remove-success" class="hidden bg-green-50 border border-green-200 text-green-700 p-4 rounded-lg">
|
| 107 |
<div class="flex items-center">
|
| 108 |
<i class="fas fa-check-circle text-green-500 text-xl mr-3"></i>
|
| 109 |
-
<div>
|
|
|
|
|
|
|
|
|
|
| 110 |
</div>
|
| 111 |
</div>
|
| 112 |
</div>
|
| 113 |
-
|
| 114 |
-
<!-- Manage Classes -->
|
| 115 |
<div id="class-form" class="space-y-6 hidden">
|
| 116 |
<div class="bg-blue-50 border border-blue-200 text-blue-700 p-4 rounded-lg">
|
| 117 |
<div class="flex items-center">
|
| 118 |
<i class="fas fa-info-circle text-blue-500 text-xl mr-3"></i>
|
| 119 |
<div>
|
| 120 |
<h3 class="font-bold">Manage Classes</h3>
|
| 121 |
-
<p class="text-sm">Add or remove classes.
|
| 122 |
</div>
|
| 123 |
</div>
|
| 124 |
</div>
|
| 125 |
-
|
| 126 |
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 127 |
<div>
|
| 128 |
<label for="class-action" class="block text-gray-700 font-medium mb-2">Action</label>
|
|
@@ -150,24 +153,20 @@
|
|
| 150 |
</select>
|
| 151 |
</div>
|
| 152 |
</div>
|
| 153 |
-
|
| 154 |
<div id="add-class-container" class="hidden">
|
| 155 |
<label for="new-class-name" class="block text-gray-700 font-medium mb-2">New Class Name</label>
|
| 156 |
<input type="text" id="new-class-name" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="e.g. CERIA">
|
| 157 |
</div>
|
| 158 |
-
|
| 159 |
<div id="remove-class-container" class="hidden">
|
| 160 |
<label for="remove-class-name" class="block text-gray-700 font-medium mb-2">Class to Remove</label>
|
| 161 |
<select id="remove-class-name" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
|
| 162 |
<option value="">Select Class</option>
|
| 163 |
</select>
|
| 164 |
-
<p class="text-sm text-red-600 mt-2">Warning: This will permanently delete the class and all its students.</p>
|
| 165 |
</div>
|
| 166 |
-
|
| 167 |
<button id="apply-class-btn" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-4 rounded-lg transition duration-200">
|
| 168 |
<i class="fas fa-save mr-2"></i> Apply Changes
|
| 169 |
</button>
|
| 170 |
-
|
| 171 |
<div id="class-success" class="hidden bg-green-50 border border-green-200 text-green-700 p-4 rounded-lg">
|
| 172 |
<div class="flex items-center">
|
| 173 |
<i class="fas fa-check-circle text-green-500 text-xl mr-3"></i>
|
|
@@ -178,40 +177,54 @@
|
|
| 178 |
</div>
|
| 179 |
</div>
|
| 180 |
</div>
|
| 181 |
-
|
| 182 |
-
<!-- Import/Export -->
|
| 183 |
<div id="import-export-form" class="space-y-4 hidden">
|
| 184 |
<div class="bg-blue-50 border border-blue-200 text-blue-700 p-4 rounded-lg mb-4">
|
| 185 |
<div class="flex items-center">
|
| 186 |
<i class="fas fa-info-circle text-blue-500 text-xl mr-3"></i>
|
| 187 |
<div>
|
| 188 |
<h3 class="font-bold">Bulk Import/Export</h3>
|
| 189 |
-
<p class="text-sm">Import from CSV or export current data.</p>
|
| 190 |
</div>
|
| 191 |
</div>
|
| 192 |
</div>
|
| 193 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
|
|
| 194 |
<div class="bg-white border border-gray-200 rounded-lg p-4">
|
| 195 |
<h3 class="text-lg font-medium mb-4 text-gray-800">Export Data</h3>
|
| 196 |
-
<p class="text-gray-600 mb-4">Download latest student list in CSV format.</p>
|
| 197 |
<button id="export-btn" class="w-full bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded-lg transition duration-200">
|
| 198 |
<i class="fas fa-file-export mr-2"></i> Export to CSV
|
| 199 |
</button>
|
| 200 |
-
<
|
| 201 |
-
<
|
| 202 |
-
|
|
|
|
|
|
|
| 203 |
<div id="export-success" class="hidden bg-green-50 border border-green-200 text-green-700 p-4 rounded-lg mt-4">
|
| 204 |
-
<div class="flex items-center
|
| 205 |
-
<div
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
</div>
|
| 207 |
-
<a id="download-link" class="mt-3 block w-full text-center bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded-lg">
|
| 208 |
<i class="fas fa-download mr-2"></i> Download CSV File
|
| 209 |
</a>
|
| 210 |
</div>
|
| 211 |
</div>
|
|
|
|
| 212 |
<div class="bg-white border border-gray-200 rounded-lg p-4">
|
| 213 |
<h3 class="text-lg font-medium mb-4 text-gray-800">Import Data</h3>
|
| 214 |
-
<p class="text-gray-600 mb-2">CSV
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
<div class="border-2 border-dashed border-gray-300 rounded-lg p-4 text-center mb-3">
|
| 216 |
<input type="file" id="csv-file" accept=".csv" class="hidden">
|
| 217 |
<label for="csv-file" class="cursor-pointer">
|
|
@@ -224,7 +237,7 @@
|
|
| 224 |
<i class="fas fa-file-import mr-2"></i> Import CSV
|
| 225 |
</button>
|
| 226 |
<div id="import-success" class="hidden bg-green-50 border border-green-200 text-green-700 p-3 rounded-lg mt-3">
|
| 227 |
-
Import completed! <span id="import-stats" class="font-bold"></span>
|
| 228 |
</div>
|
| 229 |
<div id="import-error" class="hidden bg-red-50 border border-red-200 text-red-700 p-3 rounded-lg mt-3">
|
| 230 |
<span id="error-message"></span>
|
|
@@ -234,220 +247,310 @@
|
|
| 234 |
</div>
|
| 235 |
</div>
|
| 236 |
</div>
|
| 237 |
-
|
| 238 |
<script>
|
|
|
|
| 239 |
const GITHUB_TOKEN = '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';
|
| 240 |
const REPO = 'SMSS-Waste-Less/Waste-LessV5';
|
| 241 |
const FILE_PATH = 'student-list.json';
|
| 242 |
-
const CSV_TEMPLATE = `class,form,studentName
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
let students = {};
|
| 245 |
let availableClasses = [];
|
| 246 |
-
let currentCsvBlobUrl = null;
|
| 247 |
-
|
| 248 |
async function loadStudentList() {
|
| 249 |
try {
|
| 250 |
const response = await fetch(`https://api.github.com/repos/${REPO}/contents/${FILE_PATH}`, {
|
| 251 |
-
headers: {
|
|
|
|
|
|
|
|
|
|
| 252 |
});
|
| 253 |
if (response.status === 404) {
|
| 254 |
-
students = {};
|
|
|
|
| 255 |
} else if (response.ok) {
|
| 256 |
const data = await response.json();
|
| 257 |
students = JSON.parse(atob(data.content));
|
| 258 |
-
availableClasses = [...new Set(Object.keys(students).map(
|
| 259 |
} else {
|
| 260 |
-
throw new Error('
|
| 261 |
}
|
| 262 |
-
} catch (
|
| 263 |
-
console.error(
|
| 264 |
-
alert('
|
| 265 |
-
students = {};
|
|
|
|
| 266 |
}
|
| 267 |
updateClassDropdowns();
|
| 268 |
loadStudentsForRemoval();
|
| 269 |
}
|
| 270 |
-
|
| 271 |
function updateClassDropdowns() {
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
}
|
| 283 |
-
|
| 284 |
async function saveStudentListToGitHub() {
|
| 285 |
try {
|
| 286 |
let sha = null;
|
| 287 |
-
const
|
| 288 |
-
headers: {
|
|
|
|
|
|
|
|
|
|
| 289 |
});
|
| 290 |
-
if (
|
| 291 |
-
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
method: 'PUT',
|
| 294 |
headers: {
|
| 295 |
'Authorization': `token ${GITHUB_TOKEN}`,
|
| 296 |
-
'Content-Type': 'application/json'
|
|
|
|
| 297 |
},
|
| 298 |
body: JSON.stringify({
|
| 299 |
-
message: `
|
| 300 |
-
content:
|
| 301 |
-
sha,
|
| 302 |
branch: 'main'
|
| 303 |
})
|
| 304 |
});
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
const err = await putRes.json();
|
| 308 |
throw new Error(err.message || 'Save failed');
|
| 309 |
}
|
| 310 |
return true;
|
| 311 |
-
} catch (
|
| 312 |
-
|
|
|
|
| 313 |
return false;
|
| 314 |
}
|
| 315 |
}
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
await loadStudentList();
|
| 323 |
-
const csv = 'class,form,studentName\n' + Object.keys(students).map(key => {
|
| 324 |
-
const [cls, form] = key.split('-');
|
| 325 |
-
return students[key].map(s => `${cls},${form},"${s.replace(/"/g, '""')}"`).join('\n');
|
| 326 |
-
}).join('\n');
|
| 327 |
const filename = `student-list-${new Date().toISOString().split('T')[0]}.csv`;
|
| 328 |
-
|
| 329 |
-
|
|
|
|
|
|
|
|
|
|
| 330 |
currentCsvBlobUrl = URL.createObjectURL(blob);
|
| 331 |
-
document.getElementById('download-link')
|
| 332 |
-
|
|
|
|
| 333 |
document.getElementById('export-success').classList.remove('hidden');
|
| 334 |
-
|
| 335 |
-
|
| 336 |
});
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 340 |
const url = URL.createObjectURL(blob);
|
| 341 |
-
const
|
| 342 |
-
|
| 343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
});
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
if (lines.length < 1) throw new Error('Empty file');
|
| 350 |
const headers = lines[0].toLowerCase().split(',');
|
| 351 |
-
if (!headers.includes('class') || !headers.includes('form') || !headers.includes('studentname'))
|
| 352 |
-
throw new Error('Missing columns: class, form, studentName');
|
| 353 |
-
|
| 354 |
-
const
|
| 355 |
for (let i = 1; i < lines.length; i++) {
|
| 356 |
-
const
|
|
|
|
| 357 |
if (!match) continue;
|
| 358 |
-
let
|
| 359 |
let form = match[2].trim();
|
| 360 |
-
let
|
| 361 |
-
if (!
|
| 362 |
-
const key = `${
|
| 363 |
-
if (!
|
| 364 |
-
if (!
|
| 365 |
}
|
| 366 |
-
return
|
| 367 |
}
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
const file =
|
| 371 |
-
if (!file)
|
|
|
|
|
|
|
|
|
|
| 372 |
const reader = new FileReader();
|
| 373 |
-
reader.onload = async e
|
| 374 |
try {
|
| 375 |
-
|
|
|
|
| 376 |
const saved = await saveStudentListToGitHub();
|
| 377 |
if (saved) {
|
| 378 |
-
availableClasses = [...new Set(Object.keys(students).map(
|
| 379 |
updateClassDropdowns();
|
| 380 |
-
|
|
|
|
| 381 |
document.getElementById('import-stats').textContent = `${count} students imported`;
|
| 382 |
document.getElementById('import-success').classList.remove('hidden');
|
| 383 |
setTimeout(() => document.getElementById('import-success').classList.add('hidden'), 5000);
|
| 384 |
-
|
| 385 |
document.getElementById('file-name').textContent = 'No file selected';
|
| 386 |
}
|
| 387 |
-
} catch (
|
| 388 |
-
document.getElementById('error-message').textContent =
|
| 389 |
document.getElementById('import-error').classList.remove('hidden');
|
| 390 |
setTimeout(() => document.getElementById('import-error').classList.add('hidden'), 6000);
|
| 391 |
}
|
| 392 |
};
|
| 393 |
reader.readAsText(file);
|
| 394 |
});
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
document.getElementById('file-name').textContent =
|
| 398 |
});
|
| 399 |
-
|
| 400 |
// Tab switching
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
document.getElementById(
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
});
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 420 |
function loadStudentsForRemoval() {
|
| 421 |
-
const
|
| 422 |
-
const
|
| 423 |
-
const
|
| 424 |
-
const
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
if (
|
| 428 |
-
const key = `${
|
| 429 |
-
if (students[key]
|
| 430 |
-
students[key].forEach(
|
| 431 |
-
const
|
| 432 |
-
|
| 433 |
-
|
|
|
|
| 434 |
});
|
| 435 |
-
|
|
|
|
|
|
|
| 436 |
}
|
| 437 |
}
|
| 438 |
}
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
const
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
if (!students[key]) students[key] = [];
|
| 449 |
-
if (students[key].includes(
|
| 450 |
-
|
|
|
|
|
|
|
|
|
|
| 451 |
const saved = await saveStudentListToGitHub();
|
| 452 |
if (saved) {
|
| 453 |
document.getElementById('student-name').value = '';
|
|
@@ -457,17 +560,18 @@
|
|
| 457 |
updateClassDropdowns();
|
| 458 |
}
|
| 459 |
});
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
const
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
|
|
|
| 468 |
if (students[key]) {
|
| 469 |
-
students[key] = students[key].filter(s => s !==
|
| 470 |
-
if (
|
| 471 |
}
|
| 472 |
const saved = await saveStudentListToGitHub();
|
| 473 |
if (saved) {
|
|
@@ -478,92 +582,93 @@
|
|
| 478 |
updateClassDropdowns();
|
| 479 |
}
|
| 480 |
});
|
| 481 |
-
|
| 482 |
-
// Manage Classes
|
| 483 |
-
const allForms = ['1','2','3','4','5'];
|
| 484 |
-
|
| 485 |
-
function populateRemoveClassDropdown() {
|
| 486 |
-
const select = document.getElementById('remove-class-name');
|
| 487 |
-
const scope = document.getElementById('class-scope').value;
|
| 488 |
-
const form = scope === 'all' ? null : document.getElementById('class-form-select').value;
|
| 489 |
-
select.innerHTML = '<option value="">Select Class</option>';
|
| 490 |
-
const set = new Set();
|
| 491 |
-
for (const key in students) {
|
| 492 |
-
const [c, f] = key.split('-');
|
| 493 |
-
if (!form || f === form) set.add(c);
|
| 494 |
-
}
|
| 495 |
-
if (set.size === 0) {
|
| 496 |
-
select.innerHTML = '<option value="">No classes found</option>';
|
| 497 |
-
} else {
|
| 498 |
-
set.forEach(c => {
|
| 499 |
-
const opt = document.createElement('option');
|
| 500 |
-
opt.value = opt.textContent = c;
|
| 501 |
-
select.appendChild(opt);
|
| 502 |
-
});
|
| 503 |
-
}
|
| 504 |
-
}
|
| 505 |
-
|
| 506 |
function updateClassFormVisibility() {
|
| 507 |
const action = document.getElementById('class-action').value;
|
| 508 |
const scope = document.getElementById('class-scope').value;
|
| 509 |
-
document.getElementById('add-class-container').classList.
|
| 510 |
-
document.getElementById('remove-class-container').classList.
|
| 511 |
document.getElementById('specific-form-container').classList.toggle('hidden', scope === 'all');
|
| 512 |
-
if (action === '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 513 |
}
|
| 514 |
-
|
| 515 |
document.getElementById('class-action').addEventListener('change', updateClassFormVisibility);
|
| 516 |
document.getElementById('class-scope').addEventListener('change', updateClassFormVisibility);
|
| 517 |
document.getElementById('class-form-select').addEventListener('change', () => {
|
| 518 |
-
if (document.getElementById('class-action').value === 'remove'
|
|
|
|
|
|
|
| 519 |
});
|
| 520 |
-
|
| 521 |
document.getElementById('apply-class-btn').addEventListener('click', async () => {
|
| 522 |
const action = document.getElementById('class-action').value;
|
| 523 |
const scope = document.getElementById('class-scope').value;
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
if (scope === 'specific' && !targetForms[0]) return alert('Select a form');
|
| 527 |
-
|
| 528 |
let msg = '';
|
| 529 |
if (action === 'add') {
|
| 530 |
-
const
|
| 531 |
-
if (!
|
| 532 |
-
let
|
| 533 |
-
for (const
|
| 534 |
-
const key = `${
|
| 535 |
-
if (!students[key]) {
|
|
|
|
|
|
|
|
|
|
| 536 |
}
|
| 537 |
-
if (
|
| 538 |
-
msg = `Class ${
|
| 539 |
-
} else {
|
| 540 |
-
const
|
| 541 |
-
if (!
|
| 542 |
-
let
|
| 543 |
-
for (const
|
| 544 |
-
const key = `${
|
| 545 |
if (students[key]) {
|
| 546 |
-
if (students[key].length > 0 && !confirm(`Delete ${students[key].length} students in ${
|
| 547 |
delete students[key];
|
| 548 |
-
|
| 549 |
}
|
| 550 |
}
|
| 551 |
-
if (
|
| 552 |
-
msg = `Class ${
|
| 553 |
}
|
| 554 |
-
|
| 555 |
const saved = await saveStudentListToGitHub();
|
| 556 |
if (saved) {
|
| 557 |
document.getElementById('class-success-msg').textContent = msg;
|
| 558 |
document.getElementById('class-success').classList.remove('hidden');
|
| 559 |
setTimeout(() => document.getElementById('class-success').classList.add('hidden'), 5000);
|
|
|
|
| 560 |
availableClasses = [...new Set(Object.keys(students).map(k => k.split('-')[0]))].sort();
|
| 561 |
updateClassDropdowns();
|
| 562 |
-
updateClassFormVisibility();
|
| 563 |
}
|
| 564 |
});
|
| 565 |
-
|
| 566 |
-
window.addEventListener('load', loadStudentList);
|
| 567 |
</script>
|
| 568 |
</body>
|
| 569 |
</html>
|
|
|
|
| 10 |
</head>
|
| 11 |
<body class="bg-gray-100 min-h-screen">
|
| 12 |
<div class="container mx-auto px-4 py-8 max-w-4xl">
|
| 13 |
+
<!-- Header with back button -->
|
| 14 |
<header class="bg-blue-600 text-white rounded-lg shadow-lg p-6 mb-8">
|
| 15 |
<div class="flex items-center">
|
| 16 |
<a href="admin-dashboard.html" class="text-blue-100 hover:text-white mr-4 text-xl"><i class="fas fa-arrow-left"></i></a>
|
|
|
|
| 20 |
</div>
|
| 21 |
</div>
|
| 22 |
</header>
|
| 23 |
+
<!-- Management Tabs -->
|
|
|
|
| 24 |
<div class="bg-white rounded-lg shadow-md p-6 mb-8">
|
| 25 |
<div class="flex border-b border-gray-200 mb-6 overflow-x-auto">
|
| 26 |
<button id="add-tab" class="px-4 py-2 font-medium text-blue-600 border-b-2 border-blue-600 whitespace-nowrap">
|
|
|
|
| 36 |
<i class="fas fa-file-import mr-2"></i> Import/Export
|
| 37 |
</button>
|
| 38 |
</div>
|
| 39 |
+
<!-- Add Student Form -->
|
|
|
|
| 40 |
<div id="add-form" class="space-y-4">
|
| 41 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 42 |
<div>
|
| 43 |
<label for="add-class" class="block text-gray-700 font-medium mb-2">Class</label>
|
| 44 |
<select id="add-class" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
|
| 45 |
<option value="">Select Class</option>
|
| 46 |
+
<!-- Dynamically populated from GitHub -->
|
| 47 |
</select>
|
| 48 |
</div>
|
| 49 |
<div>
|
|
|
|
| 67 |
<div id="add-success" class="hidden bg-green-50 border border-green-200 text-green-700 p-4 rounded-lg">
|
| 68 |
<div class="flex items-center">
|
| 69 |
<i class="fas fa-check-circle text-green-500 text-xl mr-3"></i>
|
| 70 |
+
<div>
|
| 71 |
+
<h3 class="font-bold">Student Added Successfully!</h3>
|
| 72 |
+
<p class="text-sm">The student has been added to the system.</p>
|
| 73 |
+
</div>
|
| 74 |
</div>
|
| 75 |
</div>
|
| 76 |
</div>
|
| 77 |
+
<!-- Remove Student Form -->
|
|
|
|
| 78 |
<div id="remove-form" class="space-y-4 hidden">
|
| 79 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 80 |
<div>
|
| 81 |
<label for="remove-class" class="block text-gray-700 font-medium mb-2">Class</label>
|
| 82 |
<select id="remove-class" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
|
| 83 |
<option value="">Select Class</option>
|
| 84 |
+
<!-- Dynamically populated from GitHub -->
|
| 85 |
</select>
|
| 86 |
</div>
|
| 87 |
<div>
|
|
|
|
| 108 |
<div id="remove-success" class="hidden bg-green-50 border border-green-200 text-green-700 p-4 rounded-lg">
|
| 109 |
<div class="flex items-center">
|
| 110 |
<i class="fas fa-check-circle text-green-500 text-xl mr-3"></i>
|
| 111 |
+
<div>
|
| 112 |
+
<h3 class="font-bold">Student Removed Successfully!</h3>
|
| 113 |
+
<p class="text-sm">The student has been removed from the system.</p>
|
| 114 |
+
</div>
|
| 115 |
</div>
|
| 116 |
</div>
|
| 117 |
</div>
|
| 118 |
+
<!-- Manage Classes Form -->
|
|
|
|
| 119 |
<div id="class-form" class="space-y-6 hidden">
|
| 120 |
<div class="bg-blue-50 border border-blue-200 text-blue-700 p-4 rounded-lg">
|
| 121 |
<div class="flex items-center">
|
| 122 |
<i class="fas fa-info-circle text-blue-500 text-xl mr-3"></i>
|
| 123 |
<div>
|
| 124 |
<h3 class="font-bold">Manage Classes</h3>
|
| 125 |
+
<p class="text-sm">Add or remove classes. You can apply to a specific form or all forms at once.</p>
|
| 126 |
</div>
|
| 127 |
</div>
|
| 128 |
</div>
|
|
|
|
| 129 |
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
|
| 130 |
<div>
|
| 131 |
<label for="class-action" class="block text-gray-700 font-medium mb-2">Action</label>
|
|
|
|
| 153 |
</select>
|
| 154 |
</div>
|
| 155 |
</div>
|
|
|
|
| 156 |
<div id="add-class-container" class="hidden">
|
| 157 |
<label for="new-class-name" class="block text-gray-700 font-medium mb-2">New Class Name</label>
|
| 158 |
<input type="text" id="new-class-name" class="w-full px-4 py-2 border border-gray-300 rounded-lg" placeholder="e.g. CERIA">
|
| 159 |
</div>
|
|
|
|
| 160 |
<div id="remove-class-container" class="hidden">
|
| 161 |
<label for="remove-class-name" class="block text-gray-700 font-medium mb-2">Class to Remove</label>
|
| 162 |
<select id="remove-class-name" class="w-full px-4 py-2 border border-gray-300 rounded-lg">
|
| 163 |
<option value="">Select Class</option>
|
| 164 |
</select>
|
| 165 |
+
<p class="text-sm text-red-600 mt-2">Warning: This will permanently delete the class and all its students from the selected form(s).</p>
|
| 166 |
</div>
|
|
|
|
| 167 |
<button id="apply-class-btn" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-4 rounded-lg transition duration-200">
|
| 168 |
<i class="fas fa-save mr-2"></i> Apply Changes
|
| 169 |
</button>
|
|
|
|
| 170 |
<div id="class-success" class="hidden bg-green-50 border border-green-200 text-green-700 p-4 rounded-lg">
|
| 171 |
<div class="flex items-center">
|
| 172 |
<i class="fas fa-check-circle text-green-500 text-xl mr-3"></i>
|
|
|
|
| 177 |
</div>
|
| 178 |
</div>
|
| 179 |
</div>
|
| 180 |
+
<!-- Import/Export Form -->
|
|
|
|
| 181 |
<div id="import-export-form" class="space-y-4 hidden">
|
| 182 |
<div class="bg-blue-50 border border-blue-200 text-blue-700 p-4 rounded-lg mb-4">
|
| 183 |
<div class="flex items-center">
|
| 184 |
<i class="fas fa-info-circle text-blue-500 text-xl mr-3"></i>
|
| 185 |
<div>
|
| 186 |
<h3 class="font-bold">Bulk Import/Export</h3>
|
| 187 |
+
<p class="text-sm">Import student lists from CSV or export current data for other schools.</p>
|
| 188 |
</div>
|
| 189 |
</div>
|
| 190 |
</div>
|
| 191 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
| 192 |
+
<!-- Export Section -->
|
| 193 |
<div class="bg-white border border-gray-200 rounded-lg p-4">
|
| 194 |
<h3 class="text-lg font-medium mb-4 text-gray-800">Export Data</h3>
|
| 195 |
+
<p class="text-gray-600 mb-4">Download the latest student list from GitHub in CSV format.</p>
|
| 196 |
<button id="export-btn" class="w-full bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded-lg transition duration-200">
|
| 197 |
<i class="fas fa-file-export mr-2"></i> Export to CSV
|
| 198 |
</button>
|
| 199 |
+
<div class="mt-2 flex space-x-2">
|
| 200 |
+
<button id="export-sample-btn" class="w-full bg-blue-100 hover:bg-blue-200 text-blue-700 font-medium py-2 px-4 rounded-lg transition duration-200">
|
| 201 |
+
<i class="fas fa-file-download mr-2"></i> Sample CSV
|
| 202 |
+
</button>
|
| 203 |
+
</div>
|
| 204 |
<div id="export-success" class="hidden bg-green-50 border border-green-200 text-green-700 p-4 rounded-lg mt-4">
|
| 205 |
+
<div class="flex items-center justify-between">
|
| 206 |
+
<div class="flex items-center">
|
| 207 |
+
<i class="fas fa-check-circle text-green-500 text-xl mr-3"></i>
|
| 208 |
+
<div>
|
| 209 |
+
<h4 class="font-bold">Export completed successfully!</h4>
|
| 210 |
+
<p class="text-sm">Click the link below to download your file.</p>
|
| 211 |
+
</div>
|
| 212 |
+
</div>
|
| 213 |
</div>
|
| 214 |
+
<a id="download-link" class="mt-3 block w-full text-center bg-green-600 hover:bg-green-700 text-white font-bold py-2 px-4 rounded-lg transition duration-200">
|
| 215 |
<i class="fas fa-download mr-2"></i> Download CSV File
|
| 216 |
</a>
|
| 217 |
</div>
|
| 218 |
</div>
|
| 219 |
+
<!-- Import Section -->
|
| 220 |
<div class="bg-white border border-gray-200 rounded-lg p-4">
|
| 221 |
<h3 class="text-lg font-medium mb-4 text-gray-800">Import Data</h3>
|
| 222 |
+
<p class="text-gray-600 mb-2">Upload a CSV file to import student data. Format should be:</p>
|
| 223 |
+
<ul class="text-sm text-gray-600 mb-4 list-disc pl-5">
|
| 224 |
+
<li>Class,Form,StudentName</li>
|
| 225 |
+
<li>BUDI,1,John Doe</li>
|
| 226 |
+
<li>USAHA,2,Jane Smith</li>
|
| 227 |
+
</ul>
|
| 228 |
<div class="border-2 border-dashed border-gray-300 rounded-lg p-4 text-center mb-3">
|
| 229 |
<input type="file" id="csv-file" accept=".csv" class="hidden">
|
| 230 |
<label for="csv-file" class="cursor-pointer">
|
|
|
|
| 237 |
<i class="fas fa-file-import mr-2"></i> Import CSV
|
| 238 |
</button>
|
| 239 |
<div id="import-success" class="hidden bg-green-50 border border-green-200 text-green-700 p-3 rounded-lg mt-3">
|
| 240 |
+
Import completed successfully! <span id="import-stats" class="font-bold"></span>
|
| 241 |
</div>
|
| 242 |
<div id="import-error" class="hidden bg-red-50 border border-red-200 text-red-700 p-3 rounded-lg mt-3">
|
| 243 |
<span id="error-message"></span>
|
|
|
|
| 247 |
</div>
|
| 248 |
</div>
|
| 249 |
</div>
|
|
|
|
| 250 |
<script>
|
| 251 |
+
// Hardcoded configuration (no config.js needed)
|
| 252 |
const GITHUB_TOKEN = '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';
|
| 253 |
const REPO = 'SMSS-Waste-Less/Waste-LessV5';
|
| 254 |
const FILE_PATH = 'student-list.json';
|
| 255 |
+
const CSV_TEMPLATE = `class,form,studentName
|
| 256 |
+
BUDI,1,John Doe
|
| 257 |
+
BUDI,1,Jane Smith
|
| 258 |
+
USAHA,2,Michael Johnson
|
| 259 |
+
USAHA,2,Sarah Williams
|
| 260 |
+
MAJU,3,David Brown
|
| 261 |
+
MAJU,3,Emily Davis`;
|
| 262 |
let students = {};
|
| 263 |
let availableClasses = [];
|
| 264 |
+
let currentCsvBlobUrl = null; // To store the blob URL for download link
|
|
|
|
| 265 |
async function loadStudentList() {
|
| 266 |
try {
|
| 267 |
const response = await fetch(`https://api.github.com/repos/${REPO}/contents/${FILE_PATH}`, {
|
| 268 |
+
headers: {
|
| 269 |
+
'Authorization': `token ${GITHUB_TOKEN}`,
|
| 270 |
+
'Accept': 'application/vnd.github.v3+json'
|
| 271 |
+
}
|
| 272 |
});
|
| 273 |
if (response.status === 404) {
|
| 274 |
+
students = {};
|
| 275 |
+
availableClasses = [];
|
| 276 |
} else if (response.ok) {
|
| 277 |
const data = await response.json();
|
| 278 |
students = JSON.parse(atob(data.content));
|
| 279 |
+
availableClasses = [...new Set(Object.keys(students).map(key => key.split('-')[0]))].sort();
|
| 280 |
} else {
|
| 281 |
+
throw new Error('API error: ' + response.status);
|
| 282 |
}
|
| 283 |
+
} catch (error) {
|
| 284 |
+
console.error('Failed to load:', error);
|
| 285 |
+
alert('Could not load student list. Check internet or create student-list.json in repo.');
|
| 286 |
+
students = {};
|
| 287 |
+
availableClasses = [];
|
| 288 |
}
|
| 289 |
updateClassDropdowns();
|
| 290 |
loadStudentsForRemoval();
|
| 291 |
}
|
|
|
|
| 292 |
function updateClassDropdowns() {
|
| 293 |
+
const addSelect = document.getElementById('add-class');
|
| 294 |
+
const removeSelect = document.getElementById('remove-class');
|
| 295 |
+
addSelect.innerHTML = '<option value="">Select Class</option>';
|
| 296 |
+
removeSelect.innerHTML = '<option value="">Select Class</option>';
|
| 297 |
+
availableClasses.forEach(cls => {
|
| 298 |
+
const optAdd = document.createElement('option');
|
| 299 |
+
optAdd.value = cls;
|
| 300 |
+
optAdd.textContent = cls;
|
| 301 |
+
addSelect.appendChild(optAdd);
|
| 302 |
+
const optRemove = document.createElement('option');
|
| 303 |
+
optRemove.value = cls;
|
| 304 |
+
optRemove.textContent = cls;
|
| 305 |
+
removeSelect.appendChild(optRemove);
|
| 306 |
});
|
| 307 |
+
if (availableClasses.length === 0) {
|
| 308 |
+
addSelect.innerHTML += '<option disabled>No classes available yet</option>';
|
| 309 |
+
removeSelect.innerHTML += '<option disabled>No classes available yet</option>';
|
| 310 |
+
}
|
| 311 |
}
|
|
|
|
| 312 |
async function saveStudentListToGitHub() {
|
| 313 |
try {
|
| 314 |
let sha = null;
|
| 315 |
+
const getResponse = await fetch(`https://api.github.com/repos/${REPO}/contents/${FILE_PATH}`, {
|
| 316 |
+
headers: {
|
| 317 |
+
'Authorization': `token ${GITHUB_TOKEN}`,
|
| 318 |
+
'Accept': 'application/vnd.github.v3+json'
|
| 319 |
+
}
|
| 320 |
});
|
| 321 |
+
if (getResponse.ok) {
|
| 322 |
+
const fileData = await getResponse.json();
|
| 323 |
+
sha = fileData.sha;
|
| 324 |
+
}
|
| 325 |
+
const newContent = JSON.stringify(students, null, 2);
|
| 326 |
+
const base64Content = btoa(newContent);
|
| 327 |
+
const putResponse = await fetch(`https://api.github.com/repos/${REPO}/contents/${FILE_PATH}`, {
|
| 328 |
method: 'PUT',
|
| 329 |
headers: {
|
| 330 |
'Authorization': `token ${GITHUB_TOKEN}`,
|
| 331 |
+
'Content-Type': 'application/json',
|
| 332 |
+
'Accept': 'application/vnd.github.v3+json'
|
| 333 |
},
|
| 334 |
body: JSON.stringify({
|
| 335 |
+
message: `Student list updated - ${new Date().toISOString()}`,
|
| 336 |
+
content: base64Content,
|
| 337 |
+
sha: sha || undefined,
|
| 338 |
branch: 'main'
|
| 339 |
})
|
| 340 |
});
|
| 341 |
+
if (!putResponse.ok) {
|
| 342 |
+
const err = await putResponse.json();
|
|
|
|
| 343 |
throw new Error(err.message || 'Save failed');
|
| 344 |
}
|
| 345 |
return true;
|
| 346 |
+
} catch (error) {
|
| 347 |
+
console.error('Save error:', error);
|
| 348 |
+
alert('Failed to save: ' + error.message);
|
| 349 |
return false;
|
| 350 |
}
|
| 351 |
}
|
| 352 |
+
// Export: fetch latest from GitHub, generate CSV, and show downloadable link
|
| 353 |
+
document.getElementById('export-btn').addEventListener('click', async function() {
|
| 354 |
+
this.disabled = true;
|
| 355 |
+
this.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Exporting...';
|
| 356 |
+
await loadStudentList(); // Fetch the latest data
|
| 357 |
+
const csv = generateCSV();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
const filename = `student-list-${new Date().toISOString().split('T')[0]}.csv`;
|
| 359 |
+
// Revoke previous blob URL if exists
|
| 360 |
+
if (currentCsvBlobUrl) {
|
| 361 |
+
URL.revokeObjectURL(currentCsvBlobUrl);
|
| 362 |
+
}
|
| 363 |
+
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
| 364 |
currentCsvBlobUrl = URL.createObjectURL(blob);
|
| 365 |
+
const downloadLink = document.getElementById('download-link');
|
| 366 |
+
downloadLink.href = currentCsvBlobUrl;
|
| 367 |
+
downloadLink.download = filename;
|
| 368 |
document.getElementById('export-success').classList.remove('hidden');
|
| 369 |
+
this.disabled = false;
|
| 370 |
+
this.innerHTML = '<i class="fas fa-file-export mr-2"></i> Export to CSV';
|
| 371 |
});
|
| 372 |
+
function generateCSV() {
|
| 373 |
+
let csv = 'class,form,studentName\n';
|
| 374 |
+
for (const key in students) {
|
| 375 |
+
const [className, form] = key.split('-');
|
| 376 |
+
students[key].forEach(student => {
|
| 377 |
+
csv += `${className},${form},"${student.replace(/"/g, '""')}"\n`;
|
| 378 |
+
});
|
| 379 |
+
}
|
| 380 |
+
return csv;
|
| 381 |
+
}
|
| 382 |
+
document.getElementById('export-sample-btn').addEventListener('click', function() {
|
| 383 |
+
const blob = new Blob([CSV_TEMPLATE], { type: 'text/csv;charset=utf-8;' });
|
| 384 |
const url = URL.createObjectURL(blob);
|
| 385 |
+
const link = document.createElement('a');
|
| 386 |
+
link.href = url;
|
| 387 |
+
link.download = 'student-list-sample.csv';
|
| 388 |
+
document.body.appendChild(link);
|
| 389 |
+
link.click();
|
| 390 |
+
document.body.removeChild(link);
|
| 391 |
+
URL.revokeObjectURL(url);
|
| 392 |
});
|
| 393 |
+
// Import CSV
|
| 394 |
+
function parseCSV(content) {
|
| 395 |
+
const lines = content.split('\n').map(l => l.trim()).filter(l => l);
|
| 396 |
+
if (lines.length < 1) throw new Error('Empty CSV');
|
|
|
|
| 397 |
const headers = lines[0].toLowerCase().split(',');
|
| 398 |
+
if (!headers.includes('class') || !headers.includes('form') || !headers.includes('studentname')) {
|
| 399 |
+
throw new Error('Missing required columns: class, form, studentName');
|
| 400 |
+
}
|
| 401 |
+
const newStudents = {};
|
| 402 |
for (let i = 1; i < lines.length; i++) {
|
| 403 |
+
const row = lines[i];
|
| 404 |
+
const match = row.match(/([^,]*),([^,]*),(.*)/);
|
| 405 |
if (!match) continue;
|
| 406 |
+
let className = match[1].trim().toUpperCase();
|
| 407 |
let form = match[2].trim();
|
| 408 |
+
let studentName = match[3].trim().replace(/^"|"$/g, '').replace(/""/g, '"');
|
| 409 |
+
if (!className || !form || !studentName) continue;
|
| 410 |
+
const key = `${className}-${form}`;
|
| 411 |
+
if (!newStudents[key]) newStudents[key] = [];
|
| 412 |
+
if (!newStudents[key].includes(studentName)) newStudents[key].push(studentName);
|
| 413 |
}
|
| 414 |
+
return newStudents;
|
| 415 |
}
|
| 416 |
+
document.getElementById('import-btn').addEventListener('click', async function() {
|
| 417 |
+
const fileInput = document.getElementById('csv-file');
|
| 418 |
+
const file = fileInput.files[0];
|
| 419 |
+
if (!file) {
|
| 420 |
+
alert('Please select a CSV file first');
|
| 421 |
+
return;
|
| 422 |
+
}
|
| 423 |
const reader = new FileReader();
|
| 424 |
+
reader.onload = async function(e) {
|
| 425 |
try {
|
| 426 |
+
const content = e.target.result;
|
| 427 |
+
students = parseCSV(content);
|
| 428 |
const saved = await saveStudentListToGitHub();
|
| 429 |
if (saved) {
|
| 430 |
+
availableClasses = [...new Set(Object.keys(students).map(key => key.split('-')[0]))].sort();
|
| 431 |
updateClassDropdowns();
|
| 432 |
+
let count = 0;
|
| 433 |
+
for (const key in students) count += students[key].length;
|
| 434 |
document.getElementById('import-stats').textContent = `${count} students imported`;
|
| 435 |
document.getElementById('import-success').classList.remove('hidden');
|
| 436 |
setTimeout(() => document.getElementById('import-success').classList.add('hidden'), 5000);
|
| 437 |
+
fileInput.value = '';
|
| 438 |
document.getElementById('file-name').textContent = 'No file selected';
|
| 439 |
}
|
| 440 |
+
} catch (error) {
|
| 441 |
+
document.getElementById('error-message').textContent = error.message;
|
| 442 |
document.getElementById('import-error').classList.remove('hidden');
|
| 443 |
setTimeout(() => document.getElementById('import-error').classList.add('hidden'), 6000);
|
| 444 |
}
|
| 445 |
};
|
| 446 |
reader.readAsText(file);
|
| 447 |
});
|
| 448 |
+
document.getElementById('csv-file').addEventListener('change', function(e) {
|
| 449 |
+
const fileName = e.target.files[0]?.name || 'No file selected';
|
| 450 |
+
document.getElementById('file-name').textContent = fileName;
|
| 451 |
});
|
| 452 |
+
window.addEventListener('load', loadStudentList);
|
| 453 |
// Tab switching
|
| 454 |
+
document.getElementById('add-tab').addEventListener('click', function() {
|
| 455 |
+
document.getElementById('add-form').classList.remove('hidden');
|
| 456 |
+
document.getElementById('remove-form').classList.add('hidden');
|
| 457 |
+
document.getElementById('class-form').classList.add('hidden');
|
| 458 |
+
document.getElementById('import-export-form').classList.add('hidden');
|
| 459 |
+
this.classList.add('text-blue-600', 'border-blue-600');
|
| 460 |
+
this.classList.remove('text-gray-500');
|
| 461 |
+
document.getElementById('remove-tab').classList.add('text-gray-500');
|
| 462 |
+
document.getElementById('remove-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 463 |
+
document.getElementById('class-tab').classList.add('text-gray-500');
|
| 464 |
+
document.getElementById('class-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 465 |
+
document.getElementById('import-export-tab').classList.add('text-gray-500');
|
| 466 |
+
document.getElementById('import-export-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 467 |
+
});
|
| 468 |
+
document.getElementById('remove-tab').addEventListener('click', function() {
|
| 469 |
+
document.getElementById('remove-form').classList.remove('hidden');
|
| 470 |
+
document.getElementById('add-form').classList.add('hidden');
|
| 471 |
+
document.getElementById('class-form').classList.add('hidden');
|
| 472 |
+
document.getElementById('import-export-form').classList.add('hidden');
|
| 473 |
+
this.classList.add('text-blue-600', 'border-blue-600');
|
| 474 |
+
this.classList.remove('text-gray-500');
|
| 475 |
+
document.getElementById('add-tab').classList.add('text-gray-500');
|
| 476 |
+
document.getElementById('add-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 477 |
+
document.getElementById('class-tab').classList.add('text-gray-500');
|
| 478 |
+
document.getElementById('class-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 479 |
+
document.getElementById('import-export-tab').classList.add('text-gray-500');
|
| 480 |
+
document.getElementById('import-export-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 481 |
});
|
| 482 |
+
document.getElementById('class-tab').addEventListener('click', function() {
|
| 483 |
+
document.getElementById('class-form').classList.remove('hidden');
|
| 484 |
+
document.getElementById('add-form').classList.add('hidden');
|
| 485 |
+
document.getElementById('remove-form').classList.add('hidden');
|
| 486 |
+
document.getElementById('import-export-form').classList.add('hidden');
|
| 487 |
+
this.classList.add('text-blue-600', 'border-blue-600');
|
| 488 |
+
this.classList.remove('text-gray-500');
|
| 489 |
+
document.getElementById('add-tab').classList.add('text-gray-500');
|
| 490 |
+
document.getElementById('add-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 491 |
+
document.getElementById('remove-tab').classList.add('text-gray-500');
|
| 492 |
+
document.getElementById('remove-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 493 |
+
document.getElementById('import-export-tab').classList.add('text-gray-500');
|
| 494 |
+
document.getElementById('import-export-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 495 |
+
updateClassFormVisibility();
|
| 496 |
+
});
|
| 497 |
+
document.getElementById('import-export-tab').addEventListener('click', function() {
|
| 498 |
+
document.getElementById('import-export-form').classList.remove('hidden');
|
| 499 |
+
document.getElementById('add-form').classList.add('hidden');
|
| 500 |
+
document.getElementById('remove-form').classList.add('hidden');
|
| 501 |
+
document.getElementById('class-form').classList.add('hidden');
|
| 502 |
+
this.classList.add('text-blue-600', 'border-blue-600');
|
| 503 |
+
this.classList.remove('text-gray-500');
|
| 504 |
+
document.getElementById('add-tab').classList.add('text-gray-500');
|
| 505 |
+
document.getElementById('add-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 506 |
+
document.getElementById('remove-tab').classList.add('text-gray-500');
|
| 507 |
+
document.getElementById('remove-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 508 |
+
document.getElementById('class-tab').classList.add('text-gray-500');
|
| 509 |
+
document.getElementById('class-tab').classList.remove('text-blue-600', 'border-blue-600');
|
| 510 |
+
});
|
| 511 |
+
document.getElementById('remove-class').addEventListener('change', loadStudentsForRemoval);
|
| 512 |
+
document.getElementById('remove-form-select').addEventListener('change', loadStudentsForRemoval);
|
| 513 |
function loadStudentsForRemoval() {
|
| 514 |
+
const classVal = document.getElementById('remove-class').value;
|
| 515 |
+
const formVal = document.getElementById('remove-form-select').value;
|
| 516 |
+
const studentSelect = document.getElementById('student-select');
|
| 517 |
+
const container = document.getElementById('student-select-container');
|
| 518 |
+
studentSelect.innerHTML = '<option value="">Select Student</option>';
|
| 519 |
+
container.classList.add('hidden');
|
| 520 |
+
if (classVal && formVal) {
|
| 521 |
+
const key = `${classVal}-${formVal}`;
|
| 522 |
+
if (students[key] && students[key].length > 0) {
|
| 523 |
+
students[key].forEach(student => {
|
| 524 |
+
const option = document.createElement('option');
|
| 525 |
+
option.value = student;
|
| 526 |
+
option.textContent = student;
|
| 527 |
+
studentSelect.appendChild(option);
|
| 528 |
});
|
| 529 |
+
container.classList.remove('hidden');
|
| 530 |
+
} else {
|
| 531 |
+
studentSelect.innerHTML = '<option value="">No students in this class/form</option>';
|
| 532 |
}
|
| 533 |
}
|
| 534 |
}
|
| 535 |
+
document.getElementById('add-student-btn').addEventListener('click', async function() {
|
| 536 |
+
const className = document.getElementById('add-class').value;
|
| 537 |
+
const formVal = document.getElementById('add-form-select').value;
|
| 538 |
+
const studentName = document.getElementById('student-name').value.trim();
|
| 539 |
+
if (!studentName) {
|
| 540 |
+
alert('Please enter student name');
|
| 541 |
+
return;
|
| 542 |
+
}
|
| 543 |
+
if (!className) {
|
| 544 |
+
alert('Please select a class');
|
| 545 |
+
return;
|
| 546 |
+
}
|
| 547 |
+
const key = `${className}-${formVal}`;
|
| 548 |
if (!students[key]) students[key] = [];
|
| 549 |
+
if (students[key].includes(studentName)) {
|
| 550 |
+
alert('This student already exists');
|
| 551 |
+
return;
|
| 552 |
+
}
|
| 553 |
+
students[key].push(studentName);
|
| 554 |
const saved = await saveStudentListToGitHub();
|
| 555 |
if (saved) {
|
| 556 |
document.getElementById('student-name').value = '';
|
|
|
|
| 560 |
updateClassDropdowns();
|
| 561 |
}
|
| 562 |
});
|
| 563 |
+
document.getElementById('remove-student-btn').addEventListener('click', async function() {
|
| 564 |
+
const className = document.getElementById('remove-class').value;
|
| 565 |
+
const formVal = document.getElementById('remove-form-select').value;
|
| 566 |
+
const studentName = document.getElementById('student-select').value;
|
| 567 |
+
if (!studentName) {
|
| 568 |
+
alert('Please select a student');
|
| 569 |
+
return;
|
| 570 |
+
}
|
| 571 |
+
const key = `${className}-${formVal}`;
|
| 572 |
if (students[key]) {
|
| 573 |
+
students[key] = students[key].filter(s => s !== studentName);
|
| 574 |
+
if (students[key].length === 0) delete students[key];
|
| 575 |
}
|
| 576 |
const saved = await saveStudentListToGitHub();
|
| 577 |
if (saved) {
|
|
|
|
| 582 |
updateClassDropdowns();
|
| 583 |
}
|
| 584 |
});
|
| 585 |
+
const forms = ['1', '2', '3', '4', '5'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 586 |
function updateClassFormVisibility() {
|
| 587 |
const action = document.getElementById('class-action').value;
|
| 588 |
const scope = document.getElementById('class-scope').value;
|
| 589 |
+
document.getElementById('add-class-container').classList.add('hidden');
|
| 590 |
+
document.getElementById('remove-class-container').classList.add('hidden');
|
| 591 |
document.getElementById('specific-form-container').classList.toggle('hidden', scope === 'all');
|
| 592 |
+
if (action === 'add') {
|
| 593 |
+
document.getElementById('add-class-container').classList.remove('hidden');
|
| 594 |
+
} else if (action === 'remove') {
|
| 595 |
+
document.getElementById('remove-class-container').classList.remove('hidden');
|
| 596 |
+
populateRemoveClassDropdown(scope);
|
| 597 |
+
}
|
| 598 |
+
}
|
| 599 |
+
function populateRemoveClassDropdown(scope) {
|
| 600 |
+
const select = document.getElementById('remove-class-name');
|
| 601 |
+
select.innerHTML = '<option value="">Select Class</option>';
|
| 602 |
+
const classes = new Set();
|
| 603 |
+
if (scope === 'all') {
|
| 604 |
+
for (const key in students) classes.add(key.split('-')[0]);
|
| 605 |
+
} else {
|
| 606 |
+
const formVal = document.getElementById('class-form-select').value;
|
| 607 |
+
if (!formVal) return;
|
| 608 |
+
for (const key in students) {
|
| 609 |
+
const [cls, form] = key.split('-');
|
| 610 |
+
if (form === formVal) classes.add(cls);
|
| 611 |
+
}
|
| 612 |
+
}
|
| 613 |
+
classes.forEach(cls => {
|
| 614 |
+
const opt = document.createElement('option');
|
| 615 |
+
opt.value = cls;
|
| 616 |
+
opt.textContent = cls;
|
| 617 |
+
select.appendChild(opt);
|
| 618 |
+
});
|
| 619 |
+
if (classes.size === 0) select.innerHTML = '<option value="">No classes found</option>';
|
| 620 |
}
|
|
|
|
| 621 |
document.getElementById('class-action').addEventListener('change', updateClassFormVisibility);
|
| 622 |
document.getElementById('class-scope').addEventListener('change', updateClassFormVisibility);
|
| 623 |
document.getElementById('class-form-select').addEventListener('change', () => {
|
| 624 |
+
if (document.getElementById('class-action').value === 'remove' && document.getElementById('class-scope').value === 'specific') {
|
| 625 |
+
populateRemoveClassDropdown('specific');
|
| 626 |
+
}
|
| 627 |
});
|
|
|
|
| 628 |
document.getElementById('apply-class-btn').addEventListener('click', async () => {
|
| 629 |
const action = document.getElementById('class-action').value;
|
| 630 |
const scope = document.getElementById('class-scope').value;
|
| 631 |
+
let affectedForms = scope === 'all' ? forms : [document.getElementById('class-form-select').value];
|
| 632 |
+
if (scope === 'specific' && !affectedForms[0]) return alert('Please select a form');
|
|
|
|
|
|
|
| 633 |
let msg = '';
|
| 634 |
if (action === 'add') {
|
| 635 |
+
const newClass = document.getElementById('new-class-name').value.trim().toUpperCase();
|
| 636 |
+
if (!newClass) return alert('Please enter a class name');
|
| 637 |
+
let addedCount = 0;
|
| 638 |
+
for (const form of affectedForms) {
|
| 639 |
+
const key = `${newClass}-${form}`;
|
| 640 |
+
if (!students[key]) {
|
| 641 |
+
students[key] = [];
|
| 642 |
+
addedCount++;
|
| 643 |
+
}
|
| 644 |
}
|
| 645 |
+
if (addedCount === 0) return alert('Class already exists');
|
| 646 |
+
msg = `Class ${newClass} added to ${addedCount} form(s)`;
|
| 647 |
+
} else if (action === 'remove') {
|
| 648 |
+
const classToRemove = document.getElementById('remove-class-name').value;
|
| 649 |
+
if (!classToRemove) return alert('Please select a class');
|
| 650 |
+
let removedCount = 0;
|
| 651 |
+
for (const form of affectedForms) {
|
| 652 |
+
const key = `${classToRemove}-${form}`;
|
| 653 |
if (students[key]) {
|
| 654 |
+
if (students[key].length > 0 && !confirm(`Delete ${students[key].length} students in ${classToRemove} Form ${form}?`)) continue;
|
| 655 |
delete students[key];
|
| 656 |
+
removedCount++;
|
| 657 |
}
|
| 658 |
}
|
| 659 |
+
if (removedCount === 0) return alert('No classes removed');
|
| 660 |
+
msg = `Class ${classToRemove} removed from ${removedCount} form(s)`;
|
| 661 |
}
|
|
|
|
| 662 |
const saved = await saveStudentListToGitHub();
|
| 663 |
if (saved) {
|
| 664 |
document.getElementById('class-success-msg').textContent = msg;
|
| 665 |
document.getElementById('class-success').classList.remove('hidden');
|
| 666 |
setTimeout(() => document.getElementById('class-success').classList.add('hidden'), 5000);
|
| 667 |
+
updateClassFormVisibility();
|
| 668 |
availableClasses = [...new Set(Object.keys(students).map(k => k.split('-')[0]))].sort();
|
| 669 |
updateClassDropdowns();
|
|
|
|
| 670 |
}
|
| 671 |
});
|
|
|
|
|
|
|
| 672 |
</script>
|
| 673 |
</body>
|
| 674 |
</html>
|
students-ate.html
CHANGED
|
@@ -79,12 +79,17 @@
|
|
| 79 |
<div id="attendance-form" class="bg-white rounded-lg shadow-md p-6 mb-8">
|
| 80 |
<h2 class="text-xl font-semibold mb-4 text-gray-800">Dining Confirmation</h2>
|
| 81 |
<h3 class="text-lg font-medium mb-4 text-center text-blue-600">Confirm Student Has Eaten</h3>
|
| 82 |
-
|
| 83 |
<div id="eating-details" class="space-y-4 mt-6">
|
| 84 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
<div>
|
| 86 |
<label for="form" class="block text-gray-700 font-medium mb-2">Form</label>
|
| 87 |
-
<select id="form" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" onchange="
|
| 88 |
<option value="">Select Form</option>
|
| 89 |
<option value="1">Form 1</option>
|
| 90 |
<option value="2">Form 2</option>
|
|
@@ -93,22 +98,14 @@
|
|
| 93 |
<option value="5">Form 5</option>
|
| 94 |
</select>
|
| 95 |
</div>
|
| 96 |
-
<div>
|
| 97 |
-
<label for="class" class="block text-gray-700 font-medium mb-2">Class</label>
|
| 98 |
-
<select id="class" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" onchange="loadStudents()" disabled>
|
| 99 |
-
<option value="">Select Form First</option>
|
| 100 |
-
</select>
|
| 101 |
-
</div>
|
| 102 |
</div>
|
| 103 |
-
|
| 104 |
<div id="student-container" class="mt-4 hidden">
|
| 105 |
<label for="student" class="block text-gray-700 font-medium mb-2">Student Name</label>
|
| 106 |
<select id="student" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" disabled>
|
| 107 |
-
<option value="">
|
| 108 |
</select>
|
| 109 |
</div>
|
| 110 |
</div>
|
| 111 |
-
|
| 112 |
<div class="mt-6">
|
| 113 |
<button id="submit-btn" class="w-full bg-green-600 hover:bg-green-700 text-white font-bold py-3 px-4 rounded-lg transition duration-200">
|
| 114 |
<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken
|
|
@@ -141,6 +138,7 @@
|
|
| 141 |
<script>
|
| 142 |
// Dynamic student list from GitHub
|
| 143 |
let students = {};
|
|
|
|
| 144 |
|
| 145 |
async function loadStudentList() {
|
| 146 |
try {
|
|
@@ -150,62 +148,38 @@
|
|
| 150 |
'Accept': 'application/vnd.github.v3+json'
|
| 151 |
}
|
| 152 |
});
|
| 153 |
-
|
| 154 |
if (response.status === 404) {
|
| 155 |
students = {};
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
} else {
|
| 160 |
-
throw new Error('Failed to load student list');
|
| 161 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
} catch (error) {
|
| 163 |
console.error('Error loading student list:', error);
|
| 164 |
alert('Could not load student list. Using empty list.');
|
| 165 |
students = {};
|
|
|
|
|
|
|
| 166 |
}
|
| 167 |
-
|
| 168 |
-
// Reset class dropdown until form is selected
|
| 169 |
-
document.getElementById('class').disabled = true;
|
| 170 |
-
document.getElementById('class').innerHTML = '<option value="">Select Form First</option>';
|
| 171 |
}
|
| 172 |
|
| 173 |
-
|
| 174 |
-
function updateClassesForForm() {
|
| 175 |
-
const formVal = document.getElementById('form').value;
|
| 176 |
const classSelect = document.getElementById('class');
|
| 177 |
-
|
| 178 |
classSelect.innerHTML = '<option value="">Select Class</option>';
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
}
|
| 186 |
-
|
| 187 |
-
const classesForForm = new Set();
|
| 188 |
-
for (const key in students) {
|
| 189 |
-
const [cls, form] = key.split('-');
|
| 190 |
-
if (form === formVal) {
|
| 191 |
-
classesForForm.add(cls);
|
| 192 |
-
}
|
| 193 |
-
}
|
| 194 |
-
|
| 195 |
-
if (classesForForm.size === 0) {
|
| 196 |
-
classSelect.innerHTML = '<option value="">No classes in this form</option>';
|
| 197 |
-
} else {
|
| 198 |
-
classesForForm.forEach(cls => {
|
| 199 |
-
const opt = document.createElement('option');
|
| 200 |
-
opt.value = cls;
|
| 201 |
-
opt.textContent = cls;
|
| 202 |
-
classSelect.appendChild(opt);
|
| 203 |
-
});
|
| 204 |
-
classSelect.disabled = false;
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
clearStudents();
|
| 208 |
-
loadStudents();
|
| 209 |
}
|
| 210 |
|
| 211 |
function loadStudents() {
|
|
@@ -235,17 +209,9 @@
|
|
| 235 |
}
|
| 236 |
}
|
| 237 |
|
| 238 |
-
function clearStudents() {
|
| 239 |
-
const studentSelect = document.getElementById('student');
|
| 240 |
-
const studentContainer = document.getElementById('student-container');
|
| 241 |
-
studentSelect.innerHTML = '<option value="">Select Student</option>';
|
| 242 |
-
studentSelect.disabled = true;
|
| 243 |
-
studentContainer.classList.add('hidden');
|
| 244 |
-
}
|
| 245 |
-
|
| 246 |
window.addEventListener('load', loadStudentList);
|
| 247 |
|
| 248 |
-
// ===
|
| 249 |
function updateDateTime() {
|
| 250 |
const now = new Date();
|
| 251 |
document.getElementById('current-time').textContent = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
@@ -270,13 +236,15 @@
|
|
| 270 |
const now = new Date();
|
| 271 |
const hours = now.getHours();
|
| 272 |
const minutes = now.getMinutes();
|
| 273 |
-
|
| 274 |
-
if (
|
| 275 |
-
if (
|
| 276 |
-
if (
|
| 277 |
-
if (
|
| 278 |
-
|
| 279 |
-
return '
|
|
|
|
|
|
|
| 280 |
}
|
| 281 |
|
| 282 |
function isCurrentTimeMealPeriod() {
|
|
@@ -285,9 +253,9 @@
|
|
| 285 |
const minutes = now.getMinutes();
|
| 286 |
return (
|
| 287 |
(hours === 6 && minutes >= 20 && minutes <= 50) ||
|
| 288 |
-
(
|
| 289 |
-
(
|
| 290 |
-
(
|
| 291 |
);
|
| 292 |
}
|
| 293 |
|
|
@@ -305,41 +273,42 @@
|
|
| 305 |
document.getElementById('menu-display-container').classList.remove('hidden');
|
| 306 |
|
| 307 |
document.querySelectorAll('.meal-time').forEach(btn => {
|
| 308 |
-
btn.
|
| 309 |
-
btn.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
});
|
| 311 |
|
| 312 |
-
const
|
| 313 |
-
|
| 314 |
-
activeBtn.classList.add(`bg-${colors[mealTime]}`, 'text-white');
|
| 315 |
-
activeBtn.classList.remove('border');
|
| 316 |
-
|
| 317 |
-
document.getElementById('meal-period-icon').className = `fas fa-utensils text-2xl text-${colors[mealTime].replace('500', '400').replace('600', '500')}`;
|
| 318 |
|
| 319 |
updateMenuDisplay(mealTime);
|
| 320 |
|
| 321 |
const mealTitles = { breakfast: 'Breakfast (6:20 AM - 6:50 AM)', lunch: 'Lunch (1:30 PM - 2:30 PM)', dinner: 'Dinner (5:50 PM - 7:00 PM)', supper: 'Supper (10:30 PM - 11:00 PM)' };
|
| 322 |
const mealIcons = { breakfast: 'fa-sun', lunch: 'fa-utensils', dinner: 'fa-moon', supper: 'fa-bed' };
|
| 323 |
document.getElementById('selected-meal-time-display').innerHTML = `<i class="fas ${mealIcons[mealTime]} mr-2"></i><span class="font-bold">${mealTitles[mealTime]}</span>`;
|
|
|
|
|
|
|
| 324 |
}
|
| 325 |
|
| 326 |
function updateMenuDisplay(mealTime) {
|
| 327 |
const regularMenu = document.getElementById('regular-menu');
|
| 328 |
regularMenu.innerHTML = '';
|
| 329 |
-
document.getElementById('default-menu-message').classList.add('hidden');
|
| 330 |
-
|
| 331 |
menus[mealTime].regular.forEach(item => {
|
| 332 |
const div = document.createElement('div');
|
| 333 |
div.className = 'flex items-center';
|
| 334 |
-
|
| 335 |
-
div.innerHTML = `<i class="fas fa-circle text-xs text-${colorMap[mealTime]}-700 mr-2"></i><span>${item}</span>`;
|
| 336 |
regularMenu.appendChild(div);
|
| 337 |
});
|
| 338 |
}
|
| 339 |
|
| 340 |
const initialMeal = getCurrentMealTime();
|
| 341 |
-
if (isCurrentTimeMealPeriod()
|
| 342 |
showMealMenu(initialMeal);
|
|
|
|
|
|
|
| 343 |
}
|
| 344 |
|
| 345 |
// Submit confirmation
|
|
@@ -351,8 +320,14 @@
|
|
| 351 |
const form = document.getElementById('form').value;
|
| 352 |
const student = document.getElementById('student').value;
|
| 353 |
|
| 354 |
-
if (!student
|
| 355 |
-
alert('Please select
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
this.disabled = false;
|
| 357 |
this.innerHTML = '<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken';
|
| 358 |
return;
|
|
@@ -360,7 +335,7 @@
|
|
| 360 |
|
| 361 |
const data = {
|
| 362 |
timestamp: new Date().toISOString(),
|
| 363 |
-
mealTime:
|
| 364 |
attendance: 'yes',
|
| 365 |
class: studentClass,
|
| 366 |
form: form,
|
|
@@ -372,6 +347,7 @@
|
|
| 372 |
if (success) {
|
| 373 |
document.getElementById('attendance-form').classList.add('hidden');
|
| 374 |
document.getElementById('success-message').classList.remove('hidden');
|
|
|
|
| 375 |
}
|
| 376 |
} catch (error) {
|
| 377 |
alert('Failed to submit: ' + error.message);
|
|
@@ -380,16 +356,19 @@
|
|
| 380 |
this.innerHTML = '<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken';
|
| 381 |
}
|
| 382 |
});
|
| 383 |
-
|
| 384 |
async function sendDataToGitHub(data) {
|
| 385 |
try {
|
| 386 |
-
|
| 387 |
-
const repoUrl = `https://api.github.com/repos/${GITHUB_CONFIG.REPOS.CONSUMED}/contents/${filePath}`;
|
| 388 |
let currentContent = '';
|
| 389 |
let sha = '';
|
| 390 |
-
|
|
|
|
|
|
|
| 391 |
const getResponse = await fetch(repoUrl, {
|
| 392 |
-
headers: {
|
|
|
|
|
|
|
|
|
|
| 393 |
});
|
| 394 |
|
| 395 |
if (getResponse.ok) {
|
|
@@ -397,17 +376,20 @@
|
|
| 397 |
sha = fileData.sha;
|
| 398 |
currentContent = atob(fileData.content);
|
| 399 |
} else if (getResponse.status !== 404) {
|
| 400 |
-
throw new Error('Failed to
|
| 401 |
}
|
| 402 |
|
|
|
|
| 403 |
const record = JSON.stringify(data);
|
| 404 |
-
const newContent = currentContent +
|
| 405 |
|
|
|
|
| 406 |
const response = await fetch(repoUrl, {
|
| 407 |
method: 'PUT',
|
| 408 |
headers: {
|
| 409 |
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`,
|
| 410 |
-
'Content-Type': 'application/json'
|
|
|
|
| 411 |
},
|
| 412 |
body: JSON.stringify({
|
| 413 |
message: `Meal confirmation - ${new Date().toLocaleString()}`,
|
|
@@ -417,26 +399,35 @@
|
|
| 417 |
})
|
| 418 |
});
|
| 419 |
|
| 420 |
-
if (!response.ok)
|
|
|
|
|
|
|
|
|
|
| 421 |
return true;
|
| 422 |
} catch (error) {
|
| 423 |
-
console.error(error);
|
| 424 |
-
throw error;
|
| 425 |
}
|
| 426 |
}
|
| 427 |
-
|
| 428 |
-
function resetForm() {
|
| 429 |
-
document.getElementById('form').value = '';
|
| 430 |
document.getElementById('class').value = '';
|
| 431 |
-
document.getElementById('
|
| 432 |
-
document.getElementById('class').innerHTML = '<option value="">Select Form First</option>';
|
| 433 |
document.getElementById('student').value = '';
|
|
|
|
| 434 |
document.getElementById('student-container').classList.add('hidden');
|
| 435 |
document.getElementById('success-message').classList.add('hidden');
|
| 436 |
document.getElementById('attendance-form').classList.remove('hidden');
|
| 437 |
}
|
| 438 |
|
| 439 |
document.getElementById('fill-again-btn').addEventListener('click', resetForm);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
</script>
|
| 441 |
</body>
|
| 442 |
</html>
|
|
|
|
| 79 |
<div id="attendance-form" class="bg-white rounded-lg shadow-md p-6 mb-8">
|
| 80 |
<h2 class="text-xl font-semibold mb-4 text-gray-800">Dining Confirmation</h2>
|
| 81 |
<h3 class="text-lg font-medium mb-4 text-center text-blue-600">Confirm Student Has Eaten</h3>
|
|
|
|
| 82 |
<div id="eating-details" class="space-y-4 mt-6">
|
| 83 |
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 84 |
+
<div>
|
| 85 |
+
<label for="class" class="block text-gray-700 font-medium mb-2">Class</label>
|
| 86 |
+
<select id="class" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" onchange="loadStudents()">
|
| 87 |
+
<option value="">Select Class</option>
|
| 88 |
+
</select>
|
| 89 |
+
</div>
|
| 90 |
<div>
|
| 91 |
<label for="form" class="block text-gray-700 font-medium mb-2">Form</label>
|
| 92 |
+
<select id="form" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" onchange="loadStudents()">
|
| 93 |
<option value="">Select Form</option>
|
| 94 |
<option value="1">Form 1</option>
|
| 95 |
<option value="2">Form 2</option>
|
|
|
|
| 98 |
<option value="5">Form 5</option>
|
| 99 |
</select>
|
| 100 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
</div>
|
|
|
|
| 102 |
<div id="student-container" class="mt-4 hidden">
|
| 103 |
<label for="student" class="block text-gray-700 font-medium mb-2">Student Name</label>
|
| 104 |
<select id="student" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" disabled>
|
| 105 |
+
<option value="">Please select Class and Form first</option>
|
| 106 |
</select>
|
| 107 |
</div>
|
| 108 |
</div>
|
|
|
|
| 109 |
<div class="mt-6">
|
| 110 |
<button id="submit-btn" class="w-full bg-green-600 hover:bg-green-700 text-white font-bold py-3 px-4 rounded-lg transition duration-200">
|
| 111 |
<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken
|
|
|
|
| 138 |
<script>
|
| 139 |
// Dynamic student list from GitHub
|
| 140 |
let students = {};
|
| 141 |
+
let availableClasses = [];
|
| 142 |
|
| 143 |
async function loadStudentList() {
|
| 144 |
try {
|
|
|
|
| 148 |
'Accept': 'application/vnd.github.v3+json'
|
| 149 |
}
|
| 150 |
});
|
|
|
|
| 151 |
if (response.status === 404) {
|
| 152 |
students = {};
|
| 153 |
+
availableClasses = [];
|
| 154 |
+
updateClassDropdown();
|
| 155 |
+
return;
|
|
|
|
|
|
|
| 156 |
}
|
| 157 |
+
if (!response.ok) throw new Error('Failed to load student list');
|
| 158 |
+
const data = await response.json();
|
| 159 |
+
students = JSON.parse(atob(data.content));
|
| 160 |
+
|
| 161 |
+
// Extract unique classes dynamically
|
| 162 |
+
availableClasses = [...new Set(Object.keys(students).map(key => key.split('-')[0]))].sort();
|
| 163 |
+
updateClassDropdown();
|
| 164 |
} catch (error) {
|
| 165 |
console.error('Error loading student list:', error);
|
| 166 |
alert('Could not load student list. Using empty list.');
|
| 167 |
students = {};
|
| 168 |
+
availableClasses = [];
|
| 169 |
+
updateClassDropdown();
|
| 170 |
}
|
| 171 |
+
loadStudents(); // Initial load
|
|
|
|
|
|
|
|
|
|
| 172 |
}
|
| 173 |
|
| 174 |
+
function updateClassDropdown() {
|
|
|
|
|
|
|
| 175 |
const classSelect = document.getElementById('class');
|
|
|
|
| 176 |
classSelect.innerHTML = '<option value="">Select Class</option>';
|
| 177 |
+
availableClasses.forEach(cls => {
|
| 178 |
+
const opt = document.createElement('option');
|
| 179 |
+
opt.value = cls;
|
| 180 |
+
opt.textContent = cls;
|
| 181 |
+
classSelect.appendChild(opt);
|
| 182 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
}
|
| 184 |
|
| 185 |
function loadStudents() {
|
|
|
|
| 209 |
}
|
| 210 |
}
|
| 211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
window.addEventListener('load', loadStudentList);
|
| 213 |
|
| 214 |
+
// === Rest of your original code (time, meal menu, submission, etc.) ===
|
| 215 |
function updateDateTime() {
|
| 216 |
const now = new Date();
|
| 217 |
document.getElementById('current-time').textContent = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
|
|
|
|
| 236 |
const now = new Date();
|
| 237 |
const hours = now.getHours();
|
| 238 |
const minutes = now.getMinutes();
|
| 239 |
+
if (hours === 6 && minutes >= 20 || hours === 6 && minutes <= 50) return 'breakfast';
|
| 240 |
+
if (hours === 13 && minutes >= 30 || hours === 14 && minutes <= 30) return 'lunch';
|
| 241 |
+
if (hours === 17 && minutes >= 50 || hours === 18 && minutes <= 30 || hours === 19 && minutes <= 0) return 'dinner';
|
| 242 |
+
if (hours === 22 && minutes >= 30 || hours === 23 && minutes <= 0) return 'supper';
|
| 243 |
+
if (hours < 6) return 'breakfast';
|
| 244 |
+
if (hours < 13) return 'lunch';
|
| 245 |
+
if (hours < 17) return 'dinner';
|
| 246 |
+
if (hours < 22) return 'supper';
|
| 247 |
+
return 'breakfast';
|
| 248 |
}
|
| 249 |
|
| 250 |
function isCurrentTimeMealPeriod() {
|
|
|
|
| 253 |
const minutes = now.getMinutes();
|
| 254 |
return (
|
| 255 |
(hours === 6 && minutes >= 20 && minutes <= 50) ||
|
| 256 |
+
(hours === 13 && minutes >= 30 || hours === 14 && minutes <= 30) ||
|
| 257 |
+
(hours === 17 && minutes >= 50 || hours === 18 || (hours === 19 && minutes <= 0)) ||
|
| 258 |
+
(hours === 22 && minutes >= 30 || hours === 23)
|
| 259 |
);
|
| 260 |
}
|
| 261 |
|
|
|
|
| 273 |
document.getElementById('menu-display-container').classList.remove('hidden');
|
| 274 |
|
| 275 |
document.querySelectorAll('.meal-time').forEach(btn => {
|
| 276 |
+
btn.className = 'meal-time px-4 py-2 rounded-full border font-medium cursor-pointer transition-colors duration-200';
|
| 277 |
+
if (btn.dataset.meal === mealTime) {
|
| 278 |
+
btn.classList.add('bg-' + (mealTime === 'breakfast' ? 'yellow-500' : mealTime === 'lunch' ? 'green-600' : mealTime === 'dinner' ? 'indigo-600' : 'purple-600'), 'text-white', 'border-' + (mealTime === 'breakfast' ? 'yellow' : mealTime === 'lunch' ? 'green' : mealTime === 'dinner' ? 'indigo' : 'purple') + '-600');
|
| 279 |
+
} else {
|
| 280 |
+
btn.classList.add('hover:bg-' + (btn.dataset.meal === 'breakfast' ? 'yellow' : btn.dataset.meal === 'lunch' ? 'green' : btn.dataset.meal === 'dinner' ? 'indigo' : 'purple') + '-100');
|
| 281 |
+
}
|
| 282 |
});
|
| 283 |
|
| 284 |
+
const mealIcon = document.getElementById('meal-period-icon');
|
| 285 |
+
mealIcon.className = 'fas fa-utensils text-2xl ' + (mealTime === 'breakfast' ? 'text-yellow-500' : mealTime === 'lunch' ? 'text-green-600' : mealTime === 'dinner' ? 'text-indigo-600' : 'text-purple-600');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
updateMenuDisplay(mealTime);
|
| 288 |
|
| 289 |
const mealTitles = { breakfast: 'Breakfast (6:20 AM - 6:50 AM)', lunch: 'Lunch (1:30 PM - 2:30 PM)', dinner: 'Dinner (5:50 PM - 7:00 PM)', supper: 'Supper (10:30 PM - 11:00 PM)' };
|
| 290 |
const mealIcons = { breakfast: 'fa-sun', lunch: 'fa-utensils', dinner: 'fa-moon', supper: 'fa-bed' };
|
| 291 |
document.getElementById('selected-meal-time-display').innerHTML = `<i class="fas ${mealIcons[mealTime]} mr-2"></i><span class="font-bold">${mealTitles[mealTime]}</span>`;
|
| 292 |
+
document.getElementById('default-menu-message').classList.add('hidden');
|
| 293 |
+
document.getElementById('attendance-form').classList.add('hidden');
|
| 294 |
}
|
| 295 |
|
| 296 |
function updateMenuDisplay(mealTime) {
|
| 297 |
const regularMenu = document.getElementById('regular-menu');
|
| 298 |
regularMenu.innerHTML = '';
|
|
|
|
|
|
|
| 299 |
menus[mealTime].regular.forEach(item => {
|
| 300 |
const div = document.createElement('div');
|
| 301 |
div.className = 'flex items-center';
|
| 302 |
+
div.innerHTML = `<i class="fas fa-circle text-xs ${mealTime === 'breakfast' ? 'text-yellow-700' : mealTime === 'lunch' ? 'text-green-700' : mealTime === 'dinner' ? 'text-indigo-700' : 'text-purple-700'} mr-2"></i><span>${item}</span>`;
|
|
|
|
| 303 |
regularMenu.appendChild(div);
|
| 304 |
});
|
| 305 |
}
|
| 306 |
|
| 307 |
const initialMeal = getCurrentMealTime();
|
| 308 |
+
if (isCurrentTimeMealPeriod()) {
|
| 309 |
showMealMenu(initialMeal);
|
| 310 |
+
} else {
|
| 311 |
+
document.getElementById('menu-display-container').classList.add('hidden');
|
| 312 |
}
|
| 313 |
|
| 314 |
// Submit confirmation
|
|
|
|
| 320 |
const form = document.getElementById('form').value;
|
| 321 |
const student = document.getElementById('student').value;
|
| 322 |
|
| 323 |
+
if (!student) {
|
| 324 |
+
alert('Please select a student name');
|
| 325 |
+
this.disabled = false;
|
| 326 |
+
this.innerHTML = '<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken';
|
| 327 |
+
return;
|
| 328 |
+
}
|
| 329 |
+
if (!studentClass || !form) {
|
| 330 |
+
alert('Please select both class and form');
|
| 331 |
this.disabled = false;
|
| 332 |
this.innerHTML = '<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken';
|
| 333 |
return;
|
|
|
|
| 335 |
|
| 336 |
const data = {
|
| 337 |
timestamp: new Date().toISOString(),
|
| 338 |
+
mealTime: getCurrentMealTime(),
|
| 339 |
attendance: 'yes',
|
| 340 |
class: studentClass,
|
| 341 |
form: form,
|
|
|
|
| 347 |
if (success) {
|
| 348 |
document.getElementById('attendance-form').classList.add('hidden');
|
| 349 |
document.getElementById('success-message').classList.remove('hidden');
|
| 350 |
+
document.getElementById('success-message').classList.add('fade-in');
|
| 351 |
}
|
| 352 |
} catch (error) {
|
| 353 |
alert('Failed to submit: ' + error.message);
|
|
|
|
| 356 |
this.innerHTML = '<i class="fas fa-check-circle mr-2"></i> Confirm Meal Taken';
|
| 357 |
}
|
| 358 |
});
|
|
|
|
| 359 |
async function sendDataToGitHub(data) {
|
| 360 |
try {
|
| 361 |
+
// First check if file exists and get current content
|
|
|
|
| 362 |
let currentContent = '';
|
| 363 |
let sha = '';
|
| 364 |
+
const filePath = 'data%20who%20has%20ate%20at%20dm';
|
| 365 |
+
const repoUrl = `https://api.github.com/repos/${GITHUB_CONFIG.REPOS.CONSUMED}/contents/${filePath}`;
|
| 366 |
+
|
| 367 |
const getResponse = await fetch(repoUrl, {
|
| 368 |
+
headers: {
|
| 369 |
+
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`,
|
| 370 |
+
'Accept': 'application/vnd.github.v3+json'
|
| 371 |
+
}
|
| 372 |
});
|
| 373 |
|
| 374 |
if (getResponse.ok) {
|
|
|
|
| 376 |
sha = fileData.sha;
|
| 377 |
currentContent = atob(fileData.content);
|
| 378 |
} else if (getResponse.status !== 404) {
|
| 379 |
+
throw new Error('Failed to fetch existing data');
|
| 380 |
}
|
| 381 |
|
| 382 |
+
// Prepare new content
|
| 383 |
const record = JSON.stringify(data);
|
| 384 |
+
const newContent = currentContent + record + '\n';
|
| 385 |
|
| 386 |
+
// Create or update file
|
| 387 |
const response = await fetch(repoUrl, {
|
| 388 |
method: 'PUT',
|
| 389 |
headers: {
|
| 390 |
'Authorization': `token ${GITHUB_CONFIG.TOKEN}`,
|
| 391 |
+
'Content-Type': 'application/json',
|
| 392 |
+
'Accept': 'application/vnd.github.v3+json'
|
| 393 |
},
|
| 394 |
body: JSON.stringify({
|
| 395 |
message: `Meal confirmation - ${new Date().toLocaleString()}`,
|
|
|
|
| 399 |
})
|
| 400 |
});
|
| 401 |
|
| 402 |
+
if (!response.ok) {
|
| 403 |
+
const errorData = await response.json();
|
| 404 |
+
throw new Error(errorData.message || 'Submission failed');
|
| 405 |
+
}
|
| 406 |
return true;
|
| 407 |
} catch (error) {
|
| 408 |
+
console.error('Submission error:', error);
|
| 409 |
+
throw new Error('Failed to confirm meal: ' + error.message);
|
| 410 |
}
|
| 411 |
}
|
| 412 |
+
function resetForm() {
|
|
|
|
|
|
|
| 413 |
document.getElementById('class').value = '';
|
| 414 |
+
document.getElementById('form').value = '';
|
|
|
|
| 415 |
document.getElementById('student').value = '';
|
| 416 |
+
document.getElementById('student').disabled = true;
|
| 417 |
document.getElementById('student-container').classList.add('hidden');
|
| 418 |
document.getElementById('success-message').classList.add('hidden');
|
| 419 |
document.getElementById('attendance-form').classList.remove('hidden');
|
| 420 |
}
|
| 421 |
|
| 422 |
document.getElementById('fill-again-btn').addEventListener('click', resetForm);
|
| 423 |
+
|
| 424 |
+
setInterval(() => {
|
| 425 |
+
const currentMeal = getCurrentMealTime();
|
| 426 |
+
if (currentMeal !== selectedMeal) {
|
| 427 |
+
selectedMeal = currentMeal;
|
| 428 |
+
updateMenuDisplay(selectedMeal);
|
| 429 |
+
}
|
| 430 |
+
}, 60000);
|
| 431 |
</script>
|
| 432 |
</body>
|
| 433 |
</html>
|