Kalender: Abwesenheiten als eigene Zeilen mit dunklen Balken, kollidierende Buchungen blinken
This commit is contained in:
parent
e83d6dc606
commit
87fd553464
6 changed files with 128 additions and 3 deletions
29
app/data.php
29
app/data.php
|
|
@ -952,6 +952,35 @@ function calendar_lanes(array $bookings): array
|
|||
return ['bookings' => $out, 'lanes' => max(1, count($laneEnds))];
|
||||
}
|
||||
|
||||
/**
|
||||
* Abwesenheiten, die eine Buchung betreffen: Übergabe-Mitarbeiter ab dem
|
||||
* Erinnerungs-Vorlauf bis Mietbeginn, Rücknahme-Mitarbeiter entsprechend bis
|
||||
* Mietende (gleiche Regel wie die Sperre in booking_validate()).
|
||||
*/
|
||||
function booking_absent_hits(array $booking, array $absences): array
|
||||
{
|
||||
$handoverEmployee = (int) ($booking['employee_id'] ?? 0);
|
||||
$returnEmployee = (int) ($booking['return_employee_id'] ?? 0) ?: $handoverEmployee;
|
||||
$start = (string) $booking['start_date'];
|
||||
$end = (string) $booking['end_date'];
|
||||
$handoverFrom = add_days($start, -BOOKING_LEAD_DAYS);
|
||||
$returnFrom = add_days($end, -BOOKING_LEAD_DAYS);
|
||||
$hits = [];
|
||||
foreach ($absences as $absence) {
|
||||
$employee = (int) $absence['employee_id'];
|
||||
$absenceStart = (string) $absence['start_date'];
|
||||
$absenceEnd = (string) $absence['end_date'];
|
||||
if ($employee === $handoverEmployee && $absenceStart <= $start && $absenceEnd >= $handoverFrom) {
|
||||
$hits[] = $absence;
|
||||
continue;
|
||||
}
|
||||
if ($employee === $returnEmployee && $absenceStart <= $end && $absenceEnd >= $returnFrom) {
|
||||
$hits[] = $absence;
|
||||
}
|
||||
}
|
||||
return $hits;
|
||||
}
|
||||
|
||||
/** Position eines Balkens im sichtbaren Zeitraum (Prozent). */
|
||||
function calendar_geometry(array $booking, string $from, string $to, int $lanes): array
|
||||
{
|
||||
|
|
|
|||
|
|
@ -492,6 +492,7 @@ function page_calendar(array $user): void
|
|||
$bars[] = [
|
||||
'booking' => $booking,
|
||||
'geo' => calendar_geometry($booking, $from, $to, $lanes),
|
||||
'absent' => booking_absent_hits($booking, $absences) !== [],
|
||||
];
|
||||
}
|
||||
$rows[] = [
|
||||
|
|
@ -527,6 +528,31 @@ function page_calendar(array $user): void
|
|||
|
||||
$employees = employees_all();
|
||||
$absences = absence_list($from, $to);
|
||||
|
||||
// Abwesenheiten als eigene Zeilen unterhalb der Anhänger.
|
||||
$absencesByEmployee = [];
|
||||
foreach ($absences as $absence) {
|
||||
$absencesByEmployee[(int) $absence['employee_id']][] = $absence;
|
||||
}
|
||||
$absenceRows = [];
|
||||
foreach ($absencesByEmployee as $employeeAbsences) {
|
||||
$laneInfo = calendar_lanes($employeeAbsences);
|
||||
$bars = [];
|
||||
foreach ($laneInfo['bookings'] as $absence) {
|
||||
$bars[] = [
|
||||
'absence' => $absence,
|
||||
'geo' => calendar_geometry($absence, $from, $to, $laneInfo['lanes']),
|
||||
];
|
||||
}
|
||||
$absenceRows[] = [
|
||||
'employee_name' => (string) $employeeAbsences[0]['employee_name'],
|
||||
'employee_id' => (int) $employeeAbsences[0]['employee_id'],
|
||||
'bars' => $bars,
|
||||
'count' => count($employeeAbsences),
|
||||
'height' => max($rowMin, $barBase * $laneInfo['lanes'] + 16),
|
||||
];
|
||||
}
|
||||
|
||||
render_page('calendar', [
|
||||
'view' => $view,
|
||||
'date' => $date,
|
||||
|
|
@ -544,6 +570,7 @@ function page_calendar(array $user): void
|
|||
'employees' => $employees,
|
||||
'bookingCount' => count($bookings),
|
||||
'absences' => $absences,
|
||||
'absenceRows' => $absenceRows,
|
||||
'urlFor' => static function (string $d) use ($view, $employeeId, $showCancelled): string {
|
||||
return calendar_url($d, $view, $employeeId, $showCancelled);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ function url(string $path = '/'): string
|
|||
}
|
||||
|
||||
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
|
||||
const DIC_ASSET_VERSION = '24';
|
||||
const DIC_ASSET_VERSION = '25';
|
||||
|
||||
function asset(string $path): string
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
/** @var string $calTitle */
|
||||
/** @var string $focusFrom */
|
||||
/** @var array $absences */
|
||||
/** @var array $absenceRows */
|
||||
/** @var string $prevDate */
|
||||
/** @var string $nextDate */
|
||||
/** @var string $today */
|
||||
|
|
@ -165,7 +166,7 @@ $minWidth = match ($view) {
|
|||
. fmt_date_with_time($booking['end_date'], $booking['end_time'] ?? null)
|
||||
. ', ' . booking_employee_summary($booking) . ($cancelled ? ', storniert' : '');
|
||||
?>
|
||||
<a class="cal-bar<?= $cancelled ? ' is-cancelled' : '' ?><?= $geo['cut_start'] ? ' is-cut-start' : '' ?><?= $geo['cut_end'] ? ' is-cut-end' : '' ?><?= $geo['span'] <= 1 ? ' is-tiny' : '' ?>"
|
||||
<a class="cal-bar<?= $cancelled ? ' is-cancelled' : '' ?><?= !empty($bar['absent']) && $booking['status'] !== 'cancelled' ? ' is-absent-conflict' : '' ?><?= $geo['cut_start'] ? ' is-cut-start' : '' ?><?= $geo['cut_end'] ? ' is-cut-end' : '' ?><?= $geo['span'] <= 1 ? ' is-tiny' : '' ?>"
|
||||
href="<?= e(url('/bookings/' . (int) $booking['id'])) ?>"
|
||||
draggable="false"
|
||||
data-panel="<?= (int) $booking['id'] ?>"
|
||||
|
|
@ -189,6 +190,43 @@ $minWidth = match ($view) {
|
|||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if (!empty($absenceRows)): ?>
|
||||
<div class="cal-separator" aria-hidden="true"><span>Abwesenheiten</span></div>
|
||||
<?php foreach ($absenceRows as $absenceRow): ?>
|
||||
<div class="cal-label cal-label--absence" style="--row-h: <?= (int) $absenceRow['height'] ?>px">
|
||||
<span class="absence-dot" aria-hidden="true"></span>
|
||||
<span class="cal-label__text">
|
||||
<strong><?= e($absenceRow['employee_name']) ?></strong>
|
||||
<small>abwesend</small>
|
||||
</span>
|
||||
</div>
|
||||
<div class="cal-track cal-track--absence" style="--row-h: <?= (int) $absenceRow['height'] ?>px; --lanes: 1">
|
||||
<div class="cal-cells">
|
||||
<?php foreach ($days as $day): ?>
|
||||
<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 endforeach; ?>
|
||||
</div>
|
||||
<?php foreach ($absenceRow['bars'] as $bar): ?>
|
||||
<?php
|
||||
$absence = $bar['absence'];
|
||||
$geo = $bar['geo'];
|
||||
$absenceLabel = trim((string) $absence['note']) !== '' ? (string) $absence['note'] : 'abwesend';
|
||||
?>
|
||||
<a class="cal-bar cal-bar--absence<?= $geo['cut_start'] ? ' is-cut-start' : '' ?><?= $geo['cut_end'] ? ' is-cut-end' : '' ?><?= $geo['span'] <= 1 ? ' is-tiny' : '' ?>"
|
||||
href="<?= e(url('/absences?period=' . rawurlencode($view === 'month' ? 'month' : 'weeks') . '&date=' . rawurlencode((string) $absence['start_date']))) ?>"
|
||||
draggable="false"
|
||||
style="--left: <?= number_format($geo['left'], 5, '.', '') ?>%; --width: <?= number_format($geo['width'], 5, '.', '') ?>%; --top: <?= number_format($geo['top'], 5, '.', '') ?>%; --height: <?= number_format($geo['height'], 5, '.', '') ?>%;"
|
||||
aria-label="<?= e($absenceRow['employee_name'] . ' abwesend ' . fmt_date_range((string) $absence['start_date'], (string) $absence['end_date']) . ($absenceLabel !== 'abwesend' ? ', ' . $absenceLabel : '')) ?>"
|
||||
title="<?= e($absenceRow['employee_name'] . ' · ' . fmt_date_range((string) $absence['start_date'], (string) $absence['end_date']) . ($absenceLabel !== 'abwesend' ? ' · ' . $absenceLabel : '')) ?>">
|
||||
<?php if ($geo['span'] >= 2): ?><span class="cal-bar__name"><?= e($absenceLabel) ?></span><?php endif; ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -198,6 +236,12 @@ $minWidth = match ($view) {
|
|||
<span class="legend-dot"></span>
|
||||
Farbige Balken gehören zum jeweiligen Anhänger. Zwei Buchungen dürfen sich am Wechseltag (letzter Tag = erster Tag) überschneiden – beide Balken bleiben sichtbar.
|
||||
</p>
|
||||
<?php if (!empty($absenceRows)): ?>
|
||||
<p>
|
||||
<span class="absence-dot" aria-hidden="true"></span>
|
||||
Dunkle Striche sind Abwesenheiten der Mitarbeiter. Blinkende Buchungen kollidieren mit einer Abwesenheit (inkl. <?= (int) BOOKING_LEAD_DAYS ?> Tagen Vorlauf).
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if ($view !== 'month'): ?>
|
||||
<p class="cal-foot__hint">Tipp: Balken lassen sich mit der Maus verschieben – horizontal ändert das Datum, vertikal den Anhänger.</p>
|
||||
<?php endif; ?>
|
||||
|
|
|
|||
|
|
@ -536,6 +536,31 @@ a .ico, button .ico { pointer-events: none; }
|
|||
.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); }
|
||||
/* Abwesenheiten: eigene Zeilen unter den Anhängern, dunkle Striche. */
|
||||
.cal-separator {
|
||||
grid-column: 1 / -1; display: flex; align-items: center; gap: 8px;
|
||||
padding: 6px 12px; background: #f4f6f8; border-top: 1px solid var(--line);
|
||||
font-size: .64rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
|
||||
}
|
||||
.cal-label--absence { background: #fbfcfd; }
|
||||
.absence-dot {
|
||||
width: 10px; height: 10px; border-radius: 3px; background: #2b3742; flex: 0 0 auto; display: inline-block;
|
||||
}
|
||||
.cal-track--absence { background: #fbfcfd; }
|
||||
.cal-bar.cal-bar--absence {
|
||||
background: #2b3742; color: #fff; border: 1px solid #1d262e;
|
||||
box-shadow: 0 1px 2px rgba(10, 20, 28, .25);
|
||||
}
|
||||
.cal-bar.cal-bar--absence .cal-bar__name { color: #fff; }
|
||||
.cal-bar.is-absent-conflict { animation: dic-absence-blink 1.6s ease-in-out infinite; }
|
||||
@keyframes dic-absence-blink {
|
||||
0%, 100% { box-shadow: 0 0 0 0 rgba(212, 68, 52, 0), inset 0 0 0 0 rgba(255, 255, 255, 0); }
|
||||
50% { box-shadow: 0 0 0 2px rgba(212, 68, 52, .95), inset 0 0 0 1px rgba(255, 255, 255, .55); }
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.cal-bar.is-absent-conflict { animation: none; box-shadow: 0 0 0 2px rgba(212, 68, 52, .95); }
|
||||
}
|
||||
|
||||
|
||||
.cal-bar {
|
||||
position: absolute; z-index: 2; display: flex; flex-direction: column; justify-content: center;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
* zwischengespeichert, damit niemand veraltete Buchungen sieht.
|
||||
*/
|
||||
|
||||
const VERSION = 'dic-v16';
|
||||
const VERSION = 'dic-v17';
|
||||
const CACHE = VERSION;
|
||||
const BASE = new URL(self.registration.scope).pathname.replace(/\/$/, '');
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue