From 85d4c196937bed6b01c51b1061b9afd650daca52 Mon Sep 17 00:00:00 2001 From: Rumperuu Date: Thu, 10 Nov 2022 02:16:12 +0000 Subject: [PATCH] Add ability to specify checkin ranges --- app/Http/Controllers/TrackerController.php | 15 ++++++++++++++- resources/views/tracker.blade.php | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/TrackerController.php b/app/Http/Controllers/TrackerController.php index cb63aa9..20bffb6 100644 --- a/app/Http/Controllers/TrackerController.php +++ b/app/Http/Controllers/TrackerController.php @@ -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 ] ); } diff --git a/resources/views/tracker.blade.php b/resources/views/tracker.blade.php index 5b095b0..8eb518f 100644 --- a/resources/views/tracker.blade.php +++ b/resources/views/tracker.blade.php @@ -31,8 +31,8 @@

@if ($showAllCheckins) Check-ins @else Recent Check-ins @endif

-
    - @if($showAllCheckins) +
      + @if($showAllCheckins || $toCheckin || $fromCheckin) @php $checkinsList = array_reverse($trip->checkins) @endphp @else @php $checkinsList = array_slice(array_reverse($trip->checkins), 0, 10) @endphp