Files
tutor-tool/app/templates/admin.html

230 lines
9.8 KiB
HTML

<!DOCTYPE html>
<html lang="en" class="dark">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Deck Admin</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/output.css') }}">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
</head>
<body class="bg-background text-text min-h-screen font-sans">
<nav class="bg-white border-gray-200 dark:bg-gray-900">
<div class="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4">
<div class="flex items-center space-x-6 rtl:space-x-reverse">
<a href="{{ url_for('main.index') }}" class="flex items-center">
<span class="self-center text-2xl font-semibold whitespace-nowrap dark:text-white">Tutortool</span>
</a>
<div class="relative group">
<button class="flex items-center text-gray-900 dark:text-white hover:text-blue-700 dark:hover:text-blue-500 font-medium py-2 px-3 rounded-lg bg-transparent">
{{active_course_name}}
<svg class="w-2.5 h-2.5 ms-2.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 10 6">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 4 4 4-4"/>
</svg>
</button>
<div class="absolute z-10 hidden group-hover:block w-44 bg-white divide-y divide-gray-100 rounded-lg shadow dark:bg-gray-700">
<ul class="py-2 text-sm text-gray-700 dark:text-gray-200">
{% for course in courses %}
<li>
<form method="POST" action="/admin/switch_course/{{ course.id }}">
<button type="submit">{{ course.name }}</button>
</form>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
<div class="w-auto" id="navbar-default">
<ul class="flex flex-row space-x-8 rtl:space-x-reverse font-medium p-0 border-0 bg-white dark:bg-gray-900">
<li>
<a href="{{ url_for('admin.admin') }}" class="rounded-sm text-blue-700 dark:text-blue-500 font-semibold" aria-current="page">Deck Admin</a>
</li>
<li>
<a href="{{ url_for('admin.banner') }}" class="text-gray-900 dark:text-white hover:text-blue-700 dark:hover:text-blue-500">Banner</a>
</li>
<li>
<a href="{{ url_for('admin.confused_notifications') }}" class="text-gray-900 dark:text-white hover:text-blue-700 dark:hover:text-blue-500">Confused</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mx-auto px-6 py-10 space-y-12">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-10">
<!-- Deck Form + Decks -->
<div class="bg-surface rounded-xl p-6 shadow-lg space-y-6">
<h2 class="text-2xl font-semibold">Add New Deck</h2>
<form method="POST" class="space-y-4">
{{ deck_form.hidden_tag() }}
<div>
<label class="block mb-1 text-sm font-medium">{{ deck_form.name.label }}</label>
{{ deck_form.name(class="w-full rounded-lg p-3 bg-background border border-border text-text placeholder-muted focus:outline-none focus:ring-2 focus:ring-primary") }}
</div>
<div>
<label class="block mb-1 text-sm font-medium">{{ deck_form.deck.label }}</label>
{{ deck_form.deck(multiple=True, class="w-full rounded-lg p-3 bg-background border border-border text-text placeholder-muted focus:outline-none focus:ring-2 focus:ring-primary") }}
</div>
<div>
<label class="block mb-1 text-sm font-medium">{{ deck_form.description.label }}</label>
{{ deck_form.description(class="w-full rounded-lg p-3 bg-background border border-border text-text placeholder-muted focus:outline-none focus:ring-2 focus:ring-primary") }}
</div>
<div>
{{ deck_form.submit_deck(class="w-full bg-primary hover:bg-blue-700 text-white py-2 px-4 rounded-lg") }}
</div>
</form>
<!-- Existing Decks Table -->
<h2 class="text-2xl font-semibold pt-6">Existing Decks</h2>
{% if decks %}
<div class="overflow-x-auto">
<table class="w-full table-auto text-left text-sm">
<thead class="text-muted border-b border-border">
<tr>
<th class="px-4 py-2">Name</th>
<th class="px-4 py-2">Passwords</th>
<th class="px-4 py-2">Action</th>
</tr>
</thead>
<tbody>
{% for deck in decks %}
<tr class="border-b border-border hover:bg-background/30">
<td class="px-4 py-2 font-medium">{{ deck.name }}</td>
<td class="px-4 py-2">
{% if deck.passwords %}
<ul class="list-disc list-inside text-muted">
{% for password in deck.passwords %}
<li>{{ password.value }}</li>
{% endfor %}
</ul>
{% else %}
<em class="text-muted">None</em>
{% endif %}
</td>
<td class="px-4 py-2">
<form method="POST" action="{{ url_for('admin.delete_deck', deck_id=deck.id) }}">
<button type="submit" class="bg-red-600 hover:bg-red-700 text-white px-3 py-1 rounded-lg text-sm">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<p class="text-center text-muted">No decks available.</p>
{% endif %}
</div>
<!-- Password Form + Passwords -->
<div class="bg-surface rounded-xl p-6 shadow-lg space-y-6">
<h2 class="text-2xl font-semibold">Add New Password</h2>
<form method="POST" class="space-y-4">
{{ password_form.hidden_tag() }}
<div>
<label class="block mb-1 text-sm font-medium">{{ password_form.value.label }}</label>
{{ password_form.value(class="w-full rounded-lg p-3 bg-background border border-border text-text placeholder-muted focus:outline-none focus:ring-2 focus:ring-primary") }}
</div>
<div>
<label class="block mb-1 text-sm font-medium">{{ password_form.expires_at.label }}</label>
{{ password_form.expires_at(class="w-full rounded-lg p-3 bg-background border border-border text-text placeholder-muted focus:outline-none focus:ring-2 focus:ring-primary", type="datetime-local") }}
</div>
<div>
<label class="block mb-1 text-sm font-medium">{{ password_form.decks.label }}</label>
{{ password_form.decks(class="w-full rounded-lg p-3 bg-background border border-border text-text placeholder-muted focus:outline-none focus:ring-2 focus:ring-primary") }}
</div>
<div>
{{ password_form.submit_password(class="w-full bg-primary hover:bg-blue-700 text-white py-2 px-4 rounded-lg") }}
</div>
</form>
<!-- Existing Passwords Table -->
<h2 class="text-2xl font-semibold pt-6">Existing Passwords</h2>
{% if passwords %}
<div class="overflow-x-auto">
<table class="w-full table-auto text-left text-sm">
<thead class="text-muted border-b border-border">
<tr>
<th class="px-4 py-2">Password</th>
<th class="px-4 py-2">Expires</th>
<th class="px-4 py-2">Decks</th>
<th class="px-4 py-2">Action</th>
</tr>
</thead>
<tbody>
{% for password in passwords %}
<tr class="border-b border-border hover:bg-background/30">
<td class="px-4 py-2 font-medium">{{ password.value }}</td>
<td class="px-4 py-2 local-time"
data-utc="{{ password.expires_at.strftime('%Y-%m-%dT%H:%M:%SZ') if password.expires_at }}">
{{ password.expires_at }}
</td>
<td class="px-4 py-2">
{% if password.decks %}
<ul class="list-disc list-inside text-muted">
{% for deck in password.decks %}
<li>{{ deck.name }}</li>
{% endfor %}
</ul>
{% else %}
<em class="text-muted">None</em>
{% endif %}
</td>
<td class="px-4 py-2">
<form method="POST" action="{{ url_for('admin.delete_password', password_id=password.id) }}">
<button type="submit" class="bg-red-600 hover:bg-red-700 text-white px-3 py-1 rounded-lg text-sm">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<p class="text-center text-muted">No passwords available.</p>
{% endif %}
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/flowbite@3.1.2/dist/flowbite.min.js"></script>
<script>
document.querySelectorAll('.local-time').forEach(el => {
const utcStr = el.getAttribute('data-utc');
if (utcStr) {
// Now utcStr is "2026-02-17T02:44:23Z"
const date = new Date(utcStr);
if (!isNaN(date)) {
el.textContent = date.toLocaleString('de-DE', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
}
}
});
</script>
</body>
</html>