Sakda101's picture
Claude Sonnet 4.6
Fix garbled UTF-8 symbols in admin.html
3b5dfb3
Raw History Blame Contribute Delete
13.8 kB
{% extends "base.html" %}
{% block title %}Admin - Explorer{% endblock %}
{% block nav_admin %}active{% endblock %}
{% block content %}
<div class="page-header">
<div class="page-header-text">
<div class="page-eyebrow">Admin</div>
<h1 class="page-title">Control the <em>training</em> system.</h1>
<p class="page-subtitle">Manage users, corrections, and the activity log from one place.</p>
</div>
</div>
<!-- Flash messages -->
{% set _tab = request.query_params.get('tab', 'users') %}
{% set _success = request.query_params.get('success', '') %}
{% set _error = request.query_params.get('error', '') %}
{% if _success %}
<div class="alert alert-success">{{ _success }}</div>
{% endif %}
{% if _error %}
<div class="alert alert-error">{{ _error }}</div>
{% endif %}
<!-- ── Tab bar ──────────────────────────────────────────── -->
<div class="tab-bar mb-2">
<button class="tab-btn {% if _tab == 'users' %}active{% endif %}"
onclick="switchTab('users')">USERS</button>
<button class="tab-btn {% if _tab == 'corrections' %}active{% endif %}"
onclick="switchTab('corrections')">CORRECTIONS</button>
<button class="tab-btn {% if _tab == 'activity' %}active{% endif %}"
onclick="switchTab('activity')">ACTIVITY LOG</button>
</div>
<!-- ══════════════════════════════════════════════════════
TAB: USERS
══════════════════════════════════════════════════════ -->
<div id="tab-users" class="tab-panel {% if _tab != 'users' %}hidden{% endif %}">
<!-- Add user form -->
<div class="card mb-2">
<div class="card-label mb-2">ADD NEW USER</div>
<form method="post" action="/admin/users/add">
<div class="grid-3 mb-2">
<div class="field">
<label>Email</label>
<input type="email" name="email" required placeholder="user@example.com" />
</div>
<div class="field">
<label>Full Name</label>
<input type="text" name="name" required placeholder="Jane Smith" />
</div>
<div class="field">
<label>Role</label>
<select name="role" required>
<option value="staff">Staff</option>
<option value="manager">Manager</option>
<option value="admin">Admin</option>
</select>
</div>
</div>
<div class="flex items-center gap-2">
<button type="submit" class="btn btn-primary">+ ADD USER</button>
<span class="text-dim" style="font-size:0.78rem;">
The user sets their own password via the login page, or you can set one via Edit below.
</span>
</div>
</form>
</div>
<!-- Export -->
<div class="flex justify-between items-center mb-2">
<div class="card-label">ALL USERS ({{ users | length }})</div>
<a href="/admin/export/users" class="btn btn-outline" style="font-size:0.72rem;padding:0.35rem 0.9rem;">&darr; Export CSV</a>
</div>
<!-- Users table -->
<div class="card">
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Email</th><th>Name</th><th>Role</th><th>Status</th>
<th>Created</th><th>Last Login</th><th></th>
</tr>
</thead>
<tbody>
{% for u in users %}
<tr>
<td>{{ u.email }}</td>
<td>{{ u.name }}</td>
<td><span class="nav-role role-{{ u.role }}">{{ u.role }}</span></td>
<td>
{% if u.active %}
<span class="text-green" style="font-size:0.8rem;font-weight:700;">Active</span>
{% else %}
<span class="text-red" style="font-size:0.8rem;font-weight:700;">Inactive</span>
{% endif %}
</td>
<td class="text-muted" style="font-size:0.78rem;">{{ (u.created_at or '')[:10] }}</td>
<td class=”text-muted” style=”font-size:0.78rem;”>{{ (u.last_login or '-')[:16] }}</td>
<td>
{% if user.role == 'admin' %}
<button class="btn btn-outline" style="font-size:0.72rem;padding:0.2rem 0.6rem;"
onclick="openEditUser('{{ u.email }}','{{ u.name }}','{{ u.role }}',{{ u.active }})">
Edit
</button>
{% endif %}
</td>
</tr>
{% else %}
<tr><td colspan="7" class="text-center text-muted" style="padding:2rem;">No users found.</td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div><!-- /tab-users -->
<!-- ══════════════════════════════════════════════════════
TAB: CORRECTIONS
══════════════════════════════════════════════════════ -->
<div id="tab-corrections" class="tab-panel {% if _tab != 'corrections' %}hidden{% endif %}">
<div class="card-label mb-2">STAFF CORRECTIONS ({{ corrections | length }})</div>
<div class="card">
<div class="table-wrap">
<table>
<thead>
<tr>
<th>ID</th><th>Staff</th><th>Quote</th>
<th>Original</th><th>Corrected To</th><th>Date</th><th></th>
</tr>
</thead>
<tbody>
{% for c in corrections %}
<tr>
<td class="text-dim" style="font-size:0.78rem;">{{ c.id }}</td>
<td>{{ c.user_name }}</td>
<td style="max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;"
title="{{ c.quote }}">{{ c.quote[:60] }}{% if c.quote|length > 60 %}...{% endif %}</td>
<td class="text-muted" style="font-size:0.78rem;">
{{ c.original_type }}<br>
<span class="text-dim">{{ c.original_cluster }}</span>
</td>
<td style="font-size:0.78rem;">
<strong>{{ c.corrected_type }}</strong><br>
<span class="text-gold">{{ c.corrected_cluster }}</span>
</td>
<td class="text-muted" style="font-size:0.78rem;">{{ (c.created_at or '')[:10] }}</td>
<td>
{% if user.role == 'admin' %}
<form method="post" action="/admin/corrections/delete"
onsubmit="return confirm('Delete correction #{{ c.id }}?')">
<input type="hidden" name="correction_id" value="{{ c.id }}" />
<button type="submit" class="btn btn-outline"
style="font-size:0.72rem;padding:0.2rem 0.6rem;color:var(--red);border-color:rgba(224,82,82,0.35);">
Delete
</button>
</form>
{% endif %}
</td>
</tr>
{% else %}
<tr><td colspan="7" class="text-center text-muted" style="padding:2rem;">No corrections yet.</td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div><!-- /tab-corrections -->
<!-- ══════════════════════════════════════════════════════
TAB: ACTIVITY LOG
══════════════════════════════════════════════════════ -->
<div id="tab-activity" class="tab-panel {% if _tab != 'activity' %}hidden{% endif %}">
<div class="card-label mb-2">ACTIVITY LOG (LAST {{ activity | length }} EVENTS)</div>
<div class="card">
<div class="table-wrap">
<table>
<thead>
<tr>
<th>Time</th><th>User</th><th>Action</th><th>Page</th><th>Details</th>
</tr>
</thead>
<tbody>
{% for a in activity %}
<tr>
<td class="text-muted" style="font-size:0.78rem;">{{ (a.timestamp or '')[:16] }}</td>
<td>{{ a.user_name }}</td>
<td>
<span class="activity-action activity-{{ a.action }}">{{ a.action }}</span>
</td>
<td class="text-dim" style="font-size:0.78rem;">{{ a.page or '-' }}</td>
<td class="text-muted" style="font-size:0.78rem;max-width:260px;overflow:hidden;
text-overflow:ellipsis;white-space:nowrap;" title="{{ a.details }}">
{{ a.details or '' }}
</td>
</tr>
{% else %}
<tr><td colspan="5" class="text-center text-muted" style="padding:2rem;">No activity recorded yet.</td></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div><!-- /tab-activity -->
<!-- ══════════════════════════════════════════════════════
EDIT USER MODAL
══════════════════════════════════════════════════════ -->
<div id="edit-user-overlay" class="modal-overlay" hidden onclick="closeEditUser()">
<div class="modal-box" onclick="event.stopPropagation()">
<div class="modal-header">
<span class="card-label">EDIT USER</span>
<button class="modal-close" onclick="closeEditUser()">&times;</button>
</div>
<div id="edit-user-email-display" class="text-muted mb-2" style="font-size:0.85rem;"></div>
<form method="post" action="/admin/users/update" id="edit-user-form">
<input type="hidden" name="email" id="edit-user-email" />
<div class="grid-2 mb-2">
<div class="field">
<label>Full Name</label>
<input type="text" name="name" id="edit-user-name" />
</div>
<div class="field">
<label>Role</label>
<select name="role" id="edit-user-role">
<option value="staff">Staff</option>
<option value="manager">Manager</option>
<option value="admin">Admin</option>
</select>
</div>
</div>
{% set _is_admin = user.role | lower == 'admin' %}
<div class="{% if _is_admin %}grid-2{% endif %} mb-2">
<div class="field">
<label>Status</label>
<select name="active" id="edit-user-active">
<option value="1">Active</option>
<option value="0">Inactive</option>
</select>
</div>
{% if _is_admin %}
<div class="field">
<label>New Password <span class="text-dim">(leave blank to keep)</span></label>
<input type="password" name="password" id="edit-user-password"
placeholder="New password..." autocomplete="new-password" />
</div>
{% endif %}
</div>
<div class="flex gap-1 mt-2">
<button type="submit" class="btn btn-primary">SAVE CHANGES</button>
<button type="button" class="btn btn-outline" onclick="closeEditUser()">Cancel</button>
<div style="flex:1;"></div>
<button type="button" id="delete-user-btn" class="btn"
style="background:#7f1d1d;color:#fca5a5;border:1px solid #991b1b;"
onclick="deleteUser()">DELETE USER</button>
</div>
</form>
<form method="post" action="/admin/users/delete" id="delete-user-form">
<input type="hidden" name="email" id="delete-user-email" />
</form>
</div>
</div>
<script>
const _currentUserEmail = {{ user.email | tojson }};
</script>
{% endblock %}