diff --git a/app/pages.php b/app/pages.php index 29abf91..17a22e2 100644 --- a/app/pages.php +++ b/app/pages.php @@ -418,6 +418,10 @@ function page_calendar(array $user): void $employeeId = query_int('employee'); $showCancelled = query_string('cancelled') === '1'; + // Startwoche: Montag der Woche, in der $date liegt. + $focusFrom = week_start($date); + $focusTo = add_days($focusFrom, CALENDAR_WEEKS * 7 - 1); + if ($view === 'day') { $from = $to = $date; } elseif ($view === 'month') { @@ -425,8 +429,15 @@ function page_calendar(array $user): void $to = month_end($date); } else { // Vier Kalenderwochen ab dem Montag der Woche, in der $date liegt. - $from = week_start($date); - $to = add_days($from, CALENDAR_WEEKS * 7 - 1); + $from = $focusFrom; + $to = $focusTo; + if (client_is_mobile()) { + // Smartphone: mehr Wochen rendern, damit sich der Kalender nach + // links und rechts wischen lässt (± 2 Monate um die Startwoche). + $from = week_start(date_obj($date)->modify('-' . CALENDAR_MOBILE_MONTHS . ' months')->format('Y-m-d')); + $later = date_obj($date)->modify('+' . CALENDAR_MOBILE_MONTHS . ' months')->format('Y-m-d'); + $to = add_days(week_start($later), 6); + } } $bookings = booking_list($from, $to, $showCancelled, $employeeId); @@ -494,8 +505,8 @@ function page_calendar(array $user): void if ($view === 'day') { $title = fmt_date_long($date); } elseif ($view === 'weeks') { - $title = 'KW ' . date_obj($from)->format('W') . '–' . date_obj($to)->format('W') - . ' · ' . fmt_date_range($from, $to); + $title = 'KW ' . date_obj($focusFrom)->format('W') . '–' . date_obj($focusTo)->format('W') + . ' · ' . fmt_date_range($focusFrom, $focusTo); } else { $title = fmt_month($date); } @@ -509,6 +520,7 @@ function page_calendar(array $user): void 'days' => $days, 'rows' => $rows, 'calTitle' => $title, + 'focusFrom' => $focusFrom, 'prevDate' => $prevDate, 'nextDate' => $nextDate, 'today' => today_iso(), diff --git a/app/util.php b/app/util.php index 179e5ea..1465b5a 100644 --- a/app/util.php +++ b/app/util.php @@ -92,7 +92,7 @@ function url(string $path = '/'): string } /** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */ -const DIC_ASSET_VERSION = '21'; +const DIC_ASSET_VERSION = '22'; function asset(string $path): string { @@ -332,6 +332,19 @@ function week_start(string $iso): string /** Anzahl der Kalenderwochen, die die Kalenderansicht standardmäßig zeigt. */ const CALENDAR_WEEKS = 4; +/** + * Auf Smartphones wird zusätzlich Zeitraum vor/nach der Startwoche gerendert, + * damit sich der Kalender seitlich durchwischen lässt (in Monaten). + */ +const CALENDAR_MOBILE_MONTHS = 2; + +/** Grobe Geräteerkennung: schmale Touch-Geräte bekommen den erweiterten Kalender. */ +function client_is_mobile(): bool +{ + $agent = (string) ($_SERVER['HTTP_USER_AGENT'] ?? ''); + return $agent !== '' && preg_match('/Android|iPhone|iPod|Windows Phone|IEMobile|Opera Mini|Mobile Safari|Mobile\//i', $agent) === 1; +} + function month_start(string $iso): string { return date_obj($iso)->modify('first day of this month')->format('Y-m-d'); diff --git a/views/calendar.php b/views/calendar.php index b6a4ae8..29e1fb7 100644 --- a/views/calendar.php +++ b/views/calendar.php @@ -6,6 +6,7 @@ /** @var array $days */ /** @var array $rows */ /** @var string $calTitle */ +/** @var string $focusFrom */ /** @var string $prevDate */ /** @var string $nextDate */ /** @var string $today */ @@ -85,7 +86,7 @@ $minWidth = match ($view) {

Seitlich scrollen, um alle Tage zu sehen

-
+
diff --git a/web/assets/app.js b/web/assets/app.js index 05f9c34..4d3959e 100644 --- a/web/assets/app.js +++ b/web/assets/app.js @@ -535,6 +535,19 @@ start.addEventListener('change', sync); }); + /* ------------------------------------------------- Kalender: Startwoche */ + // Auf Smartphones wird ein größerer Zeitraum gerendert; die Ansicht startet + // trotzdem bei der aktuellen Woche (bzw. der gewählten Startwoche). + document.querySelectorAll('.cal-shell[data-calendar-focus]').forEach((shell) => { + const scroller = shell.querySelector('.cal-scroll'); + const focus = shell.dataset.calendarFocus; + if (!scroller || !focus) return; + const cell = shell.querySelector(`.cal-cell[data-date="${focus}"]`); + if (!cell) return; + if (scroller.scrollWidth <= scroller.clientWidth + 4) return; + scroller.scrollLeft = Math.max(0, cell.offsetLeft - 8); + }); + /* -------------------------------------------------------- Kalender: Ziehen */ const calendar = document.querySelector('.cal-shell'); if (calendar && window.matchMedia('(pointer: fine)').matches) { diff --git a/web/sw.js b/web/sw.js index ce82fa3..a710e46 100644 --- a/web/sw.js +++ b/web/sw.js @@ -6,7 +6,7 @@ * zwischengespeichert, damit niemand veraltete Buchungen sieht. */ -const VERSION = 'dic-v13'; +const VERSION = 'dic-v14'; const CACHE = VERSION; const BASE = new URL(self.registration.scope).pathname.replace(/\/$/, '');