diff --git a/static/admin.html b/static/admin.html index 7c40056..905d01f 100644 --- a/static/admin.html +++ b/static/admin.html @@ -49,23 +49,80 @@

User Management

-
- - - - - - - - - - - - - - - -
IDUsernameEmailCategoryIs AdminIs ActiveTotal PointsCreated AtActions
+ + + + +
+ +
+
+ + + + + + + + + + + + + +
IDUsernameEmailCategoryTotal PointsCreated AtActions
+
+
+ + +
+
+ + + + + + + + + + + + + +
IDUsernameEmailCategoryTotal PointsCreated AtActions
+
+
+ + +
+
+ + + + + + + + + + + + + +
IDUsernameEmailCategoryTotal PointsCreated AtActions
+
+
diff --git a/static/js/admin/users.js b/static/js/admin/users.js index 46eac8b..596ecf7 100644 --- a/static/js/admin/users.js +++ b/static/js/admin/users.js @@ -10,13 +10,17 @@ export function setCurrentUser(user) { } export async function loadUsers() { - const tbody = document.getElementById('usersTable'); - if (!tbody) return; + const adminsTable = document.getElementById('adminsTable'); + const activeStudentsTable = document.getElementById('activeStudentsTable'); + const inactiveStudentsTable = document.getElementById('inactiveStudentsTable'); + if (!adminsTable || !activeStudentsTable || !inactiveStudentsTable) return; try { console.log('Loading users with X-User-ID:', currentUser.id.toString()); const users = await API.get('/admin/users'); console.log('Loaded users:', users.length, 'users'); - tbody.innerHTML = ''; + adminsTable.innerHTML = ''; + activeStudentsTable.innerHTML = ''; + inactiveStudentsTable.innerHTML = ''; users.forEach(user => { const row = document.createElement('tr'); @@ -25,8 +29,6 @@ export async function loadUsers() { ${escapeHtml(user.username)} ${escapeHtml(user.email)} ${escapeHtml(normalizeCategory(user.category))} - ${user.is_admin ? 'Yes' : 'No'} - ${user.is_active ? 'Yes' : 'No'} ${user.total_points} ${new Date(user.created_at).toLocaleDateString()} @@ -35,11 +37,20 @@ export async function loadUsers() { ${user.id === currentUser.id ? 'disabled' : ''}>Delete `; - tbody.appendChild(row); + if (user.is_admin) { + adminsTable.appendChild(row); + } else if (user.is_active) { + activeStudentsTable.appendChild(row); + } else { + inactiveStudentsTable.appendChild(row); + } }); } catch (error) { console.error('Error loading users:', error); - tbody.innerHTML = 'Failed to load users. Please refresh the page to try again.'; + const msg = 'Failed to load users. Please refresh the page to try again.'; + if (adminsTable) adminsTable.innerHTML = msg; + if (activeStudentsTable) activeStudentsTable.innerHTML = msg; + if (inactiveStudentsTable) inactiveStudentsTable.innerHTML = msg; } }