diff --git a/public/js/ui.js b/public/js/ui.js index 7c63000..ef5b4fd 100644 --- a/public/js/ui.js +++ b/public/js/ui.js @@ -149,12 +149,14 @@ export async function renderEmployeeDashboard() { // In js/ui.js +// In js/ui.js + export async function renderAdminDashboard() { showView('admin'); const [logsRes, usersRes, requestsRes] = await Promise.all([apiCall('/admin/logs'), apiCall('/admin/users'), apiCall('/admin/time-off-requests/pending')]); if (!logsRes.success || !usersRes.success || !requestsRes.success) return; - // Existing data processing logic... + // Data processing logic... allTimeEntries = logsRes.data; allUsers = usersRes.data; const pendingRequests = requestsRes.data; @@ -163,7 +165,7 @@ export async function renderAdminDashboard() { const punchedInEntries = allTimeEntries.filter(e => e.status === 'in'); const employeesOnly = allUsers.filter(u => u.role === 'employee'); - // --- New Tabbed HTML Structure --- + // --- Tabbed HTML Structure --- mainViews.admin.innerHTML = `
@@ -180,6 +182,16 @@ export async function renderAdminDashboard() {

Currently Punched In

    ${punchedInEntries.map(e => `
  • ${e.username}
    Since: ${utils.formatDateTime(e.punch_in_time)}
  • `).join('') || '
  • None
  • '}

Pending Time Off Requests

${pendingRequests.map(r => ``).join('') || ''}
EmployeeDatesReasonActions
${r.username}${utils.formatDate(r.start_date)} - ${utils.formatDate(r.end_date)}${r.reason||''}
No pending requests.
+ +
+

Employee Notes

+
+ + +
+
+
+

Manage Users

${allUsers.map(u => ``).join('')}
UsernameRoleActions
${u.username}${u.role}
${u.isPrimary ? `Primary Admin` : `${u.username !== user.username ? `` : ''}`}
-
-

Employee Notes

-
- - -
-
-
+
-
`; - attachAdminDashboardListeners(); // This remains the same + attachAdminDashboardListeners(); - // Logic for running timers also remains the same - punchedInEntries.forEach(entry => { /* ... */ }); + punchedInEntries.forEach(entry => { + const durationCell = document.getElementById(`admin-duration-${entry.id}`); + if (durationCell) { + const punchInTime = new Date(entry.punch_in_time); + const intervalId = setInterval(() => { + durationCell.textContent = utils.formatDuration(Date.now() - punchInTime.getTime()); + }, 1000); + adminTimerIntervals.push(intervalId); + } + }); } + + export function renderArchiveView() { apiCall('/admin/archives').then(res => {