Add ability to specify checkin ranges

This commit is contained in:
Ben Goldsworthy 2022-11-10 02:16:12 +00:00
parent 6eaaff513c
commit 85d4c19693
2 changed files with 16 additions and 3 deletions

View file

@ -34,13 +34,26 @@ class TrackerController extends Controller
if (!$tripId) return view('no-trip');
$viewMode = $request->input('show', null);
$fromCheckin = $request->input('from', null);
$toCheckin = $request->input('to', null);
$tripData = $this->get_trip_data($tripId);
if ($fromCheckin) {
$tripData->checkins = array_filter($tripData->checkins, function($key) use ($fromCheckin) { return $key >= $fromCheckin; }, ARRAY_FILTER_USE_KEY);
}
if ($toCheckin) {
$tripData->checkins = array_filter($tripData->checkins, function($key) use ($toCheckin) { return $key <= $toCheckin; }, ARRAY_FILTER_USE_KEY);
}
return view(
'tracker',
[
'trip' => $tripData,
'showAllCheckins' => ($viewMode === 'all')
'showAllCheckins' => ($viewMode === 'all'),
'fromCheckin' => $fromCheckin,
'toCheckin' => $toCheckin
]
);
}

View file

@ -31,8 +31,8 @@
</section>
<section id="checkinList">
<h2 class="section__title">@if ($showAllCheckins) Check-ins @else Recent Check-ins @endif</h2>
<ol start="{{ count($trip->checkins) }}" reversed>
@if($showAllCheckins)
<ol start="{{ $toCheckin ?? count($trip->checkins) }}" reversed>
@if($showAllCheckins || $toCheckin || $fromCheckin)
@php $checkinsList = array_reverse($trip->checkins) @endphp
@else
@php $checkinsList = array_slice(array_reverse($trip->checkins), 0, 10) @endphp