#48 add custom fields/values to flights
This commit is contained in:
parent
35133fe0e6
commit
5ffd152a43
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Models\Airline;
|
||||||
|
use App\Models\FlightFields;
|
||||||
|
use App\Models\Airport;
|
||||||
use App\Http\Requests\CreateFlightRequest;
|
use App\Http\Requests\CreateFlightRequest;
|
||||||
use App\Http\Requests\UpdateFlightRequest;
|
use App\Http\Requests\UpdateFlightRequest;
|
||||||
use App\Repositories\FlightRepository;
|
use App\Repositories\FlightRepository;
|
||||||
@ -101,7 +104,6 @@ class FlightController extends BaseController
|
|||||||
$avail_subfleets = $this->getAvailSubfleets($flight);
|
$avail_subfleets = $this->getAvailSubfleets($flight);
|
||||||
return view('admin.flights.show', [
|
return view('admin.flights.show', [
|
||||||
'flight' => $flight,
|
'flight' => $flight,
|
||||||
'fields' => $flight->fields(),
|
|
||||||
'avail_subfleets' => $avail_subfleets,
|
'avail_subfleets' => $avail_subfleets,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -125,7 +127,8 @@ class FlightController extends BaseController
|
|||||||
$avail_subfleets = $this->getAvailSubfleets($flight);
|
$avail_subfleets = $this->getAvailSubfleets($flight);
|
||||||
return view('admin.flights.edit', [
|
return view('admin.flights.edit', [
|
||||||
'flight' => $flight,
|
'flight' => $flight,
|
||||||
'fields' => $flight->fields(),
|
'airlines' => Airline::all()->pluck('name', 'id'),
|
||||||
|
'airports' => Airport::all()->pluck('icao', 'id'),
|
||||||
'avail_subfleets' => $avail_subfleets,
|
'avail_subfleets' => $avail_subfleets,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -175,6 +178,49 @@ class FlightController extends BaseController
|
|||||||
return redirect(route('admin.flights.index'));
|
return redirect(route('admin.flights.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function return_fields_view($flight)
|
||||||
|
{
|
||||||
|
$flight->refresh();
|
||||||
|
return view('admin.flights.flight_fields', [
|
||||||
|
'flight' => $flight,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fields(Request $request)
|
||||||
|
{
|
||||||
|
print_r($request->toArray());
|
||||||
|
$id = $request->id;
|
||||||
|
|
||||||
|
$flight = $this->flightRepository->findWithoutFail($id);
|
||||||
|
if (empty($flight)) {
|
||||||
|
Flash::error('Flight not found');
|
||||||
|
return redirect(route('admin.flights.index'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// add custom field to flight
|
||||||
|
if ($request->isMethod('post')) {
|
||||||
|
$field = new FlightFields;
|
||||||
|
$field->flight_id = $id;
|
||||||
|
$field->name = $request->name;
|
||||||
|
$field->value = $request->value;
|
||||||
|
$field->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
elseif ($request->isMethod('put')) {
|
||||||
|
$field = FlightFields::where('id', $request->field_id)->first();
|
||||||
|
$field->value = $request->value;
|
||||||
|
$field->save();
|
||||||
|
// update the field value
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove custom field from flight
|
||||||
|
elseif ($request->isMethod('delete')) {
|
||||||
|
FlightFields::destroy($request->field_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->return_fields_view($flight);
|
||||||
|
}
|
||||||
|
|
||||||
protected function return_subfleet_view($flight)
|
protected function return_subfleet_view($flight)
|
||||||
{
|
{
|
||||||
$avail_subfleets = $this->getAvailSubfleets($flight);
|
$avail_subfleets = $this->getAvailSubfleets($flight);
|
||||||
|
@ -44,6 +44,7 @@ class CreateFlightsTable extends Migration
|
|||||||
$table->uuid('flight_id');
|
$table->uuid('flight_id');
|
||||||
$table->string('name', 50);
|
$table->string('name', 50);
|
||||||
$table->text('value');
|
$table->text('value');
|
||||||
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,10 +143,10 @@ subfleet_fare:
|
|||||||
|
|
||||||
subfleet_flight:
|
subfleet_flight:
|
||||||
- subfleet_id: 1
|
- subfleet_id: 1
|
||||||
flight_id: 1
|
flight_id: flightid_1
|
||||||
|
|
||||||
flights:
|
flights:
|
||||||
- id: 1
|
- id: flightid_1
|
||||||
airline_id: 1
|
airline_id: 1
|
||||||
flight_number: 100
|
flight_number: 100
|
||||||
dpt_airport_id: 1
|
dpt_airport_id: 1
|
||||||
@ -155,13 +155,13 @@ flights:
|
|||||||
|
|
||||||
flight_fields:
|
flight_fields:
|
||||||
- id: 1
|
- id: 1
|
||||||
flight_id: 1
|
flight_id: flightid_1
|
||||||
name: terminal
|
name: terminal
|
||||||
value: B
|
value: B
|
||||||
|
|
||||||
pireps:
|
pireps:
|
||||||
- user_id: 1
|
- user_id: 1
|
||||||
flight_id: 1
|
flight_id: flightid_1
|
||||||
aircraft_id: 1
|
aircraft_id: 1
|
||||||
dpt_airport_id: 1
|
dpt_airport_id: 1
|
||||||
arr_airport_id: 2
|
arr_airport_id: 2
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<section class="content-header">
|
<section class="content-header">
|
||||||
<h1>Edit {!! $flight->airline->name !!}{!! $flight->number !!}</h1>
|
<h1>Edit {!! $flight->airline->code !!}{!! $flight->flight_number !!}</h1>
|
||||||
</section>
|
</section>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@include('adminlte-templates::common.errors')
|
@include('adminlte-templates::common.errors')
|
||||||
@ -17,6 +17,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="box box-primary">
|
||||||
|
<div class="box-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<h3>custom fields</h3>
|
||||||
|
<div class="box-body">
|
||||||
|
@include('admin.flights.flight_fields')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="box box-primary">
|
<div class="box box-primary">
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -33,17 +47,33 @@
|
|||||||
@endsection
|
@endsection
|
||||||
@section('scripts')
|
@section('scripts')
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$(".select2_dropdown").select2();
|
|
||||||
|
|
||||||
$(document).on('submit', 'form.pjax_form', function (event) {
|
$('#flight_fields_wrapper a.inline').editable({
|
||||||
event.preventDefault();
|
type: 'text',
|
||||||
$.pjax.submit(event, '#subfleet_flight_wrapper', {push: false});
|
mode: 'inline',
|
||||||
});
|
emptytext: '0',
|
||||||
|
url: '/admin/flights/{!! $flight->id !!}/fields',
|
||||||
$(document).on('pjax:complete', function() {
|
ajaxOptions: {'type': 'put'},
|
||||||
$(".select2_dropdown").select2();
|
params: function(params) {
|
||||||
});
|
return {
|
||||||
|
field_id: params.pk,
|
||||||
|
name: params.name,
|
||||||
|
value: params.value
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".select2_dropdown").select2();
|
||||||
|
|
||||||
|
$(document).on('submit', 'form.pjax_form', function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
$.pjax.submit(event, '#flight_fields_wrapper', {push: false});
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on('pjax:complete', function() {
|
||||||
|
$(".select2_dropdown").select2();
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
<!-- Airline Id Field -->
|
<!-- Airline Id Field -->
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-5">
|
||||||
{!! Form::label('airline_id', 'Airline:') !!}
|
{!! Form::label('airline_id', 'Airline:') !!}
|
||||||
{!! Form::text('airline_id', null, ['class' => 'form-control']) !!}
|
{!! Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Flight Number Field -->
|
<!-- Flight Number Field -->
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-5">
|
||||||
{!! Form::label('flight_number', 'Flight Number:') !!}
|
{!! Form::label('flight_number', 'Flight Number:') !!}
|
||||||
{!! Form::text('flight_number', null, ['class' => 'form-control']) !!}
|
{!! Form::text('flight_number', null, ['class' => 'form-control']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Active Field -->
|
||||||
|
<div class="form-group col-sm-2">
|
||||||
|
{!! Form::label('active', 'Active:') !!}
|
||||||
|
{!! Form::checkbox('active', $flight->active, ['class' => 'form-control']) !!}
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Route Code Field -->
|
<!-- Route Code Field -->
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
{!! Form::label('route_code', 'Route Code:') !!}
|
{!! Form::label('route_code', 'Route Code:') !!}
|
||||||
@ -22,22 +28,42 @@
|
|||||||
{!! Form::text('route_leg', null, ['class' => 'form-control']) !!}
|
{!! Form::text('route_leg', null, ['class' => 'form-control']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
SAME ROW
|
||||||
|
-->
|
||||||
|
|
||||||
<!-- Dpt Airport Id Field -->
|
<!-- Dpt Airport Id Field -->
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-4">
|
||||||
{!! Form::label('dpt_airport_id', 'Dpt Airport Id:') !!}
|
{!! Form::label('dpt_airport_id', 'Departure Airport:') !!}
|
||||||
{!! Form::text('dpt_airport_id', null, ['class' => 'form-control']) !!}
|
{!! Form::select('dpt_airport_id', $airports, null , ['class' => 'form-control select2']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Arr Airport Id Field -->
|
<!-- Arr Airport Id Field -->
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-4">
|
||||||
{!! Form::label('arr_airport_id', 'Arr Airport Id:') !!}
|
{!! Form::label('arr_airport_id', 'Arrival Airport:') !!}
|
||||||
{!! Form::text('arr_airport_id', null, ['class' => 'form-control']) !!}
|
{!! Form::select('arr_airport_id', $airports, null , ['class' => 'form-control select2']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Alt Airport Id Field -->
|
<!-- Alt Airport Id Field -->
|
||||||
|
<div class="form-group col-sm-4">
|
||||||
|
{!! Form::label('alt_airport_id', 'Alt Airport:') !!}
|
||||||
|
{!! Form::select('alt_airport_id', $airports, null , ['class' => 'form-control select2']) !!}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
END SAME ROW
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Dpt Time Field -->
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
{!! Form::label('alt_airport_id', 'Alt Airport Id:') !!}
|
{!! Form::label('dpt_time', 'Departure Time:') !!}
|
||||||
{!! Form::text('alt_airport_id', null, ['class' => 'form-control']) !!}
|
{!! Form::text('dpt_time', null, ['class' => 'form-control']) !!}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Arr Time Field -->
|
||||||
|
<div class="form-group col-sm-6">
|
||||||
|
{!! Form::label('arr_time', 'Arrival Time:') !!}
|
||||||
|
{!! Form::text('arr_time', null, ['class' => 'form-control']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Route Field -->
|
<!-- Route Field -->
|
||||||
@ -46,30 +72,12 @@
|
|||||||
{!! Form::text('route', null, ['class' => 'form-control']) !!}
|
{!! Form::text('route', null, ['class' => 'form-control']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Dpt Time Field -->
|
|
||||||
<div class="form-group col-sm-6">
|
|
||||||
{!! Form::label('dpt_time', 'Dpt Time:') !!}
|
|
||||||
{!! Form::text('dpt_time', null, ['class' => 'form-control']) !!}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Arr Time Field -->
|
|
||||||
<div class="form-group col-sm-6">
|
|
||||||
{!! Form::label('arr_time', 'Arr Time:') !!}
|
|
||||||
{!! Form::text('arr_time', null, ['class' => 'form-control']) !!}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Notes Field -->
|
<!-- Notes Field -->
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
{!! Form::label('notes', 'Notes:') !!}
|
{!! Form::label('notes', 'Notes:') !!}
|
||||||
{!! Form::text('notes', null, ['class' => 'form-control']) !!}
|
{!! Form::text('notes', null, ['class' => 'form-control']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Active Field -->
|
|
||||||
<div class="form-group col-sm-6">
|
|
||||||
{!! Form::label('active', 'Active:') !!}
|
|
||||||
{!! Form::text('active', null, ['class' => 'form-control']) !!}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Submit Field -->
|
<!-- Submit Field -->
|
||||||
<div class="form-group col-sm-12">
|
<div class="form-group col-sm-12">
|
||||||
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
|
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
|
||||||
|
56
resources/views/admin/flights/flight_fields.blade.php
Normal file
56
resources/views/admin/flights/flight_fields.blade.php
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
<div id="flight_fields_wrapper">
|
||||||
|
<table class="table table-responsive" id="flight-fields-table">
|
||||||
|
<thead>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Value</th>
|
||||||
|
<th style="text-align: center;">Actions</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($flight->fields as $field)
|
||||||
|
<tr>
|
||||||
|
<td>{!! $field->name !!}</td>
|
||||||
|
<td>
|
||||||
|
<a class="inline" href="#" data-pk="{!! $field->id !!}" data-name="{!! $field->name !!}">{!! $field->value !!}</a>
|
||||||
|
</td>
|
||||||
|
<td style="width: 10%; text-align: center;" class="form-inline">
|
||||||
|
{!! Form::open(['url' => '/admin/flights/'.$flight->id.'/fields',
|
||||||
|
'method' => 'delete',
|
||||||
|
'class' => 'pjax_form flight_fields'
|
||||||
|
]) !!}
|
||||||
|
{!! Form::hidden('field_id', $field->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 pull-right">
|
||||||
|
{!! Form::open([
|
||||||
|
'url' => '/admin/flights/'.$flight->id.'/fields',
|
||||||
|
'method' => 'post',
|
||||||
|
'class' => 'pjax_form form-inline'
|
||||||
|
])
|
||||||
|
!!}
|
||||||
|
|
||||||
|
<div class="form-group col-xs-12 form-inline">
|
||||||
|
|
||||||
|
{!! Form::label('name', 'Name:') !!}
|
||||||
|
{!! Form::text('name', null, ['class' => 'form-control']) !!}
|
||||||
|
|
||||||
|
{!! Form::label('value', 'Value:') !!}
|
||||||
|
{!! Form::text('value', null, ['class' => 'form-control']) !!}
|
||||||
|
|
||||||
|
{!! Form::button('<i class="glyphicon glyphicon-plus"></i> add',
|
||||||
|
['type' => 'submit',
|
||||||
|
'class' => 'btn btn-success btn-s']) !!}
|
||||||
|
</div>
|
||||||
|
{!! Form::close() !!}
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -1,6 +1,6 @@
|
|||||||
<!-- Airline Id Field -->
|
<!-- Airline Id Field -->
|
||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
{!! Form::label('airline_id', 'Airline Id:') !!}
|
{!! Form::label('airline_id', 'Airline:') !!}
|
||||||
{!! Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) !!}
|
{!! Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ Route::group([
|
|||||||
|
|
||||||
# flights and aircraft associations
|
# flights and aircraft associations
|
||||||
Route::resource('flights', 'FlightController');
|
Route::resource('flights', 'FlightController');
|
||||||
|
Route::match(['get', 'post', 'put', 'delete'], 'flights/{id}/fields', 'FlightController@fields');
|
||||||
Route::match(['get', 'post', 'put', 'delete'], 'flights/{id}/subfleets', 'FlightController@subfleets');
|
Route::match(['get', 'post', 'put', 'delete'], 'flights/{id}/subfleets', 'FlightController@subfleets');
|
||||||
|
|
||||||
# rankings
|
# rankings
|
||||||
|
Loading…
Reference in New Issue
Block a user