enhanced client results and export functionality with coach and supervisor details, added date filters for results
This commit is contained in:
@ -19,6 +19,7 @@ export async function usersPage() {
|
||||
<div class="page-header">
|
||||
<h1>Users</h1>
|
||||
<div class="actions">
|
||||
<button class="btn" id="downloadUsersBtn" ${usersList.length ? '' : 'disabled'}>Download CSV</button>
|
||||
<button class="btn btn-primary" id="showCreateFormBtn">+ Create User</button>
|
||||
</div>
|
||||
</div>
|
||||
@ -34,6 +35,7 @@ export async function usersPage() {
|
||||
hideCreateForm();
|
||||
}
|
||||
});
|
||||
document.getElementById('downloadUsersBtn').addEventListener('click', downloadUsersCSV);
|
||||
|
||||
await loadUsers();
|
||||
}
|
||||
@ -45,6 +47,8 @@ async function loadUsers() {
|
||||
supervisorsList = data.supervisors || [];
|
||||
callerRole = data.callerRole || callerRole;
|
||||
renderUsers();
|
||||
const dlBtn = document.getElementById('downloadUsersBtn');
|
||||
if (dlBtn) dlBtn.disabled = !usersList.length;
|
||||
} catch (e) {
|
||||
showToast(e.message, 'error');
|
||||
document.getElementById('usersContent').innerHTML =
|
||||
@ -319,6 +323,45 @@ function showError(el, msg) {
|
||||
el.style.display = '';
|
||||
}
|
||||
|
||||
function downloadUsersCSV() {
|
||||
if (!usersList.length) {
|
||||
showToast('No users to export', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const headers = ['username', 'role', 'location', 'supervisor', 'mustChangePassword', 'createdAt', 'userID'];
|
||||
const rows = usersList.map(u => [
|
||||
u.username,
|
||||
u.role,
|
||||
u.role === 'coach' ? '' : (u.location || ''),
|
||||
u.role === 'coach' ? (u.supervisorUsername || u.supervisorID || '') : '',
|
||||
u.mustChangePassword == 1 ? 'yes' : 'no',
|
||||
u.createdAt ? new Date(parseInt(u.createdAt, 10) * 1000).toISOString() : '',
|
||||
u.userID,
|
||||
]);
|
||||
|
||||
let csv = '\uFEFF';
|
||||
csv += headers.map(csvEsc).join(',') + '\n';
|
||||
rows.forEach(r => { csv += r.map(csvEsc).join(',') + '\n'; });
|
||||
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = `users_${new Date().toISOString().slice(0, 10)}.csv`;
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
showToast('Users exported', 'success');
|
||||
}
|
||||
|
||||
function csvEsc(val) {
|
||||
const s = String(val ?? '');
|
||||
if (s.includes(',') || s.includes('"') || s.includes('\n')) {
|
||||
return '"' + s.replace(/"/g, '""') + '"';
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function esc(s) {
|
||||
const d = document.createElement('div');
|
||||
d.textContent = s ?? '';
|
||||
|
||||
Reference in New Issue
Block a user