Spaces:
Sleeping
Sleeping
Upload admin.html
Browse files- frontend/admin.html +92 -0
frontend/admin.html
CHANGED
|
@@ -121,6 +121,19 @@
|
|
| 121 |
.spin{width:16px;height:16px;border:2px solid var(--border);border-top-color:var(--teal);border-radius:50%;animation:spin 0.7s linear infinite;flex-shrink:0;}
|
| 122 |
@keyframes spin{to{transform:rotate(360deg);}}
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
/* CONCLUSION */
|
| 125 |
.conclusion-bar{background:#F8F5F0;border-top:1px solid var(--border);padding:12px 18px;display:flex;gap:16px;flex-wrap:wrap;align-items:flex-start;}
|
| 126 |
.conclusion-tier{font-size:13px;font-weight:700;padding:3px 12px;border-radius:20px;white-space:nowrap;}
|
|
@@ -184,6 +197,9 @@
|
|
| 184 |
<div class="user-list" id="userList">
|
| 185 |
<div class="loading"><div class="spin"></div> Loading users…</div>
|
| 186 |
</div>
|
|
|
|
|
|
|
|
|
|
| 187 |
</div>
|
| 188 |
|
| 189 |
<div class="main" id="mainPanel">
|
|
@@ -313,6 +329,8 @@ async function selectUser(id, username, email, createdAt, sessionCount, messageC
|
|
| 313 |
<div class="user-stats">
|
| 314 |
<div class="user-stat"><div class="n">${sessionCount}</div><div class="l">Sessions</div></div>
|
| 315 |
<div class="user-stat"><div class="n">${messageCount}</div><div class="l">Messages</div></div>
|
|
|
|
|
|
|
| 316 |
</div>
|
| 317 |
</div>
|
| 318 |
<div class="export-bar">
|
|
@@ -437,6 +455,80 @@ function fmtTime(iso) {
|
|
| 437 |
: d.toLocaleDateString([],{month:'short',day:'numeric'})+' '+d.toLocaleTimeString([],{hour:'2-digit',minute:'2-digit'});
|
| 438 |
} catch{return iso;}
|
| 439 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
</script>
|
| 441 |
</body>
|
| 442 |
</html>
|
|
|
|
| 121 |
.spin{width:16px;height:16px;border:2px solid var(--border);border-top-color:var(--teal);border-radius:50%;animation:spin 0.7s linear infinite;flex-shrink:0;}
|
| 122 |
@keyframes spin{to{transform:rotate(360deg);}}
|
| 123 |
|
| 124 |
+
/* LOGS */
|
| 125 |
+
.log-table{width:100%;border-collapse:collapse;font-size:12px;}
|
| 126 |
+
.log-table th{text-align:left;padding:8px 12px;font-size:10px;font-weight:600;color:var(--muted);text-transform:uppercase;letter-spacing:0.5px;border-bottom:1px solid var(--border);background:#FAFAF8;}
|
| 127 |
+
.log-table td{padding:8px 12px;border-bottom:1px solid #F0EDE8;vertical-align:top;color:var(--text);}
|
| 128 |
+
.log-table tr:hover td{background:#FAFAF8;}
|
| 129 |
+
.log-action{display:inline-block;font-size:10px;font-weight:600;padding:2px 8px;border-radius:10px;white-space:nowrap;}
|
| 130 |
+
.log-REGISTER{background:#D1FAE5;color:#065F46;}
|
| 131 |
+
.log-LOGIN{background:#DBEAFE;color:#1E40AF;}
|
| 132 |
+
.log-CHAT_MESSAGE{background:var(--teal-lt);color:var(--teal);}
|
| 133 |
+
.log-tabs{display:flex;gap:0;margin-bottom:20px;border:1.5px solid var(--border);border-radius:10px;overflow:hidden;width:fit-content;}
|
| 134 |
+
.log-tab{padding:8px 20px;font-size:13px;font-weight:500;cursor:pointer;background:none;border:none;color:var(--muted);transition:background 0.15s,color 0.15s;}
|
| 135 |
+
.log-tab.active{background:var(--navy);color:#fff;}
|
| 136 |
+
|
| 137 |
/* CONCLUSION */
|
| 138 |
.conclusion-bar{background:#F8F5F0;border-top:1px solid var(--border);padding:12px 18px;display:flex;gap:16px;flex-wrap:wrap;align-items:flex-start;}
|
| 139 |
.conclusion-tier{font-size:13px;font-weight:700;padding:3px 12px;border-radius:20px;white-space:nowrap;}
|
|
|
|
| 197 |
<div class="user-list" id="userList">
|
| 198 |
<div class="loading"><div class="spin"></div> Loading users…</div>
|
| 199 |
</div>
|
| 200 |
+
<div style="padding:12px 16px;border-top:1px solid var(--border);">
|
| 201 |
+
<button class="new-chat-side" style="width:100%;" onclick="showAllLogs()">📋 View All Logs</button>
|
| 202 |
+
</div>
|
| 203 |
</div>
|
| 204 |
|
| 205 |
<div class="main" id="mainPanel">
|
|
|
|
| 329 |
<div class="user-stats">
|
| 330 |
<div class="user-stat"><div class="n">${sessionCount}</div><div class="l">Sessions</div></div>
|
| 331 |
<div class="user-stat"><div class="n">${messageCount}</div><div class="l">Messages</div></div>
|
| 332 |
+
<button class="export-btn" style="margin-left:8px;" onclick="showUserLogs(${id},'${escHtml(username)}')">📋 Logs</button>
|
| 333 |
+
<button class="export-btn" style="margin-left:4px;border-color:#FECACA;color:var(--red);" onclick="resetPassword(${id},'${escHtml(username)}')">🔑 Reset PW</button>
|
| 334 |
</div>
|
| 335 |
</div>
|
| 336 |
<div class="export-bar">
|
|
|
|
| 455 |
: d.toLocaleDateString([],{month:'short',day:'numeric'})+' '+d.toLocaleTimeString([],{hour:'2-digit',minute:'2-digit'});
|
| 456 |
} catch{return iso;}
|
| 457 |
}
|
| 458 |
+
|
| 459 |
+
// ── Logs ──
|
| 460 |
+
async function showAllLogs() {
|
| 461 |
+
selectedUserId = null;
|
| 462 |
+
document.querySelectorAll('.user-item').forEach(el => el.classList.remove('active'));
|
| 463 |
+
const main = document.getElementById('mainPanel');
|
| 464 |
+
main.innerHTML = `<div class="loading"><div class="spin"></div> Loading logs…</div>`;
|
| 465 |
+
try {
|
| 466 |
+
const res = await authFetch('/admin/logs');
|
| 467 |
+
const data = await res.json();
|
| 468 |
+
renderLogsTable(main, data.logs || [], 'All User Activity');
|
| 469 |
+
} catch(e) { main.innerHTML = `<div style="color:var(--red);padding:20px">Error: ${e.message}</div>`; }
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
async function showUserLogs(userId, username) {
|
| 473 |
+
const main = document.getElementById('mainPanel');
|
| 474 |
+
const logsDiv = document.getElementById(`user_logs_${userId}`);
|
| 475 |
+
if (logsDiv) { logsDiv.remove(); return; }
|
| 476 |
+
try {
|
| 477 |
+
const res = await authFetch(`/admin/user/${userId}/logs`);
|
| 478 |
+
const data = await res.json();
|
| 479 |
+
const logs = data.logs || [];
|
| 480 |
+
const container = document.createElement('div');
|
| 481 |
+
container.id = `user_logs_${userId}`;
|
| 482 |
+
container.style.marginTop = '20px';
|
| 483 |
+
renderLogsTable(container, logs, `Activity Log — ${username}`);
|
| 484 |
+
main.appendChild(container);
|
| 485 |
+
container.scrollIntoView({behavior:'smooth'});
|
| 486 |
+
} catch(e) { console.error(e); }
|
| 487 |
+
}
|
| 488 |
+
|
| 489 |
+
function renderLogsTable(container, logs, title) {
|
| 490 |
+
if (!logs.length) {
|
| 491 |
+
container.innerHTML = `<h3 style="font-family:'Libre Baskerville',serif;font-size:17px;color:var(--navy);margin-bottom:16px;">${title}</h3><p style="color:var(--muted);font-size:13px;">No activity logged yet.</p>`;
|
| 492 |
+
return;
|
| 493 |
+
}
|
| 494 |
+
container.innerHTML = `
|
| 495 |
+
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:14px;">
|
| 496 |
+
<h3 style="font-family:'Libre Baskerville',serif;font-size:17px;color:var(--navy);">${title}</h3>
|
| 497 |
+
<span style="font-size:12px;color:var(--muted);">${logs.length} events</span>
|
| 498 |
+
</div>
|
| 499 |
+
<table class="log-table">
|
| 500 |
+
<thead>
|
| 501 |
+
<tr>
|
| 502 |
+
<th>Time</th>
|
| 503 |
+
<th>User</th>
|
| 504 |
+
<th>Action</th>
|
| 505 |
+
<th>Detail</th>
|
| 506 |
+
<th>IP</th>
|
| 507 |
+
</tr>
|
| 508 |
+
</thead>
|
| 509 |
+
<tbody>
|
| 510 |
+
${logs.map(l => `
|
| 511 |
+
<tr>
|
| 512 |
+
<td style="font-family:'DM Mono',monospace;white-space:nowrap;color:var(--muted);">${fmtTime(l.created_at)}</td>
|
| 513 |
+
<td style="font-weight:500;">${escHtml(l.username||'—')}</td>
|
| 514 |
+
<td><span class="log-action log-${l.action}">${l.action}</span></td>
|
| 515 |
+
<td style="max-width:320px;word-break:break-word;">${escHtml(l.detail||'—')}</td>
|
| 516 |
+
<td style="font-family:'DM Mono',monospace;font-size:11px;color:var(--muted);">${escHtml(l.ip_address||'—')}</td>
|
| 517 |
+
</tr>
|
| 518 |
+
`).join('')}
|
| 519 |
+
</tbody>
|
| 520 |
+
</table>
|
| 521 |
+
`;
|
| 522 |
+
}
|
| 523 |
+
async function resetPassword(userId, username) {
|
| 524 |
+
if (!confirm(`Reset password for ${username}? A new random password will be generated.`)) return;
|
| 525 |
+
try {
|
| 526 |
+
const res = await authFetch(`/admin/user/${userId}/reset-password`, {method:'POST'});
|
| 527 |
+
const data = await res.json();
|
| 528 |
+
if (!res.ok) throw new Error(data.detail || 'Failed');
|
| 529 |
+
alert(`✅ Password reset for ${data.username}\n\nNew password: ${data.new_password}\n\nShare this with the user securely.`);
|
| 530 |
+
} catch(e) { alert(`Error: ${e.message}`); }
|
| 531 |
+
}
|
| 532 |
</script>
|
| 533 |
</body>
|
| 534 |
</html>
|