From 06717427031de14e6d0c20ea2bf796c51f3a6981 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 23 Mar 2018 20:30:31 -0500 Subject: [PATCH] Load subfleet page first, can add aircraft from there #217 --- .../Controllers/Admin/AircraftController.php | 22 ++++++++++++++----- .../views/admin/aircraft/fields.blade.php | 6 ++++- .../views/admin/aircraft/index.blade.php | 5 +++-- resources/views/admin/menu.blade.php | 6 ++--- .../views/admin/subfleets/fields.blade.php | 21 ++++++++++++++---- .../views/admin/subfleets/index.blade.php | 2 +- .../views/admin/subfleets/table.blade.php | 5 +++-- 7 files changed, 49 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/Admin/AircraftController.php b/app/Http/Controllers/Admin/AircraftController.php index c8f8a898..509312b7 100644 --- a/app/Http/Controllers/Admin/AircraftController.php +++ b/app/Http/Controllers/Admin/AircraftController.php @@ -43,26 +43,38 @@ class AircraftController extends Controller /** * Display a listing of the Aircraft. - * @throws \Prettus\Repository\Exceptions\RepositoryException + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function index(Request $request) { - $this->aircraftRepo->pushCriteria(new RequestCriteria($request)); - $aircraft = $this->aircraftRepo->orderBy('registration', 'asc')->all(); + // If subfleet ID is passed part of the query string, then only + // show the aircraft that are in that subfleet + $w = []; + if($request->filled('subfleet')) { + $w['subfleet_id'] = $request->input('subfleet'); + } + + $aircraft = $this->aircraftRepo->whereOrder($w, 'registration', 'asc'); + $aircraft = $aircraft->all(); return view('admin.aircraft.index', [ - 'aircraft' => $aircraft + 'aircraft' => $aircraft, + 'subfleet_id' => $request->input('subfleet'), ]); } /** * Show the form for creating a new Aircraft. + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function create() + public function create(Request $request) { return view('admin.aircraft.create', [ 'subfleets' => Subfleet::all()->pluck('name', 'id'), 'statuses' => AircraftStatus::select(true), + 'subfleet_id' => $request->query('subfleet') ]); } diff --git a/resources/views/admin/aircraft/fields.blade.php b/resources/views/admin/aircraft/fields.blade.php index 28e33c05..639f18b0 100644 --- a/resources/views/admin/aircraft/fields.blade.php +++ b/resources/views/admin/aircraft/fields.blade.php @@ -1,7 +1,11 @@
{{ Form::label('subfleet_id', 'Subfleet:') }} - {{ Form::select('subfleet_id', $subfleets, null, ['class' => 'form-control select2', 'placeholder' => 'Select Subfleet']) }} + {{ Form::select('subfleet_id', $subfleets, $subfleet_id ?? null, [ + 'class' => 'form-control select2', + 'placeholder' => 'Select Subfleet' + ]) + }}

{{ $errors->first('subfleet_id') }}

diff --git a/resources/views/admin/aircraft/index.blade.php b/resources/views/admin/aircraft/index.blade.php index 7b99af5e..25666c0c 100644 --- a/resources/views/admin/aircraft/index.blade.php +++ b/resources/views/admin/aircraft/index.blade.php @@ -4,8 +4,9 @@ @section('actions')
  • Export to CSV
  • Import from CSV
  • -
  • Subfleets
  • -
  • New Aircraft
  • + {{--
  • Subfleets
  • --}} +
  • + New Aircraft
  • @endsection @section('content') diff --git a/resources/views/admin/menu.blade.php b/resources/views/admin/menu.blade.php index 848c4464..f38c192c 100644 --- a/resources/views/admin/menu.blade.php +++ b/resources/views/admin/menu.blade.php @@ -16,7 +16,7 @@
  • flights
  • -
  • fleet
  • +
  • fleet
  • fares
  • finances
  • @@ -31,9 +31,9 @@