From 2a18d629aacb660150c7d15323176a5167e2e15f Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Mon, 19 Jun 2017 14:29:10 -0500 Subject: [PATCH] #14 Assign aircraft to the flights --- .../Controllers/Admin/FlightController.php | 46 ++++-- database/seeds/dev.yml | 4 + .../views/admin/aircraft/fares.blade.php | 4 +- resources/views/admin/aircraft/show.blade.php | 6 +- .../views/admin/airports/index.blade.php | 2 +- .../views/admin/flights/aircraft.blade.php | 51 ++++++ resources/views/admin/flights/show.blade.php | 42 +++-- .../views/admin/flights/show_fields.blade.php | 145 ++++++++---------- resources/views/admin/flights/table.blade.php | 2 + 9 files changed, 201 insertions(+), 101 deletions(-) create mode 100644 resources/views/admin/flights/aircraft.blade.php diff --git a/app/Http/Controllers/Admin/FlightController.php b/app/Http/Controllers/Admin/FlightController.php index 71bde937..aa2fd85b 100644 --- a/app/Http/Controllers/Admin/FlightController.php +++ b/app/Http/Controllers/Admin/FlightController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; use App\Http\Requests\CreateFlightRequest; use App\Http\Requests\UpdateFlightRequest; use App\Repositories\FlightRepository; +use App\Repositories\AircraftRepository; use Illuminate\Http\Request; use Flash; use Prettus\Repository\Criteria\RequestCriteria; @@ -13,11 +14,30 @@ use Response; class FlightController extends BaseController { /** @var FlightRepository */ - private $flightRepository; + private $flightRepository, $aircraftRepository; - public function __construct(FlightRepository $flightRepo) + public function __construct( + FlightRepository $flightRepo, + AircraftRepository $aircraftRepository + ) { $this->flightRepository = $flightRepo; + $this->aircraftRepository = $aircraftRepository; + } + + protected function getAvailAircraft($flight) + { + $retval = []; + + $flight->refresh(); + $all_aircraft = $this->aircraftRepository->all(); + $avail_aircraft = $all_aircraft->except($flight->aircraft->modelKeys()); + + foreach ($avail_aircraft as $ac) { + $retval[$ac->id] = $ac->icao.' - '.$ac->registration; + } + + return $retval; } /** @@ -79,7 +99,10 @@ class FlightController extends BaseController return redirect(route('admin.flights.index')); } - return view('admin.flights.show')->with('flight', $flight); + $avail_aircraft = $this->getAvailAircraft($flight); + return view('admin.flights.show') + ->with('flight', $flight) + ->with('avail_aircraft', $avail_aircraft); } /** @@ -147,12 +170,20 @@ class FlightController extends BaseController return redirect(route('admin.flights.index')); } + protected function return_aircraft_view($flight) + { + $avail_aircraft = $this->getAvailAircraft($flight); + return view('admin.flights.aircraft') + ->with('flight', $flight) + ->with('avail_aircraft', $avail_aircraft); + } + public function aircraft(Request $request) { $id = $request->id; + print_r($request->toArray()); $flight = $this->flightRepository->findWithoutFail($id); - if (empty($flight)) { Flash::error('Flight not found'); return redirect(route('admin.flights.index')); @@ -165,14 +196,11 @@ class FlightController extends BaseController // add } - // update the pivot table with overrides for the fares - elseif ($request->isMethod('put')) { - // update - } - // dissassociate fare from teh aircraft elseif ($request->isMethod('delete')) { // del } + + return $this->return_aircraft_view($flight); } } diff --git a/database/seeds/dev.yml b/database/seeds/dev.yml index 075aed48..78d22db5 100644 --- a/database/seeds/dev.yml +++ b/database/seeds/dev.yml @@ -123,3 +123,7 @@ flights: dpt_airport_id: 1 arr_airport_id: 2 route: KAUS KJFK + +flight_aircraft: + - flight_id: 1 + aircraft_id: 1 diff --git a/resources/views/admin/aircraft/fares.blade.php b/resources/views/admin/aircraft/fares.blade.php index b6e40f8a..b0937a06 100644 --- a/resources/views/admin/aircraft/fares.blade.php +++ b/resources/views/admin/aircraft/fares.blade.php @@ -61,8 +61,8 @@
-
-
+
+
{!! Form::open(['url' => '/admin/aircraft/'.$aircraft->id.'/fares', 'method' => 'post', 'class' => 'rm_fare form-inline' diff --git a/resources/views/admin/aircraft/show.blade.php b/resources/views/admin/aircraft/show.blade.php index 9dd5a13b..79eff73d 100644 --- a/resources/views/admin/aircraft/show.blade.php +++ b/resources/views/admin/aircraft/show.blade.php @@ -2,11 +2,11 @@ @section('content')
-

{!! $aircraft->name !!}

+

{!! $aircraft->name !!}

Edit -

- + +
diff --git a/resources/views/admin/airports/index.blade.php b/resources/views/admin/airports/index.blade.php index 5265fa3c..46957048 100644 --- a/resources/views/admin/airports/index.blade.php +++ b/resources/views/admin/airports/index.blade.php @@ -2,7 +2,7 @@ @section('content')
-

$MODEL_NAME_PLURAL_HUMAN$

+

Airports

Add New

diff --git a/resources/views/admin/flights/aircraft.blade.php b/resources/views/admin/flights/aircraft.blade.php new file mode 100644 index 00000000..3957b387 --- /dev/null +++ b/resources/views/admin/flights/aircraft.blade.php @@ -0,0 +1,51 @@ +
+ + + + + + + + + @foreach($flight->aircraft as $ac) + + + + + + + @endforeach + +
ICAONameRegistrationActions
{!! $ac->icao !!}{!! $ac->name !!}{!! $ac->registration !!} + {!! Form::open(['url' => '/admin/flights/'.$flight->id.'/aircraft', 'method' => 'delete', 'class' => 'flight_ac_frm']) !!} + {!! Form::hidden('flight_id', $flight->id) !!} +
+ {!! Form::button('', + ['type' => 'submit', + 'class' => 'btn btn-danger btn-xs']) + !!} +
+ {!! Form::close() !!} +
+
+
+
+
+ {!! Form::open(['url' => '/admin/flights/'.$flight->id.'/aircraft', + 'method' => 'post', + 'class' => 'flight_ac_frm form-inline' + ]) + !!} + {!! Form::select('aircraft_id', $avail_aircraft, null, [ + 'placeholder' => 'Select Aircraft', + 'class' => 'ac-flight-dropdown form-control input-lg', + ]) + !!} + {!! Form::button(' add', + ['type' => 'submit', + 'class' => 'btn btn-success btn-s']) !!} + {!! Form::close() !!} +
+
+
+
diff --git a/resources/views/admin/flights/show.blade.php b/resources/views/admin/flights/show.blade.php index b5774eaa..e54fccd5 100644 --- a/resources/views/admin/flights/show.blade.php +++ b/resources/views/admin/flights/show.blade.php @@ -1,17 +1,41 @@ @extends('admin.app') @section('content') -
-

Flights

-
-
-
-
-
- @include('admin.flights.show_fields') - Back +
+

{!! $flight->airline->code !!}{!! $flight->flight_number !!}

+

+ Edit +

+
+
+
+
+ @include('admin.flights.show_fields') +
+
+
+
+
+

assigned aircraft

+
+ @include('admin.flights.aircraft') +
+
+@endsection +@section('scripts') + @endsection diff --git a/resources/views/admin/flights/show_fields.blade.php b/resources/views/admin/flights/show_fields.blade.php index d58f7d41..47c74618 100644 --- a/resources/views/admin/flights/show_fields.blade.php +++ b/resources/views/admin/flights/show_fields.blade.php @@ -1,90 +1,81 @@ - -
- {!! Form::label('id', 'Id:') !!} -

{!! $flight->id !!}

+
+
+
+ {{----}} +

{!! Form::label('dpt_airport_id', 'Dep ICAO') !!}

+
+

+ {!! $flight->dpt_airport->icao !!} - {!! $flight->dpt_airport->name !!} +

+
- -
- {!! Form::label('airline_id', 'Airline Id:') !!} -

{!! $flight->airline_id !!}

+
+
+
+ {{----}} +

{!! Form::label('arr_airport_id', 'Arrival ICAO') !!}

+
+

+ {!! $flight->arr_airport->icao !!} - {!! $flight->arr_airport->name !!} +

+
+
- -
- {!! Form::label('flight_number', 'Flight Number:') !!} -

{!! $flight->flight_number !!}

-
- -
- {!! Form::label('route_code', 'Route Code:') !!} -

{!! $flight->route_code !!}

-
+
+
+
+ +
+ {!! Form::label('route_code', 'Route Code:') !!} + {!! $flight->route_code !!} +
- -
- {!! Form::label('route_leg', 'Route Leg:') !!} -

{!! $flight->route_leg !!}

-
+ +
+ {!! Form::label('route_leg', 'Route Leg:') !!} + {!! $flight->route_leg !!} +
- -
- {!! Form::label('dpt_airport_id', 'Dpt Airport Id:') !!} -

{!! $flight->dpt_airport_id !!}

-
+ + @if($flight->alt_airport_id) +
+ {!! Form::label('alt_airport_id', 'Alt Airport Id:') !!} +

{!! $flight->alt_airport->icao !!}

+
+ @endif - -
- {!! Form::label('arr_airport_id', 'Arr Airport Id:') !!} -

{!! $flight->arr_airport_id !!}

-
+ +
+ {!! Form::label('route', 'Route:') !!} +

{!! $flight->route !!}

+
- -
- {!! Form::label('alt_airport_id', 'Alt Airport Id:') !!} -

{!! $flight->alt_airport_id !!}

-
+ +
+ {!! Form::label('dpt_time', 'Departure Time:') !!} + {!! $flight->dpt_time !!} +
- -
- {!! Form::label('route', 'Route:') !!} -

{!! $flight->route !!}

-
+ +
+ {!! Form::label('arr_time', 'Arrival Time:') !!} + {!! $flight->arr_time !!} +
- -
- {!! Form::label('dpt_time', 'Dpt Time:') !!} -

{!! $flight->dpt_time !!}

-
+ +
+ {!! Form::label('notes', 'Notes:') !!} +

{!! $flight->notes !!}

+
- -
- {!! Form::label('arr_time', 'Arr Time:') !!} -

{!! $flight->arr_time !!}

+ +
+ {!! Form::label('active', 'Active:') !!} +

{!! $flight->active !!}

+
+
+
- - -
- {!! Form::label('notes', 'Notes:') !!} -

{!! $flight->notes !!}

-
- - -
- {!! Form::label('active', 'Active:') !!} -

{!! $flight->active !!}

-
- - -
- {!! Form::label('created_at', 'Created At:') !!} -

{!! $flight->created_at !!}

-
- - -
- {!! Form::label('updated_at', 'Updated At:') !!} -

{!! $flight->updated_at !!}

-
- diff --git a/resources/views/admin/flights/table.blade.php b/resources/views/admin/flights/table.blade.php index e8b73ea2..32bc2cbf 100644 --- a/resources/views/admin/flights/table.blade.php +++ b/resources/views/admin/flights/table.blade.php @@ -14,10 +14,12 @@ @foreach($flights as $flight) + {!! $flight->airline->code !!}{!! $flight->flight_number !!} @if($flight->route_code) (C: {!! $flight->route_code !!} L: {!! $flight->route_leg !!}) @endif + {!! $flight->dpt_airport->icao !!}