Add ranks from the subfleet edit page closes #160
This commit is contained in:
parent
1c143f3b23
commit
14d04604cb
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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');
|
||||
|
@ -10,6 +10,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-blue-bottom">
|
||||
<div class="content">
|
||||
@include('admin.subfleets.ranks')
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card border-blue-bottom">
|
||||
<div class="content">
|
||||
@include('admin.subfleets.fares')
|
||||
|
@ -10,15 +10,14 @@
|
||||
</div>
|
||||
<br />
|
||||
<table id="aircraft_fares"
|
||||
class="table table-bordered table-hover dataTable"
|
||||
role="grid" aria-describedby="aircraft_fares_info">
|
||||
class="table table-hover dataTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>name</th>
|
||||
<th>code</th>
|
||||
<th>capacity (default)</th>
|
||||
<th>price (default)</th>
|
||||
<th>cost (default)</th>
|
||||
<th style="text-align: center;">code</th>
|
||||
<th style="text-align: center;">capacity (default)</th>
|
||||
<th style="text-align: center;">price (default)</th>
|
||||
<th style="text-align: center;">cost (default)</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -27,12 +26,15 @@
|
||||
<tr>
|
||||
<td class="sorting_1">{!! $atf->name !!}</td>
|
||||
<td style="text-align: center;">{!! $atf->code !!}</td>
|
||||
<td><a href="#" data-pk="{!! $atf->id !!}" data-name="capacity">{!! $atf->pivot->capacity !!}</a>
|
||||
<td style="text-align: center;">
|
||||
<a href="#" data-pk="{!! $atf->id !!}" data-name="capacity">{!! $atf->pivot->capacity !!}</a>
|
||||
<span class="small background-color-grey-light">({!! $atf->capacity !!})</span>
|
||||
</td>
|
||||
<td><a href="#" data-pk="{!! $atf->id !!}" data-name="price">{!! $atf->pivot->price !!}</a>
|
||||
<td style="text-align: center;">
|
||||
<a href="#" data-pk="{!! $atf->id !!}" data-name="price">{!! $atf->pivot->price !!}</a>
|
||||
<span class="small background-color-grey-light">({!! $atf->price !!})</span></td>
|
||||
<td><a href="#" data-pk="{!! $atf->id !!}" data-name="cost">{!! $atf->pivot->cost !!}</a>
|
||||
<td style="text-align: center;">
|
||||
<a href="#" data-pk="{!! $atf->id !!}" data-name="cost">{!! $atf->pivot->cost !!}</a>
|
||||
<span class="small background-color-grey-light">({!! $atf->cost!!})</span></td>
|
||||
<td style="text-align: right; width:3%;">
|
||||
{!! Form::open(['url' => '/admin/subfleets/'.$subfleet->id.'/fares',
|
||||
|
@ -1,9 +1,4 @@
|
||||
<div class="row">
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('airline_id', 'Airline:') !!}
|
||||
{!! Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) !!}
|
||||
<p class="text-danger">{{ $errors->first('airline_id') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('name', 'Name:') !!}
|
||||
@ -17,6 +12,12 @@
|
||||
<p class="text-danger">{{ $errors->first('type') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('airline_id', 'Airline:') !!}
|
||||
{!! Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) !!}
|
||||
<p class="text-danger">{{ $errors->first('airline_id') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group col-sm-6">
|
||||
{!! Form::label('fuel_type', 'Fuel Type:') !!}
|
||||
{!! Form::select('fuel_type', $fuel_types, null , ['class' => 'form-control select2']) !!}
|
||||
|
58
resources/views/admin/subfleets/ranks.blade.php
Normal file
58
resources/views/admin/subfleets/ranks.blade.php
Normal file
@ -0,0 +1,58 @@
|
||||
<div id="subfleet_ranks_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
|
||||
<div class="header">
|
||||
<h3>ranks</h3>
|
||||
<p class="category">
|
||||
<i class="icon fa fa-info"> </i>
|
||||
These ranks are allowed to fly aircraft in this subfleet
|
||||
</p>
|
||||
</div>
|
||||
<br />
|
||||
<table id="subfleet_ranks" class="table table-hover dataTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>name</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($subfleet->ranks as $rank)
|
||||
<tr>
|
||||
<td class="sorting_1">{!! $rank->name !!}</td>
|
||||
<td style="text-align: right; width:3%;">
|
||||
{!! Form::open(['url' => '/admin/subfleets/'.$subfleet->id.'/ranks',
|
||||
'method' => 'delete',
|
||||
'class' => 'modify_rank'])
|
||||
!!}
|
||||
{!! Form::hidden('rank_id', $rank->id) !!}
|
||||
{!! Form::button('<i class="fa fa-times"></i>',
|
||||
['type' => 'submit',
|
||||
'class' => 'btn btn-sm btn-danger btn-icon']) !!}
|
||||
{!! Form::close() !!}
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="text-right">
|
||||
{!! 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('<i class="glyphicon glyphicon-plus"></i> add',
|
||||
['type' => 'submit',
|
||||
'class' => 'btn btn-success btn-s']) !!}
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{--</div></div>--}}
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user