#41 inline editing of fuel prices

This commit is contained in:
Nabeel Shahzad
2017-07-05 18:48:32 -05:00
parent d44d374218
commit 10baaab646
10 changed files with 156 additions and 58 deletions

View File

@@ -33,9 +33,10 @@ class AirportController extends InfyOmBaseController
$this->airportRepository->pushCriteria(new RequestCriteria($request));
$airports = $this->airportRepository->all();
return view('admin.airports.index')
->with('airports', $airports)
->with('coords', ['lat' => '', 'lon' => '']);
return view('admin.airports.index', [
'airports' => $airports,
'coords' => ['lat' => '', 'lon' => ''],
]);
}
/**
@@ -50,27 +51,21 @@ class AirportController extends InfyOmBaseController
/**
* Store a newly created Airport in storage.
*
* @param CreateAirportRequest $request
*
* @return Response
*/
public function store(CreateAirportRequest $request)
{
$input = $request->all();
$airport = $this->airportRepository->create($input);
Flash::success('Airport saved successfully.');
return redirect(route('admin.airports.index'));
}
/**
* Display the specified Airport.
*
* @param int $id
*
* @return Response
*/
public function show($id)
@@ -82,15 +77,14 @@ class AirportController extends InfyOmBaseController
return redirect(route('admin.airports.index'));
}
return view('admin.airports.show')
->with('airport', $airport);
return view('admin.airports.show', [
'airport' => $airport,
]);
}
/**
* Show the form for editing the specified Airport.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
@@ -99,19 +93,18 @@ class AirportController extends InfyOmBaseController
if (empty($airport)) {
Flash::error('Airport not found');
return redirect(route('admin.airports.index'));
}
return view('admin.airports.edit')->with('airport', $airport);
return view('admin.airports.edit', [
'airport' => $airport,
]);
}
/**
* Update the specified Airport in storage.
*
* @param int $id
* @param UpdateAirportRequest $request
*
* @return Response
*/
public function update($id, UpdateAirportRequest $request)
@@ -120,22 +113,18 @@ class AirportController extends InfyOmBaseController
if (empty($airport)) {
Flash::error('Airport not found');
return redirect(route('admin.airports.index'));
}
$airport = $this->airportRepository->update($request->all(), $id);
Flash::success('Airport updated successfully.');
return redirect(route('admin.airports.index'));
}
/**
* Remove the specified Airport from storage.
*
* @param int $id
*
* @return Response
*/
public function destroy($id)
@@ -144,14 +133,30 @@ class AirportController extends InfyOmBaseController
if (empty($airport)) {
Flash::error('Airport not found');
return redirect(route('admin.airports.index'));
}
$this->airportRepository->delete($id);
Flash::success('Airport deleted successfully.');
return redirect(route('admin.airports.index'));
}
public function fuel(Request $request)
{
$id = $request->id;
$airport = $this->airportRepository->findWithoutFail($id);
if (empty($airport)) {
Flash::error('Flight not found');
return redirect(route('admin.flights.index'));
}
// add aircraft to flight
if ($request->isMethod('put')) {
$airport->{$request->name} = $request->value;
}
$airport->save();
}
}

View File

@@ -11,13 +11,15 @@ use Eloquent as Model;
class Airport extends Model
{
public $table = 'airports';
protected $dates = ['deleted_at'];
public $fillable = [
'icao'
'icao',
'name',
'location',
'fuel_100ll_cost',
'fuel_jeta_cost',
'fuel_mogas_cost',
];
/**

View File

@@ -1,6 +1,12 @@
<?php
return [
'status' => [
'INACTIVE' => 0,
'ACTIVE' => 1,
],
'sources' => [
'MANUAL' => 0,
'ACARS' => 1,

View File

@@ -19,9 +19,9 @@ class CreateAirportsTable extends Migration
$table->string('name');
$table->string('location')->nullable();
$table->string('country')->nullable();
$table->double('fuel_100ll_cost', 19, 2)->nullable();
$table->double('fuel_jeta_cost', 19, 2)->nullable();
$table->double('fuel_mogas_cost', 19, 2)->nullable();
$table->double('fuel_100ll_cost', 19, 2)->default(0);
$table->double('fuel_jeta_cost', 19, 2)->default(0);
$table->double('fuel_mogas_cost', 19, 2)->default(0);
$table->float('lat', 7, 4)->default(0.0);
$table->float('lon', 7, 4)->default(0.0);
$table->timestamps();

View File

@@ -32,5 +32,48 @@
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="PHP" type="php">
<CLASSES>
<root url="file://$APPLICATION_HOME_DIR$/bin" />
<root url="file://$MODULE_DIR$/vendor/chrisbjr/api-guard" />
<root url="file://$MODULE_DIR$/vendor/dompdf/dompdf" />
<root url="file://$MODULE_DIR$/vendor/ellipsesynergie/api-response" />
<root url="file://$MODULE_DIR$/vendor/jeremeamia/SuperClosure" />
<root url="file://$MODULE_DIR$/vendor/league/fractal" />
<root url="file://$MODULE_DIR$/vendor/maatwebsite/excel" />
<root url="file://$MODULE_DIR$/vendor/nikic/php-parser" />
<root url="file://$MODULE_DIR$/vendor/phenx/php-font-lib" />
<root url="file://$MODULE_DIR$/vendor/phenx/php-svg-lib" />
<root url="file://$MODULE_DIR$/vendor/phpoffice/phpexcel" />
<root url="file://$MODULE_DIR$/vendor/spatie/fractalistic" />
<root url="file://$MODULE_DIR$/vendor/spatie/laravel-fractal" />
<root url="file://$MODULE_DIR$/vendor/symfony/polyfill-php56" />
<root url="file://$MODULE_DIR$/vendor/symfony/polyfill-util" />
<root url="file://$MODULE_DIR$/vendor/webpatser/laravel-uuid" />
<root url="file://$MODULE_DIR$/vendor/yajra/laravel-datatables-oracle" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$APPLICATION_HOME_DIR$/bin" />
<root url="file://$MODULE_DIR$/vendor/chrisbjr/api-guard" />
<root url="file://$MODULE_DIR$/vendor/dompdf/dompdf" />
<root url="file://$MODULE_DIR$/vendor/ellipsesynergie/api-response" />
<root url="file://$MODULE_DIR$/vendor/jeremeamia/SuperClosure" />
<root url="file://$MODULE_DIR$/vendor/league/fractal" />
<root url="file://$MODULE_DIR$/vendor/maatwebsite/excel" />
<root url="file://$MODULE_DIR$/vendor/nikic/php-parser" />
<root url="file://$MODULE_DIR$/vendor/phenx/php-font-lib" />
<root url="file://$MODULE_DIR$/vendor/phenx/php-svg-lib" />
<root url="file://$MODULE_DIR$/vendor/phpoffice/phpexcel" />
<root url="file://$MODULE_DIR$/vendor/spatie/fractalistic" />
<root url="file://$MODULE_DIR$/vendor/spatie/laravel-fractal" />
<root url="file://$MODULE_DIR$/vendor/symfony/polyfill-php56" />
<root url="file://$MODULE_DIR$/vendor/symfony/polyfill-util" />
<root url="file://$MODULE_DIR$/vendor/webpatser/laravel-uuid" />
<root url="file://$MODULE_DIR$/vendor/yajra/laravel-datatables-oracle" />
</SOURCES>
</library>
</orderEntry>
</component>
</module>

View File

@@ -20,4 +20,4 @@
</div>
</div>
@endsection
@include('admin.airports.script')

View File

@@ -0,0 +1,21 @@
@section('scripts')
<script>
$(document).ready(function() {
$('#airports-table a.inline').editable({
type: 'text',
mode: 'inline',
emptytext: '0',
url: '/admin/airports/fuel',
title: 'Enter price per unit of fuel',
ajaxOptions: {'type': 'put'},
params: function(params) {
return {
id: params.pk,
name: params.name,
value: params.value
}
}
});
});
</script>
@endsection

View File

@@ -1,26 +1,40 @@
<table class="table table-responsive" id="airports-table">
<thead>
<th>ICAO</th>
<th>Name</th>
<th>Location</th>
<th colspan="3">Action</th>
</thead>
<tbody>
@foreach($airports as $airport)
<tr>
<td>{!! $airport->icao !!}</td>
<td>{!! $airport->name !!}</td>
<td>{!! $airport->location !!} ({!! $airport->lat !!}x{!! $airport->lon !!})</td>
<td>
{!! Form::open(['route' => ['admin.airports.destroy', $airport->id], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{!! route('admin.airports.show', [$airport->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
<a href="{!! route('admin.airports.edit', [$airport->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?')"]) !!}
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
<div id="airports_table_wrapper">
<table class="table table-responsive" id="airports-table">
<thead>
<th>ICAO</th>
<th>Name</th>
<th>Location</th>
<th style="text-align: center;">100LL</th>
<th style="text-align: center;">JetA</th>
<th style="text-align: center;">MOGAS</th>
<th colspan="3">Action</th>
</thead>
<tbody>
@foreach($airports as $airport)
<tr>
<td>{!! $airport->icao !!}</td>
<td>{!! $airport->name !!}</td>
<td>{!! $airport->location !!}</td>
<td style="text-align: center;">
<a class="inline" href="#" data-pk="{!! $airport->id !!}" data-name="fuel_100ll_cost">{!! $airport->fuel_100ll_cost !!}</a>
</td>
<td style="text-align: center;">
<a class="inline" href="#" data-pk="{!! $airport->id !!}" data-name="fuel_jeta_cost">{!! $airport->fuel_jeta_cost !!}</a>
</td>
<td style="text-align: center;">
<a class="inline" href="#" data-pk="{!! $airport->id !!}" data-name="fuel_mogas_cost">{!! $airport->fuel_mogas_cost !!}</a>
</td>
<td>
{!! Form::open(['route' => ['admin.airports.destroy', $airport->id], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{!! route('admin.airports.show', [$airport->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
<a href="{!! route('admin.airports.edit', [$airport->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?')"]) !!}
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>

View File

@@ -7,8 +7,11 @@ Route::group([
'namespace' => 'Admin', 'prefix' => 'admin', 'as' => 'admin.',
'middleware' => ['role:admin'],
], function () {
Route::resource('airports', 'AirportController');
Route::resource('airlines', 'AirlinesController');
Route::match(['get', 'put'], 'airports/fuel', 'AirportController@fuel');
Route::resource('airports', 'AirportController');
Route::resource('aircraftclasses', 'AircraftClassController');
Route::resource('fares', 'FareController');

View File

@@ -55,12 +55,14 @@ airports:
location: Austin, Texas, USA
lat: 30.1945278
lon: -97.6698889
fuel_jeta_cost: 100
- id: 2
icao: KJFK
name: John F Kennedy
location: New York, New York, USA
lat: 40.6399257
lon: -73.7786950
fuel_jeta_cost: 50
aircraft:
- id: 1
@@ -96,10 +98,12 @@ subfleets:
airline_id: 1
name: 747-400 Winglets
type: 744W
fuel_type: 1
- id: 2
airline_id: 1
name: 777-200 LR
type: 772-LR
fuel_type: 1
# add a few mods to aircraft and fares
subfleet_fare: