#11 inline editing for pivot values for price/cost/capacity on fares

This commit is contained in:
Nabeel Shahzad
2017-06-13 15:11:11 -05:00
parent 4b137460e3
commit 15ed2bd846
7 changed files with 90 additions and 20 deletions

View File

@@ -168,11 +168,28 @@ class AircraftController extends BaseController
$fare_svc = app('App\Services\FareService');
// associate or dissociate the fare with this aircraft
if ($request->isMethod('post') || $request->isMethod('put')) {
if ($request->isMethod('get')) {
return $this->return_fares_view($aircraft);
}
/**
* update specific fare data
*/
if ($request->isMethod('post')) {
$fare = $this->fareRepository->findWithoutFail($request->fare_id);
$fare_svc->setForAircraft($aircraft, $fare);
} elseif ($request->isMethod('delete')) {
}
// update the pivot table with overrides for the fares
elseif ($request->isMethod('put')) {
$override = [];
$fare = $this->fareRepository->findWithoutFail($request->fare_id);
$override[$request->name] = $request->value;
$fare_svc->setForAircraft($aircraft, $fare, $override);
}
// dissassociate fare from teh aircraft
elseif ($request->isMethod('delete')) {
$fare = $this->fareRepository->findWithoutFail($request->fare_id);
$fare_svc->delFromAircraft($aircraft, $fare);
}

View File

@@ -29,7 +29,7 @@ class Kernel extends HttpKernel
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
#\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

View File

@@ -17,7 +17,7 @@ class CreateFaresTable extends Migration
$table->increments('id');
$table->string('code');
$table->string('name');
$table->float('price');
$table->float('price')->default(0.0);
$table->float('cost')->default(0.0);
$table->integer('capacity')->default(0);
$table->string('notes')->nullable();
@@ -32,7 +32,7 @@ class CreateFaresTable extends Migration
$table->integer('fare_id');
$table->float('price')->nullable();
$table->float('cost')->nullable();
$table->float('capacity')->nullable();
$table->integer('capacity')->nullable();
$table->timestamps();
$table->softDeletes();
});

View File

@@ -31,16 +31,20 @@ airlines:
airports:
- icao: KAUS
name: Austin-Bergstrom International Airport
name: Austin-Bergstrom
location: Austin, Texas, USA
lat: 30.1945278
lon: -97.6698889
- icao: KJFK
name: John F Kennedy International Airport
name: John F Kennedy
location: New York, New York, USA
lat: 40.6399257
lon: -73.7786950
- icao: EGLL
name: London Heathrow
location: London, England
lat: 51.4775
lon: -0.4614
#
aircraft_classes:
- id: 1
@@ -70,12 +74,35 @@ fares:
price: 100
capacity: 200
- id: 2
code: F
name: First-Class
code: B
name: Business
price: 500
capacity: 10
- id: 3
code: F
name: First-Class
price: 800
capacity: 5
#
# add a few mods to aircraft and fares
aircraft_fare:
# Fare classes on the 747
- aircraft_id: 1
fare_id: 1
price: 200
capacity: 400
- aircraft_id: 1
fare_id: 2
capacity: 20
- aircraft_id: 1
fare_id: 3
price: 1000
capacity: 10
# Fare classes on the 777
- aircraft_id: 2
fare_id: 1
- aircraft_id: 2
fare_id: 3
capacity: 10

View File

@@ -18,17 +18,17 @@
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
rowspan="1" colspan="1"
aria-label="capacity: activate to sort column ascending">
capacity
capacity (default)
</th>
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
rowspan="1" colspan="1"
aria-label="price: activate to sort column ascending">
price
price (default)
</th>
<th class="sorting" tabindex="0" aria-controls="aircraft_fares"
rowspan="1" colspan="1"
aria-label="cost: activate to sort column ascending">
cost
cost (default)
</th>
<th></th>
</tr>
@@ -38,9 +38,13 @@
<tr role="row" class="@if ($loop->iteration%2) even @else odd @endif">
<td class="sorting_1">{!! $atf->name !!}</td>
<td>{!! $atf->code !!}</td>
<td>{!! $atf->capacity !!}</td>
<td>{!! $atf->price !!}</td>
<td>{!! $atf->cost !!}</td>
<td><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>
<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>
<span class="small background-color-grey-light">({!! $atf->cost!!})</span></td>
<td style="text-align: right; width:3%;">
<div class='btn-group'>
{!! Form::open(['url' => '/admin/aircraft/'.$aircraft->id.'/fares', 'method' => 'delete', 'class' => 'rm_fare']) !!}

View File

@@ -10,9 +10,13 @@
<div class="box-body">
<div class="row">
<div class="col-xs-12">
<hr/>
<h3 class="box-header">fares</h3>
<h3>fares</h3>
<div class="box-body">
<div class="callout callout-info">
<i class="icon fa fa-info">&nbsp;&nbsp;</i>
Fares assigned to the current aircraft. These can be overridden,
otherwise, the value used is the default, which comes from the fare.
</div>
@include('admin.aircraft.fares')
</div>
</div>
@@ -25,6 +29,22 @@
<script>
$(document).ready(function() {
$(".ac-fare-dropdown").select2();
$('#aircraft_fares a').editable({
type: 'text',
mode: 'inline',
emptytext: 'default',
url: '/admin/aircraft/{!! $aircraft->id !!}/fares',
title: 'Enter override value',
ajaxOptions: { 'type': 'put'},
params: function(params) {
return {
fare_id: params.pk,
name: params.name,
value: params.value
}
}
});
$(document).on('submit', 'form.rm_fare', function(event) {
event.preventDefault();
$.pjax.submit(event, '#aircraft_fares_wrapper', {push: false});

View File

@@ -179,6 +179,8 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/js/select2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/iCheck/1.0.2/icheck.min.js"></script>
<script src="/vendor/pjax/jquery.pjax.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/css/bootstrap-editable.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/x-editable/1.5.0/bootstrap3-editable/js/bootstrap-editable.min.js"></script>
<!-- AdminLTE App -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/admin-lte/2.3.3/js/app.min.js"></script>