13 Commits

Author SHA1 Message Date
Priec
1b4b79a642 working card for existing reservation 2026-05-16 21:00:09 +02:00
Priec
b5d1fd46ed better admin calendar 2026-05-16 19:17:12 +02:00
Priec
8e99e53d8a mobile resolution 2026-05-16 18:17:27 +02:00
Priec
08884536d7 contrast added 2026-05-16 17:40:15 +02:00
Priec
70920ede87 admin functionality 2026-05-16 17:21:14 +02:00
Priec
7220ec87bc compact calendar now 2026-05-16 17:06:18 +02:00
Priec
a2c851a853 calendar contrast 2026-05-16 16:28:10 +02:00
Priec
51b2b1a98c admin features 2026-05-16 16:06:15 +02:00
Priec
40ee4cf398 details for the admin 2026-05-16 15:11:58 +02:00
Priec
231b11b8b3 working with UI library now 2026-05-16 14:59:17 +02:00
Priec
6006e1e7b1 dark light mode 2026-05-16 13:02:24 +02:00
Priec
6c87a9d58f ui 2026-05-16 12:45:38 +02:00
Priec
164dacb678 working better, small changes 2026-05-16 12:12:33 +02:00
14 changed files with 1105 additions and 180 deletions

View File

@@ -20,4 +20,5 @@ target/
*.sqlite-*
# Local secrets (hardcoded admin credentials)
.env
.env
todo.md

View File

@@ -27,10 +27,13 @@ manage-courts = Courts
back-to-calendar = Back to calendar
add-booking = New Booking
edit-booking = Edit Booking
booking-details = Booking details
edit = Edit
date = Date
hour = Hour
booking-color = Colour
booking-name = Name
booking-name = Name (private)
booking-title = Title (public)
booking-contact = Contact
booking-note = Note
save = Save
@@ -41,3 +44,22 @@ court-name = Name
court-surface = Surface
court-indoor = Indoor
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
menu = Menu
prev-day = Previous day
next-day = Next day
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.

View File

@@ -27,10 +27,13 @@ manage-courts = Kurty
back-to-calendar = Späť na kalendár
add-booking = Nová rezervácia
edit-booking = Upraviť rezerváciu
booking-details = Detail rezervácie
edit = Upraviť
date = Dátum
hour = Hodina
booking-color = Farba
booking-name = Meno
booking-name = Meno (súkromné)
booking-title = Názov (verejný)
booking-contact = Kontakt
booking-note = Poznámka
save = Uložiť
@@ -41,3 +44,22 @@ court-name = Názov
court-surface = Povrch
court-indoor = Krytý
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ň
menu = Menu
prev-day = Predchádzajúci deň
next-day = Nasledujúci 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ň.

View File

@@ -0,0 +1,58 @@
{% extends "base.html" %}
{% block title %}{{ t(key="booking-details", lang=lang) }}{% endblock title %}
{% block content %}
<div class="mx-auto max-w-md">
<div class="mb-4 flex items-center justify-between">
<h1 class="text-2xl font-bold">{{ t(key="booking-details", lang=lang) }}</h1>
<a href="/admin?court={{ court_id }}&week={{ date }}" class="btn btn-ghost btn-sm">« {{ t(key="back-to-calendar", lang=lang) }}</a>
</div>
<div class="card border border-base-300 bg-base-100 shadow-sm">
<div class="card-body gap-0">
<dl class="divide-y divide-base-300">
<div class="flex justify-between gap-4 py-2">
<dt class="text-sm opacity-70">{{ t(key="court-label", lang=lang) }}</dt>
<dd class="text-right text-sm font-medium">{{ court_name }}</dd>
</div>
<div class="flex justify-between gap-4 py-2">
<dt class="text-sm opacity-70">{{ t(key="date", lang=lang) }}</dt>
<dd class="text-right text-sm font-medium">{{ date_label }}</dd>
</div>
<div class="flex justify-between gap-4 py-2">
<dt class="text-sm opacity-70">{{ t(key="hour", lang=lang) }}</dt>
<dd class="text-right text-sm font-medium">{{ hour_label }}</dd>
</div>
<div class="flex items-center justify-between gap-4 py-2">
<dt class="text-sm opacity-70">{{ t(key="booking-color", lang=lang) }}</dt>
<dd class="flex items-center gap-2">
<span class="inline-block h-5 w-8 rounded border border-base-300" style="background-color: {{ color }}"></span>
<span class="text-sm font-medium">{{ color }}</span>
</dd>
</div>
<div class="flex justify-between gap-4 py-2">
<dt class="text-sm opacity-70">{{ t(key="booking-name", lang=lang) }}</dt>
<dd class="text-right text-sm font-medium">{{ name }}</dd>
</div>
<div class="flex justify-between gap-4 py-2">
<dt class="text-sm opacity-70">{{ t(key="booking-title", lang=lang) }}</dt>
<dd class="text-right text-sm font-medium">{% if title %}{{ title }}{% else %}<span class="opacity-40"></span>{% endif %}</dd>
</div>
<div class="flex justify-between gap-4 py-2">
<dt class="text-sm opacity-70">{{ t(key="booking-contact", lang=lang) }}</dt>
<dd class="text-right text-sm font-medium">{% if contact %}{{ contact }}{% else %}<span class="opacity-40"></span>{% endif %}</dd>
</div>
<div class="flex justify-between gap-4 py-2">
<dt class="text-sm opacity-70">{{ t(key="booking-note", lang=lang) }}</dt>
<dd class="whitespace-pre-line text-right text-sm font-medium">{% if note %}{{ note }}{% else %}<span class="opacity-40"></span>{% endif %}</dd>
</div>
</dl>
<div class="flex items-center gap-2 pt-4">
<a href="/admin/booking/{{ booking_id }}/edit" class="btn btn-neutral">{{ t(key="edit", lang=lang) }}</a>
<a href="/admin?court={{ court_id }}&week={{ date }}" class="btn btn-ghost">{{ t(key="back-to-calendar", lang=lang) }}</a>
</div>
</div>
</div>
</div>
{% endblock content %}

View File

@@ -10,55 +10,109 @@
<h1 class="text-2xl font-bold">
{% if mode == "edit" %}{{ t(key="edit-booking", lang=lang) }}{% else %}{{ t(key="add-booking", lang=lang) }}{% endif %}
</h1>
<a href="/admin" class="text-sm text-blue-600 hover:underline">&larr; {{ 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>
<form method="post" action="{{ action }}" class="space-y-3 rounded-lg border bg-white p-4">
<input type="hidden" name="court_id" value="{{ court_id }}">
<div class="text-sm text-gray-600">{{ t(key="court-label", lang=lang) }}: <strong>{{ court_name }}</strong></div>
<div>
<label class="block text-sm text-gray-600">{{ t(key="date", lang=lang) }}</label>
<input type="date" name="date" value="{{ date }}" required class="w-full rounded border-gray-300 text-sm">
<div class="card border border-base-300 bg-base-100 shadow-sm">
<div class="card-body">
<form method="post" action="{{ action }}" class="space-y-2">
<input type="hidden" name="court_id" value="{{ court_id }}">
<div class="text-sm opacity-70">
{{ 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>
<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>
</div>
{% if mode == "edit" %}
<form method="post" action="/admin/booking/{{ booking_id }}/delete" class="mt-3"
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">
{{ t(key="delete", lang=lang) }}
</button>
<button class="btn btn-outline btn-error btn-sm">{{ t(key="delete", lang=lang) }}</button>
</form>
{% endif %}
</div>
{% 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 %}

View File

@@ -5,47 +5,87 @@
{% block content %}
<div class="mb-4 flex items-center justify-between">
<h1 class="text-2xl font-bold">{{ t(key="manage-courts", lang=lang) }}</h1>
<a href="/admin" class="text-sm text-blue-600 hover:underline">&larr; {{ 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 class="mb-6 overflow-auto rounded-lg border bg-white">
<table class="w-full text-sm">
{% if name_error %}
<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>
<tr class="bg-gray-100 text-left">
<th class="p-2">{{ t(key="court-name", lang=lang) }}</th>
<th class="p-2">{{ t(key="court-surface", lang=lang) }}</th>
<th class="p-2">{{ t(key="court-indoor", lang=lang) }}</th>
<tr>
<th>{{ t(key="court-name", lang=lang) }}</th>
<th>{{ t(key="court-surface", lang=lang) }}</th>
<th>{{ t(key="court-indoor", lang=lang) }}</th>
<th class="text-right">{{ t(key="court-remove", lang=lang) }}</th>
</tr>
</thead>
<tbody>
{% for c in courts %}
<tr class="border-t">
<td class="p-2">{{ c.name }}</td>
<td class="p-2">{{ c.surface }}</td>
<td class="p-2">{{ c.indoor }}</td>
<tr>
<td class="font-medium">{{ c.name }}</td>
<td>{{ c.surface }}</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>
{% endfor %}
</tbody>
</table>
</div>
<div class="max-w-md rounded-lg border bg-white p-4">
<h2 class="mb-3 font-semibold">{{ t(key="add-court", lang=lang) }}</h2>
<form method="post" action="/admin/courts" class="space-y-3">
<div>
<label class="block text-sm text-gray-600">{{ t(key="court-name", lang=lang) }}</label>
<input name="name" required class="w-full rounded border-gray-300 text-sm">
</div>
<div>
<label class="block text-sm text-gray-600">{{ t(key="court-surface", lang=lang) }}</label>
<input name="surface" class="w-full rounded border-gray-300 text-sm">
</div>
<label class="flex items-center gap-2 text-sm">
<input type="checkbox" name="indoor" value="1"> {{ t(key="court-indoor", lang=lang) }}
</label>
<button class="rounded bg-gray-900 px-4 py-2 text-sm text-white hover:bg-gray-700">
{{ t(key="add-court", lang=lang) }}
</button>
</form>
<div class="card max-w-md border border-base-300 bg-base-100 shadow-sm">
<div class="card-body">
<h2 class="card-title text-base">{{ t(key="add-court", lang=lang) }}</h2>
<form method="post" action="/admin/courts" class="space-y-2">
<div class="form-control">
<label class="label"><span class="label-text">{{ t(key="court-name", lang=lang) }}</span></label>
<input name="name" required class="input input-bordered w-full">
</div>
<div class="form-control">
<label class="label"><span class="label-text">{{ t(key="court-surface", lang=lang) }}</span></label>
<input name="surface" class="input input-bordered w-full">
</div>
<div class="form-control">
<label class="label cursor-pointer justify-start gap-3">
<input type="checkbox" name="indoor" value="1" class="checkbox checkbox-sm">
<span class="label-text">{{ t(key="court-indoor", lang=lang) }}</span>
</label>
</div>
<button class="btn btn-neutral mt-1">{{ t(key="add-court", lang=lang) }}</button>
</form>
</div>
</div>
{% 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 %}

View File

@@ -3,23 +3,27 @@
{% block title %}{{ t(key="login-title", lang=lang) }}{% endblock title %}
{% block content %}
<div class="mx-auto mt-8 max-w-sm rounded-lg border bg-white p-6">
<h1 class="mb-4 text-xl font-bold">{{ t(key="login-title", lang=lang) }}</h1>
{% if error %}
<div class="mb-3 rounded bg-red-100 px-3 py-2 text-sm text-red-700">{{ t(key="login-error", lang=lang) }}</div>
{% endif %}
<form method="post" action="/admin/login" class="space-y-3">
<div>
<label class="block text-sm text-gray-600">{{ t(key="email", lang=lang) }}</label>
<input type="email" name="email" required class="w-full rounded border-gray-300 text-sm">
<div class="mx-auto mt-8 max-w-sm">
<div class="card border border-base-300 bg-base-100 shadow-sm">
<div class="card-body">
<h1 class="card-title">{{ t(key="login-title", lang=lang) }}</h1>
{% if error %}
<div class="alert alert-error">
<span>{{ t(key="login-error", lang=lang) }}</span>
</div>
{% 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>
<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 %}

View File

@@ -1,40 +1,212 @@
<!DOCTYPE html>
<html lang="{{ lang }}">
<html lang="{{ lang }}" data-theme="light">
<head>
<meta charset="utf-8">
<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>
<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>
<style>
/* Keep buttons static — disable daisyUI's press-shrink animation. */
.btn { --animation-btn: 0; --btn-focus-scale: 1; }
/* App-wide contrast. The daisyUI base palette is very low-contrast, so
panels, tables and form fields blend into the page. Tie their edges to
base-content so every region is easy to pick out by eye, on light and
dark alike. The calendar grid keeps its own stronger #cal rules. */
.border.border-base-300 { border-color: hsl(var(--bc) / 0.2); }
.navbar { border-bottom: 1px solid hsl(var(--bc) / 0.15); }
.input.input-bordered,
.select.select-bordered,
.textarea.textarea-bordered { border-color: hsl(var(--bc) / 0.3); }
.checkbox { border-color: hsl(var(--bc) / 0.3); }
.table thead th { background-color: hsl(var(--bc) / 0.08); }
.table tbody tr:not(:last-child) :where(th, td) {
border-bottom-color: hsl(var(--bc) / 0.18);
}
/* Mobile: pin navbar dropdowns to the viewport's right edge and cap their
width so they can never spill off-screen, whatever the trigger's spot. */
@media (max-width: 767px) {
.navbar .dropdown-content {
position: fixed;
top: 4rem;
right: 0.5rem;
left: auto;
margin-top: 0;
max-width: calc(100vw - 1rem);
}
}
</style>
{% block head %}{% endblock head %}
</head>
<body class="min-h-screen bg-gray-50 text-gray-900 font-sans antialiased">
<header class="border-b bg-white">
<div class="mx-auto flex max-w-6xl items-center justify-between px-5 py-3">
<a href="/" class="text-lg font-bold">{{ t(key="brand", lang=lang) }}</a>
<nav class="flex items-center gap-4 text-sm">
<a href="/" class="hover:underline">{{ t(key="nav-calendar", lang=lang) }}</a>
{% if is_admin %}
<a href="/admin" class="hover:underline">{{ t(key="admin-title", lang=lang) }}</a>
<a href="/admin/courts" class="hover:underline">{{ t(key="manage-courts", lang=lang) }}</a>
<form method="post" action="/admin/logout" class="inline">
<button class="hover:underline">{{ t(key="logout", lang=lang) }}</button>
</form>
{% else %}
<a href="/admin/login" class="hover:underline">{{ t(key="nav-admin", lang=lang) }}</a>
{% endif %}
<span class="flex gap-1">
<button onclick="setLang('en')"
class="rounded px-2 py-0.5 {% if lang == 'en' %}bg-gray-900 text-white{% else %}bg-gray-200{% endif %}">EN</button>
<button onclick="setLang('sk')"
class="rounded px-2 py-0.5 {% if lang == 'sk' %}bg-gray-900 text-white{% else %}bg-gray-200{% endif %}">SK</button>
</span>
<body class="min-h-screen bg-base-200 font-sans text-base-content antialiased">
<div class="navbar bg-base-100 shadow-sm">
<div class="mx-auto flex w-full max-w-6xl items-center justify-between gap-2 px-4">
<a href="/" class="min-w-0 truncate text-lg font-bold">{{ t(key="brand", lang=lang) }}</a>
<nav class="flex items-center gap-1">
<!-- Page links — inline on desktop, tucked into a menu on mobile. -->
<div class="hidden items-center gap-1 md:flex">
<a href="/" class="btn btn-ghost btn-sm">{{ t(key="nav-calendar", lang=lang) }}</a>
{% if logged_in | default(value=false) %}
<a href="/admin" class="btn btn-ghost btn-sm">{{ t(key="admin-title", 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">
<button class="btn btn-ghost btn-sm">{{ t(key="logout", lang=lang) }}</button>
</form>
{% else %}
<a href="/admin/login" class="btn btn-ghost btn-sm">{{ t(key="nav-admin", lang=lang) }}</a>
{% endif %}
</div>
<div class="dropdown dropdown-end md:hidden">
<div tabindex="0" role="button" class="btn btn-ghost btn-sm btn-circle"
aria-label="{{ t(key='menu', 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-5 w-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" />
</svg>
</div>
<div tabindex="0"
class="dropdown-content z-50 mt-3 flex w-52 flex-col gap-1 rounded-box border border-base-300 bg-base-100 p-2 shadow-lg">
<a href="/" class="btn btn-ghost btn-sm justify-start">{{ t(key="nav-calendar", lang=lang) }}</a>
{% if logged_in | default(value=false) %}
<a href="/admin" class="btn btn-ghost btn-sm justify-start">{{ t(key="admin-title", lang=lang) }}</a>
<a href="/admin/courts" class="btn btn-ghost btn-sm justify-start">{{ t(key="manage-courts", lang=lang) }}</a>
<form method="post" action="/admin/logout">
<button class="btn btn-ghost btn-sm w-full justify-start">{{ t(key="logout", lang=lang) }}</button>
</form>
{% else %}
<a href="/admin/login" class="btn btn-ghost btn-sm justify-start">{{ t(key="nav-admin", lang=lang) }}</a>
{% endif %}
</div>
</div>
<div class="dropdown dropdown-end">
<div tabindex="0" role="button" class="btn btn-ghost btn-sm btn-circle"
aria-label="{{ t(key='settings', lang=lang) }}" title="{{ t(key='settings', 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-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>
</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 %}
</main>

View File

@@ -2,6 +2,94 @@
{% 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; }
/* Mobile: show a small window of days (2 on a narrow phone, 3 otherwise)
instead of the full week. JS marks the visible columns with .cal-day-on
and the day navigator slides the window; before JS runs, the first three
days stand in. Wider screens keep the full 7-day grid. */
@media (max-width: 767px) {
#cal thead { display: none; }
#cal .cal-day { display: none; }
#cal .cal-day-0,
#cal .cal-day-1,
#cal .cal-day-2 { display: table-cell; }
#cal.cal-js .cal-day { display: none; }
#cal.cal-js .cal-day.cal-day-on { display: table-cell; }
/* Slim the hour column to its compact label so bookings get the width. */
#cal tbody td:first-child {
width: 1%;
white-space: nowrap;
padding: 0.3rem 0.4rem;
font-size: 0.7rem;
line-height: 1.15;
}
}
</style>
{% if is_admin %}
<style>
/* Admin calendar — strict, content-independent column widths. A long
booking can never widen its column; it grows taller instead. (The public
calendar has merged free rows with a colspan, so it keeps auto layout.) */
#cal { table-layout: fixed; }
@media (max-width: 767px) {
#cal tbody td:first-child { width: 3.25rem; }
}
/* Detailed-view toggle. */
.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 { 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;
}
/* Detailed fields wrap to as many lines as needed — the full booking info
shows and the cell just grows taller, never wider. */
#cal.cal--detailed .cal-name,
#cal.cal--detailed .cal-detail > span {
white-space: normal;
overflow-wrap: anywhere;
}
/* A long note is capped with an ellipsis so one booking can't run away. */
#cal.cal--detailed .cal-note {
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 6;
overflow: hidden;
}
</style>
{% endif %}
{% endblock head %}
{% block content %}
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
<h1 class="text-2xl font-bold">
@@ -9,9 +97,9 @@
</h1>
{% if has_courts %}
<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 }}">
<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 %}
<option value="{{ c.id }}" {% if c.selected %}selected{% endif %}>{{ c.name }}</option>
{% endfor %}
@@ -22,61 +110,238 @@
{% if has_courts %}
<div class="mb-3 flex flex-wrap items-center justify-between gap-2">
<div class="flex gap-2">
<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">&larr; {{ t(key="prev-week", lang=lang) }}</a>
<a href="{{ base_path }}?court={{ court_id }}&week={{ this_week }}"
class="rounded border bg-white px-3 py-1 text-sm hover:bg-gray-100">{{ t(key="this-week", lang=lang) }}</a>
<a href="{{ base_path }}?court={{ court_id }}&week={{ next_week }}"
class="rounded border bg-white px-3 py-1 text-sm hover:bg-gray-100">{{ t(key="next-week", lang=lang) }} &rarr;</a>
<div class="flex flex-wrap items-center gap-2">
<div class="join">
{% if can_prev %}
<a href="{{ base_path }}?court={{ court_id }}&week={{ prev_week }}"
class="btn btn-sm join-item">«<span class="ml-1 hidden sm:inline">{{ t(key="prev-week", lang=lang) }}</span></a>
{% else %}
<span class="btn btn-sm join-item btn-disabled" aria-disabled="true">«<span
class="ml-1 hidden sm:inline">{{ t(key="prev-week", lang=lang) }}</span></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"><span class="mr-1 hidden sm:inline">{{ t(key="next-week", lang=lang) }}</span>»</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>
<span class="hidden sm:inline">{{ t(key="view-details", lang=lang) }}</span>
</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>
<span class="hidden sm:inline">{{ t(key="pick-week", lang=lang) }}</span>
</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 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 class="overflow-auto rounded-lg border bg-white">
<table class="w-full border-collapse text-sm">
<div id="cal-daynav" class="mb-3 flex items-center gap-2 md:hidden">
<button type="button" id="cal-day-prev" class="btn btn-square"
aria-label="{{ t(key='prev-day', lang=lang) }}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2"
stroke="currentColor" class="h-5 w-5">
<path stroke-linecap="round" stroke-linejoin="round" d="M15.75 19.5 8.25 12l7.5-7.5" />
</svg>
</button>
<div id="cal-daynav-label" class="flex-1 text-center text-base font-semibold"></div>
<button type="button" id="cal-day-next" class="btn btn-square"
aria-label="{{ t(key='next-day', lang=lang) }}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2"
stroke="currentColor" class="h-5 w-5">
<path stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5" />
</svg>
</button>
</div>
<div class="overflow-x-auto border border-base-300 bg-base-100 shadow-sm">
<table id="cal" data-day="{{ mobile_day }}" class="w-full border-collapse text-sm">
<thead>
<tr class="bg-gray-100">
<th class="w-16 border p-2"></th>
<tr class="bg-base-200">
<th class="w-16 border border-base-300 p-2"></th>
{% for d in days %}
<th class="border p-2 text-center">
<th class="cal-day cal-day-{{ loop.index0 }} border border-base-300 p-2 text-center"
data-d="{{ t(key=d.key, lang=lang) }} {{ d.num }}">
<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>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in rows %}
{% if row.free_group %}
<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 %}
<td class="h-14 border p-1 align-top">
<td class="cal-day cal-day-{{ loop.index0 }} relative h-14 border border-base-300">
{% if cell.booked %}
{% if is_admin %}
<a href="/admin/booking/{{ cell.booking_id }}"
class="block h-full rounded px-1 py-1 text-xs font-medium text-white"
style="background-color: {{ cell.color }}">{{ cell.name }}</a>
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 }}">
<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="cal-note opacity-80">{{ cell.note }}</span>{% endif -%}
</span>
{% endif %}
</a>
{% else %}
<div class="h-full rounded px-1 py-1 text-xs font-medium text-white"
style="background-color: {{ cell.color }}" title="{{ cell.name }}">{{ t(key="booked", lang=lang) }}</div>
<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 }}"{% 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 %}
{% else %}
{% if is_admin %}
<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 %}
<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 %}
</td>
{% endfor %}
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
{% 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 %}
{% endblock content %}
{% block js %}
<script>
// Mobile: show a sliding window of days (2 on a narrow phone, 3 otherwise)
// rather than the whole week. The navigator buttons and a horizontal swipe
// slide the window; a resize re-fits it. Public and admin calendars alike.
(function () {
var cal = document.getElementById('cal');
var nav = document.getElementById('cal-daynav');
if (!cal || !nav) return;
var label = document.getElementById('cal-daynav-label');
var prevBtn = document.getElementById('cal-day-prev');
var nextBtn = document.getElementById('cal-day-next');
var dayLabels = [].slice.call(cal.querySelectorAll('thead th[data-d]'))
.map(function (th) { return th.getAttribute('data-d'); });
var start = parseInt(cal.getAttribute('data-day'), 10) || 0;
cal.classList.add('cal-js');
function windowSize() {
return window.innerWidth < 480 ? 2 : 3;
}
function apply() {
var size = windowSize();
var maxStart = 7 - size;
if (start > maxStart) start = maxStart;
if (start < 0) start = 0;
for (var d = 0; d < 7; d++) {
var on = d >= start && d < start + size;
var cells = cal.querySelectorAll('.cal-day-' + d);
for (var i = 0; i < cells.length; i++) {
cells[i].classList.toggle('cal-day-on', on);
}
}
var last = start + size - 1;
label.textContent = (dayLabels[start] || '') + ' ' + (dayLabels[last] || '');
prevBtn.disabled = start <= 0;
nextBtn.disabled = start >= maxStart;
}
function slide(delta) { start += delta; apply(); }
prevBtn.addEventListener('click', function () { slide(-1); });
nextBtn.addEventListener('click', function () { slide(1); });
window.addEventListener('resize', apply);
var x0 = null, y0 = null;
cal.addEventListener('touchstart', function (e) {
x0 = e.touches[0].clientX;
y0 = e.touches[0].clientY;
}, { passive: true });
cal.addEventListener('touchend', function (e) {
if (x0 === null) return;
var dx = e.changedTouches[0].clientX - x0;
var dy = e.changedTouches[0].clientY - y0;
if (Math.abs(dx) > 50 && Math.abs(dx) > Math.abs(dy)) slide(dx < 0 ? 1 : -1);
x0 = y0 = null;
}, { passive: true });
apply();
})();
</script>
{% 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 %}

View File

@@ -5,6 +5,7 @@ mod m20220101_000001_users;
mod m20260515_162423_courts;
mod m20260515_170417_bookings;
mod m20260516_111747_add_title_to_bookings;
pub struct Migrator;
#[async_trait::async_trait]
@@ -14,6 +15,7 @@ impl MigratorTrait for Migrator {
Box::new(m20220101_000001_users::Migration),
Box::new(m20260515_162423_courts::Migration),
Box::new(m20260515_170417_bookings::Migration),
Box::new(m20260516_111747_add_title_to_bookings::Migration),
// inject-above (do not remove this comment)
]
}

View File

@@ -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(())
}
}

View File

@@ -36,6 +36,23 @@ pub struct AdminAuth {
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 {
type Rejection = Redirect;
@@ -43,28 +60,11 @@ impl FromRequestParts<AppContext> for AdminAuth {
parts: &mut Parts,
ctx: &AppContext,
) -> 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 token = jar
.get(AUTH_COOKIE)
.map(|c| c.value().to_string())
.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());
match current_admin(ctx, &jar).await {
Some(user) => Ok(Self { user }),
None => Err(Redirect::to("/admin/login")),
}
Ok(Self { user })
}
}
@@ -138,18 +138,25 @@ pub async fn dashboard(
Query(q): Query<calendar::CalQuery>,
) -> Result<Response> {
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)
}
// ---------------------------------------------------------------- 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]
pub async fn courts_page(
_auth: AdminAuth,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
jar: CookieJar,
Query(q): Query<CourtsQuery>,
) -> Result<Response> {
let lang = current_lang(&jar);
let list = courts::Entity::find()
@@ -170,7 +177,13 @@ pub async fn courts_page(
format::render().view(
&v,
"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())
}
#[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 --
fn hour_options() -> Vec<serde_json::Value> {
@@ -206,6 +256,15 @@ fn hour_options() -> Vec<serde_json::Value> {
.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)]
pub struct NewBookingQuery {
pub court: Option<i32>,
@@ -236,28 +295,37 @@ pub async fn booking_new(
.and_then(|c| c.name.clone())
.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(
&v,
"admin/booking_form.html",
data!({
"lang": lang,
"is_admin": true,
"logged_in": true,
"mode": "new",
"action": "/admin/booking",
"court_id": court_id,
"court_name": court_name,
"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",
"name": "",
"title": "",
"contact": "",
"note": "",
"hours": hour_options(),
"hours_end": end_hour_options(),
"booking_id": 0,
}),
)
}
/// Form fields for editing a single existing booking.
#[derive(Debug, Deserialize)]
pub struct BookingForm {
pub court_id: i32,
@@ -265,6 +333,23 @@ pub struct BookingForm {
pub hour: i32,
pub color: 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 note: Option<String>,
}
@@ -274,28 +359,112 @@ fn parse_date(s: &str) -> Result<chrono::NaiveDate> {
.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]
pub async fn booking_create(
_auth: AdminAuth,
State(ctx): State<AppContext>,
Form(form): Form<BookingForm>,
Form(form): Form<BookingCreateForm>,
) -> Result<Response> {
let date = parse_date(&form.date)?;
bookings::ActiveModel {
court_id: Set(form.court_id),
date: Set(date),
hour: Set(form.hour),
color: Set(form.color),
name: Set(form.name),
contact: Set(form.contact.filter(|s| !s.is_empty())),
note: Set(form.note.filter(|s| !s.is_empty())),
..Default::default()
let start_date = parse_date(&form.date)?;
// Normalise the hour block to `[hour_start, hour_end)`; a non-positive
// span falls back to a single hour so the form cannot create nothing.
let hour_start = form.hour_start.clamp(FIRST_HOUR, LAST_HOUR);
let hour_end = form.hour_end.clamp(hour_start + 1, LAST_HOUR + 1);
let weeks = form.repeat_weeks.unwrap_or(1).clamp(1, 52);
let title = form.title.filter(|s| !s.is_empty());
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())
}
/// Read-only detail card for an existing booking. Clicking a booking in the
/// calendar lands here first, so a stray click can never change anything; the
/// card's "Edit" button is the only way through to the editable form.
#[debug_handler]
pub async fn booking_view(
_auth: AdminAuth,
ViewEngine(v): ViewEngine<TeraView>,
State(ctx): State<AppContext>,
jar: CookieJar,
Path(id): Path<i32>,
) -> Result<Response> {
let lang = current_lang(&jar);
let booking = bookings::Entity::find_by_id(id)
.one(&ctx.db)
.await?
.ok_or(Error::NotFound)?;
let court_name = courts::Entity::find_by_id(booking.court_id)
.one(&ctx.db)
.await?
.and_then(|c| c.name)
.unwrap_or_else(|| format!("Court {}", booking.court_id));
format::render().view(
&v,
"admin/booking_detail.html",
data!({
"lang": lang,
"is_admin": true,
"logged_in": true,
"court_id": booking.court_id,
"court_name": court_name,
"date": booking.date.format("%Y-%m-%d").to_string(),
"date_label": booking.date.format("%d %b %Y").to_string(),
"hour_label": format!("{:02}:00 {:02}:00", booking.hour, booking.hour + 1),
"color": booking.color,
"name": booking.name,
"title": booking.title.unwrap_or_default(),
"contact": booking.contact.unwrap_or_default(),
"note": booking.note.unwrap_or_default(),
"booking_id": id,
}),
)
}
#[debug_handler]
pub async fn booking_edit(
_auth: AdminAuth,
@@ -321,6 +490,7 @@ pub async fn booking_edit(
data!({
"lang": lang,
"is_admin": true,
"logged_in": true,
"mode": "edit",
"action": format!("/admin/booking/{id}"),
"court_id": booking.court_id,
@@ -329,6 +499,7 @@ pub async fn booking_edit(
"hour": booking.hour,
"color": booking.color,
"name": booking.name,
"title": booking.title.unwrap_or_default(),
"contact": booking.contact.unwrap_or_default(),
"note": booking.note.unwrap_or_default(),
"hours": hour_options(),
@@ -355,6 +526,7 @@ pub async fn booking_update(
active.hour = Set(form.hour);
active.color = Set(form.color);
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.note = Set(form.note.filter(|s| !s.is_empty()));
active.update(&ctx.db).await?;
@@ -384,9 +556,11 @@ pub fn routes() -> Routes {
.add("/", get(dashboard))
.add("/courts", get(courts_page))
.add("/courts", post(create_court))
.add("/courts/{id}/delete", post(delete_court))
.add("/booking", get(booking_new))
.add("/booking", post(booking_create))
.add("/booking/{id}", get(booking_edit))
.add("/booking/{id}", get(booking_view))
.add("/booking/{id}/edit", get(booking_edit))
.add("/booking/{id}", post(booking_update))
.add("/booking/{id}/delete", post(booking_delete))
}

View File

@@ -50,19 +50,32 @@ pub struct Cell {
pub booked: bool,
pub color: String,
pub booking_id: i32,
/// Private — admin only. Never rendered on the public calendar.
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)]
pub struct Row {
pub hour_label: String,
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)]
pub struct CalendarPage {
pub lang: String,
/// `true` only on the admin dashboard — enables the editable cells.
pub is_admin: bool,
/// `true` whenever the admin is signed in — controls the nav links.
pub logged_in: bool,
pub base_path: String,
pub has_courts: bool,
pub courts: Vec<CourtOpt>,
@@ -73,16 +86,23 @@ pub struct CalendarPage {
pub prev_week: String,
pub this_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,
/// Index (06, MonSun) of the day shown first in the mobile single-day
/// view — today when the displayed week contains it, otherwise Monday.
pub mobile_day: i64,
pub days: Vec<DayHead>,
pub rows: Vec<Row>,
}
/// Resolves the UI language from the `lang` cookie (`sk` or `en`, default `en`).
/// Resolves the UI language from the `lang` cookie. Slovak is the default;
/// English applies only when the cookie explicitly asks for it.
#[must_use]
pub fn current_lang(jar: &CookieJar) -> String {
match jar.get("lang").map(|c| c.value().to_string()) {
Some(ref l) if l == "sk" => "sk".to_string(),
_ => "en".to_string(),
Some(ref l) if l == "en" => "en".to_string(),
_ => "sk".to_string(),
}
}
@@ -97,11 +117,52 @@ fn week_monday(week: Option<&str>) -> NaiveDate {
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.
pub async fn build_calendar(
ctx: &AppContext,
lang: &str,
is_admin: bool,
logged_in: bool,
q_court: Option<i32>,
q_week: Option<String>,
) -> Result<CalendarPage> {
@@ -131,6 +192,18 @@ pub async fn build_calendar(
.unwrap_or_default();
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;
// The mobile day-window opens on the requested day when a week was given
// (so returning from the booking editor lands back on it), else on today.
let pivot = q_week
.as_deref()
.and_then(|w| NaiveDate::parse_from_str(w, "%Y-%m-%d").ok())
.unwrap_or_else(|| Utc::now().date_naive());
let day_offset = (pivot - monday).num_days();
let mobile_day = if (0..7).contains(&day_offset) { day_offset } else { 0 };
let sunday = monday + Duration::days(6);
let days: Vec<DayHead> = (0..7i64)
@@ -169,6 +242,9 @@ pub async fn build_calendar(
color: b.color.clone(),
booking_id: b.id,
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 {
date: iso,
@@ -177,6 +253,9 @@ pub async fn build_calendar(
color: String::new(),
booking_id: 0,
name: String::new(),
title: String::new(),
contact: String::new(),
note: String::new(),
},
}
})
@@ -184,13 +263,19 @@ pub async fn build_calendar(
Row {
hour_label: format!("{hour:02}:00"),
cells,
free_group: false,
}
})
.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 {
lang: lang.to_string(),
is_admin,
logged_in,
base_path: if is_admin { "/admin" } else { "/" }.to_string(),
has_courts: !courts_opts.is_empty(),
courts: courts_opts,
@@ -203,6 +288,8 @@ pub async fn build_calendar(
.format("%Y-%m-%d")
.to_string(),
next_week: (monday + Duration::days(7)).format("%Y-%m-%d").to_string(),
can_prev,
mobile_day,
days,
rows,
})
@@ -216,7 +303,12 @@ pub async fn index(
Query(q): Query<CalQuery>,
) -> Result<Response> {
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)
}

View File

@@ -18,6 +18,7 @@ pub struct Model {
#[sea_orm(column_type = "Text", nullable)]
pub note: Option<String>,
pub court_id: i32,
pub title: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]