Spaces:
Running
Running
Download attendance.html from EHDEM/WasteLessV6.2AlphaB1: direct link, hf CLI and curl.
- Browser
- Download file 35.3 kB
-
https://huggingface.co/spaces/EHDEM/WasteLessV6.2AlphaB1/resolve/main/attendance.html
- Command line
-
hf download hf://spaces/EHDEM/WasteLessV6.2AlphaB1/attendance.html
-
curl -L -o attendance.html https://huggingface.co/spaces/EHDEM/WasteLessV6.2AlphaB1/resolve/main/attendance.html
35.3 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>WASTE-LESS - Dining Attendance</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <link rel="stylesheet" href="style.css"> | |
| <style> | |
| .meal-card { transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); } | |
| .meal-card.active { transform: scale(1.03); box-shadow: 0 10px 25px rgba(0,0,0,0.15); } | |
| .meal-card:hover:not(.active) { transform: translateY(-2px); } | |
| .rfid-pulse { animation: rfidPulse 2s infinite; } | |
| @keyframes rfidPulse { | |
| 0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); } | |
| 50% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); } | |
| } | |
| .menu-card { animation: slideDown 0.3s ease-out; } | |
| @keyframes slideDown { | |
| from { opacity: 0; transform: translateY(-10px); } | |
| to { opacity: 1; transform: translateY(0); } | |
| } | |
| </style> | |
| </head> | |
| <body class="min-h-screen"> | |
| <custom-navbar></custom-navbar> | |
| <div class="container mx-auto px-4 py-12 max-w-4xl"> | |
| <!-- Header --> | |
| <header class="relative overflow-hidden rounded-2xl shadow-2xl mb-12 text-white p-8"> | |
| <div class="absolute inset-0 bg-gradient-to-r from-green-600 via-emerald-600 to-teal-600"></div> | |
| <div class="absolute inset-0 opacity-10" style="background: url('data:image/svg+xml,<svg width="100" height="100" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><path d="M0,0 L100,0 L100,100 Q50,80 0,100 Z" fill="white"/></svg>')"></div> | |
| <div class="relative z-10"> | |
| <div class="flex flex-col md:flex-row justify-between items-center"> | |
| <div class="mb-6 md:mb-0"> | |
| <a href="index.html" class="inline-flex items-center text-white/90 hover:text-white mb-4 transition-colors"> | |
| <i class="fas fa-arrow-left mr-2"></i> Back to Home | |
| </a> | |
| <h1 class="text-4xl md:text-5xl font-bold tracking-tight">Attendance Form A</h1> | |
| <p class="text-white/90 text-xl mt-3 max-w-2xl">For Students Who Want To Eat at the Dining Hall</p> | |
| </div> | |
| <div class="flex items-center space-x-6"> | |
| <div class="text-center"> | |
| <div class="text-3xl" id="meal-period-icon"><i class="fas fa-utensils"></i></div> | |
| <div class="text-sm opacity-90">Meal Period</div> | |
| </div> | |
| <div class="text-center"> | |
| <div class="text-3xl"><i class="fas fa-calendar-alt"></i></div> | |
| <div class="text-sm opacity-90">Schedule</div> | |
| </div> | |
| <div class="text-center"> | |
| <div class="text-3xl"><i class="fas fa-users"></i></div> | |
| <div class="text-sm opacity-90">Students</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </header> | |
| <!-- Current Time Display --> | |
| <div class="card mb-8 text-center bg-gradient-to-r from-green-50 to-emerald-50 border-green-100"> | |
| <div class="flex flex-col md:flex-row items-center justify-between"> | |
| <div class="mb-4 md:mb-0"> | |
| <div class="text-3xl md:text-4xl font-bold text-gray-800" id="current-time">Loading time...</div> | |
| <div class="text-green-600 font-medium text-lg" id="current-date">Loading date...</div> | |
| </div> | |
| <div class="bg-white rounded-xl p-4 shadow-lg"> | |
| <div class="text-sm text-gray-600">Current meal period</div> | |
| <div class="text-xl font-bold text-green-600" id="current-meal-display">Loading...</div> | |
| <div class="text-sm text-gray-500">Next: <span id="next-meal-time" class="font-medium">Loading...</span></div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Meal Periods & Menu --> | |
| <div class="card mb-8"> | |
| <h2 class="text-2xl font-bold mb-6 text-gray-800 border-b pb-4">Meal Periods & Menu</h2> | |
| <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-6"> | |
| <div class="meal-card px-6 py-5 rounded-xl border-2 cursor-pointer transition-all duration-300" | |
| style="border-color: #fde68a; background: linear-gradient(135deg, #fef9c3, #fef3c7);" | |
| data-meal="breakfast" onclick="showMealMenu('breakfast')"> | |
| <div class="flex items-center"> | |
| <div class="p-3 rounded-full mr-4" style="background: rgba(234, 179, 8, 0.15);"> | |
| <i class="fas fa-sun text-yellow-600 text-2xl"></i> | |
| </div> | |
| <div> | |
| <div class="text-lg font-bold text-yellow-800">Breakfast</div> | |
| <div class="text-yellow-700 text-sm font-medium">6:20 AM - 6:50 AM</div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="meal-card px-6 py-5 rounded-xl border-2 cursor-pointer transition-all duration-300" | |
| style="border-color: #bbf7d0; background: linear-gradient(135deg, #dcfce7, #d1fae5);" | |
| data-meal="lunch" onclick="showMealMenu('lunch')"> | |
| <div class="flex items-center"> | |
| <div class="p-3 rounded-full mr-4" style="background: rgba(22, 163, 74, 0.15);"> | |
| <i class="fas fa-utensils text-green-600 text-2xl"></i> | |
| </div> | |
| <div> | |
| <div class="text-lg font-bold text-green-800">Lunch</div> | |
| <div class="text-green-700 text-sm font-medium">1:30 PM - 2:30 PM</div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="meal-card px-6 py-5 rounded-xl border-2 cursor-pointer transition-all duration-300" | |
| style="border-color: #c7d2fe; background: linear-gradient(135deg, #e0e7ff, #ddd6fe);" | |
| data-meal="dinner" onclick="showMealMenu('dinner')"> | |
| <div class="flex items-center"> | |
| <div class="p-3 rounded-full mr-4" style="background: rgba(99, 102, 241, 0.15);"> | |
| <i class="fas fa-moon text-indigo-600 text-2xl"></i> | |
| </div> | |
| <div> | |
| <div class="text-lg font-bold text-indigo-800">Dinner</div> | |
| <div class="text-indigo-700 text-sm font-medium">5:50 PM - 7:00 PM</div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="meal-card px-6 py-5 rounded-xl border-2 cursor-pointer transition-all duration-300" | |
| style="border-color: #fbcfe8; background: linear-gradient(135deg, #fce7f3, #f5d0fe);" | |
| data-meal="supper" onclick="showMealMenu('supper')"> | |
| <div class="flex items-center"> | |
| <div class="p-3 rounded-full mr-4" style="background: rgba(192, 38, 211, 0.15);"> | |
| <i class="fas fa-bed text-fuchsia-600 text-2xl"></i> | |
| </div> | |
| <div> | |
| <div class="text-lg font-bold text-fuchsia-800">Supper</div> | |
| <div class="text-fuchsia-700 text-sm font-medium">10:30 PM - 11:00 PM</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Menu Display --> | |
| <div id="menu-display-container" class="hidden menu-card"> | |
| <div class="rounded-xl p-6 shadow-inner border" id="menu-display" style="background: linear-gradient(135deg, #f8fafc, #f1f5f9); border-color: #e2e8f0;"> | |
| <div class="font-bold mb-4 flex items-center text-lg" id="selected-meal-time-display"> | |
| <i class="fas fa-utensils mr-3 text-gray-600"></i> | |
| <span>Select a meal period</span> | |
| </div> | |
| <div class="space-y-3" id="regular-menu"> | |
| <div class="text-gray-500 italic" id="default-menu-message">Please click on a meal period above to view its menu</div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="text-sm text-gray-600 mt-4 bg-gray-50 p-3 rounded-lg"> | |
| <p>Current time: <span id="current-meal-time-display" class="font-medium text-gray-800"></span></p> | |
| <p>Next meal: <span id="next-meal-time-display" class="font-medium text-gray-800"></span></p> | |
| </div> | |
| </div> | |
| <!-- RFID Scan Section --> | |
| <div class="card mb-8 bg-gradient-to-r from-blue-50 to-indigo-50 border-blue-200"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-800 flex items-center"> | |
| <i class="fas fa-wifi mr-2 text-blue-600"></i> RFID Card Scan | |
| </h2> | |
| <div class="flex flex-col md:flex-row gap-4 items-end"> | |
| <div class="flex-1"> | |
| <label for="rfid-input" class="block text-gray-700 font-medium mb-2">Scan RFID Card</label> | |
| <input type="text" id="rfid-input" | |
| class="w-full px-4 py-3 border-2 border-blue-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 font-mono text-lg tracking-widest rfid-pulse" | |
| placeholder="Tap card or enter ID..." autocomplete="off"> | |
| </div> | |
| <button id="rfid-scan-btn" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-6 rounded-lg transition duration-200"> | |
| <i class="fas fa-search mr-2"></i> Lookup | |
| </button> | |
| </div> | |
| <div id="rfid-status" class="mt-3 hidden"></div> | |
| <p class="text-sm text-gray-500 mt-2"><i class="fas fa-info-circle mr-1"></i> Or use the manual form below to select your details</p> | |
| </div> | |
| <!-- Attendance Form --> | |
| <div id="attendance-form" class="bg-white rounded-lg shadow-md p-6 mb-8"> | |
| <h2 class="text-xl font-semibold mb-4 text-gray-800">Attendance Form</h2> | |
| <div class="mb-8"> | |
| <label class="block text-gray-700 font-bold text-lg mb-4">Will you be eating today? 🍽️</label> | |
| <div class="grid grid-cols-2 gap-4"> | |
| <label class="cursor-pointer"> | |
| <input type="radio" name="attendance" value="yes" class="hidden peer" checked> | |
| <div class="p-6 rounded-xl border-2 border-green-200 bg-green-50 text-green-800 peer-checked:bg-green-100 peer-checked:border-green-500 peer-checked:ring-2 peer-checked:ring-green-200 peer-checked:scale-[1.02] transition-all duration-200 hover:shadow-lg"> | |
| <div class="flex flex-col items-center"> | |
| <div class="text-4xl mb-2">✓</div> | |
| <div class="font-bold text-lg">Yes!</div> | |
| <div class="text-sm mt-1">I'll be eating</div> | |
| </div> | |
| </div> | |
| </label> | |
| <label class="cursor-pointer"> | |
| <input type="radio" name="attendance" value="no" class="hidden peer"> | |
| <div class="p-6 rounded-xl border-2 border-red-200 bg-red-50 text-red-800 peer-checked:bg-red-100 peer-checked:border-red-500 peer-checked:ring-2 peer-checked:ring-red-200 peer-checked:scale-[1.02] transition-all duration-200 hover:shadow-lg"> | |
| <div class="flex flex-col items-center"> | |
| <div class="text-4xl mb-2">✗</div> | |
| <div class="font-bold text-lg">No</div> | |
| <div class="text-sm mt-1">I won't be eating</div> | |
| </div> | |
| </div> | |
| </label> | |
| </div> | |
| </div> | |
| <div id="eating-details" class="space-y-4"> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| <div> | |
| <label for="class" class="block text-gray-700 font-medium mb-2">Class</label> | |
| <select id="class" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" onchange="loadStudents()"> | |
| <option value="">Select Class</option> | |
| </select> | |
| </div> | |
| <div> | |
| <label for="form" class="block text-gray-700 font-medium mb-2">Form</label> | |
| <select id="form" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" onchange="loadStudents()"> | |
| <option value="">Select Form</option> | |
| <option value="1">Form 1</option> | |
| <option value="2">Form 2</option> | |
| <option value="3">Form 3</option> | |
| <option value="4">Form 4</option> | |
| <option value="5">Form 5</option> | |
| </select> | |
| </div> | |
| </div> | |
| <div id="student-container" class="mt-4 hidden"> | |
| <label for="student" class="block text-gray-700 font-medium mb-2">Student Name</label> | |
| <select id="student" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-green-500" disabled> | |
| <option value="">Please select Class and Form first</option> | |
| </select> | |
| </div> | |
| </div> | |
| <div class="mt-6"> | |
| <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"> | |
| <i class="fas fa-paper-plane mr-2"></i> Submit Attendance | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Success Message --> | |
| <div id="success-message" class="hidden fade-in bg-green-50 border border-green-200 text-green-700 p-4 rounded-lg mb-8"> | |
| <div class="flex items-center mb-3"> | |
| <i class="fas fa-check-circle text-green-500 text-2xl mr-3"></i> | |
| <div> | |
| <h3 class="font-bold">Attendance Submitted Successfully!</h3> | |
| <p class="text-sm">Your dining hall attendance has been recorded.</p> | |
| </div> | |
| </div> | |
| <button id="fill-again-btn" class="w-full bg-green-600 hover:bg-green-700 text-white font-medium py-2 px-4 rounded transition duration-200"> | |
| <i class="fas fa-redo mr-2"></i> Fill Again | |
| </button> | |
| </div> | |
| <!-- Footer --> | |
| <footer class="text-center text-gray-600 text-sm mt-12"> | |
| <p>© 2025 Waste-Less Dining Hall Attendance System. All rights reserved.</p> | |
| <p class="mt-1">Data will be saved to <a href="https://github.com/SMSS-Waste-Less/Waste-LessV5/blob/main/Data%20Students%20who%20want%20to%20eat" class="text-green-600 hover:underline" target="_blank">GitHub repository</a></p> | |
| </footer> | |
| </div> | |
| <script src="config.js"></script> | |
| <script> | |
| // ===== RFID SYSTEM ===== | |
| let rfidMappings = {}; | |
| async function loadRfidMappings() { | |
| try { | |
| const response = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/${GITHUB_CONFIG.PATHS.RFID || 'rfid-mappings.json'}`, { | |
| headers: { | |
| 'Authorization': `token ${GITHUB_CONFIG.TOKEN}`, | |
| 'Accept': 'application/vnd.github.v3+json' | |
| } | |
| }); | |
| if (response.ok) { | |
| const data = await response.json(); | |
| rfidMappings = JSON.parse(atob(data.content)); | |
| } else if (response.status === 404) { | |
| rfidMappings = {}; | |
| } | |
| } catch (e) { | |
| console.error('Error loading RFID mappings:', e); | |
| rfidMappings = {}; | |
| } | |
| } | |
| async function handleRfidScan() { | |
| const rfidId = document.getElementById('rfid-input').value.trim(); | |
| if (!rfidId) return; | |
| if (!rfidMappings || Object.keys(rfidMappings).length === 0) { | |
| await loadRfidMappings(); | |
| } | |
| const mapping = rfidMappings[rfidId]; | |
| const statusDiv = document.getElementById('rfid-status'); | |
| if (mapping) { | |
| document.getElementById('class').value = mapping.class; | |
| document.getElementById('form').value = mapping.form; | |
| loadStudents(); | |
| setTimeout(() => { | |
| const studentSelect = document.getElementById('student'); | |
| for (let i = 0; i < studentSelect.options.length; i++) { | |
| if (studentSelect.options[i].value === mapping.studentName) { | |
| studentSelect.selectedIndex = i; | |
| break; | |
| } | |
| } | |
| }, 600); | |
| statusDiv.className = 'mt-3 p-3 bg-green-100 border border-green-300 rounded-lg text-green-700 flex items-center'; | |
| statusDiv.innerHTML = `<i class="fas fa-check-circle mr-2"></i> Card recognized: <strong>${mapping.studentName}</strong> (${mapping.class} Form ${mapping.form})`; | |
| statusDiv.classList.remove('hidden'); | |
| } else { | |
| statusDiv.className = 'mt-3 p-3 bg-red-100 border border-red-300 rounded-lg text-red-700 flex items-center'; | |
| statusDiv.innerHTML = `<i class="fas fa-exclamation-circle mr-2"></i> RFID card not found in system. Please use manual entry below.`; | |
| statusDiv.classList.remove('hidden'); | |
| } | |
| } | |
| document.getElementById('rfid-scan-btn').addEventListener('click', handleRfidScan); | |
| document.getElementById('rfid-input').addEventListener('keypress', function(e) { | |
| if (e.key === 'Enter') { | |
| e.preventDefault(); | |
| handleRfidScan(); | |
| } | |
| }); | |
| // ===== DYNAMIC STUDENT LIST ===== | |
| let students = {}; | |
| let availableClasses = []; | |
| async function loadStudentList() { | |
| try { | |
| const response = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.STUDENT_LIST || GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/student-list.json`, { | |
| headers: { | |
| 'Authorization': `token ${GITHUB_CONFIG.TOKEN}`, | |
| 'Accept': 'application/vnd.github.v3+json' | |
| } | |
| }); | |
| if (response.status === 404) { | |
| students = {}; | |
| availableClasses = []; | |
| updateClassDropdown(); | |
| return; | |
| } | |
| if (!response.ok) throw new Error('Failed to load student list'); | |
| const data = await response.json(); | |
| students = JSON.parse(atob(data.content)); | |
| availableClasses = [...new Set(Object.keys(students).map(key => key.split('-')[0]))].sort(); | |
| updateClassDropdown(); | |
| } catch (error) { | |
| console.error('Error loading student list:', error); | |
| alert('Could not load student list. Using empty list.'); | |
| students = {}; | |
| availableClasses = []; | |
| updateClassDropdown(); | |
| } | |
| loadStudents(); | |
| } | |
| function updateClassDropdown() { | |
| const classSelect = document.getElementById('class'); | |
| classSelect.innerHTML = '<option value="">Select Class</option>'; | |
| availableClasses.forEach(cls => { | |
| const opt = document.createElement('option'); | |
| opt.value = cls; | |
| opt.textContent = cls; | |
| classSelect.appendChild(opt); | |
| }); | |
| } | |
| function loadStudents() { | |
| const classVal = document.getElementById('class').value; | |
| const formVal = document.getElementById('form').value; | |
| const studentContainer = document.getElementById('student-container'); | |
| const studentSelect = document.getElementById('student'); | |
| studentSelect.innerHTML = '<option value="">Select Student</option>'; | |
| studentSelect.disabled = true; | |
| studentContainer.classList.add('hidden'); | |
| if (classVal && formVal) { | |
| const key = `${classVal}-${formVal}`; | |
| if (students[key] && students[key].length > 0) { | |
| students[key].forEach(name => { | |
| const option = document.createElement('option'); | |
| option.value = name; | |
| option.textContent = name; | |
| studentSelect.appendChild(option); | |
| }); | |
| studentSelect.disabled = false; | |
| studentContainer.classList.remove('hidden'); | |
| } else { | |
| studentSelect.innerHTML = '<option value="">No students found</option>'; | |
| } | |
| } | |
| } | |
| document.querySelectorAll('input[name="attendance"]').forEach(radio => { | |
| radio.addEventListener('change', loadStudents); | |
| }); | |
| window.addEventListener('load', loadStudentList); | |
| // ===== TIME & MEAL FUNCTIONS ===== | |
| function updateDateTime() { | |
| const now = new Date(); | |
| document.getElementById('current-time').textContent = now.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' }); | |
| document.getElementById('current-date').textContent = now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' }); | |
| const currentMeal = getCurrentMealTime(); | |
| document.getElementById('current-meal-display').textContent = currentMeal.charAt(0).toUpperCase() + currentMeal.slice(1); | |
| document.getElementById('current-meal-time-display').textContent = currentMeal.charAt(0).toUpperCase() + currentMeal.slice(1); | |
| const hours = now.getHours(); | |
| let nextMeal = ''; | |
| if (hours < 6) nextMeal = 'Breakfast (6:20 AM)'; | |
| else if (hours < 13) nextMeal = 'Lunch (1:30 PM)'; | |
| else if (hours < 17) nextMeal = 'Dinner (5:50 PM)'; | |
| else if (hours < 22) nextMeal = 'Supper (10:30 PM)'; | |
| else nextMeal = 'Breakfast (6:20 AM)'; | |
| document.getElementById('next-meal-time').textContent = nextMeal; | |
| document.getElementById('next-meal-time-display').textContent = nextMeal; | |
| } | |
| setInterval(updateDateTime, 1000); | |
| updateDateTime(); | |
| function getCurrentMealTime() { | |
| const now = new Date(); | |
| const hours = now.getHours(); | |
| const minutes = now.getMinutes(); | |
| if ((hours === 6 && minutes >= 20) || (hours === 6 && minutes <= 50)) return 'breakfast'; | |
| if ((hours === 13 && minutes >= 30) || (hours === 14 && minutes <= 30)) return 'lunch'; | |
| if ((hours === 17 && minutes >= 50) || hours === 18 || (hours === 19 && minutes <= 0)) return 'dinner'; | |
| if ((hours === 22 && minutes >= 30) || hours === 23) return 'supper'; | |
| if (hours < 6) return 'breakfast'; | |
| if (hours < 13) return 'lunch'; | |
| if (hours < 17) return 'dinner'; | |
| if (hours < 22) return 'supper'; | |
| return 'breakfast'; | |
| } | |
| function isCurrentTimeMealPeriod() { | |
| const now = new Date(); | |
| const hours = now.getHours(); | |
| const minutes = now.getMinutes(); | |
| return ( | |
| (hours === 6 && minutes >= 20 && minutes <= 50) || | |
| (hours === 13 && minutes >= 30 || hours === 14 && minutes <= 30) || | |
| (hours === 17 && minutes >= 50 || hours === 18 || (hours === 19 && minutes <= 0)) || | |
| (hours === 22 && minutes >= 30 || hours === 23) | |
| ); | |
| } | |
| const menus = { | |
| breakfast: { | |
| regular: ["Nasi Lemak with Fried Chicken", "Fried Noodles with Vegetables", "Fruits (Watermelon & Papaya)", "Teh Tarik / Coffee"], | |
| color: '#ca8a04', bg: 'linear-gradient(135deg, #fef9c3, #fef3c7)', border: '#fde68a', icon: 'fa-sun', name: 'Breakfast', | |
| time: '6:20 AM - 6:50 AM' | |
| }, | |
| lunch: { | |
| regular: ["Steamed Rice with Beef Rendang", "Stir-fried Vegetables", "Fish Ball Soup", "Fruits (Pineapple & Dragon Fruit)"], | |
| color: '#16a34a', bg: 'linear-gradient(135deg, #dcfce7, #d1fae5)', border: '#bbf7d0', icon: 'fa-utensils', name: 'Lunch', | |
| time: '1:30 PM - 2:30 PM' | |
| }, | |
| dinner: { | |
| regular: ["Fried Rice with Chicken Satay", "Mixed Vegetables", "Egg Drop Soup", "Fruits (Apple & Pear)"], | |
| color: '#4f46e5', bg: 'linear-gradient(135deg, #e0e7ff, #ddd6fe)', border: '#c7d2fe', icon: 'fa-moon', name: 'Dinner', | |
| time: '5:50 PM - 7:00 PM' | |
| }, | |
| supper: { | |
| regular: ["Sandwiches with Egg Mayo", "Milo and Biscuits", "Fruits (Banana)"], | |
| color: '#c026d3', bg: 'linear-gradient(135deg, #fce7f3, #f5d0fe)', border: '#fbcfe8', icon: 'fa-bed', name: 'Supper', | |
| time: '10:30 PM - 11:00 PM' | |
| } | |
| }; | |
| let selectedMeal = getCurrentMealTime(); | |
| function showMealMenu(mealTime) { | |
| selectedMeal = mealTime; | |
| const container = document.getElementById('menu-display-container'); | |
| container.classList.remove('hidden'); | |
| const mealData = menus[mealTime]; | |
| // Reset all meal cards | |
| document.querySelectorAll('.meal-card').forEach(btn => { | |
| btn.classList.remove('active'); | |
| btn.style.borderWidth = '2px'; | |
| btn.style.borderColor = mealData.border; // restore original | |
| }); | |
| // Highlight selected | |
| const selectedBtn = document.querySelector(`.meal-card[data-meal="${mealTime}"]`); | |
| if (selectedBtn) { | |
| selectedBtn.classList.add('active'); | |
| selectedBtn.style.borderColor = mealData.color; | |
| selectedBtn.style.borderWidth = '3px'; | |
| } | |
| // Update meal icon | |
| const mealIcon = document.getElementById('meal-period-icon'); | |
| mealIcon.innerHTML = `<i class="fas ${mealData.icon}" style="color: ${mealData.color}"></i>`; | |
| updateMenuDisplay(mealTime); | |
| document.getElementById('selected-meal-time-display').innerHTML = | |
| `<i class="fas ${mealData.icon} mr-3" style="color: ${mealData.color}"></i>` + | |
| `<span class="font-bold" style="color: ${mealData.color}">${mealData.name} (${mealData.time})</span>`; | |
| document.getElementById('default-menu-message').classList.add('hidden'); | |
| document.getElementById('attendance-form').classList.remove('hidden'); | |
| } | |
| function updateMenuDisplay(mealTime) { | |
| const regularMenu = document.getElementById('regular-menu'); | |
| const mealData = menus[mealTime]; | |
| regularMenu.innerHTML = ''; | |
| mealData.regular.forEach((item, index) => { | |
| const div = document.createElement('div'); | |
| div.className = 'flex items-center p-3 rounded-lg hover:bg-white/50 transition-colors'; | |
| div.style.background = index % 2 === 0 ? 'rgba(255,255,255,0.4)' : 'transparent'; | |
| div.innerHTML = ` | |
| <div class="w-8 h-8 rounded-full flex items-center justify-center mr-3 flex-shrink-0" style="background: ${mealData.color}15;"> | |
| <i class="fas fa-circle text-xs" style="color: ${mealData.color}"></i> | |
| </div> | |
| <span class="font-medium text-gray-700">${item}</span> | |
| `; | |
| regularMenu.appendChild(div); | |
| }); | |
| const menuDisplay = document.getElementById('menu-display'); | |
| menuDisplay.style.borderColor = mealData.border; | |
| } | |
| if (isCurrentTimeMealPeriod()) { | |
| showMealMenu(getCurrentMealTime()); | |
| } else { | |
| document.getElementById('menu-display-container').classList.add('hidden'); | |
| } | |
| // ===== SUBMISSION ===== | |
| document.getElementById('submit-btn').addEventListener('click', async function() { | |
| this.disabled = true; | |
| this.innerHTML = '<i class="fas fa-spinner fa-spin mr-2"></i> Submitting...'; | |
| const studentClass = document.getElementById('class').value; | |
| const form = document.getElementById('form').value; | |
| const student = document.getElementById('student').value; | |
| const attendance = document.querySelector('input[name="attendance"]:checked').value; | |
| if (!student) { | |
| alert('Please select your name'); | |
| this.disabled = false; | |
| this.innerHTML = '<i class="fas fa-paper-plane mr-2"></i> Submit Attendance'; | |
| return; | |
| } | |
| if (!studentClass || !form) { | |
| alert('Please select class and form'); | |
| this.disabled = false; | |
| this.innerHTML = '<i class="fas fa-paper-plane mr-2"></i> Submit Attendance'; | |
| return; | |
| } | |
| const data = { | |
| timestamp: new Date().toISOString(), | |
| mealTime: getCurrentMealTime(), | |
| attendance: attendance, | |
| class: studentClass, | |
| form: form, | |
| studentName: student | |
| }; | |
| try { | |
| const success = await sendDataToGitHub(data); | |
| if (success) { | |
| document.getElementById('attendance-form').classList.add('hidden'); | |
| document.getElementById('success-message').classList.remove('hidden'); | |
| document.getElementById('success-message').classList.add('fade-in'); | |
| } | |
| } catch (error) { | |
| alert('Failed to submit: ' + error.message); | |
| } finally { | |
| this.disabled = false; | |
| this.innerHTML = '<i class="fas fa-paper-plane mr-2"></i> Submit Attendance'; | |
| } | |
| }); | |
| async function sendDataToGitHub(data) { | |
| try { | |
| let currentContent = ''; | |
| let sha = ''; | |
| const filePath = 'Data%20Students%20who%20want%20to%20eat'; | |
| const repoUrl = `https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/${filePath}`; | |
| const getResponse = await fetch(repoUrl, { | |
| headers: { | |
| 'Authorization': `token ${GITHUB_CONFIG.TOKEN}`, | |
| 'Accept': 'application/vnd.github.v3+json' | |
| } | |
| }); | |
| if (getResponse.ok) { | |
| const fileData = await getResponse.json(); | |
| sha = fileData.sha; | |
| currentContent = atob(fileData.content); | |
| } else if (getResponse.status !== 404) { | |
| throw new Error('Failed to fetch existing data'); | |
| } | |
| const record = JSON.stringify(data); | |
| const newContent = currentContent + record + '\n'; | |
| const response = await fetch(repoUrl, { | |
| method: 'PUT', | |
| headers: { | |
| 'Authorization': `token ${GITHUB_CONFIG.TOKEN}`, | |
| 'Content-Type': 'application/json', | |
| 'Accept': 'application/vnd.github.v3+json' | |
| }, | |
| body: JSON.stringify({ | |
| message: `Attendance record - ${new Date().toLocaleString()}`, | |
| content: btoa(newContent), | |
| sha: sha || undefined, | |
| branch: 'main' | |
| }) | |
| }); | |
| if (!response.ok) { | |
| const errorData = await response.json(); | |
| throw new Error(errorData.message || 'Submission failed'); | |
| } | |
| return true; | |
| } catch (error) { | |
| console.error('Submission error:', error); | |
| throw new Error('Failed to submit attendance: ' + error.message); | |
| } | |
| } | |
| function resetForm() { | |
| document.getElementById('class').value = ''; | |
| document.getElementById('form').value = ''; | |
| document.getElementById('student').innerHTML = '<option value="">Select Student</option>'; | |
| document.getElementById('student').disabled = true; | |
| document.getElementById('student-container').classList.add('hidden'); | |
| document.querySelector('input[name="attendance"][value="yes"]').checked = true; | |
| document.getElementById('success-message').classList.add('hidden'); | |
| document.getElementById('attendance-form').classList.remove('hidden'); | |
| document.getElementById('rfid-input').value = ''; | |
| document.getElementById('rfid-status').classList.add('hidden'); | |
| if (isCurrentTimeMealPeriod()) { | |
| document.getElementById('menu-display-container').classList.remove('hidden'); | |
| } else { | |
| document.getElementById('menu-display-container').classList.add('hidden'); | |
| } | |
| } | |
| document.getElementById('fill-again-btn').addEventListener('click', resetForm); | |
| setInterval(() => { | |
| const currentMeal = getCurrentMealTime(); | |
| if (currentMeal !== selectedMeal) { | |
| selectedMeal = currentMeal; | |
| if (!document.getElementById('menu-display-container').classList.contains('hidden')) { | |
| updateMenuDisplay(selectedMeal); | |
| } | |
| } | |
| }, 60000); | |
| </script> | |
| </body> | |
| </html> |