Spaces:
Running
Running
Download side-menu.js from EHDEM/wastlessv6test2: direct link, hf CLI and curl.
- Browser
- Download file 7.65 kB
-
https://huggingface.co/spaces/EHDEM/wastlessv6test2/resolve/main/side-menu.js
- Command line
-
hf download hf://spaces/EHDEM/wastlessv6test2/side-menu.js
-
curl -L -o side-menu.js https://huggingface.co/spaces/EHDEM/wastlessv6test2/resolve/main/side-menu.js
7.65 kB
| class SideMenu extends HTMLElement { | |
| constructor() { | |
| super(); | |
| this.attachShadow({ mode: 'open' | |
| } | |
| constructor() { | |
| super(); | |
| this.attachShadow({ mode: 'open' }); | |
| // ... existing constructor code ... | |
| // Load student data when class/form changes | |
| this.shadowRoot.querySelector('#class-select').addEventListener('change', this.loadStudents.bind(this)); | |
| this.shadowRoot.querySelector('#form-select').addEventListener('change', this.loadStudents.bind(this)); | |
| this.shadowRoot.querySelector('#submit-attendance').addEventListener('click', this.submitAttendance.bind(this)); | |
| } | |
| loadStudents() { | |
| const classVal = this.shadowRoot.querySelector('#class-select').value; | |
| const formVal = this.shadowRoot.querySelector('#form-select').value; | |
| const studentSelect = this.shadowRoot.querySelector('#student-select'); | |
| studentSelect.innerHTML = '<option value="">Select Student</option>'; | |
| studentSelect.disabled = true; | |
| if (classVal && formVal) { | |
| const key = `${classVal}-${formVal}`; | |
| if (students[key]) { | |
| students[key].forEach(student => { | |
| const option = document.createElement('option'); | |
| option.value = student; | |
| option.textContent = student; | |
| studentSelect.appendChild(option); | |
| }); | |
| studentSelect.disabled = false; | |
| } | |
| } | |
| } | |
| submitAttendance() { | |
| const classVal = this.shadowRoot.querySelector('#class-select').value; | |
| const formVal = this.shadowRoot.querySelector('#form-select').value; | |
| const studentVal = this.shadowRoot.querySelector('#student-select').value; | |
| const attendance = this.shadowRoot.querySelector('input[name="attendance"]:checked').value; | |
| if (!classVal || !formVal) { | |
| alert('Please select both class and form'); | |
| return; | |
| } | |
| if (attendance === 'yes' && !studentVal) { | |
| alert('Please select a student'); | |
| return; | |
| } | |
| // Create attendance record | |
| const record = { | |
| timestamp: new Date().toISOString(), | |
| mealTime: getCurrentMealTime(), | |
| attendance: attendance, | |
| class: classVal, | |
| form: formVal, | |
| studentName: attendance === 'yes' ? studentVal : 'N/A' | |
| }; | |
| // Save to localStorage | |
| let records = JSON.parse(localStorage.getItem('attendanceRecords') || '[]'); | |
| records.push(record); | |
| localStorage.setItem('attendanceRecords', JSON.stringify(records)); | |
| alert('Attendance submitted successfully!'); | |
| this.fetchAttendanceData(); | |
| } | |
| ); | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| :host { | |
| position: fixed; | |
| top: 0; | |
| left: -300px; | |
| width: 300px; | |
| height: 100vh; | |
| background: white; | |
| box-shadow: 2px 0 10px rgba(0,0,0,0.1); | |
| transition: left 0.3s ease; | |
| z-index: 1000; | |
| padding: 20px; | |
| box-sizing: border-box; | |
| display: flex; | |
| flex-direction: column; | |
| } | |
| :host(.open) { | |
| left: 0; | |
| } | |
| .close-btn { | |
| position: absolute; | |
| top: 10px; | |
| right: 10px; | |
| background: none; | |
| border: none; | |
| font-size: 20px; | |
| cursor: pointer; | |
| } | |
| h2 { | |
| margin-top: 0; | |
| color: #3b82f6; | |
| padding-bottom: 10px; | |
| border-bottom: 1px solid #eee; | |
| } | |
| .section { | |
| margin: 15px 0; | |
| padding-bottom: 15px; | |
| border-bottom: 1px solid #eee; | |
| } | |
| .section:last-child { | |
| border-bottom: none; | |
| } | |
| .section-title { | |
| font-weight: bold; | |
| margin-bottom: 10px; | |
| display: flex; | |
| align-items: center; | |
| } | |
| .section-title i { | |
| margin-right: 8px; | |
| color: #3b82f6; | |
| } | |
| .student-list { | |
| max-height: 200px; | |
| overflow-y: auto; | |
| } | |
| .student-item { | |
| padding: 8px; | |
| margin: 4px 0; | |
| background: #f5f5f5; | |
| border-radius: 4px; | |
| } | |
| input, button { | |
| width: 100%; | |
| padding: 8px; | |
| margin: 5px 0; | |
| border: 1px solid #ddd; | |
| border-radius: 4px; | |
| } | |
| button { | |
| background: #3b82f6; | |
| color: white; | |
| border: none; | |
| cursor: pointer; | |
| } | |
| .admin-section { | |
| display: none; | |
| } | |
| .stat-item { | |
| display: flex; | |
| justify-content: space-between; | |
| margin-bottom: 8px; | |
| } | |
| </style> | |
| <div> | |
| <button class="close-btn">×</button> | |
| <h2>Dining Hall Menu</h2> | |
| <!-- Attendance Form --> | |
| <div class="section"> | |
| <div class="section-title"><i class="fas fa-edit"></i> Attendance Form</div> | |
| <div class="form-group"> | |
| <label>Will you be eating?</label> | |
| <div class="radio-group"> | |
| <label> | |
| <input type="radio" name="attendance" value="yes" checked> Yes | |
| </label> | |
| <label> | |
| <input type="radio" name="attendance" value="no"> No | |
| </label> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <select id="class-select" class="form-control"> | |
| <option value="">Select Class</option> | |
| <option value="BUDI">BUDI</option> | |
| <option value="USAHA">USAHA</option> | |
| <option value="MAJU">MAJU</option> | |
| <option value="JAYA">JAYA</option> | |
| </select> | |
| </div> | |
| <div class="form-group"> | |
| <select id="form-select" class="form-control"> | |
| <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 class="form-group"> | |
| <select id="student-select" class="form-control" disabled> | |
| <option value="">Select Student</option> | |
| </select> | |
| </div> | |
| <button id="submit-attendance" class="submit-btn">Submit</button> | |
| </div> | |
| <!-- Students Who Want to Eat --> | |
| <div class="section"> | |
| <div class="section-title"><i class="fas fa-utensils"></i> Will Eat Today</div> | |
| <div class="student-list" id="want-to-eat-list"> | |
| <div class="student-item">No data available</div> | |
| </div> | |
| </div> | |
| <!-- Students Who Have Eaten --> | |
| <div class="section"> | |
| <div class="section-title"><i class="fas fa-check-circle"></i> Have Eaten Today</div> | |
| <div class="student-list" id="have-eaten-list"> | |
| <div class="student-item">No data available</div> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| } | |
| connectedCallback() { | |
| this.shadowRoot.querySelector('.close-btn').addEventListener('click', () => { | |
| this.classList.remove('open'); | |
| }); | |
| } | |
| updateStudentList(listId, students) { | |
| const list = this.shadowRoot.querySelector(`#${listId}`); | |
| list.innerHTML = ''; | |
| if (students.length === 0) { | |
| list.innerHTML = '<div class="student-item">No data available</div>'; | |
| return; | |
| } | |
| students.forEach(student => { | |
| const item = document.createElement('div'); | |
| item.className = 'student-item'; | |
| item.textContent = `${student.studentName} (${student.class} ${student.form})`; | |
| list.appendChild(item); | |
| }); | |
| } | |
| } | |
| customElements.define('side-menu', SideMenu); |