#23 assign subfleets to ranks

This commit is contained in:
Nabeel Shahzad 2017-07-01 21:06:55 -05:00
parent 0821258a2d
commit 244d1ae7bd
11 changed files with 247 additions and 41 deletions

View File

@ -50,8 +50,9 @@ class FlightController extends BaseController
{
$this->flightRepository->pushCriteria(new RequestCriteria($request));
$flights = $this->flightRepository->all();
return view('admin.flights.index')
->with('flights', $flights);
return view('admin.flights.index', [
'flights' => $flights,
]);
}
/**
@ -78,7 +79,6 @@ class FlightController extends BaseController
$flight = $this->flightRepository->create($input);
Flash::success('Flight saved successfully.');
return redirect(route('admin.flights.index'));
}
@ -99,9 +99,10 @@ class FlightController extends BaseController
}
$avail_subfleets = $this->getAvailSubfleets($flight);
return view('admin.flights.show')
->with('flight', $flight)
->with('avail_subfleets', $avail_subfleets);
return view('admin.flights.show', [
'flight' => $flight,
'avail_subfleets' => $avail_subfleets,
]);
}
/**
@ -120,7 +121,11 @@ class FlightController extends BaseController
return redirect(route('admin.flights.index'));
}
return view('admin.flights.edit')->with('flight', $flight);
$avail_subfleets = $this->getAvailSubfleets($flight);
return view('admin.flights.edit', [
'flight' => $flight,
'avail_subfleets' => $avail_subfleets,
]);
}
/**
@ -171,9 +176,10 @@ class FlightController extends BaseController
protected function return_subfleet_view($flight)
{
$avail_subfleets = $this->getAvailSubfleets($flight);
return view('admin.flights.subfleets')
->with('flight', $flight)
->with('avail_subfleets', $avail_subfleets);
return view('admin.flights.subfleets', [
'flight' => $flight,
'avail_subfleets' => $avail_subfleets,
]);
}
public function subfleets(Request $request)

View File

@ -5,7 +5,7 @@ namespace App\Http\Controllers\Admin;
use App\Http\Requests\CreateRankRequest;
use App\Http\Requests\UpdateRankRequest;
use App\Repositories\RankRepository;
use App\Http\Controllers\AppBaseController as InfyOmBaseController;
use App\Repositories\SubfleetRepository;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
@ -14,11 +14,28 @@ use Response;
class RankController extends BaseController
{
/** @var RankRepository */
private $rankRepository;
private $rankRepository, $subfleetRepo;
public function __construct(RankRepository $rankingRepo)
public function __construct(
RankRepository $rankingRepo,
SubfleetRepository $subfleetRepo
)
{
$this->rankRepository = $rankingRepo;
$this->subfleetRepo = $subfleetRepo;
}
protected function getAvailSubfleets($rank)
{
$retval = [];
$all_subfleets = $this->subfleetRepo->all();
$avail_subfleets = $all_subfleets->except($rank->subfleets->modelKeys());
foreach ($avail_subfleets as $subfleet) {
$retval[$subfleet->id] = $subfleet->name.
' (airline: '.$subfleet->airline->code.')';
}
return $retval;
}
/**
@ -32,8 +49,9 @@ class RankController extends BaseController
$this->rankRepository->pushCriteria(new RequestCriteria($request));
$ranks = $this->rankRepository->all();
return view('admin.ranks.index')
->with('ranks', $ranks);
return view('admin.ranks.index', [
'ranks' => $ranks,
]);
}
/**
@ -48,12 +66,10 @@ class RankController extends BaseController
/**
* Store a newly created Ranking in storage.
*
* @param CreateRankRequest $request
*
* @return Response
*/
public function store(Request $request)
public function store(CreateRankRequest $request)
{
$input = $request->all();
@ -61,8 +77,9 @@ class RankController extends BaseController
Flash::success('Ranking saved successfully.');
$ranks = $this->rankRepository->all();
return view('admin.ranks.table')
->with('ranks', $ranks);
return view('admin.ranks.table', [
'ranks' => $ranks,
]);
}
/**
@ -81,7 +98,9 @@ class RankController extends BaseController
return redirect(route('admin.ranks.index'));
}
return view('admin.ranks.show')->with('rank', $rank);
return view('admin.ranks.show', [
'rank' => $rank
]);
}
/**
@ -100,7 +119,11 @@ class RankController extends BaseController
return redirect(route('admin.ranks.index'));
}
return view('admin.ranks.edit')->with('rank', $rank);
$avail_subfleets = $this->getAvailSubfleets($rank);
return view('admin.ranks.edit', [
'rank' => $rank,
'avail_subfleets' => $avail_subfleets,
]);
}
/**
@ -123,7 +146,6 @@ class RankController extends BaseController
$rank = $this->rankRepository->update($request->all(), $id);
Flash::success('Ranking updated successfully.');
return redirect(route('admin.ranks.index'));
}
@ -146,7 +168,38 @@ class RankController extends BaseController
$this->rankRepository->delete($id);
Flash::success('Ranking deleted successfully.');
return redirect(route('admin.ranks.index'));
}
protected function return_subfleet_view($rank)
{
$avail_subfleets = $this->getAvailSubfleets($rank);
return view('admin.ranks.subfleets', [
'rank' => $rank,
'avail_subfleets' => $avail_subfleets,
]);
}
public function subfleets(Request $request)
{
$id = $request->id;
$rank = $this->rankRepository->findWithoutFail($id);
if (empty($rank)) {
Flash::error('Rank not found!');
return redirect(route('admin.ranks.index'));
}
// add aircraft to flight
if ($request->isMethod('post')) {
$rank->subfleets()->syncWithoutDetaching([$request->subfleet_id]);
}
// remove aircraft from flight
elseif ($request->isMethod('delete')) {
$rank->subfleets()->detach($request->subfleet_id);
}
return $this->return_subfleet_view($rank);
}
}

View File

@ -2,6 +2,9 @@
namespace App\Services;
use App\Models\Pirep;
use App\Models\PirepFieldValues;
use App\Repositories\PirepRepository;
use App\Repositories\SubfleetRepository;
@ -21,7 +24,21 @@ class PIREPService extends BaseService {
$this->pirepRepo = $pirepRepo;
}
public function create() {
public function create(
Pirep $pirep,
array $field_values # PirepFieldValues
) {
$pirep->save();
foreach($field_values as $fv) {
$v = new PirepFieldValues();
$v->name = $fv['name'];
$v->value = $fv['value'];
$v->source = $fv['source'];
$v->save();
}
# TODO: Financials
}
}

View File

@ -26,6 +26,14 @@ class CreateSubfleetsTable extends Migration
$table->softDeletes();
});
Schema::create('subfleet_expenses', function(Blueprint $table) {
$table->integer('subfleet_id')->unsigned();
$table->string('name');
$table->decimal('cost', 19, 2)->unsigned();
$table->primary(['subfleet_id', 'name']);
});
Schema::create('subfleet_fare', function (Blueprint $table) {
$table->integer('subfleet_id')->unsigned();
$table->integer('fare_id')->unsigned();
@ -65,7 +73,9 @@ class CreateSubfleetsTable extends Migration
public function down()
{
Schema::drop('subfleets');
Schema::drop('subfleet_rank');
Schema::drop('subfleet_expenses');
Schema::drop('subfleet_fare');
Schema::drop('subfleet_flight');
Schema::drop('subfleet_rank');
}
}

View File

@ -17,5 +17,33 @@
</div>
</div>
</div>
<div class="box box-primary">
<div class="box-body">
<div class="row">
<div class="col-xs-12">
<h3>assigned subfleets</h3>
<div class="box-body">
@include('admin.flights.subfleets')
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('scripts')
<script>
$(document).ready(function () {
$(".select2_dropdown").select2();
$(document).on('submit', 'form.pjax_form', function (event) {
event.preventDefault();
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
});
$(document).on('pjax:complete', function() {
$(".select2_dropdown").select2();
});
});
</script>
@endsection

View File

@ -29,13 +29,17 @@
@endsection
@section('scripts')
<script>
$(document).ready(function () {
$(".ac-flight-dropdown").select2();
$(document).ready(function () {
$(".select2_dropdown").select2();
$(document).on('submit', 'form.flight_subfleet', function (event) {
event.preventDefault();
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
});
$(document).on('submit', 'form.pjax_form', function (event) {
event.preventDefault();
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
});
$(document).on('pjax:complete', function() {
$(".select2_dropdown").select2();
});
});
</script>
@endsection

View File

@ -29,14 +29,15 @@
<div class="row">
<div class="col-xs-12">
<div class="input-group input-group-lg pull-right">
{!! Form::open(['url' => '/admin/flights/'.$flight->id.'/subfleets',
'method' => 'post',
'class' => 'flight_subfleet form-inline'
])
{!! Form::open([
'url' => '/admin/flights/'.$flight->id.'/subfleets',
'method' => 'post',
'class' => 'pjax_form form-inline'
])
!!}
{!! Form::select('subfleet_id', $avail_subfleets, null, [
'placeholder' => 'Select Subfleet',
'class' => 'ac-flight-dropdown form-control input-lg',
'class' => 'select2_dropdown form-control input-lg',
])
!!}
{!! Form::button('<i class="glyphicon glyphicon-plus"></i> add',

View File

@ -2,14 +2,14 @@
@section('content')
<section class="content-header">
<h1>{!! $rank->name !!}</h1>
<h1>Edit "{!! $rank->name !!}"</h1>
</section>
<div class="content">
@include('adminlte-templates::common.errors')
<div class="box box-primary">
<div class="box-body">
<div class="row">
{!! Form::model($ranking, ['route' => ['admin.ranks.update', $rank->id], 'method' => 'patch']) !!}
{!! Form::model($rank, ['route' => ['admin.ranks.update', $rank->id], 'method' => 'patch']) !!}
@include('admin.ranks.fields')
@ -17,5 +17,34 @@
</div>
</div>
</div>
<div class="box box-primary">
<div class="box-body">
<div class="row">
<div class="col-xs-12">
<h3>subfleets</h3>
<div class="box-body">
@include('admin.ranks.subfleets')
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
@section('scripts')
<script>
$(document).ready(function() {
$(".select2_dropdown").select2();
$(document).on('submit', 'form.pjax_form', function(event) {
event.preventDefault();
$.pjax.submit(event, '#rank_subfleet_wrapper', {push: false});
});
$(document).on('pjax:complete', function() {
$(".select2_dropdown").select2();
});
});
</script>
@endsection

View File

@ -0,0 +1,57 @@
<div id="rank_subfleet_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
<table class="table table-responsive" id="subfleets-table">
<thead>
<th>Airline</th>
<th>Name</th>
<th>Type</th>
<th style="text-align: center;">Actions</th>
</thead>
<tbody>
@foreach($rank->subfleets as $sf)
<tr>
<td>{!! $sf->airline->name !!}</td>
<td>{!! $sf->name !!}</td>
<td>{!! $sf->type !!}</td>
<td style="width: 10%; text-align: center;" class="form-inline">
{!! Form::open(['url' => '/admin/ranks/'.$rank->id.'/subfleets', 'method' => 'delete', 'class' => 'pjax_form']) !!}
{!! Form::hidden('subfleet_id', $sf->id) !!}
<div class='btn-group'>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>',
['type' => 'submit',
'class' => 'btn btn-danger btn-xs'])
!!}
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
<hr />
<div class="row">
<div class="col-xs-12">
<div class="input-group input-group-lg pull-right">
{!! Form::open(['url' => '/admin/ranks/'.$rank->id.'/subfleets',
'method' => 'post',
'class' => 'pjax_form form-inline'
])
!!}
{!! Form::select('subfleet_id', $avail_subfleets, null, [
'placeholder' => 'Select Subfleet',
'class' => 'select2_dropdown form-control input-lg',
])
!!}
{!! Form::button('<i class="glyphicon glyphicon-plus"></i> add',
['type' => 'submit',
'class' => 'btn btn-success btn-s']) !!}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
<script>
$(document).ready(function () {
$(".select2_dropdown").select2();
});
</script>

View File

@ -19,9 +19,9 @@
<td>
{!! Form::open(['route' => ['admin.ranks.destroy', $rank->id], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{!! route('admin.ranks.show', [$rank->id]) !!}"
{{--<a href="{!! route('admin.ranks.show', [$rank->id]) !!}"
class='btn btn-default btn-xs'><i
class="glyphicon glyphicon-eye-open"></i></a>
class="glyphicon glyphicon-eye-open"></i></a>--}}
<a href="{!! route('admin.ranks.edit', [$rank->id]) !!}"
class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!}

View File

@ -25,6 +25,7 @@ Route::group([
# rankings
Route::resource('ranks', 'RankController');
Route::match(['get', 'post', 'put', 'delete'], 'ranks/{id}/subfleets', 'RankController@subfleets');
# view/update settings
Route::match(['get'], 'settings', 'SettingsController@index');