Kalender: Standardansicht auf 4 Kalenderwochen ab aktueller KW umgestellt

This commit is contained in:
torsten 2026-11-25 22:14:39 +01:00
parent b8fe34512d
commit 660cab1001
9 changed files with 38 additions and 25 deletions

View file

@ -9,7 +9,7 @@ Die Anforderungen stammen aus
## Was die App kann
- **Kalender** mit Tages-, Wochen- und Monatsansicht (Monat ist Standard). Alle Anhänger haben
- **Kalender** mit Tages-, 4-Wochen- und Monatsansicht (4 Kalenderwochen sind Standard und starten mit der aktuellen KW). Alle Anhänger haben
eine eigene Zeile und sind immer gleichzeitig sichtbar. Jeder Termin ist ein
durchgehender, farbiger Balken in der Farbe des Anhängers.
- **Buchungen** mit Anfangs- und Endtermin (Datum, Uhrzeit optional), Miete,

View file

@ -407,9 +407,9 @@ function calendar_url(string $date, string $view, int $employeeId, bool $showCan
function page_calendar(array $user): void
{
$view = query_string('view', 'month');
if (!in_array($view, ['day', 'week', 'month'], true)) {
$view = 'month';
$view = query_string('view', 'weeks');
if (!in_array($view, ['day', 'weeks', 'month'], true)) {
$view = 'weeks';
}
$date = query_string('date');
if (!valid_date($date)) {
@ -424,8 +424,9 @@ function page_calendar(array $user): void
$from = month_start($date);
$to = month_end($date);
} else {
// Vier Kalenderwochen ab dem Montag der Woche, in der $date liegt.
$from = week_start($date);
$to = add_days($from, 6);
$to = add_days($from, CALENDAR_WEEKS * 7 - 1);
}
$bookings = booking_list($from, $to, $showCancelled, $employeeId);
@ -449,13 +450,14 @@ function page_calendar(array $user): void
'weekday' => fmt_weekday_short($cursor),
'is_today' => $cursor === today_iso(),
'is_weekend' => (int) date_obj($cursor)->format('N') >= 6,
'is_week_start' => date_obj($cursor)->format('N') === '1',
'is_first_of_month' => date_obj($cursor)->format('j') === '1',
];
$cursor = add_days($cursor, 1);
}
$barBase = ['day' => 76, 'week' => 48, 'month' => 34][$view];
$rowMin = ['day' => 104, 'week' => 64, 'month' => 44][$view];
$barBase = ['day' => 76, 'weeks' => 34, 'month' => 34][$view];
$rowMin = ['day' => 104, 'weeks' => 44, 'month' => 44][$view];
$rows = [];
foreach ($trailers as $trailer) {
@ -480,9 +482,9 @@ function page_calendar(array $user): void
if ($view === 'day') {
$prevDate = add_days($date, -1);
$nextDate = add_days($date, 1);
} elseif ($view === 'week') {
$prevDate = add_days($date, -7);
$nextDate = add_days($date, 7);
} elseif ($view === 'weeks') {
$prevDate = add_days($date, -CALENDAR_WEEKS * 7);
$nextDate = add_days($date, CALENDAR_WEEKS * 7);
} else {
$prevDate = date_obj(month_start($date))->modify('first day of previous month')->format('Y-m-d');
$nextDate = date_obj(month_start($date))->modify('first day of next month')->format('Y-m-d');
@ -490,8 +492,9 @@ function page_calendar(array $user): void
if ($view === 'day') {
$title = fmt_date_long($date);
} elseif ($view === 'week') {
$title = 'KW ' . date_obj($from)->format('W') . ' · ' . fmt_date_range($from, $to);
} elseif ($view === 'weeks') {
$title = 'KW ' . date_obj($from)->format('W') . '–' . date_obj($to)->format('W')
. ' · ' . fmt_date_range($from, $to);
} else {
$title = fmt_month($date);
}
@ -850,7 +853,7 @@ function page_booking_delete(array $user, int $id): void
}
booking_delete($id);
flash('success', 'Buchung von ' . $booking['customer_name'] . ' wurde endgültig gelöscht.');
redirect('/calendar?view=month&date=' . $booking['start_date']);
redirect('/calendar?date=' . $booking['start_date']);
}
function page_booking_move(array $user, int $id): void

View file

@ -92,7 +92,7 @@ function url(string $path = '/'): string
}
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
const DIC_ASSET_VERSION = '20';
const DIC_ASSET_VERSION = '21';
function asset(string $path): string
{
@ -329,6 +329,9 @@ function week_start(string $iso): string
return $date->modify('-' . ($weekday - 1) . ' days')->format('Y-m-d');
}
/** Anzahl der Kalenderwochen, die die Kalenderansicht standardmäßig zeigt. */
const CALENDAR_WEEKS = 4;
function month_start(string $iso): string
{
return date_obj($iso)->modify('first day of this month')->format('Y-m-d');

View file

@ -62,7 +62,7 @@ entstehen.
Zwei Buchungen mit Wechseltag liegen in zwei Lanes und bleiben beide
sichtbar. Lanes und Balkenpositionen werden serverseitig in Prozent
berechnet; das funktioniert ohne JavaScript und ohne externe Kalender-Library.
- Tages-, Wochen- und Monatsansicht nutzen dieselbe Zeilenstruktur
- Tages-, 4-Wochen- und Monatsansicht nutzen dieselbe Zeilenstruktur
(Anhänger × Zeitraum). Die Monatsansicht ist bewusst als horizontale
Zeitachse umgesetzt, damit auch dort jeder Anhänger eine eigene Zeile behält
und kein Termin in „weitere Termine“ wandert.
@ -173,7 +173,7 @@ sind die primäre Anzeige und funktionieren ohne Mailversand.
| Anforderung | Umsetzung |
|---|---|
| 2. Kalender, ein Anhänger je Zeile | `trailers` (Start-Anhänger aus der Anforderung, weitere anlegbar), Kalenderzeilen mit fester Lane-Spalte, alle aktiven Anhänger immer sichtbar |
| Tag/Woche/Monat, Google-ähnlich | `?view=day|week|month`, Navigation, Heute, Datumssprung |
| Tag/4 Wochen/Monat, Google-ähnlich | `?view=day|weeks|month` (Default `weeks`, 4 Kalenderwochen ab Montag), Navigation, Heute, Datumssprung |
| Durchgehende farbige Balken | absolute Balken pro Zeile, Farbe aus `trailers.color_hex` |
| Keine ausgeblendeten Termine | alle Buchungen im Zeitraum werden gerendert; Lanes statt „weitere Termine“ |
| 3. Mietzeiträume | `DATE`-Zeitraum inklusive Endtag; Uhrzeiten (`start_time`, `end_time`) optional, ohne Angabe ganztägig |

View file

@ -31,7 +31,7 @@ $groupMeta = [
<p class="page-head__lede">Zeitraum wählen – die App zeigt, welche Anhänger und Truhen in dieser Zeit frei sind.</p>
</div>
<div class="page-head__actions">
<a class="btn" href="<?= e(url('/calendar?view=month&date=' . $from)) ?>">
<a class="btn" href="<?= e(url('/calendar?date=' . $from)) ?>">
<svg class="ico" aria-hidden="true"><use href="#i-calendar"/></svg> Im Kalender
</a>
<a class="btn" href="<?= e(url('/')) ?>">

View file

@ -12,7 +12,7 @@ $due = due_cents((int) $booking['total_cents'], (int) $booking['deposit_cents'])
$returnTo = '/bookings/' . (int) $booking['id'];
?>
<div class="breadcrumb">
<a href="<?= e(url('/calendar?view=month&date=' . $booking['start_date'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-left"/></svg> Kalender</a>
<a href="<?= e(url('/calendar?date=' . $booking['start_date'])) ?>"><svg class="ico" aria-hidden="true"><use href="#i-left"/></svg> Kalender</a>
<span>/</span>
<span>Buchung #<?= (int) $booking['id'] ?></span>
</div>

View file

@ -19,7 +19,7 @@ $canCreate = ($user['role'] ?? '') === 'admin';
$cols = count($days);
$laneWidth = 150;
$minWidth = match ($view) {
'week' => $laneWidth + 7 * 92,
'weeks' => $laneWidth + $cols * 44,
'month' => $laneWidth + $cols * 40,
default => 0,
};
@ -41,7 +41,7 @@ $minWidth = match ($view) {
<div class="cal-toolbar">
<div class="cal-toolbar__left">
<div class="segmented" role="group" aria-label="Ansicht">
<?php foreach (['day' => 'Tag', 'week' => 'Woche', 'month' => 'Monat'] as $key => $label): ?>
<?php foreach (['day' => 'Tag', 'weeks' => '4 Wochen', 'month' => 'Monat'] as $key => $label): ?>
<a href="<?= e(url(calendar_url($date, $key, $employeeId, $showCancelled))) ?>"<?= $view === $key ? ' class="is-active" aria-current="page"' : '' ?>><?= $label ?></a>
<?php endforeach; ?>
</div>
@ -94,7 +94,7 @@ $minWidth = match ($view) {
</div>
<div class="cal-head">
<?php foreach ($days as $day): ?>
<div class="cal-head__day<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?>">
<div class="cal-head__day<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?><?= $day['is_week_start'] ? ' is-week-start' : '' ?>">
<span class="cal-head__weekday"><?= e($day['weekday']) ?></span>
<span class="cal-head__num"><?= (int) $day['day'] ?></span>
<?php // Monat in jeder Tagesüberschrift, damit er auch in der Handy-Ansicht
@ -103,6 +103,9 @@ $minWidth = match ($view) {
<?php if ($view !== 'day' && $day['is_first_of_month']): ?>
<span class="cal-head__year"><?= e(date_obj($day['iso'])->format('Y')) ?></span>
<?php endif; ?>
<?php if ($view === 'weeks' && $day['is_week_start']): ?>
<span class="cal-head__week">KW <?= e(date_obj($day['iso'])->format('W')) ?></span>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
@ -123,13 +126,13 @@ $minWidth = match ($view) {
<div class="cal-cells">
<?php foreach ($days as $day): ?>
<?php if ($canCreate): ?>
<a class="cal-cell<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?>"
<a class="cal-cell<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?><?= $day['is_week_start'] ? ' is-week-start' : '' ?>"
href="<?= e(url('/bookings/new?trailer=' . (int) $trailer['id'] . '&start=' . $day['iso'] . '&end=' . $day['iso'])) ?>"
data-cell="1"
data-date="<?= e($day['iso']) ?>"
aria-label="Neue Buchung <?= e($trailer['label']) ?> am <?= e(fmt_date($day['iso'])) ?>"></a>
<?php else: ?>
<span class="cal-cell<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?>"
<span class="cal-cell<?= $day['is_today'] ? ' is-today' : '' ?><?= $day['is_weekend'] ? ' is-weekend' : '' ?><?= $day['is_week_start'] ? ' is-week-start' : '' ?>"
data-cell="1"
data-date="<?= e($day['iso']) ?>"></span>
<?php endif; ?>
@ -141,7 +144,7 @@ $minWidth = match ($view) {
$geo = $bar['geo'];
$cancelled = $booking['status'] === 'cancelled';
$showMeta = $view === 'day' || $geo['span'] >= 2;
$label = $view === 'month' ? truncate((string) $booking['customer_name'], 18) : (string) $booking['customer_name'];
$label = in_array($view, ['month', 'weeks'], true) ? truncate((string) $booking['customer_name'], 18) : (string) $booking['customer_name'];
$aria = $booking['customer_name'] . ', ' . $booking['trailer_label'] . ', '
. fmt_date_with_time($booking['start_date'], $booking['start_time'] ?? null) . ' bis '
. fmt_date_with_time($booking['end_date'], $booking['end_time'] ?? null)

View file

@ -506,6 +506,9 @@ a .ico, button .ico { pointer-events: none; }
.cal-head__day.is-weekend { background: #fbfdff; }
.cal-head__day.is-today { background: var(--ice-100); }
.cal-head__day.is-today .cal-head__num, .cal-head__day.is-today .cal-head__weekday { color: var(--brand-700); }
/* Wochenwechsel in der 4-Wochen-Ansicht sichtbar machen. */
.cal-head__day.is-week-start { border-left: 2px solid var(--line); }
.cal-head__week { font-family: var(--font-display); font-size: .56rem; font-weight: 800; letter-spacing: .04em; color: var(--brand-700); margin-top: 1px; white-space: nowrap; }
.cal-label {
position: sticky; left: 0; z-index: 5; background: #fff;
@ -531,6 +534,7 @@ a .ico, button .ico { pointer-events: none; }
.cal-cell.is-weekend:hover { background: #f1f8ff; }
.cal-cell.is-today { background: rgba(230, 241, 252, .5); }
.cal-cell.is-today:hover { background: rgba(211, 230, 249, .7); }
.cal-cell.is-week-start { border-left: 2px solid var(--line); }
.cal-track.is-drop-target { background: rgba(25, 106, 188, .06); }
.cal-bar {

View file

@ -6,7 +6,7 @@
* zwischengespeichert, damit niemand veraltete Buchungen sieht.
*/
const VERSION = 'dic-v12';
const VERSION = 'dic-v13';
const CACHE = VERSION;
const BASE = new URL(self.registration.scope).pathname.replace(/\/$/, '');