Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 74 additions & 17 deletions static/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,80 @@
<h2>User Management</h2>
<button class="btn btn-primary" onclick="showCreateUserModal()">Add User</button>
</div>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Category</th>
<th>Is Admin</th>
<th>Is Active</th>
<th>Total Points</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="usersTable"></tbody>
</table>

<!-- User tabs -->
<ul class="nav nav-tabs mb-3" id="userTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="admins-tab" data-bs-toggle="tab" data-bs-target="#admins-pane" type="button" role="tab" aria-controls="admins-pane" aria-selected="true">Admins</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="active-students-tab" data-bs-toggle="tab" data-bs-target="#active-students-pane" type="button" role="tab" aria-controls="active-students-pane" aria-selected="false">Active Students</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="inactive-students-tab" data-bs-toggle="tab" data-bs-target="#inactive-students-pane" type="button" role="tab" aria-controls="inactive-students-pane" aria-selected="false">Inactive Students</button>
</li>
</ul>

<div class="tab-content" id="userTabsContent">
<!-- Admins Tab -->
<div class="tab-pane fade show active" id="admins-pane" role="tabpanel" aria-labelledby="admins-tab">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Category</th>
<th>Total Points</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="adminsTable"></tbody>
</table>
</div>
</div>

<!-- Active Students Tab -->
<div class="tab-pane fade" id="active-students-pane" role="tabpanel" aria-labelledby="active-students-tab">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Category</th>
<th>Total Points</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="activeStudentsTable"></tbody>
</table>
</div>
</div>

<!-- Inactive Students Tab -->
<div class="tab-pane fade" id="inactive-students-pane" role="tabpanel" aria-labelledby="inactive-students-tab">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
<th>Category</th>
<th>Total Points</th>
<th>Created At</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="inactiveStudentsTable"></tbody>
</table>
</div>
</div>
</div>
</div>

Expand Down
25 changes: 18 additions & 7 deletions static/js/admin/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -25,8 +29,6 @@ export async function loadUsers() {
<td>${escapeHtml(user.username)}</td>
<td>${escapeHtml(user.email)}</td>
<td>${escapeHtml(normalizeCategory(user.category))}</td>
<td>${user.is_admin ? 'Yes' : 'No'}</td>
<td>${user.is_active ? 'Yes' : 'No'}</td>
<td>${user.total_points}</td>
<td>${new Date(user.created_at).toLocaleDateString()}</td>
<td>
Expand All @@ -35,11 +37,20 @@ export async function loadUsers() {
${user.id === currentUser.id ? 'disabled' : ''}>Delete</button>
</td>
`;
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 = '<tr><td colspan="9" class="text-center text-danger py-3">Failed to load users. Please refresh the page to try again.</td></tr>';
const msg = '<tr><td colspan="7" class="text-center text-danger py-3">Failed to load users. Please refresh the page to try again.</td></tr>';
if (adminsTable) adminsTable.innerHTML = msg;
if (activeStudentsTable) activeStudentsTable.innerHTML = msg;
if (inactiveStudentsTable) inactiveStudentsTable.innerHTML = msg;
}
}

Expand Down