Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70920ede87 | ||
|
|
7220ec87bc | ||
|
|
a2c851a853 | ||
|
|
51b2b1a98c | ||
|
|
40ee4cf398 | ||
|
|
231b11b8b3 | ||
|
|
6006e1e7b1 | ||
|
|
6c87a9d58f | ||
|
|
164dacb678 |
3
ht_booking/.gitignore
vendored
3
ht_booking/.gitignore
vendored
@@ -20,4 +20,5 @@ target/
|
|||||||
*.sqlite-*
|
*.sqlite-*
|
||||||
|
|
||||||
# Local secrets (hardcoded admin credentials)
|
# Local secrets (hardcoded admin credentials)
|
||||||
.env
|
.env
|
||||||
|
todo.md
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ edit-booking = Edit Booking
|
|||||||
date = Date
|
date = Date
|
||||||
hour = Hour
|
hour = Hour
|
||||||
booking-color = Colour
|
booking-color = Colour
|
||||||
booking-name = Name
|
booking-name = Name (private)
|
||||||
|
booking-title = Title (public)
|
||||||
booking-contact = Contact
|
booking-contact = Contact
|
||||||
booking-note = Note
|
booking-note = Note
|
||||||
save = Save
|
save = Save
|
||||||
@@ -41,3 +42,19 @@ court-name = Name
|
|||||||
court-surface = Surface
|
court-surface = Surface
|
||||||
court-indoor = Indoor
|
court-indoor = Indoor
|
||||||
add-court = Add Court
|
add-court = Add Court
|
||||||
|
court-remove = Remove
|
||||||
|
court-delete-prompt = To remove this court and all its bookings, type its name below to confirm:
|
||||||
|
court-delete-mismatch = The name you typed does not match the court name.
|
||||||
|
court-delete-error = Court name did not match — nothing was removed.
|
||||||
|
theme-system = System
|
||||||
|
theme-light = Light
|
||||||
|
theme-dark = Dark
|
||||||
|
settings = Settings
|
||||||
|
settings-language = Language
|
||||||
|
settings-theme = Theme
|
||||||
|
view-details = Details
|
||||||
|
pick-week = Go to week
|
||||||
|
hour-from = From
|
||||||
|
hour-to = Until
|
||||||
|
repeat-weeks = Repeat for (weeks)
|
||||||
|
repeat-hint = 1 books a single week. A higher number repeats the same hours every following week.
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ edit-booking = Upraviť rezerváciu
|
|||||||
date = Dátum
|
date = Dátum
|
||||||
hour = Hodina
|
hour = Hodina
|
||||||
booking-color = Farba
|
booking-color = Farba
|
||||||
booking-name = Meno
|
booking-name = Meno (súkromné)
|
||||||
|
booking-title = Názov (verejný)
|
||||||
booking-contact = Kontakt
|
booking-contact = Kontakt
|
||||||
booking-note = Poznámka
|
booking-note = Poznámka
|
||||||
save = Uložiť
|
save = Uložiť
|
||||||
@@ -41,3 +42,19 @@ court-name = Názov
|
|||||||
court-surface = Povrch
|
court-surface = Povrch
|
||||||
court-indoor = Krytý
|
court-indoor = Krytý
|
||||||
add-court = Pridať kurt
|
add-court = Pridať kurt
|
||||||
|
court-remove = Odstrániť
|
||||||
|
court-delete-prompt = Ak chcete odstrániť tento kurt a všetky jeho rezervácie, na potvrdenie napíšte nižšie jeho názov:
|
||||||
|
court-delete-mismatch = Zadaný názov sa nezhoduje s názvom kurtu.
|
||||||
|
court-delete-error = Názov kurtu sa nezhodoval — nič sa neodstránilo.
|
||||||
|
theme-system = Systém
|
||||||
|
theme-light = Svetlý
|
||||||
|
theme-dark = Tmavý
|
||||||
|
settings = Nastavenia
|
||||||
|
settings-language = Jazyk
|
||||||
|
settings-theme = Téma
|
||||||
|
view-details = Detaily
|
||||||
|
pick-week = Prejsť na týždeň
|
||||||
|
hour-from = Od
|
||||||
|
hour-to = Do
|
||||||
|
repeat-weeks = Opakovať (počet týždňov)
|
||||||
|
repeat-hint = 1 rezervuje jeden týždeň. Vyššie číslo opakuje rovnaké hodiny každý ďalší týždeň.
|
||||||
|
|||||||
@@ -10,55 +10,109 @@
|
|||||||
<h1 class="text-2xl font-bold">
|
<h1 class="text-2xl font-bold">
|
||||||
{% if mode == "edit" %}{{ t(key="edit-booking", lang=lang) }}{% else %}{{ t(key="add-booking", lang=lang) }}{% endif %}
|
{% if mode == "edit" %}{{ t(key="edit-booking", lang=lang) }}{% else %}{{ t(key="add-booking", lang=lang) }}{% endif %}
|
||||||
</h1>
|
</h1>
|
||||||
<a href="/admin" class="text-sm text-blue-600 hover:underline">← {{ t(key="back-to-calendar", lang=lang) }}</a>
|
<a href="/admin?court={{ court_id }}&week={{ date }}" class="btn btn-ghost btn-sm">« {{ t(key="back-to-calendar", lang=lang) }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form method="post" action="{{ action }}" class="space-y-3 rounded-lg border bg-white p-4">
|
<div class="card border border-base-300 bg-base-100 shadow-sm">
|
||||||
<input type="hidden" name="court_id" value="{{ court_id }}">
|
<div class="card-body">
|
||||||
<div class="text-sm text-gray-600">{{ t(key="court-label", lang=lang) }}: <strong>{{ court_name }}</strong></div>
|
<form method="post" action="{{ action }}" class="space-y-2">
|
||||||
<div>
|
<input type="hidden" name="court_id" value="{{ court_id }}">
|
||||||
<label class="block text-sm text-gray-600">{{ t(key="date", lang=lang) }}</label>
|
<div class="text-sm opacity-70">
|
||||||
<input type="date" name="date" value="{{ date }}" required class="w-full rounded border-gray-300 text-sm">
|
{{ t(key="court-label", lang=lang) }}: <strong>{{ court_name }}</strong>
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="date", lang=lang) }}</span></label>
|
||||||
|
<input type="date" name="date" value="{{ date }}" required class="input input-bordered w-full">
|
||||||
|
</div>
|
||||||
|
{% if mode == "new" %}
|
||||||
|
<div class="grid grid-cols-2 gap-2">
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="hour-from", lang=lang) }}</span></label>
|
||||||
|
<select name="hour_start" id="hour_start" class="select select-bordered w-full">
|
||||||
|
{% for h in hours %}
|
||||||
|
<option value="{{ h.v }}" {% if h.v == hour_start %}selected{% endif %}>{{ h.label }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="hour-to", lang=lang) }}</span></label>
|
||||||
|
<select name="hour_end" id="hour_end" class="select select-bordered w-full">
|
||||||
|
{% for h in hours_end %}
|
||||||
|
<option value="{{ h.v }}" {% if h.v == hour_end %}selected{% endif %}>{{ h.label }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="repeat-weeks", lang=lang) }}</span></label>
|
||||||
|
<input type="number" name="repeat_weeks" value="{{ repeat_weeks }}" min="1" max="52" required
|
||||||
|
class="input input-bordered w-full">
|
||||||
|
<label class="label">
|
||||||
|
<span class="label-text-alt opacity-60">{{ t(key="repeat-hint", lang=lang) }}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="hour", lang=lang) }}</span></label>
|
||||||
|
<select name="hour" class="select select-bordered w-full">
|
||||||
|
{% for h in hours %}
|
||||||
|
<option value="{{ h.v }}" {% if h.v == hour %}selected{% endif %}>{{ h.label }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="booking-color", lang=lang) }}</span></label>
|
||||||
|
<input type="color" name="color" value="{{ color }}"
|
||||||
|
class="h-10 w-20 cursor-pointer rounded border border-base-300">
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="booking-name", lang=lang) }}</span></label>
|
||||||
|
<input name="name" value="{{ name }}" required class="input input-bordered w-full">
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="booking-title", lang=lang) }}</span></label>
|
||||||
|
<input name="title" value="{{ title }}" class="input input-bordered w-full">
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="booking-contact", lang=lang) }}</span></label>
|
||||||
|
<input name="contact" value="{{ contact }}" class="input input-bordered w-full">
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="booking-note", lang=lang) }}</span></label>
|
||||||
|
<textarea name="note" rows="3" class="textarea textarea-bordered w-full">{{ note }}</textarea>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-2 pt-2">
|
||||||
|
<button class="btn btn-neutral">{{ t(key="save", lang=lang) }}</button>
|
||||||
|
<a href="/admin?court={{ court_id }}&week={{ date }}" class="btn btn-ghost">{{ t(key="cancel", lang=lang) }}</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</div>
|
||||||
<label class="block text-sm text-gray-600">{{ t(key="hour", lang=lang) }}</label>
|
|
||||||
<select name="hour" class="w-full rounded border-gray-300 text-sm">
|
|
||||||
{% for h in hours %}
|
|
||||||
<option value="{{ h.v }}" {% if h.v == hour %}selected{% endif %}>{{ h.label }}</option>
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="block text-sm text-gray-600">{{ t(key="booking-color", lang=lang) }}</label>
|
|
||||||
<input type="color" name="color" value="{{ color }}" class="h-9 w-16 rounded border-gray-300">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="block text-sm text-gray-600">{{ t(key="booking-name", lang=lang) }}</label>
|
|
||||||
<input name="name" value="{{ name }}" required class="w-full rounded border-gray-300 text-sm">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="block text-sm text-gray-600">{{ t(key="booking-contact", lang=lang) }}</label>
|
|
||||||
<input name="contact" value="{{ contact }}" class="w-full rounded border-gray-300 text-sm">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label class="block text-sm text-gray-600">{{ t(key="booking-note", lang=lang) }}</label>
|
|
||||||
<textarea name="note" rows="3" class="w-full rounded border-gray-300 text-sm">{{ note }}</textarea>
|
|
||||||
</div>
|
|
||||||
<div class="flex items-center gap-2">
|
|
||||||
<button class="rounded bg-gray-900 px-4 py-2 text-sm text-white hover:bg-gray-700">
|
|
||||||
{{ t(key="save", lang=lang) }}
|
|
||||||
</button>
|
|
||||||
<a href="/admin" class="rounded border px-4 py-2 text-sm hover:bg-gray-100">{{ t(key="cancel", lang=lang) }}</a>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
{% if mode == "edit" %}
|
{% if mode == "edit" %}
|
||||||
<form method="post" action="/admin/booking/{{ booking_id }}/delete" class="mt-3"
|
<form method="post" action="/admin/booking/{{ booking_id }}/delete" class="mt-3"
|
||||||
onsubmit="return confirm('{{ t(key="confirm-delete", lang=lang) }}');">
|
onsubmit="return confirm('{{ t(key="confirm-delete", lang=lang) }}');">
|
||||||
<button class="rounded bg-red-600 px-4 py-2 text-sm text-white hover:bg-red-700">
|
<button class="btn btn-outline btn-error btn-sm">{{ t(key="delete", lang=lang) }}</button>
|
||||||
{{ t(key="delete", lang=lang) }}
|
|
||||||
</button>
|
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
{% if mode == "new" %}
|
||||||
|
<script>
|
||||||
|
// Keep the "until" time after the "from" time as the start hour changes.
|
||||||
|
(function () {
|
||||||
|
var s = document.getElementById('hour_start');
|
||||||
|
var e = document.getElementById('hour_end');
|
||||||
|
if (!s || !e) return;
|
||||||
|
s.addEventListener('change', function () {
|
||||||
|
if (parseInt(e.value, 10) <= parseInt(s.value, 10)) {
|
||||||
|
e.value = String(parseInt(s.value, 10) + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock js %}
|
||||||
|
|||||||
@@ -5,47 +5,87 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="mb-4 flex items-center justify-between">
|
<div class="mb-4 flex items-center justify-between">
|
||||||
<h1 class="text-2xl font-bold">{{ t(key="manage-courts", lang=lang) }}</h1>
|
<h1 class="text-2xl font-bold">{{ t(key="manage-courts", lang=lang) }}</h1>
|
||||||
<a href="/admin" class="text-sm text-blue-600 hover:underline">← {{ t(key="back-to-calendar", lang=lang) }}</a>
|
<a href="/admin" class="btn btn-ghost btn-sm">« {{ t(key="back-to-calendar", lang=lang) }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-6 overflow-auto rounded-lg border bg-white">
|
{% if name_error %}
|
||||||
<table class="w-full text-sm">
|
<div class="alert alert-error mb-4">
|
||||||
|
<span>{{ t(key="court-delete-error", lang=lang) }}</span>
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<div class="mb-6 overflow-x-auto rounded-lg border border-base-300 bg-base-100 shadow-sm">
|
||||||
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="bg-gray-100 text-left">
|
<tr>
|
||||||
<th class="p-2">{{ t(key="court-name", lang=lang) }}</th>
|
<th>{{ t(key="court-name", lang=lang) }}</th>
|
||||||
<th class="p-2">{{ t(key="court-surface", lang=lang) }}</th>
|
<th>{{ t(key="court-surface", lang=lang) }}</th>
|
||||||
<th class="p-2">{{ t(key="court-indoor", lang=lang) }}</th>
|
<th>{{ t(key="court-indoor", lang=lang) }}</th>
|
||||||
|
<th class="text-right">{{ t(key="court-remove", lang=lang) }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for c in courts %}
|
{% for c in courts %}
|
||||||
<tr class="border-t">
|
<tr>
|
||||||
<td class="p-2">{{ c.name }}</td>
|
<td class="font-medium">{{ c.name }}</td>
|
||||||
<td class="p-2">{{ c.surface }}</td>
|
<td>{{ c.surface }}</td>
|
||||||
<td class="p-2">{{ c.indoor }}</td>
|
<td>
|
||||||
|
{% if c.indoor %}
|
||||||
|
<span class="badge badge-success badge-sm">✓</span>
|
||||||
|
{% else %}
|
||||||
|
<span class="badge badge-ghost badge-sm">—</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
<td class="text-right">
|
||||||
|
<form method="post" action="/admin/courts/{{ c.id }}/delete" class="inline"
|
||||||
|
data-court-name="{{ c.name }}" onsubmit="return promptCourtDelete(this);">
|
||||||
|
<input type="hidden" name="confirm_name">
|
||||||
|
<button class="btn btn-error btn-sm">{{ t(key="delete", lang=lang) }}</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="max-w-md rounded-lg border bg-white p-4">
|
<div class="card max-w-md border border-base-300 bg-base-100 shadow-sm">
|
||||||
<h2 class="mb-3 font-semibold">{{ t(key="add-court", lang=lang) }}</h2>
|
<div class="card-body">
|
||||||
<form method="post" action="/admin/courts" class="space-y-3">
|
<h2 class="card-title text-base">{{ t(key="add-court", lang=lang) }}</h2>
|
||||||
<div>
|
<form method="post" action="/admin/courts" class="space-y-2">
|
||||||
<label class="block text-sm text-gray-600">{{ t(key="court-name", lang=lang) }}</label>
|
<div class="form-control">
|
||||||
<input name="name" required class="w-full rounded border-gray-300 text-sm">
|
<label class="label"><span class="label-text">{{ t(key="court-name", lang=lang) }}</span></label>
|
||||||
</div>
|
<input name="name" required class="input input-bordered w-full">
|
||||||
<div>
|
</div>
|
||||||
<label class="block text-sm text-gray-600">{{ t(key="court-surface", lang=lang) }}</label>
|
<div class="form-control">
|
||||||
<input name="surface" class="w-full rounded border-gray-300 text-sm">
|
<label class="label"><span class="label-text">{{ t(key="court-surface", lang=lang) }}</span></label>
|
||||||
</div>
|
<input name="surface" class="input input-bordered w-full">
|
||||||
<label class="flex items-center gap-2 text-sm">
|
</div>
|
||||||
<input type="checkbox" name="indoor" value="1"> {{ t(key="court-indoor", lang=lang) }}
|
<div class="form-control">
|
||||||
</label>
|
<label class="label cursor-pointer justify-start gap-3">
|
||||||
<button class="rounded bg-gray-900 px-4 py-2 text-sm text-white hover:bg-gray-700">
|
<input type="checkbox" name="indoor" value="1" class="checkbox checkbox-sm">
|
||||||
{{ t(key="add-court", lang=lang) }}
|
<span class="label-text">{{ t(key="court-indoor", lang=lang) }}</span>
|
||||||
</button>
|
</label>
|
||||||
</form>
|
</div>
|
||||||
|
<button class="btn btn-neutral mt-1">{{ t(key="add-court", lang=lang) }}</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<script>
|
||||||
|
// The name confirmation appears only after the Delete button is pressed.
|
||||||
|
function promptCourtDelete(form) {
|
||||||
|
var expected = form.dataset.courtName;
|
||||||
|
var typed = prompt('{{ t(key="court-delete-prompt", lang=lang) }}\n\n' + expected);
|
||||||
|
if (typed === null) return false; // cancelled
|
||||||
|
if (typed.trim() !== expected) {
|
||||||
|
alert('{{ t(key="court-delete-mismatch", lang=lang) }}');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
form.confirm_name.value = typed.trim();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{% endblock js %}
|
||||||
|
|||||||
@@ -3,23 +3,27 @@
|
|||||||
{% block title %}{{ t(key="login-title", lang=lang) }}{% endblock title %}
|
{% block title %}{{ t(key="login-title", lang=lang) }}{% endblock title %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="mx-auto mt-8 max-w-sm rounded-lg border bg-white p-6">
|
<div class="mx-auto mt-8 max-w-sm">
|
||||||
<h1 class="mb-4 text-xl font-bold">{{ t(key="login-title", lang=lang) }}</h1>
|
<div class="card border border-base-300 bg-base-100 shadow-sm">
|
||||||
{% if error %}
|
<div class="card-body">
|
||||||
<div class="mb-3 rounded bg-red-100 px-3 py-2 text-sm text-red-700">{{ t(key="login-error", lang=lang) }}</div>
|
<h1 class="card-title">{{ t(key="login-title", lang=lang) }}</h1>
|
||||||
{% endif %}
|
{% if error %}
|
||||||
<form method="post" action="/admin/login" class="space-y-3">
|
<div class="alert alert-error">
|
||||||
<div>
|
<span>{{ t(key="login-error", lang=lang) }}</span>
|
||||||
<label class="block text-sm text-gray-600">{{ t(key="email", lang=lang) }}</label>
|
</div>
|
||||||
<input type="email" name="email" required class="w-full rounded border-gray-300 text-sm">
|
{% endif %}
|
||||||
|
<form method="post" action="/admin/login" class="space-y-2">
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="email", lang=lang) }}</span></label>
|
||||||
|
<input type="email" name="email" required class="input input-bordered w-full">
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<label class="label"><span class="label-text">{{ t(key="password", lang=lang) }}</span></label>
|
||||||
|
<input type="password" name="password" required class="input input-bordered w-full">
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-neutral mt-2 w-full">{{ t(key="login-button", lang=lang) }}</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
</div>
|
||||||
<label class="block text-sm text-gray-600">{{ t(key="password", lang=lang) }}</label>
|
|
||||||
<input type="password" name="password" required class="w-full rounded border-gray-300 text-sm">
|
|
||||||
</div>
|
|
||||||
<button class="w-full rounded bg-gray-900 py-2 text-sm text-white hover:bg-gray-700">
|
|
||||||
{{ t(key="login-button", lang=lang) }}
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|||||||
@@ -1,40 +1,158 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="{{ lang }}">
|
<html lang="{{ lang }}" data-theme="light">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<script>
|
||||||
|
// Resolve and apply the saved theme before first paint to avoid a flash.
|
||||||
|
function applyTheme(t) {
|
||||||
|
var dark = t === 'dark'
|
||||||
|
|| (t === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);
|
||||||
|
document.documentElement.setAttribute('data-theme', dark ? 'dark' : 'light');
|
||||||
|
}
|
||||||
|
function highlightTheme(t) {
|
||||||
|
document.querySelectorAll('[data-theme-opt]').forEach(function (b) {
|
||||||
|
var on = b.getAttribute('data-theme-opt') === t;
|
||||||
|
b.classList.toggle('active', on);
|
||||||
|
var chk = b.querySelector('.opt-check');
|
||||||
|
if (chk) chk.classList.toggle('hidden', !on);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function setTheme(t) {
|
||||||
|
localStorage.setItem('theme', t);
|
||||||
|
applyTheme(t);
|
||||||
|
highlightTheme(t);
|
||||||
|
}
|
||||||
|
applyTheme(localStorage.getItem('theme') || 'system');
|
||||||
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', function () {
|
||||||
|
if ((localStorage.getItem('theme') || 'system') === 'system') applyTheme('system');
|
||||||
|
});
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
highlightTheme(localStorage.getItem('theme') || 'system');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
<title>{% block title %}{{ t(key="brand", lang=lang) }}{% endblock title %}</title>
|
<title>{% block title %}{{ t(key="brand", lang=lang) }}{% endblock title %}</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/daisyui@4/dist/full.min.css" rel="stylesheet" type="text/css" />
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
<style>
|
||||||
|
/* Keep buttons static — disable daisyUI's press-shrink animation. */
|
||||||
|
.btn { --animation-btn: 0; --btn-focus-scale: 1; }
|
||||||
|
</style>
|
||||||
{% block head %}{% endblock head %}
|
{% block head %}{% endblock head %}
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="min-h-screen bg-gray-50 text-gray-900 font-sans antialiased">
|
<body class="min-h-screen bg-base-200 font-sans text-base-content antialiased">
|
||||||
<header class="border-b bg-white">
|
<div class="navbar bg-base-100 shadow-sm">
|
||||||
<div class="mx-auto flex max-w-6xl items-center justify-between px-5 py-3">
|
<div class="mx-auto flex w-full max-w-6xl flex-wrap items-center justify-between gap-2 px-4">
|
||||||
<a href="/" class="text-lg font-bold">{{ t(key="brand", lang=lang) }}</a>
|
<a href="/" class="text-lg font-bold">{{ t(key="brand", lang=lang) }}</a>
|
||||||
<nav class="flex items-center gap-4 text-sm">
|
<nav class="flex flex-wrap items-center gap-1">
|
||||||
<a href="/" class="hover:underline">{{ t(key="nav-calendar", lang=lang) }}</a>
|
<a href="/" class="btn btn-ghost btn-sm">{{ t(key="nav-calendar", lang=lang) }}</a>
|
||||||
{% if is_admin %}
|
{% if logged_in | default(value=false) %}
|
||||||
<a href="/admin" class="hover:underline">{{ t(key="admin-title", lang=lang) }}</a>
|
<a href="/admin" class="btn btn-ghost btn-sm">{{ t(key="admin-title", lang=lang) }}</a>
|
||||||
<a href="/admin/courts" class="hover:underline">{{ t(key="manage-courts", lang=lang) }}</a>
|
<a href="/admin/courts" class="btn btn-ghost btn-sm">{{ t(key="manage-courts", lang=lang) }}</a>
|
||||||
<form method="post" action="/admin/logout" class="inline">
|
<form method="post" action="/admin/logout">
|
||||||
<button class="hover:underline">{{ t(key="logout", lang=lang) }}</button>
|
<button class="btn btn-ghost btn-sm">{{ t(key="logout", lang=lang) }}</button>
|
||||||
</form>
|
</form>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="/admin/login" class="hover:underline">{{ t(key="nav-admin", lang=lang) }}</a>
|
<a href="/admin/login" class="btn btn-ghost btn-sm">{{ t(key="nav-admin", lang=lang) }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="flex gap-1">
|
|
||||||
<button onclick="setLang('en')"
|
<div class="dropdown dropdown-end">
|
||||||
class="rounded px-2 py-0.5 {% if lang == 'en' %}bg-gray-900 text-white{% else %}bg-gray-200{% endif %}">EN</button>
|
<div tabindex="0" role="button" class="btn btn-ghost btn-sm btn-circle"
|
||||||
<button onclick="setLang('sk')"
|
aria-label="{{ t(key='settings', lang=lang) }}" title="{{ t(key='settings', lang=lang) }}">
|
||||||
class="rounded px-2 py-0.5 {% if lang == 'sk' %}bg-gray-900 text-white{% else %}bg-gray-200{% endif %}">SK</button>
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||||
</span>
|
stroke="currentColor" class="h-5 w-5">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
d="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 1.125 0 0 1 1.37.49l1.296 2.247a1.125 1.125 0 0 1-.26 1.431l-1.003.827c-.293.241-.438.613-.43.992a7.723 7.723 0 0 1 0 .255c-.008.378.137.75.43.991l1.004.827c.424.35.534.955.26 1.43l-1.298 2.247a1.125 1.125 0 0 1-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.47 6.47 0 0 1-.22.128c-.331.183-.581.495-.644.869l-.213 1.281c-.09.543-.56.94-1.11.94h-2.594c-.55 0-1.019-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 6.52 0 0 1-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 0 1-1.369-.49l-1.297-2.247a1.125 1.125 0 0 1 .26-1.431l1.004-.827c.292-.24.437-.613.43-.991a6.932 6.932 0 0 1 0-.255c.007-.38-.138-.751-.43-.992l-1.004-.827a1.125 1.125 0 0 1-.26-1.43l1.297-2.247a1.125 1.125 0 0 1 1.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.086.22-.128.332-.183.582-.495.644-.869l.214-1.28Z" />
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0Z" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<ul tabindex="0"
|
||||||
|
class="menu dropdown-content z-50 mt-3 w-56 rounded-box border border-base-300 bg-base-100 p-2 shadow-lg">
|
||||||
|
<li class="menu-title">{{ t(key="settings-language", lang=lang) }}</li>
|
||||||
|
<li>
|
||||||
|
<button type="button" onclick="setLang('en')" class="{% if lang == 'en' %}active{% endif %}">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||||
|
stroke="currentColor" class="h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
d="M12 21a9.004 9.004 0 0 0 8.716-6.747M12 21a9.004 9.004 0 0 1-8.716-6.747M12 21c2.485 0 4.5-4.03 4.5-9S14.485 3 12 3m0 18c-2.485 0-4.5-4.03-4.5-9S9.515 3 12 3m0 0a8.997 8.997 0 0 1 7.843 4.582M12 3a8.997 8.997 0 0 0-7.843 4.582m15.686 0A11.953 11.953 0 0 1 12 10.5c-2.998 0-5.74-1.1-7.843-2.918m15.686 0A8.959 8.959 0 0 1 21 12c0 .778-.099 1.533-.284 2.253m0 0A17.919 17.919 0 0 1 12 16.5c-3.162 0-6.133-.815-8.716-2.247" />
|
||||||
|
</svg>
|
||||||
|
<span>English</span>
|
||||||
|
{% if lang == 'en' %}
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3"
|
||||||
|
stroke="currentColor" class="ml-auto h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" />
|
||||||
|
</svg>
|
||||||
|
{% endif %}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<button type="button" onclick="setLang('sk')" class="{% if lang == 'sk' %}active{% endif %}">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||||
|
stroke="currentColor" class="h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
d="M12 21a9.004 9.004 0 0 0 8.716-6.747M12 21a9.004 9.004 0 0 1-8.716-6.747M12 21c2.485 0 4.5-4.03 4.5-9S14.485 3 12 3m0 18c-2.485 0-4.5-4.03-4.5-9S9.515 3 12 3m0 0a8.997 8.997 0 0 1 7.843 4.582M12 3a8.997 8.997 0 0 0-7.843 4.582m15.686 0A11.953 11.953 0 0 1 12 10.5c-2.998 0-5.74-1.1-7.843-2.918m15.686 0A8.959 8.959 0 0 1 21 12c0 .778-.099 1.533-.284 2.253m0 0A17.919 17.919 0 0 1 12 16.5c-3.162 0-6.133-.815-8.716-2.247" />
|
||||||
|
</svg>
|
||||||
|
<span>Slovenčina</span>
|
||||||
|
{% if lang == 'sk' %}
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3"
|
||||||
|
stroke="currentColor" class="ml-auto h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" />
|
||||||
|
</svg>
|
||||||
|
{% endif %}
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li class="menu-title">{{ t(key="settings-theme", lang=lang) }}</li>
|
||||||
|
<li>
|
||||||
|
<button type="button" data-theme-opt="system" onclick="setTheme('system')">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||||
|
stroke="currentColor" class="h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
d="M9 17.25v1.007a3 3 0 0 1-.879 2.122L7.5 21h9l-.621-.621A3 3 0 0 1 15 18.257V17.25m6-12V15a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 15V5.25m18 0A2.25 2.25 0 0 0 18.75 3H5.25A2.25 2.25 0 0 0 3 5.25m18 0V12a2.25 2.25 0 0 1-2.25 2.25H5.25A2.25 2.25 0 0 1 3 12V5.25" />
|
||||||
|
</svg>
|
||||||
|
<span>{{ t(key="theme-system", lang=lang) }}</span>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3"
|
||||||
|
stroke="currentColor" class="opt-check ml-auto hidden h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<button type="button" data-theme-opt="light" onclick="setTheme('light')">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||||
|
stroke="currentColor" class="h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z" />
|
||||||
|
</svg>
|
||||||
|
<span>{{ t(key="theme-light", lang=lang) }}</span>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3"
|
||||||
|
stroke="currentColor" class="opt-check ml-auto hidden h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<button type="button" data-theme-opt="dark" onclick="setTheme('dark')">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||||
|
stroke="currentColor" class="h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z" />
|
||||||
|
</svg>
|
||||||
|
<span>{{ t(key="theme-dark", lang=lang) }}</span>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="3"
|
||||||
|
stroke="currentColor" class="opt-check ml-auto hidden h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round" d="m4.5 12.75 6 6 9-13.5" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</div>
|
||||||
|
|
||||||
<main class="mx-auto max-w-6xl px-5 py-6">
|
<main class="mx-auto max-w-6xl px-4 py-6">
|
||||||
{% block content %}{% endblock content %}
|
{% block content %}{% endblock content %}
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,55 @@
|
|||||||
|
|
||||||
{% block title %}{{ t(key="calendar-title", lang=lang) }}{% endblock title %}
|
{% block title %}{{ t(key="calendar-title", lang=lang) }}{% endblock title %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
<style>
|
||||||
|
/* Sharpen the calendar grid. The daisyUI base tones give very low-contrast
|
||||||
|
hairline borders and dimmed text in both themes. Tying the borders and
|
||||||
|
the header tint to base-content keeps the table legible and easy to
|
||||||
|
follow on light and dark alike (public + admin calendars). */
|
||||||
|
#cal th,
|
||||||
|
#cal td {
|
||||||
|
border-color: hsl(var(--bc) / 0.25);
|
||||||
|
}
|
||||||
|
#cal thead tr,
|
||||||
|
#cal tbody td:first-child {
|
||||||
|
background-color: hsl(var(--bc) / 0.1);
|
||||||
|
}
|
||||||
|
#cal tbody td:first-child { opacity: 1; }
|
||||||
|
#cal thead .opacity-50 { opacity: 0.8; }
|
||||||
|
#cal td .opacity-30 { opacity: 0.7; }
|
||||||
|
#cal td a.opacity-30:hover { opacity: 1; }
|
||||||
|
</style>
|
||||||
|
{% if is_admin %}
|
||||||
|
<style>
|
||||||
|
/* Admin calendar — detailed-view toggle. The public calendar is unaffected. */
|
||||||
|
.cal-detail { display: none; }
|
||||||
|
#cal.cal--detailed .cal-chip {
|
||||||
|
position: static;
|
||||||
|
inset: auto;
|
||||||
|
margin: 0.25rem;
|
||||||
|
min-height: 3rem;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
#cal.cal--detailed .cal-name {
|
||||||
|
white-space: normal;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
#cal.cal--detailed .cal-detail {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1px;
|
||||||
|
margin-top: 2px;
|
||||||
|
font-weight: 400;
|
||||||
|
line-height: 1.25;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock head %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
|
||||||
<h1 class="text-2xl font-bold">
|
<h1 class="text-2xl font-bold">
|
||||||
@@ -9,9 +58,9 @@
|
|||||||
</h1>
|
</h1>
|
||||||
{% if has_courts %}
|
{% if has_courts %}
|
||||||
<form method="get" action="{{ base_path }}" class="flex items-center gap-2">
|
<form method="get" action="{{ base_path }}" class="flex items-center gap-2">
|
||||||
<label class="text-sm text-gray-600">{{ t(key="court-label", lang=lang) }}</label>
|
<label class="text-sm font-medium opacity-70">{{ t(key="court-label", lang=lang) }}</label>
|
||||||
<input type="hidden" name="week" value="{{ week }}">
|
<input type="hidden" name="week" value="{{ week }}">
|
||||||
<select name="court" onchange="this.form.submit()" class="rounded border-gray-300 text-sm">
|
<select name="court" onchange="this.form.submit()" class="select select-bordered select-sm">
|
||||||
{% for c in courts %}
|
{% for c in courts %}
|
||||||
<option value="{{ c.id }}" {% if c.selected %}selected{% endif %}>{{ c.name }}</option>
|
<option value="{{ c.id }}" {% if c.selected %}selected{% endif %}>{{ c.name }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
@@ -22,61 +71,160 @@
|
|||||||
|
|
||||||
{% if has_courts %}
|
{% if has_courts %}
|
||||||
<div class="mb-3 flex flex-wrap items-center justify-between gap-2">
|
<div class="mb-3 flex flex-wrap items-center justify-between gap-2">
|
||||||
<div class="flex gap-2">
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
<a href="{{ base_path }}?court={{ court_id }}&week={{ prev_week }}"
|
<div class="join">
|
||||||
class="rounded border bg-white px-3 py-1 text-sm hover:bg-gray-100">← {{ t(key="prev-week", lang=lang) }}</a>
|
{% if can_prev %}
|
||||||
<a href="{{ base_path }}?court={{ court_id }}&week={{ this_week }}"
|
<a href="{{ base_path }}?court={{ court_id }}&week={{ prev_week }}"
|
||||||
class="rounded border bg-white px-3 py-1 text-sm hover:bg-gray-100">{{ t(key="this-week", lang=lang) }}</a>
|
class="btn btn-sm join-item">« {{ t(key="prev-week", lang=lang) }}</a>
|
||||||
<a href="{{ base_path }}?court={{ court_id }}&week={{ next_week }}"
|
{% else %}
|
||||||
class="rounded border bg-white px-3 py-1 text-sm hover:bg-gray-100">{{ t(key="next-week", lang=lang) }} →</a>
|
<span class="btn btn-sm join-item btn-disabled" aria-disabled="true">« {{ t(key="prev-week", lang=lang) }}</span>
|
||||||
|
{% endif %}
|
||||||
|
<a href="{{ base_path }}?court={{ court_id }}&week={{ this_week }}"
|
||||||
|
class="btn btn-sm join-item">{{ t(key="this-week", lang=lang) }}</a>
|
||||||
|
<a href="{{ base_path }}?court={{ court_id }}&week={{ next_week }}"
|
||||||
|
class="btn btn-sm join-item">{{ t(key="next-week", lang=lang) }} »</a>
|
||||||
|
</div>
|
||||||
|
{% if is_admin %}
|
||||||
|
<button type="button" id="cal-detail-toggle" class="btn btn-sm gap-1" aria-pressed="false"
|
||||||
|
title="{{ t(key='view-details', lang=lang) }}">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||||
|
stroke="currentColor" class="h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
d="M8.25 6.75h12M8.25 12h12m-12 5.25h12M3.75 6.75h.007v.008H3.75V6.75Zm.375 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0ZM3.75 12h.007v.008H3.75V12Zm.375 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Zm-.375 5.25h.007v.008H3.75v-.008Zm.375 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Z" />
|
||||||
|
</svg>
|
||||||
|
{{ t(key="view-details", lang=lang) }}
|
||||||
|
</button>
|
||||||
|
<form method="get" action="{{ base_path }}" class="relative inline-flex">
|
||||||
|
<input type="hidden" name="court" value="{{ court_id }}">
|
||||||
|
<button type="button" id="cal-jump-btn" class="btn btn-sm gap-1"
|
||||||
|
title="{{ t(key='pick-week', lang=lang) }}">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
|
||||||
|
stroke="currentColor" class="h-4 w-4">
|
||||||
|
<path stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
d="M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 0 1 2.25-2.25h13.5A2.25 2.25 0 0 1 21 7.5v11.25m-18 0A2.25 2.25 0 0 0 5.25 21h13.5A2.25 2.25 0 0 0 21 18.75m-18 0v-7.5A2.25 2.25 0 0 1 5.25 9h13.5A2.25 2.25 0 0 1 21 11.25v7.5" />
|
||||||
|
</svg>
|
||||||
|
{{ t(key="pick-week", lang=lang) }}
|
||||||
|
</button>
|
||||||
|
<input type="date" name="week" id="cal-jump" value="{{ week }}"
|
||||||
|
onchange="this.form.submit()" tabindex="-1" aria-hidden="true"
|
||||||
|
class="pointer-events-none absolute inset-0 -z-10 opacity-0">
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-sm font-medium text-gray-600">{{ court_name }} · {{ week_label }}</div>
|
<div class="text-sm font-medium opacity-60">{{ court_name }} · {{ week_label }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="overflow-auto rounded-lg border bg-white">
|
<div class="overflow-x-auto border border-base-300 bg-base-100 shadow-sm">
|
||||||
<table class="w-full border-collapse text-sm">
|
<table id="cal" class="w-full border-collapse text-sm">
|
||||||
<thead>
|
<thead>
|
||||||
<tr class="bg-gray-100">
|
<tr class="bg-base-200">
|
||||||
<th class="w-16 border p-2"></th>
|
<th class="w-16 border border-base-300 p-2"></th>
|
||||||
{% for d in days %}
|
{% for d in days %}
|
||||||
<th class="border p-2 text-center">
|
<th class="border border-base-300 p-2 text-center">
|
||||||
<div class="font-semibold">{{ t(key=d.key, lang=lang) }}</div>
|
<div class="font-semibold">{{ t(key=d.key, lang=lang) }}</div>
|
||||||
<div class="text-xs font-normal text-gray-500">{{ d.num }}</div>
|
<div class="text-xs font-normal opacity-50">{{ d.num }}</div>
|
||||||
</th>
|
</th>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for row in rows %}
|
{% for row in rows %}
|
||||||
|
{% if row.free_group %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="border p-2 text-center font-medium text-gray-500">{{ row.hour_label }}</td>
|
<td class="border border-base-300 bg-base-200 px-2 py-1 text-center text-xs font-medium">{{ row.hour_label }}</td>
|
||||||
|
<td colspan="7" class="border border-base-300 px-2 py-1">
|
||||||
|
<div class="text-center text-xs uppercase tracking-wide opacity-30">{{ t(key="free", lang=lang) }}</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% else %}
|
||||||
|
<tr>
|
||||||
|
<td class="border border-base-300 bg-base-200 p-2 text-center font-medium opacity-70">{{ row.hour_label }}</td>
|
||||||
{% for cell in row.cells %}
|
{% for cell in row.cells %}
|
||||||
<td class="h-14 border p-1 align-top">
|
<td class="relative h-14 border border-base-300">
|
||||||
{% if cell.booked %}
|
{% if cell.booked %}
|
||||||
{% if is_admin %}
|
{% if is_admin %}
|
||||||
<a href="/admin/booking/{{ cell.booking_id }}"
|
<a href="/admin/booking/{{ cell.booking_id }}"
|
||||||
class="block h-full rounded px-1 py-1 text-xs font-medium text-white"
|
class="cal-chip absolute inset-1 flex items-center overflow-hidden rounded px-1.5 text-xs font-medium text-white shadow-sm transition hover:opacity-90"
|
||||||
style="background-color: {{ cell.color }}">{{ cell.name }}</a>
|
style="background-color: {{ cell.color }}">
|
||||||
|
<span class="cal-name min-w-0 truncate">{{ cell.name }}</span>
|
||||||
|
{% if cell.title or cell.contact or cell.note %}
|
||||||
|
<span class="cal-detail">
|
||||||
|
{%- if cell.title %}<span class="truncate opacity-95">{{ cell.title }}</span>{% endif -%}
|
||||||
|
{%- if cell.contact %}<span class="truncate opacity-80">{{ cell.contact }}</span>{% endif -%}
|
||||||
|
{%- if cell.note %}<span class="opacity-80">{{ cell.note }}</span>{% endif -%}
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="h-full rounded px-1 py-1 text-xs font-medium text-white"
|
<div class="absolute inset-1 flex items-center overflow-hidden rounded px-1.5 text-xs font-medium text-white shadow-sm"
|
||||||
style="background-color: {{ cell.color }}" title="{{ cell.name }}">{{ t(key="booked", lang=lang) }}</div>
|
style="background-color: {{ cell.color }}"{% if cell.title %} title="{{ cell.title }}"{% endif %}>
|
||||||
|
<span class="min-w-0 truncate">
|
||||||
|
{%- if cell.title %}{{ cell.title }}{% else %}{{ t(key="booked", lang=lang) }}{% endif -%}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if is_admin %}
|
{% if is_admin %}
|
||||||
<a href="/admin/booking?court={{ court_id }}&date={{ cell.date }}&hour={{ cell.hour }}"
|
<a href="/admin/booking?court={{ court_id }}&date={{ cell.date }}&hour={{ cell.hour }}"
|
||||||
class="block h-full rounded px-1 py-1 text-xs text-gray-400 hover:bg-gray-100">+</a>
|
class="absolute inset-0 flex items-center justify-center text-lg opacity-30 transition hover:bg-base-200 hover:opacity-100">+</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="h-full px-1 py-1 text-xs text-gray-300">{{ t(key="free", lang=lang) }}</div>
|
<div class="absolute inset-0 flex items-center justify-center text-xs opacity-30">{{ t(key="free", lang=lang) }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="rounded-lg border bg-white p-8 text-center text-gray-500">{{ t(key="no-courts", lang=lang) }}</div>
|
<div class="card border border-base-300 bg-base-100 shadow-sm">
|
||||||
|
<div class="card-body items-center text-center opacity-60">{{ t(key="no-courts", lang=lang) }}</div>
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
{% if is_admin %}
|
||||||
|
<script>
|
||||||
|
// Detailed-view toggle for the admin calendar. The choice is remembered
|
||||||
|
// per browser; the public calendar never loads this script.
|
||||||
|
(function () {
|
||||||
|
var KEY = 'cal_detailed';
|
||||||
|
var tbl = document.getElementById('cal');
|
||||||
|
var btn = document.getElementById('cal-detail-toggle');
|
||||||
|
if (!tbl || !btn) return;
|
||||||
|
function apply(on) {
|
||||||
|
tbl.classList.toggle('cal--detailed', on);
|
||||||
|
btn.classList.toggle('btn-active', on);
|
||||||
|
btn.setAttribute('aria-pressed', on ? 'true' : 'false');
|
||||||
|
}
|
||||||
|
apply(localStorage.getItem(KEY) === '1');
|
||||||
|
btn.addEventListener('click', function () {
|
||||||
|
var on = !tbl.classList.contains('cal--detailed');
|
||||||
|
localStorage.setItem(KEY, on ? '1' : '0');
|
||||||
|
apply(on);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<script>
|
||||||
|
// "Go to week" — open the native date picker; picking any day loads the
|
||||||
|
// week it belongs to. Admin only.
|
||||||
|
(function () {
|
||||||
|
var btn = document.getElementById('cal-jump-btn');
|
||||||
|
var input = document.getElementById('cal-jump');
|
||||||
|
if (!btn || !input) return;
|
||||||
|
btn.addEventListener('click', function () {
|
||||||
|
if (typeof input.showPicker === 'function') {
|
||||||
|
input.showPicker();
|
||||||
|
} else {
|
||||||
|
input.focus();
|
||||||
|
input.click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock js %}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ mod m20220101_000001_users;
|
|||||||
|
|
||||||
mod m20260515_162423_courts;
|
mod m20260515_162423_courts;
|
||||||
mod m20260515_170417_bookings;
|
mod m20260515_170417_bookings;
|
||||||
|
mod m20260516_111747_add_title_to_bookings;
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
@@ -14,6 +15,7 @@ impl MigratorTrait for Migrator {
|
|||||||
Box::new(m20220101_000001_users::Migration),
|
Box::new(m20220101_000001_users::Migration),
|
||||||
Box::new(m20260515_162423_courts::Migration),
|
Box::new(m20260515_162423_courts::Migration),
|
||||||
Box::new(m20260515_170417_bookings::Migration),
|
Box::new(m20260515_170417_bookings::Migration),
|
||||||
|
Box::new(m20260516_111747_add_title_to_bookings::Migration),
|
||||||
// inject-above (do not remove this comment)
|
// inject-above (do not remove this comment)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
use loco_rs::schema::*;
|
||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
add_column(m, "bookings", "title", ColType::StringNull).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, m: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
remove_column(m, "bookings", "title").await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,23 @@ pub struct AdminAuth {
|
|||||||
pub user: users::Model,
|
pub user: users::Model,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the logged-in admin user if the request carries a valid admin
|
||||||
|
/// cookie. Unlike the [`AdminAuth`] guard this never rejects, so public pages
|
||||||
|
/// can detect an admin visitor without redirecting non-admins away.
|
||||||
|
pub async fn current_admin(ctx: &AppContext, jar: &CookieJar) -> Option<users::Model> {
|
||||||
|
let admin = admin_email();
|
||||||
|
if admin.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let token = jar.get(AUTH_COOKIE).map(|c| c.value().to_string())?;
|
||||||
|
let (secret, _) = jwt_settings(ctx)?;
|
||||||
|
let claims = jwt::JWT::new(&secret).validate(&token).ok()?;
|
||||||
|
let user = users::Model::find_by_pid(&ctx.db, &claims.claims.pid)
|
||||||
|
.await
|
||||||
|
.ok()?;
|
||||||
|
(user.email == admin).then_some(user)
|
||||||
|
}
|
||||||
|
|
||||||
impl FromRequestParts<AppContext> for AdminAuth {
|
impl FromRequestParts<AppContext> for AdminAuth {
|
||||||
type Rejection = Redirect;
|
type Rejection = Redirect;
|
||||||
|
|
||||||
@@ -43,28 +60,11 @@ impl FromRequestParts<AppContext> for AdminAuth {
|
|||||||
parts: &mut Parts,
|
parts: &mut Parts,
|
||||||
ctx: &AppContext,
|
ctx: &AppContext,
|
||||||
) -> std::result::Result<Self, Self::Rejection> {
|
) -> std::result::Result<Self, Self::Rejection> {
|
||||||
let deny = || Redirect::to("/admin/login");
|
|
||||||
let admin = admin_email();
|
|
||||||
if admin.is_empty() {
|
|
||||||
return Err(deny());
|
|
||||||
}
|
|
||||||
|
|
||||||
let jar = CookieJar::from_headers(&parts.headers);
|
let jar = CookieJar::from_headers(&parts.headers);
|
||||||
let token = jar
|
match current_admin(ctx, &jar).await {
|
||||||
.get(AUTH_COOKIE)
|
Some(user) => Ok(Self { user }),
|
||||||
.map(|c| c.value().to_string())
|
None => Err(Redirect::to("/admin/login")),
|
||||||
.ok_or_else(deny)?;
|
|
||||||
let (secret, _) = jwt_settings(ctx).ok_or_else(deny)?;
|
|
||||||
let claims = jwt::JWT::new(&secret)
|
|
||||||
.validate(&token)
|
|
||||||
.map_err(|_| deny())?;
|
|
||||||
let user = users::Model::find_by_pid(&ctx.db, &claims.claims.pid)
|
|
||||||
.await
|
|
||||||
.map_err(|_| deny())?;
|
|
||||||
if user.email != admin {
|
|
||||||
return Err(deny());
|
|
||||||
}
|
}
|
||||||
Ok(Self { user })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,18 +138,25 @@ pub async fn dashboard(
|
|||||||
Query(q): Query<calendar::CalQuery>,
|
Query(q): Query<calendar::CalQuery>,
|
||||||
) -> Result<Response> {
|
) -> Result<Response> {
|
||||||
let lang = current_lang(&jar);
|
let lang = current_lang(&jar);
|
||||||
let page = build_calendar(&ctx, &lang, true, q.court, q.week).await?;
|
let page = build_calendar(&ctx, &lang, true, true, q.court, q.week).await?;
|
||||||
format::render().view(&v, "calendar/week.html", &page)
|
format::render().view(&v, "calendar/week.html", &page)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------- courts ---
|
// ---------------------------------------------------------------- courts ---
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct CourtsQuery {
|
||||||
|
/// Set to `name` when a court-delete confirmation name did not match.
|
||||||
|
pub err: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn courts_page(
|
pub async fn courts_page(
|
||||||
_auth: AdminAuth,
|
_auth: AdminAuth,
|
||||||
ViewEngine(v): ViewEngine<TeraView>,
|
ViewEngine(v): ViewEngine<TeraView>,
|
||||||
State(ctx): State<AppContext>,
|
State(ctx): State<AppContext>,
|
||||||
jar: CookieJar,
|
jar: CookieJar,
|
||||||
|
Query(q): Query<CourtsQuery>,
|
||||||
) -> Result<Response> {
|
) -> Result<Response> {
|
||||||
let lang = current_lang(&jar);
|
let lang = current_lang(&jar);
|
||||||
let list = courts::Entity::find()
|
let list = courts::Entity::find()
|
||||||
@@ -170,7 +177,13 @@ pub async fn courts_page(
|
|||||||
format::render().view(
|
format::render().view(
|
||||||
&v,
|
&v,
|
||||||
"admin/courts.html",
|
"admin/courts.html",
|
||||||
data!({ "lang": lang, "is_admin": true, "courts": items }),
|
data!({
|
||||||
|
"lang": lang,
|
||||||
|
"is_admin": true,
|
||||||
|
"logged_in": true,
|
||||||
|
"courts": items,
|
||||||
|
"name_error": q.err.as_deref() == Some("name"),
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +211,43 @@ pub async fn create_court(
|
|||||||
Ok(Redirect::to("/admin/courts").into_response())
|
Ok(Redirect::to("/admin/courts").into_response())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct DeleteCourtForm {
|
||||||
|
/// The court name the admin retyped to confirm removal.
|
||||||
|
pub confirm_name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes a court. As a safeguard the admin must retype the court's exact
|
||||||
|
/// name; a mismatch aborts and redirects back with an error. Deleting a court
|
||||||
|
/// also removes all of its bookings, since they would otherwise be orphaned.
|
||||||
|
#[debug_handler]
|
||||||
|
pub async fn delete_court(
|
||||||
|
_auth: AdminAuth,
|
||||||
|
State(ctx): State<AppContext>,
|
||||||
|
Path(id): Path<i32>,
|
||||||
|
Form(form): Form<DeleteCourtForm>,
|
||||||
|
) -> Result<Response> {
|
||||||
|
let court = courts::Entity::find_by_id(id)
|
||||||
|
.one(&ctx.db)
|
||||||
|
.await?
|
||||||
|
.ok_or(Error::NotFound)?;
|
||||||
|
let actual = court
|
||||||
|
.name
|
||||||
|
.clone()
|
||||||
|
.unwrap_or_else(|| format!("Court {}", court.id));
|
||||||
|
|
||||||
|
if form.confirm_name.trim() != actual {
|
||||||
|
return Ok(Redirect::to("/admin/courts?err=name").into_response());
|
||||||
|
}
|
||||||
|
|
||||||
|
bookings::Entity::delete_many()
|
||||||
|
.filter(bookings::Column::CourtId.eq(id))
|
||||||
|
.exec(&ctx.db)
|
||||||
|
.await?;
|
||||||
|
courts::Entity::delete_by_id(id).exec(&ctx.db).await?;
|
||||||
|
Ok(Redirect::to("/admin/courts").into_response())
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------- bookings --
|
// --------------------------------------------------------------- bookings --
|
||||||
|
|
||||||
fn hour_options() -> Vec<serde_json::Value> {
|
fn hour_options() -> Vec<serde_json::Value> {
|
||||||
@@ -206,6 +256,15 @@ fn hour_options() -> Vec<serde_json::Value> {
|
|||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// End-of-block hour options (07:00‥22:00) for the "until" select. A booking
|
||||||
|
/// covers the hours in `[start, end)`, so the end runs one slot past the last
|
||||||
|
/// bookable hour.
|
||||||
|
fn end_hour_options() -> Vec<serde_json::Value> {
|
||||||
|
(FIRST_HOUR + 1..=LAST_HOUR + 1)
|
||||||
|
.map(|h| data!({ "v": h, "label": format!("{h:02}:00") }))
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct NewBookingQuery {
|
pub struct NewBookingQuery {
|
||||||
pub court: Option<i32>,
|
pub court: Option<i32>,
|
||||||
@@ -236,28 +295,37 @@ pub async fn booking_new(
|
|||||||
.and_then(|c| c.name.clone())
|
.and_then(|c| c.name.clone())
|
||||||
.unwrap_or_else(|| format!("Court {court_id}"));
|
.unwrap_or_else(|| format!("Court {court_id}"));
|
||||||
|
|
||||||
|
let hour_start = q.hour.unwrap_or(FIRST_HOUR).clamp(FIRST_HOUR, LAST_HOUR);
|
||||||
|
let hour_end = (hour_start + 1).min(LAST_HOUR + 1);
|
||||||
|
|
||||||
format::render().view(
|
format::render().view(
|
||||||
&v,
|
&v,
|
||||||
"admin/booking_form.html",
|
"admin/booking_form.html",
|
||||||
data!({
|
data!({
|
||||||
"lang": lang,
|
"lang": lang,
|
||||||
"is_admin": true,
|
"is_admin": true,
|
||||||
|
"logged_in": true,
|
||||||
"mode": "new",
|
"mode": "new",
|
||||||
"action": "/admin/booking",
|
"action": "/admin/booking",
|
||||||
"court_id": court_id,
|
"court_id": court_id,
|
||||||
"court_name": court_name,
|
"court_name": court_name,
|
||||||
"date": q.date.unwrap_or_default(),
|
"date": q.date.unwrap_or_default(),
|
||||||
"hour": q.hour.unwrap_or(FIRST_HOUR),
|
"hour_start": hour_start,
|
||||||
|
"hour_end": hour_end,
|
||||||
|
"repeat_weeks": 1,
|
||||||
"color": "#3b82f6",
|
"color": "#3b82f6",
|
||||||
"name": "",
|
"name": "",
|
||||||
|
"title": "",
|
||||||
"contact": "",
|
"contact": "",
|
||||||
"note": "",
|
"note": "",
|
||||||
"hours": hour_options(),
|
"hours": hour_options(),
|
||||||
|
"hours_end": end_hour_options(),
|
||||||
"booking_id": 0,
|
"booking_id": 0,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Form fields for editing a single existing booking.
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct BookingForm {
|
pub struct BookingForm {
|
||||||
pub court_id: i32,
|
pub court_id: i32,
|
||||||
@@ -265,6 +333,23 @@ pub struct BookingForm {
|
|||||||
pub hour: i32,
|
pub hour: i32,
|
||||||
pub color: String,
|
pub color: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
pub title: Option<String>,
|
||||||
|
pub contact: Option<String>,
|
||||||
|
pub note: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Form fields for creating bookings. Unlike editing, creation books a range
|
||||||
|
/// of hours (`[hour_start, hour_end)`) and can repeat the block weekly.
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct BookingCreateForm {
|
||||||
|
pub court_id: i32,
|
||||||
|
pub date: String,
|
||||||
|
pub hour_start: i32,
|
||||||
|
pub hour_end: i32,
|
||||||
|
pub repeat_weeks: Option<i32>,
|
||||||
|
pub color: String,
|
||||||
|
pub name: String,
|
||||||
|
pub title: Option<String>,
|
||||||
pub contact: Option<String>,
|
pub contact: Option<String>,
|
||||||
pub note: Option<String>,
|
pub note: Option<String>,
|
||||||
}
|
}
|
||||||
@@ -274,25 +359,65 @@ fn parse_date(s: &str) -> Result<chrono::NaiveDate> {
|
|||||||
.map_err(|_| Error::string("invalid date"))
|
.map_err(|_| Error::string("invalid date"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates one or more bookings from the admin form. The selected hour range
|
||||||
|
/// expands into one row per hour, and — when `repeat_weeks > 1` — the whole
|
||||||
|
/// block is duplicated on the same weekday for each following week. A slot
|
||||||
|
/// that is already taken is skipped, so an overlap can never double-book.
|
||||||
#[debug_handler]
|
#[debug_handler]
|
||||||
pub async fn booking_create(
|
pub async fn booking_create(
|
||||||
_auth: AdminAuth,
|
_auth: AdminAuth,
|
||||||
State(ctx): State<AppContext>,
|
State(ctx): State<AppContext>,
|
||||||
Form(form): Form<BookingForm>,
|
Form(form): Form<BookingCreateForm>,
|
||||||
) -> Result<Response> {
|
) -> Result<Response> {
|
||||||
let date = parse_date(&form.date)?;
|
let start_date = parse_date(&form.date)?;
|
||||||
bookings::ActiveModel {
|
|
||||||
court_id: Set(form.court_id),
|
// Normalise the hour block to `[hour_start, hour_end)`; a non-positive
|
||||||
date: Set(date),
|
// span falls back to a single hour so the form cannot create nothing.
|
||||||
hour: Set(form.hour),
|
let hour_start = form.hour_start.clamp(FIRST_HOUR, LAST_HOUR);
|
||||||
color: Set(form.color),
|
let hour_end = form.hour_end.clamp(hour_start + 1, LAST_HOUR + 1);
|
||||||
name: Set(form.name),
|
let weeks = form.repeat_weeks.unwrap_or(1).clamp(1, 52);
|
||||||
contact: Set(form.contact.filter(|s| !s.is_empty())),
|
|
||||||
note: Set(form.note.filter(|s| !s.is_empty())),
|
let title = form.title.filter(|s| !s.is_empty());
|
||||||
..Default::default()
|
let contact = form.contact.filter(|s| !s.is_empty());
|
||||||
|
let note = form.note.filter(|s| !s.is_empty());
|
||||||
|
|
||||||
|
let last_date = start_date + chrono::Duration::weeks(i64::from(weeks - 1));
|
||||||
|
|
||||||
|
// Slots already booked on this court within the affected window, used to
|
||||||
|
// skip conflicts rather than insert a duplicate.
|
||||||
|
let taken: std::collections::HashSet<(chrono::NaiveDate, i32)> =
|
||||||
|
bookings::Entity::find()
|
||||||
|
.filter(bookings::Column::CourtId.eq(form.court_id))
|
||||||
|
.filter(bookings::Column::Date.gte(start_date))
|
||||||
|
.filter(bookings::Column::Date.lte(last_date))
|
||||||
|
.all(&ctx.db)
|
||||||
|
.await?
|
||||||
|
.into_iter()
|
||||||
|
.map(|b| (b.date, b.hour))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
for w in 0..weeks {
|
||||||
|
let date = start_date + chrono::Duration::weeks(i64::from(w));
|
||||||
|
for hour in hour_start..hour_end {
|
||||||
|
if taken.contains(&(date, hour)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bookings::ActiveModel {
|
||||||
|
court_id: Set(form.court_id),
|
||||||
|
date: Set(date),
|
||||||
|
hour: Set(hour),
|
||||||
|
color: Set(form.color.clone()),
|
||||||
|
name: Set(form.name.clone()),
|
||||||
|
title: Set(title.clone()),
|
||||||
|
contact: Set(contact.clone()),
|
||||||
|
note: Set(note.clone()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
.insert(&ctx.db)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.insert(&ctx.db)
|
|
||||||
.await?;
|
|
||||||
Ok(Redirect::to(&format!("/admin?court={}&week={}", form.court_id, form.date)).into_response())
|
Ok(Redirect::to(&format!("/admin?court={}&week={}", form.court_id, form.date)).into_response())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,6 +446,7 @@ pub async fn booking_edit(
|
|||||||
data!({
|
data!({
|
||||||
"lang": lang,
|
"lang": lang,
|
||||||
"is_admin": true,
|
"is_admin": true,
|
||||||
|
"logged_in": true,
|
||||||
"mode": "edit",
|
"mode": "edit",
|
||||||
"action": format!("/admin/booking/{id}"),
|
"action": format!("/admin/booking/{id}"),
|
||||||
"court_id": booking.court_id,
|
"court_id": booking.court_id,
|
||||||
@@ -329,6 +455,7 @@ pub async fn booking_edit(
|
|||||||
"hour": booking.hour,
|
"hour": booking.hour,
|
||||||
"color": booking.color,
|
"color": booking.color,
|
||||||
"name": booking.name,
|
"name": booking.name,
|
||||||
|
"title": booking.title.unwrap_or_default(),
|
||||||
"contact": booking.contact.unwrap_or_default(),
|
"contact": booking.contact.unwrap_or_default(),
|
||||||
"note": booking.note.unwrap_or_default(),
|
"note": booking.note.unwrap_or_default(),
|
||||||
"hours": hour_options(),
|
"hours": hour_options(),
|
||||||
@@ -355,6 +482,7 @@ pub async fn booking_update(
|
|||||||
active.hour = Set(form.hour);
|
active.hour = Set(form.hour);
|
||||||
active.color = Set(form.color);
|
active.color = Set(form.color);
|
||||||
active.name = Set(form.name);
|
active.name = Set(form.name);
|
||||||
|
active.title = Set(form.title.filter(|s| !s.is_empty()));
|
||||||
active.contact = Set(form.contact.filter(|s| !s.is_empty()));
|
active.contact = Set(form.contact.filter(|s| !s.is_empty()));
|
||||||
active.note = Set(form.note.filter(|s| !s.is_empty()));
|
active.note = Set(form.note.filter(|s| !s.is_empty()));
|
||||||
active.update(&ctx.db).await?;
|
active.update(&ctx.db).await?;
|
||||||
@@ -384,6 +512,7 @@ pub fn routes() -> Routes {
|
|||||||
.add("/", get(dashboard))
|
.add("/", get(dashboard))
|
||||||
.add("/courts", get(courts_page))
|
.add("/courts", get(courts_page))
|
||||||
.add("/courts", post(create_court))
|
.add("/courts", post(create_court))
|
||||||
|
.add("/courts/{id}/delete", post(delete_court))
|
||||||
.add("/booking", get(booking_new))
|
.add("/booking", get(booking_new))
|
||||||
.add("/booking", post(booking_create))
|
.add("/booking", post(booking_create))
|
||||||
.add("/booking/{id}", get(booking_edit))
|
.add("/booking/{id}", get(booking_edit))
|
||||||
|
|||||||
@@ -50,19 +50,32 @@ pub struct Cell {
|
|||||||
pub booked: bool,
|
pub booked: bool,
|
||||||
pub color: String,
|
pub color: String,
|
||||||
pub booking_id: i32,
|
pub booking_id: i32,
|
||||||
|
/// Private — admin only. Never rendered on the public calendar.
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
/// Public-facing label shown on the calendar when set.
|
||||||
|
pub title: String,
|
||||||
|
/// Private — admin only. Shown in the dashboard's detailed view.
|
||||||
|
pub contact: String,
|
||||||
|
/// Private — admin only. Shown in the dashboard's detailed view.
|
||||||
|
pub note: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct Row {
|
pub struct Row {
|
||||||
pub hour_label: String,
|
pub hour_label: String,
|
||||||
pub cells: Vec<Cell>,
|
pub cells: Vec<Cell>,
|
||||||
|
/// Public view only: `true` when this row collapses a run of fully-free
|
||||||
|
/// hours into one compact strip. The admin grid never sets it.
|
||||||
|
pub free_group: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub struct CalendarPage {
|
pub struct CalendarPage {
|
||||||
pub lang: String,
|
pub lang: String,
|
||||||
|
/// `true` only on the admin dashboard — enables the editable cells.
|
||||||
pub is_admin: bool,
|
pub is_admin: bool,
|
||||||
|
/// `true` whenever the admin is signed in — controls the nav links.
|
||||||
|
pub logged_in: bool,
|
||||||
pub base_path: String,
|
pub base_path: String,
|
||||||
pub has_courts: bool,
|
pub has_courts: bool,
|
||||||
pub courts: Vec<CourtOpt>,
|
pub courts: Vec<CourtOpt>,
|
||||||
@@ -73,6 +86,9 @@ pub struct CalendarPage {
|
|||||||
pub prev_week: String,
|
pub prev_week: String,
|
||||||
pub this_week: String,
|
pub this_week: String,
|
||||||
pub next_week: String,
|
pub next_week: String,
|
||||||
|
/// `false` on the public calendar once it reaches the two-week look-back
|
||||||
|
/// limit, which disables the "previous week" button. Always `true` for admin.
|
||||||
|
pub can_prev: bool,
|
||||||
pub days: Vec<DayHead>,
|
pub days: Vec<DayHead>,
|
||||||
pub rows: Vec<Row>,
|
pub rows: Vec<Row>,
|
||||||
}
|
}
|
||||||
@@ -97,11 +113,52 @@ fn week_monday(week: Option<&str>) -> NaiveDate {
|
|||||||
monday_of(base)
|
monday_of(base)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Collapses runs of fully-free hour rows into one compact strip so a court
|
||||||
|
/// that isn't booked solid doesn't waste vertical space. Rows holding at
|
||||||
|
/// least one booking are kept full-size so bookings stay easy to read.
|
||||||
|
/// Public calendar only — the admin grid always shows every hour.
|
||||||
|
fn group_free_rows(rows: Vec<Row>) -> Vec<Row> {
|
||||||
|
let mut out: Vec<Row> = Vec::new();
|
||||||
|
let mut run: Vec<Row> = Vec::new();
|
||||||
|
for row in rows {
|
||||||
|
if row.cells.iter().all(|c| !c.booked) {
|
||||||
|
run.push(row);
|
||||||
|
} else {
|
||||||
|
flush_free_run(&mut run, &mut out);
|
||||||
|
out.push(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flush_free_run(&mut run, &mut out);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Drains a pending run of free rows into `out` as a single collapsed row.
|
||||||
|
fn flush_free_run(run: &mut Vec<Row>, out: &mut Vec<Row>) {
|
||||||
|
if run.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let hour_of = |r: &Row| r.cells.first().map_or(FIRST_HOUR, |c| c.hour);
|
||||||
|
let first = run.first().map_or(FIRST_HOUR, hour_of);
|
||||||
|
let last = run.last().map_or(first, hour_of);
|
||||||
|
let hour_label = if run.len() > 1 {
|
||||||
|
format!("{first:02}:00 – {:02}:00", last + 1)
|
||||||
|
} else {
|
||||||
|
format!("{first:02}:00")
|
||||||
|
};
|
||||||
|
out.push(Row {
|
||||||
|
hour_label,
|
||||||
|
cells: Vec::new(),
|
||||||
|
free_group: true,
|
||||||
|
});
|
||||||
|
run.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/// Builds the calendar grid for the selected court and week.
|
/// Builds the calendar grid for the selected court and week.
|
||||||
pub async fn build_calendar(
|
pub async fn build_calendar(
|
||||||
ctx: &AppContext,
|
ctx: &AppContext,
|
||||||
lang: &str,
|
lang: &str,
|
||||||
is_admin: bool,
|
is_admin: bool,
|
||||||
|
logged_in: bool,
|
||||||
q_court: Option<i32>,
|
q_court: Option<i32>,
|
||||||
q_week: Option<String>,
|
q_week: Option<String>,
|
||||||
) -> Result<CalendarPage> {
|
) -> Result<CalendarPage> {
|
||||||
@@ -131,6 +188,10 @@ pub async fn build_calendar(
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let monday = week_monday(q_week.as_deref());
|
let monday = week_monday(q_week.as_deref());
|
||||||
|
// The public calendar may look back at most two weeks; the admin has no limit.
|
||||||
|
let min_monday = monday_of(Utc::now().date_naive()) - Duration::weeks(2);
|
||||||
|
let monday = if is_admin { monday } else { monday.max(min_monday) };
|
||||||
|
let can_prev = is_admin || monday > min_monday;
|
||||||
let sunday = monday + Duration::days(6);
|
let sunday = monday + Duration::days(6);
|
||||||
|
|
||||||
let days: Vec<DayHead> = (0..7i64)
|
let days: Vec<DayHead> = (0..7i64)
|
||||||
@@ -169,6 +230,9 @@ pub async fn build_calendar(
|
|||||||
color: b.color.clone(),
|
color: b.color.clone(),
|
||||||
booking_id: b.id,
|
booking_id: b.id,
|
||||||
name: b.name.clone(),
|
name: b.name.clone(),
|
||||||
|
title: b.title.clone().unwrap_or_default(),
|
||||||
|
contact: b.contact.clone().unwrap_or_default(),
|
||||||
|
note: b.note.clone().unwrap_or_default(),
|
||||||
},
|
},
|
||||||
None => Cell {
|
None => Cell {
|
||||||
date: iso,
|
date: iso,
|
||||||
@@ -177,6 +241,9 @@ pub async fn build_calendar(
|
|||||||
color: String::new(),
|
color: String::new(),
|
||||||
booking_id: 0,
|
booking_id: 0,
|
||||||
name: String::new(),
|
name: String::new(),
|
||||||
|
title: String::new(),
|
||||||
|
contact: String::new(),
|
||||||
|
note: String::new(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -184,13 +251,19 @@ pub async fn build_calendar(
|
|||||||
Row {
|
Row {
|
||||||
hour_label: format!("{hour:02}:00"),
|
hour_label: format!("{hour:02}:00"),
|
||||||
cells,
|
cells,
|
||||||
|
free_group: false,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
// The public calendar collapses empty stretches to stay compact; the admin
|
||||||
|
// grid always shows every hour so each slot stays individually editable.
|
||||||
|
let rows = if is_admin { rows } else { group_free_rows(rows) };
|
||||||
|
|
||||||
Ok(CalendarPage {
|
Ok(CalendarPage {
|
||||||
lang: lang.to_string(),
|
lang: lang.to_string(),
|
||||||
is_admin,
|
is_admin,
|
||||||
|
logged_in,
|
||||||
base_path: if is_admin { "/admin" } else { "/" }.to_string(),
|
base_path: if is_admin { "/admin" } else { "/" }.to_string(),
|
||||||
has_courts: !courts_opts.is_empty(),
|
has_courts: !courts_opts.is_empty(),
|
||||||
courts: courts_opts,
|
courts: courts_opts,
|
||||||
@@ -203,6 +276,7 @@ pub async fn build_calendar(
|
|||||||
.format("%Y-%m-%d")
|
.format("%Y-%m-%d")
|
||||||
.to_string(),
|
.to_string(),
|
||||||
next_week: (monday + Duration::days(7)).format("%Y-%m-%d").to_string(),
|
next_week: (monday + Duration::days(7)).format("%Y-%m-%d").to_string(),
|
||||||
|
can_prev,
|
||||||
days,
|
days,
|
||||||
rows,
|
rows,
|
||||||
})
|
})
|
||||||
@@ -216,7 +290,12 @@ pub async fn index(
|
|||||||
Query(q): Query<CalQuery>,
|
Query(q): Query<CalQuery>,
|
||||||
) -> Result<Response> {
|
) -> Result<Response> {
|
||||||
let lang = current_lang(&jar);
|
let lang = current_lang(&jar);
|
||||||
let page = build_calendar(&ctx, &lang, false, q.court, q.week).await?;
|
// The public calendar is read-only for everyone, admin included. When an
|
||||||
|
// admin is signed in we still flag it so the nav keeps the admin links.
|
||||||
|
let logged_in = crate::controllers::admin::current_admin(&ctx, &jar)
|
||||||
|
.await
|
||||||
|
.is_some();
|
||||||
|
let page = build_calendar(&ctx, &lang, false, logged_in, q.court, q.week).await?;
|
||||||
format::render().view(&v, "calendar/week.html", &page)
|
format::render().view(&v, "calendar/week.html", &page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ pub struct Model {
|
|||||||
#[sea_orm(column_type = "Text", nullable)]
|
#[sea_orm(column_type = "Text", nullable)]
|
||||||
pub note: Option<String>,
|
pub note: Option<String>,
|
||||||
pub court_id: i32,
|
pub court_id: i32,
|
||||||
|
pub title: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
|||||||
Reference in New Issue
Block a user