diff --git a/app/Http/Controllers/Admin/RankController.php b/app/Http/Controllers/Admin/RankController.php index d2491577..a2dd548e 100644 --- a/app/Http/Controllers/Admin/RankController.php +++ b/app/Http/Controllers/Admin/RankController.php @@ -41,9 +41,9 @@ class RankController extends BaseController /** * Display a listing of the Ranking. - * * @param Request $request * @return Response + * @throws \Prettus\Repository\Exceptions\RepositoryException */ public function index(Request $request) { diff --git a/app/Http/Controllers/Admin/SubfleetController.php b/app/Http/Controllers/Admin/SubfleetController.php index ad422de4..820c3447 100644 --- a/app/Http/Controllers/Admin/SubfleetController.php +++ b/app/Http/Controllers/Admin/SubfleetController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Admin; +use App\Repositories\RankRepository; use Illuminate\Http\Request; use Flash; use Prettus\Repository\Criteria\RequestCriteria; @@ -24,7 +25,7 @@ use App\Services\FareService; class SubfleetController extends BaseController { /** @var SubfleetRepository */ - private $aircraftRepo, $subfleetRepo, $fareRepo, $fareSvc; + private $aircraftRepo, $rankRepo, $subfleetRepo, $fareRepo, $fareSvc; /** * SubfleetController constructor. @@ -36,16 +37,35 @@ class SubfleetController extends BaseController */ public function __construct( AircraftRepository $aircraftRepo, + RankRepository $rankRepo, SubfleetRepository $subfleetRepo, FareRepository $fareRepo, FareService $fareSvc ) { $this->aircraftRepo = $aircraftRepo; + $this->rankRepo = $rankRepo; $this->subfleetRepo = $subfleetRepo; $this->fareRepo = $fareRepo; $this->fareSvc = $fareSvc; } + /** + * Get the ranks that are available to the subfleet + * @param $subfleet + * @return array + */ + protected function getAvailRanks($subfleet) + { + $retval = []; + $all_ranks = $this->rankRepo->all(); + $avail_ranks = $all_ranks->except($subfleet->ranks->modelKeys()); + foreach ($avail_ranks as $rank) { + $retval[$rank->id] = $rank->name; + } + + return $retval; + } + /** * Get all the fares that haven't been assigned to a given subfleet */ @@ -144,10 +164,13 @@ class SubfleetController extends BaseController } $avail_fares = $this->getAvailFares($subfleet); + $avail_ranks = $this->getAvailRanks($subfleet); + return view('admin.subfleets.edit', [ 'airlines' => Airline::all()->pluck('name', 'id'), 'fuel_types' => FuelType::labels(), 'avail_fares' => $avail_fares, + 'avail_ranks' => $avail_ranks, 'subfleet' => $subfleet, ]); } @@ -202,6 +225,22 @@ class SubfleetController extends BaseController return redirect(route('admin.subfleets.index')); } + /** + * @param Subfleet $subfleet + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + protected function return_ranks_view(Subfleet $subfleet) + { + $subfleet->refresh(); + + $avail_ranks = $this->getAvailRanks($subfleet); + + return view('admin.subfleets.ranks', [ + 'subfleet' => $subfleet, + 'avail_ranks' => $avail_ranks, + ]); + } + /** * @param Subfleet $subfleet * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View @@ -209,6 +248,7 @@ class SubfleetController extends BaseController protected function return_fares_view(Subfleet $subfleet) { $subfleet->refresh(); + $avail_fares = $this->getAvailFares($subfleet); return view('admin.subfleets.fares', [ @@ -218,13 +258,46 @@ class SubfleetController extends BaseController } /** + * Operations for associating ranks to the subfleet + * @param $id * @param Request $request * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ - public function fares(Request $request) + public function ranks($id, Request $request) { - $id = $request->id; + $subfleet = $this->subfleetRepo->findWithoutFail($id); + if (empty($subfleet)) { + return $this->return_ranks_view($subfleet); + } + if ($request->isMethod('get')) { + return $this->return_ranks_view($subfleet); + } + + /** + * update specific rank data + */ + if ($request->isMethod('post')) { + $subfleet->ranks()->syncWithoutDetaching([$request->input('rank_id')]); + } + + // dissassociate fare from teh aircraft + elseif ($request->isMethod('delete')) { + $subfleet->ranks()->detach($request->input('rank_id')); + } + + $subfleet->save(); + return $this->return_ranks_view($subfleet); + } + + /** + * Operations on fares to the subfleet + * @param $id + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function fares($id, Request $request) + { $subfleet = $this->subfleetRepo->findWithoutFail($id); if (empty($subfleet)) { return $this->return_fares_view($subfleet); diff --git a/app/Routes/admin.php b/app/Routes/admin.php index 4be061e0..e03f5e34 100644 --- a/app/Routes/admin.php +++ b/app/Routes/admin.php @@ -17,6 +17,7 @@ Route::group([ # subfleet Route::resource('subfleets', 'SubfleetController'); Route::match(['get', 'post', 'put', 'delete'], 'subfleets/{id}/fares', 'SubfleetController@fares'); + Route::match(['get', 'post', 'delete'], 'subfleets/{id}/ranks', 'SubfleetController@ranks'); # aircraft and fare associations Route::resource('aircraft', 'AircraftController'); diff --git a/resources/views/admin/subfleets/edit.blade.php b/resources/views/admin/subfleets/edit.blade.php index bc3bf845..64d1db33 100644 --- a/resources/views/admin/subfleets/edit.blade.php +++ b/resources/views/admin/subfleets/edit.blade.php @@ -10,6 +10,12 @@ +
+
+ @include('admin.subfleets.ranks') +
+
+
@include('admin.subfleets.fares') diff --git a/resources/views/admin/subfleets/fares.blade.php b/resources/views/admin/subfleets/fares.blade.php index 8137e787..5a8e7b05 100644 --- a/resources/views/admin/subfleets/fares.blade.php +++ b/resources/views/admin/subfleets/fares.blade.php @@ -10,15 +10,14 @@

+ class="table table-hover dataTable"> - - - - + + + + @@ -27,12 +26,15 @@ - - -
namecodecapacity (default)price (default)cost (default)codecapacity (default)price (default)cost (default)
{!! $atf->name !!} {!! $atf->code !!}{!! $atf->pivot->capacity !!} + + {!! $atf->pivot->capacity !!} ({!! $atf->capacity !!}) {!! $atf->pivot->price !!} + + {!! $atf->pivot->price !!} ({!! $atf->price !!}){!! $atf->pivot->cost !!} + + {!! $atf->pivot->cost !!} ({!! $atf->cost!!}) {!! Form::open(['url' => '/admin/subfleets/'.$subfleet->id.'/fares', diff --git a/resources/views/admin/subfleets/fields.blade.php b/resources/views/admin/subfleets/fields.blade.php index f56111e3..daa844de 100644 --- a/resources/views/admin/subfleets/fields.blade.php +++ b/resources/views/admin/subfleets/fields.blade.php @@ -1,9 +1,4 @@
-
- {!! Form::label('airline_id', 'Airline:') !!} - {!! Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) !!} -

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

-
{!! Form::label('name', 'Name:') !!} @@ -17,6 +12,12 @@

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

+
+ {!! Form::label('airline_id', 'Airline:') !!} + {!! Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) !!} +

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

+
+
{!! Form::label('fuel_type', 'Fuel Type:') !!} {!! Form::select('fuel_type', $fuel_types, null , ['class' => 'form-control select2']) !!} diff --git a/resources/views/admin/subfleets/ranks.blade.php b/resources/views/admin/subfleets/ranks.blade.php new file mode 100644 index 00000000..532b7549 --- /dev/null +++ b/resources/views/admin/subfleets/ranks.blade.php @@ -0,0 +1,58 @@ +
+
+

ranks

+

+    + These ranks are allowed to fly aircraft in this subfleet +

+
+
+ + + + + + + + + @foreach($subfleet->ranks as $rank) + + + + + @endforeach + +
name
{!! $rank->name !!} + {!! Form::open(['url' => '/admin/subfleets/'.$subfleet->id.'/ranks', + 'method' => 'delete', + 'class' => 'modify_rank']) + !!} + {!! Form::hidden('rank_id', $rank->id) !!} + {!! Form::button('', + ['type' => 'submit', + 'class' => 'btn btn-sm btn-danger btn-icon']) !!} + {!! Form::close() !!} +
+
+
+
+
+ {!! Form::open(['url' => '/admin/subfleets/'.$subfleet->id.'/ranks', + 'method' => 'post', + 'class' => 'modify_rank form-inline']) + !!} + {!! Form::select('rank_id', $avail_ranks, null, [ + 'placeholder' => 'Select Rank', + 'class' => 'ac-fare-dropdown form-control input-lg select2', + + ]) + !!} + {!! Form::button(' add', + ['type' => 'submit', + 'class' => 'btn btn-success btn-s']) !!} + {!! Form::close() !!} +
+
+
+
+{{--
--}} diff --git a/resources/views/admin/subfleets/script.blade.php b/resources/views/admin/subfleets/script.blade.php index 1c1ac383..afeac49c 100644 --- a/resources/views/admin/subfleets/script.blade.php +++ b/resources/views/admin/subfleets/script.blade.php @@ -29,6 +29,12 @@ $(document).ready(function() { setEditable(); }); + $(document).on('submit', 'form.modify_rank', function (event) { + event.preventDefault(); + console.log(event); + $.pjax.submit(event, '#subfleet_ranks_wrapper', {push: false}); + }); + $(document).on('pjax:complete', function() { $(".select2").select2(); setEditable();