EHDEM commited on
Commit
5f0e8ab
·
verified ·
1 Parent(s): e229ac1

make the student data table in admin dashboard functional

Browse files
Files changed (1) hide show
  1. admin-dashboard.html +157 -72
admin-dashboard.html CHANGED
@@ -81,56 +81,74 @@
81
  </div>
82
  <!-- Attendance Data Tables -->
83
  <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
84
- <!-- Form A Data -->
85
- <div class="bg-white rounded-lg shadow-md p-6">
86
- <h2 class="text-xl font-semibold mb-4 text-gray-800">Students Who Want To Eat</h2>
87
- <div class="overflow-x-auto max-h-96 overflow-y-auto">
88
- <table class="min-w-full divide-y divide-gray-200">
89
- <thead class="bg-gray-50 sticky top-0">
90
- <tr>
91
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Student</th>
92
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Class</th>
93
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Meal</th>
94
- </tr>
95
- </thead>
96
- <tbody class="bg-white divide-y divide-gray-200" id="formAData">
97
- <!-- Data will be loaded here -->
98
- </tbody>
99
- </table>
100
- </div>
101
- <div class="mt-4 text-sm text-gray-500">
102
- <a href="https://github.com/SMSS-Waste-Less/Waste-LessV5/blob/main/Data%20Students%20who%20want%20to%20eat"
103
- target="_blank" class="text-blue-600 hover:underline">
104
- View full data on GitHub
105
- </a>
 
 
 
 
 
 
 
 
 
 
106
  </div>
107
- </div>
108
 
109
- <!-- Form B Data -->
110
- <div class="bg-white rounded-lg shadow-md p-6">
111
- <h2 class="text-xl font-semibold mb-4 text-gray-800">Students Who Have Eaten</h2>
112
- <div class="overflow-x-auto max-h-96 overflow-y-auto">
113
- <table class="min-w-full divide-y divide-gray-200">
114
- <thead class="bg-gray-50 sticky top-0">
115
- <tr>
116
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Student</th>
117
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Class</th>
118
- <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Meal</th>
119
- </tr>
120
- </thead>
121
- <tbody class="bg-white divide-y divide-gray-200" id="formBData">
122
- <!-- Data will be loaded here -->
123
- </tbody>
124
- </table>
125
- </div>
126
- <div class="mt-4 text-sm text-gray-500">
127
- <a href="https://github.com/WaffleExecutors/Waste-LessV5/blob/main/data%20who%20has%20ate%20at%20dm"
128
- target="_blank" class="text-blue-600 hover:underline">
129
- View full data on GitHub
130
- </a>
 
 
 
 
 
 
 
 
 
 
131
  </div>
132
- </div>
133
- </div>
134
  <!-- Charts and Recent Activity -->
135
  <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
136
  <!-- Attendance Trend -->
@@ -165,32 +183,68 @@
165
 
166
  // Update last activity time
167
  localStorage.setItem('lastLogin', new Date().toISOString());
168
- // Fetch and display attendance data
169
- async function fetchAttendanceData() {
170
  try {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  // Fetch Form A data (Students who want to eat)
172
  const formAResponse = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/Data%20Students%20who%20want%20to%20eat`, {
173
  headers: {
174
  'Authorization': `token ${GITHUB_CONFIG.TOKEN}`
175
  }
176
  });
177
- const formAData = await formAResponse.json();
 
 
 
178
  const formAContent = atob(formAData.content);
179
 
180
  // Parse and display Form A data
181
  const formARows = formAContent.split('\n')
182
  .filter(line => line.trim() !== '')
183
  .map(line => {
184
- const record = JSON.parse(line);
185
- return `
186
- <tr>
187
- <td class="px-4 py-2 whitespace-nowrap text-sm">${record.studentName}</td>
188
- <td class="px-4 py-2 whitespace-nowrap text-sm">${record.class} ${record.form}</td>
189
- <td class="px-4 py-2 whitespace-nowrap text-sm">${record.mealTime.charAt(0).toUpperCase() + record.mealTime.slice(1)}</td>
190
- </tr>
191
- `;
 
 
 
 
 
 
 
 
 
 
192
  }).join('');
193
- document.getElementById('formAData').innerHTML = formARows;
 
 
 
 
 
194
 
195
  // Fetch Form B data (Students who have eaten)
196
  const formBResponse = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.CONSUMED}/contents/data%20who%20has%20ate%20at%20dm`, {
@@ -198,42 +252,73 @@ const formAData = await formAResponse.json();
198
  'Authorization': `token ${GITHUB_CONFIG.TOKEN}`
199
  }
200
  });
201
- const formBData = await formBResponse.json();
 
 
 
202
  const formBContent = atob(formBData.content);
203
 
204
  // Parse and display Form B data
205
  const formBRows = formBContent.split('\n')
206
  .filter(line => line.trim() !== '')
207
  .map(line => {
208
- const record = JSON.parse(line);
209
- return `
210
- <tr>
211
- <td class="px-4 py-2 whitespace-nowrap text-sm">${record.studentName}</td>
212
- <td class="px-4 py-2 whitespace-nowrap text-sm">${record.class} ${record.form}</td>
213
- <td class="px-4 py-2 whitespace-nowrap text-sm">${record.mealTime.charAt(0).toUpperCase() + record.mealTime.slice(1)}</td>
214
- </tr>
215
- `;
 
 
 
 
 
 
 
 
 
 
216
  }).join('');
217
- document.getElementById('formBData').innerHTML = formBRows;
 
 
 
 
 
 
218
  } catch (error) {
219
  console.error('Error fetching attendance data:', error);
220
  document.getElementById('formAData').innerHTML = `
221
  <tr>
222
- <td colspan="3" class="px-4 py-2 text-sm text-red-500">Failed to load data. Please try again later.</td>
223
  </tr>
224
  `;
225
  document.getElementById('formBData').innerHTML = `
226
  <tr>
227
- <td colspan="3" class="px-4 py-2 text-sm text-red-500">Failed to load data. Please try again later.</td>
228
  </tr>
229
  `;
230
  }
231
  }
232
-
233
  // Initialize charts and fetch data
234
  document.addEventListener('DOMContentLoaded', async function() {
235
  // Fetch attendance data first
236
  await fetchAttendanceData();
 
 
 
 
 
 
 
 
 
 
 
 
 
237
  // Attendance Trend Chart
238
  const attendanceCtx = document.getElementById('attendanceChart').getContext('2d');
239
  const attendanceChart = new Chart(attendanceCtx, {
 
81
  </div>
82
  <!-- Attendance Data Tables -->
83
  <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
84
+ <!-- Form A Data -->
85
+ <div class="bg-white rounded-lg shadow-md p-6">
86
+ <div class="flex justify-between items-center mb-4">
87
+ <h2 class="text-xl font-semibold text-gray-800">Students Who Want To Eat</h2>
88
+ <button id="refresh-formA" class="text-blue-600 hover:text-blue-800">
89
+ <i class="fas fa-sync-alt mr-1"></i> Refresh
90
+ </button>
91
+ </div>
92
+ <div class="overflow-x-auto max-h-96 overflow-y-auto">
93
+ <table class="min-w-full divide-y divide-gray-200">
94
+ <thead class="bg-gray-50 sticky top-0">
95
+ <tr>
96
+ <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Student</th>
97
+ <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Class</th>
98
+ <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Form</th>
99
+ <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Meal</th>
100
+ <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Time</th>
101
+ </tr>
102
+ </thead>
103
+ <tbody class="bg-white divide-y divide-gray-200" id="formAData">
104
+ <tr>
105
+ <td colspan="5" class="px-4 py-4 text-center text-gray-500">Loading data...</td>
106
+ </tr>
107
+ </tbody>
108
+ </table>
109
+ </div>
110
+ <div class="mt-4 text-sm text-gray-500">
111
+ <a href="https://github.com/SMSS-Waste-Less/Waste-LessV5/blob/main/Data%20Students%20who%20want%20to%20eat"
112
+ target="_blank" class="text-blue-600 hover:underline">
113
+ View full data on GitHub
114
+ </a>
115
+ </div>
116
  </div>
 
117
 
118
+ <!-- Form B Data -->
119
+ <div class="bg-white rounded-lg shadow-md p-6">
120
+ <div class="flex justify-between items-center mb-4">
121
+ <h2 class="text-xl font-semibold text-gray-800">Students Who Have Eaten</h2>
122
+ <button id="refresh-formB" class="text-blue-600 hover:text-blue-800">
123
+ <i class="fas fa-sync-alt mr-1"></i> Refresh
124
+ </button>
125
+ </div>
126
+ <div class="overflow-x-auto max-h-96 overflow-y-auto">
127
+ <table class="min-w-full divide-y divide-gray-200">
128
+ <thead class="bg-gray-50 sticky top-0">
129
+ <tr>
130
+ <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Student</th>
131
+ <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Class</th>
132
+ <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Form</th>
133
+ <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Meal</th>
134
+ <th class="px-4 py-2 text-left text-xs font-medium text-gray-500 uppercase">Time</th>
135
+ </tr>
136
+ </thead>
137
+ <tbody class="bg-white divide-y divide-gray-200" id="formBData">
138
+ <tr>
139
+ <td colspan="5" class="px-4 py-4 text-center text-gray-500">Loading data...</td>
140
+ </tr>
141
+ </tbody>
142
+ </table>
143
+ </div>
144
+ <div class="mt-4 text-sm text-gray-500">
145
+ <a href="https://github.com/WaffleExecutors/Waste-LessV5/blob/main/data%20who%20has%20ate%20at%20dm"
146
+ target="_blank" class="text-blue-600 hover:underline">
147
+ View full data on GitHub
148
+ </a>
149
+ </div>
150
  </div>
151
+ </div>
 
152
  <!-- Charts and Recent Activity -->
153
  <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
154
  <!-- Attendance Trend -->
 
183
 
184
  // Update last activity time
185
  localStorage.setItem('lastLogin', new Date().toISOString());
186
+ // Fetch and display attendance data
187
+ async function fetchAttendanceData() {
188
  try {
189
+ // Show loading state
190
+ document.getElementById('formAData').innerHTML = `
191
+ <tr>
192
+ <td colspan="5" class="px-4 py-4 text-center text-gray-500">
193
+ <div class="inline-block animate-spin rounded-full h-6 w-6 border-t-2 border-b-2 border-blue-500 mr-2"></div>
194
+ Loading data...
195
+ </td>
196
+ </tr>
197
+ `;
198
+ document.getElementById('formBData').innerHTML = `
199
+ <tr>
200
+ <td colspan="5" class="px-4 py-4 text-center text-gray-500">
201
+ <div class="inline-block animate-spin rounded-full h-6 w-6 border-t-2 border-b-2 border-blue-500 mr-2"></div>
202
+ Loading data...
203
+ </td>
204
+ </tr>
205
+ `;
206
+
207
  // Fetch Form A data (Students who want to eat)
208
  const formAResponse = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.ATTENDANCE}/contents/Data%20Students%20who%20want%20to%20eat`, {
209
  headers: {
210
  'Authorization': `token ${GITHUB_CONFIG.TOKEN}`
211
  }
212
  });
213
+
214
+ if (!formAResponse.ok) throw new Error(`Failed to fetch Form A data: ${formAResponse.status}`);
215
+
216
+ const formAData = await formAResponse.json();
217
  const formAContent = atob(formAData.content);
218
 
219
  // Parse and display Form A data
220
  const formARows = formAContent.split('\n')
221
  .filter(line => line.trim() !== '')
222
  .map(line => {
223
+ try {
224
+ const record = JSON.parse(line);
225
+ const date = new Date(record.timestamp);
226
+ const timeString = date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
227
+
228
+ return `
229
+ <tr class="hover:bg-gray-50">
230
+ <td class="px-4 py-2 whitespace-nowrap text-sm">${record.studentName}</td>
231
+ <td class="px-4 py-2 whitespace-nowrap text-sm">${record.class}</td>
232
+ <td class="px-4 py-2 whitespace-nowrap text-sm">${record.form}</td>
233
+ <td class="px-4 py-2 whitespace-nowrap text-sm capitalize">${record.mealTime}</td>
234
+ <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-500">${timeString}</td>
235
+ </tr>
236
+ `;
237
+ } catch (e) {
238
+ console.error('Error parsing record:', e);
239
+ return '';
240
+ }
241
  }).join('');
242
+
243
+ document.getElementById('formAData').innerHTML = formARows || `
244
+ <tr>
245
+ <td colspan="5" class="px-4 py-4 text-center text-gray-500">No attendance records found</td>
246
+ </tr>
247
+ `;
248
 
249
  // Fetch Form B data (Students who have eaten)
250
  const formBResponse = await fetch(`https://api.github.com/repos/${GITHUB_CONFIG.REPOS.CONSUMED}/contents/data%20who%20has%20ate%20at%20dm`, {
 
252
  'Authorization': `token ${GITHUB_CONFIG.TOKEN}`
253
  }
254
  });
255
+
256
+ if (!formBResponse.ok) throw new Error(`Failed to fetch Form B data: ${formBResponse.status}`);
257
+
258
+ const formBData = await formBResponse.json();
259
  const formBContent = atob(formBData.content);
260
 
261
  // Parse and display Form B data
262
  const formBRows = formBContent.split('\n')
263
  .filter(line => line.trim() !== '')
264
  .map(line => {
265
+ try {
266
+ const record = JSON.parse(line);
267
+ const date = new Date(record.timestamp);
268
+ const timeString = date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit' });
269
+
270
+ return `
271
+ <tr class="hover:bg-gray-50">
272
+ <td class="px-4 py-2 whitespace-nowrap text-sm">${record.studentName}</td>
273
+ <td class="px-4 py-2 whitespace-nowrap text-sm">${record.class}</td>
274
+ <td class="px-4 py-2 whitespace-nowrap text-sm">${record.form}</td>
275
+ <td class="px-4 py-2 whitespace-nowrap text-sm capitalize">${record.mealTime}</td>
276
+ <td class="px-4 py-2 whitespace-nowrap text-sm text-gray-500">${timeString}</td>
277
+ </tr>
278
+ `;
279
+ } catch (e) {
280
+ console.error('Error parsing record:', e);
281
+ return '';
282
+ }
283
  }).join('');
284
+
285
+ document.getElementById('formBData').innerHTML = formBRows || `
286
+ <tr>
287
+ <td colspan="5" class="px-4 py-4 text-center text-gray-500">No attendance records found</td>
288
+ </tr>
289
+ `;
290
+
291
  } catch (error) {
292
  console.error('Error fetching attendance data:', error);
293
  document.getElementById('formAData').innerHTML = `
294
  <tr>
295
+ <td colspan="5" class="px-4 py-4 text-sm text-red-500">Failed to load data: ${error.message}</td>
296
  </tr>
297
  `;
298
  document.getElementById('formBData').innerHTML = `
299
  <tr>
300
+ <td colspan="5" class="px-4 py-4 text-sm text-red-500">Failed to load data: ${error.message}</td>
301
  </tr>
302
  `;
303
  }
304
  }
 
305
  // Initialize charts and fetch data
306
  document.addEventListener('DOMContentLoaded', async function() {
307
  // Fetch attendance data first
308
  await fetchAttendanceData();
309
+
310
+ // Add refresh button handlers
311
+ document.getElementById('refresh-formA').addEventListener('click', async function() {
312
+ this.innerHTML = '<i class="fas fa-spinner fa-spin mr-1"></i> Refreshing...';
313
+ await fetchAttendanceData();
314
+ this.innerHTML = '<i class="fas fa-sync-alt mr-1"></i> Refresh';
315
+ });
316
+
317
+ document.getElementById('refresh-formB').addEventListener('click', async function() {
318
+ this.innerHTML = '<i class="fas fa-spinner fa-spin mr-1"></i> Refreshing...';
319
+ await fetchAttendanceData();
320
+ this.innerHTML = '<i class="fas fa-sync-alt mr-1"></i> Refresh';
321
+ });
322
  // Attendance Trend Chart
323
  const attendanceCtx = document.getElementById('attendanceChart').getContext('2d');
324
  const attendanceChart = new Chart(attendanceCtx, {