#14 Assign aircraft to the flights
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
|||||||
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;
|
||||||
|
use App\Repositories\AircraftRepository;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Flash;
|
use Flash;
|
||||||
use Prettus\Repository\Criteria\RequestCriteria;
|
use Prettus\Repository\Criteria\RequestCriteria;
|
||||||
@@ -13,11 +14,30 @@ use Response;
|
|||||||
class FlightController extends BaseController
|
class FlightController extends BaseController
|
||||||
{
|
{
|
||||||
/** @var FlightRepository */
|
/** @var FlightRepository */
|
||||||
private $flightRepository;
|
private $flightRepository, $aircraftRepository;
|
||||||
|
|
||||||
public function __construct(FlightRepository $flightRepo)
|
public function __construct(
|
||||||
|
FlightRepository $flightRepo,
|
||||||
|
AircraftRepository $aircraftRepository
|
||||||
|
)
|
||||||
{
|
{
|
||||||
$this->flightRepository = $flightRepo;
|
$this->flightRepository = $flightRepo;
|
||||||
|
$this->aircraftRepository = $aircraftRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getAvailAircraft($flight)
|
||||||
|
{
|
||||||
|
$retval = [];
|
||||||
|
|
||||||
|
$flight->refresh();
|
||||||
|
$all_aircraft = $this->aircraftRepository->all();
|
||||||
|
$avail_aircraft = $all_aircraft->except($flight->aircraft->modelKeys());
|
||||||
|
|
||||||
|
foreach ($avail_aircraft as $ac) {
|
||||||
|
$retval[$ac->id] = $ac->icao.' - '.$ac->registration;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,7 +99,10 @@ class FlightController extends BaseController
|
|||||||
return redirect(route('admin.flights.index'));
|
return redirect(route('admin.flights.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('admin.flights.show')->with('flight', $flight);
|
$avail_aircraft = $this->getAvailAircraft($flight);
|
||||||
|
return view('admin.flights.show')
|
||||||
|
->with('flight', $flight)
|
||||||
|
->with('avail_aircraft', $avail_aircraft);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,12 +170,20 @@ class FlightController extends BaseController
|
|||||||
return redirect(route('admin.flights.index'));
|
return redirect(route('admin.flights.index'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function return_aircraft_view($flight)
|
||||||
|
{
|
||||||
|
$avail_aircraft = $this->getAvailAircraft($flight);
|
||||||
|
return view('admin.flights.aircraft')
|
||||||
|
->with('flight', $flight)
|
||||||
|
->with('avail_aircraft', $avail_aircraft);
|
||||||
|
}
|
||||||
|
|
||||||
public function aircraft(Request $request)
|
public function aircraft(Request $request)
|
||||||
{
|
{
|
||||||
$id = $request->id;
|
$id = $request->id;
|
||||||
|
print_r($request->toArray());
|
||||||
|
|
||||||
$flight = $this->flightRepository->findWithoutFail($id);
|
$flight = $this->flightRepository->findWithoutFail($id);
|
||||||
|
|
||||||
if (empty($flight)) {
|
if (empty($flight)) {
|
||||||
Flash::error('Flight not found');
|
Flash::error('Flight not found');
|
||||||
return redirect(route('admin.flights.index'));
|
return redirect(route('admin.flights.index'));
|
||||||
@@ -165,14 +196,11 @@ class FlightController extends BaseController
|
|||||||
// add
|
// add
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the pivot table with overrides for the fares
|
|
||||||
elseif ($request->isMethod('put')) {
|
|
||||||
// update
|
|
||||||
}
|
|
||||||
|
|
||||||
// dissassociate fare from teh aircraft
|
// dissassociate fare from teh aircraft
|
||||||
elseif ($request->isMethod('delete')) {
|
elseif ($request->isMethod('delete')) {
|
||||||
// del
|
// del
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->return_aircraft_view($flight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,3 +123,7 @@ flights:
|
|||||||
dpt_airport_id: 1
|
dpt_airport_id: 1
|
||||||
arr_airport_id: 2
|
arr_airport_id: 2
|
||||||
route: KAUS KJFK
|
route: KAUS KJFK
|
||||||
|
|
||||||
|
flight_aircraft:
|
||||||
|
- flight_id: 1
|
||||||
|
aircraft_id: 1
|
||||||
|
|||||||
@@ -61,8 +61,8 @@
|
|||||||
</table>
|
</table>
|
||||||
<hr />
|
<hr />
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12" style="text-align: right;">
|
<div class="col-xs-12">
|
||||||
<div class="input-group input-group-lg">
|
<div class="input-group input-group-lg pull-right">
|
||||||
{!! Form::open(['url' => '/admin/aircraft/'.$aircraft->id.'/fares',
|
{!! Form::open(['url' => '/admin/aircraft/'.$aircraft->id.'/fares',
|
||||||
'method' => 'post',
|
'method' => 'post',
|
||||||
'class' => 'rm_fare form-inline'
|
'class' => 'rm_fare form-inline'
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<section class="content-header">
|
<section class="content-header">
|
||||||
<h1 class="pull-left">{!! $aircraft->name !!}</h1></section>
|
<h1 class="pull-left">{!! $aircraft->name !!}</h1>
|
||||||
<h1 class="pull-right">
|
<h1 class="pull-right">
|
||||||
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('admin.aircraft.edit', $aircraft->id) !!}">Edit</a>
|
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('admin.aircraft.edit', $aircraft->id) !!}">Edit</a>
|
||||||
</h1>
|
</h1>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<section class="content-header">
|
<section class="content-header">
|
||||||
<h1 class="pull-left">$MODEL_NAME_PLURAL_HUMAN$</h1>
|
<h1 class="pull-left">Airports</h1>
|
||||||
<h1 class="pull-right">
|
<h1 class="pull-right">
|
||||||
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('admin.airports.create') !!}">Add New</a>
|
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('admin.airports.create') !!}">Add New</a>
|
||||||
</h1>
|
</h1>
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<div id="flight_aircraft_wrapper" >
|
||||||
|
<table class="table table-responsive" id="aircrafts-table">
|
||||||
|
<thead>
|
||||||
|
<th>ICAO</th>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Registration</th>
|
||||||
|
<th style="text-align: center;">Actions</th>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($flight->aircraft as $ac)
|
||||||
|
<tr>
|
||||||
|
<td>{!! $ac->icao !!}</td>
|
||||||
|
<td>{!! $ac->name !!}</td>
|
||||||
|
<td>{!! $ac->registration !!}</td>
|
||||||
|
<td style="width: 10%; text-align: center;" class="form-inline">
|
||||||
|
{!! Form::open(['url' => '/admin/flights/'.$flight->id.'/aircraft', 'method' => 'delete', 'class' => 'flight_ac_frm']) !!}
|
||||||
|
{!! Form::hidden('flight_id', $flight->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/flights/'.$flight->id.'/aircraft',
|
||||||
|
'method' => 'post',
|
||||||
|
'class' => 'flight_ac_frm form-inline'
|
||||||
|
])
|
||||||
|
!!}
|
||||||
|
{!! Form::select('aircraft_id', $avail_aircraft, null, [
|
||||||
|
'placeholder' => 'Select Aircraft',
|
||||||
|
'class' => 'ac-flight-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>
|
||||||
@@ -1,17 +1,41 @@
|
|||||||
@extends('admin.app')
|
@extends('admin.app')
|
||||||
|
|
||||||
@section('content')
|
@section('content')
|
||||||
<section class="content-header">
|
<section class="content-header">
|
||||||
<h1>Flights</h1>
|
<h1 class="pull-left">{!! $flight->airline->code !!}{!! $flight->flight_number !!}</h1>
|
||||||
</section>
|
<h1 class="pull-right">
|
||||||
<div class="content">
|
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px"
|
||||||
<div class="box box-primary">
|
href="{!! route('admin.flights.edit', $flight->id) !!}">Edit</a>
|
||||||
<div class="box-body">
|
</h1>
|
||||||
<div class="row" style="padding-left: 20px">
|
</section>
|
||||||
@include('admin.flights.show_fields')
|
<section class="content">
|
||||||
<a href="{!! route('admin.flights.index') !!}" class="btn btn-default">Back</a>
|
<div class="clearfix"></div>
|
||||||
|
<div class="row">
|
||||||
|
@include('admin.flights.show_fields')
|
||||||
|
</div>
|
||||||
|
<div class="box box-primary">
|
||||||
|
<div class="box-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12">
|
||||||
|
<h3>assigned aircraft</h3>
|
||||||
|
<div class="box-body">
|
||||||
|
@include('admin.flights.aircraft')
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</section>
|
||||||
|
@endsection
|
||||||
|
@section('scripts')
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$(".ac-flight-dropdown").select2();
|
||||||
|
|
||||||
|
$(document).on('submit', 'form.flight_ac_frm', function (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
$.pjax.submit(event, '#flight_aircraft_wrapper', {push: false});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
@@ -1,90 +1,81 @@
|
|||||||
<!-- Id Field -->
|
<div class="form-group col-sm-6">
|
||||||
<div class="form-group">
|
<div class="box box-solid">
|
||||||
{!! Form::label('id', 'Id:') !!}
|
<div class="box-header with-border">
|
||||||
<p>{!! $flight->id !!}</p>
|
{{--<i class="fa fa-text-width"></i>--}}
|
||||||
|
<h3 class="box-title">{!! Form::label('dpt_airport_id', 'Dep ICAO') !!}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body"><p class="lead">
|
||||||
|
{!! $flight->dpt_airport->icao !!} - {!! $flight->dpt_airport->name !!}
|
||||||
|
</p></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Airline Id Field -->
|
<div class="form-group col-sm-6">
|
||||||
<div class="form-group">
|
<div class="box box-solid">
|
||||||
{!! Form::label('airline_id', 'Airline Id:') !!}
|
<div class="box-header with-border">
|
||||||
<p>{!! $flight->airline_id !!}</p>
|
{{--<i class="fa fa-text-width"></i>--}}
|
||||||
|
<h3 class="box-title">{!! Form::label('arr_airport_id', 'Arrival ICAO') !!}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="box-body"><p class="lead">
|
||||||
|
{!! $flight->arr_airport->icao !!} - {!! $flight->arr_airport->name !!}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Flight Number Field -->
|
|
||||||
<div class="form-group">
|
|
||||||
{!! Form::label('flight_number', 'Flight Number:') !!}
|
|
||||||
<p>{!! $flight->flight_number !!}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Route Code Field -->
|
<div class="form-group col-sm-12">
|
||||||
<div class="form-group">
|
<div class="box box-primary">
|
||||||
{!! Form::label('route_code', 'Route Code:') !!}
|
<div class="box-body">
|
||||||
<p>{!! $flight->route_code !!}</p>
|
<!-- Route Code Field -->
|
||||||
</div>
|
<div class="form-group">
|
||||||
|
{!! Form::label('route_code', 'Route Code:') !!}
|
||||||
|
{!! $flight->route_code !!}
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Route Leg Field -->
|
<!-- Route Leg Field -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{!! Form::label('route_leg', 'Route Leg:') !!}
|
{!! Form::label('route_leg', 'Route Leg:') !!}
|
||||||
<p>{!! $flight->route_leg !!}</p>
|
{!! $flight->route_leg !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Dpt Airport Id Field -->
|
<!-- Alt Airport Id Field -->
|
||||||
<div class="form-group">
|
@if($flight->alt_airport_id)
|
||||||
{!! Form::label('dpt_airport_id', 'Dpt Airport Id:') !!}
|
<div class="form-group">
|
||||||
<p>{!! $flight->dpt_airport_id !!}</p>
|
{!! Form::label('alt_airport_id', 'Alt Airport Id:') !!}
|
||||||
</div>
|
<p>{!! $flight->alt_airport->icao !!}</p>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<!-- Arr Airport Id Field -->
|
<!-- Route Field -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{!! Form::label('arr_airport_id', 'Arr Airport Id:') !!}
|
{!! Form::label('route', 'Route:') !!}
|
||||||
<p>{!! $flight->arr_airport_id !!}</p>
|
<p>{!! $flight->route !!}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Alt Airport Id Field -->
|
<!-- Dpt Time Field -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{!! Form::label('alt_airport_id', 'Alt Airport Id:') !!}
|
{!! Form::label('dpt_time', 'Departure Time:') !!}
|
||||||
<p>{!! $flight->alt_airport_id !!}</p>
|
{!! $flight->dpt_time !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Route Field -->
|
<!-- Arr Time Field -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{!! Form::label('route', 'Route:') !!}
|
{!! Form::label('arr_time', 'Arrival Time:') !!}
|
||||||
<p>{!! $flight->route !!}</p>
|
{!! $flight->arr_time !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Dpt Time Field -->
|
<!-- Notes Field -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{!! Form::label('dpt_time', 'Dpt Time:') !!}
|
{!! Form::label('notes', 'Notes:') !!}
|
||||||
<p>{!! $flight->dpt_time !!}</p>
|
<p>{!! $flight->notes !!}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Arr Time Field -->
|
<!-- Active Field -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
{!! Form::label('arr_time', 'Arr Time:') !!}
|
{!! Form::label('active', 'Active:') !!}
|
||||||
<p>{!! $flight->arr_time !!}</p>
|
<p>{!! $flight->active !!}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Notes Field -->
|
|
||||||
<div class="form-group">
|
|
||||||
{!! Form::label('notes', 'Notes:') !!}
|
|
||||||
<p>{!! $flight->notes !!}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Active Field -->
|
|
||||||
<div class="form-group">
|
|
||||||
{!! Form::label('active', 'Active:') !!}
|
|
||||||
<p>{!! $flight->active !!}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Created At Field -->
|
|
||||||
<div class="form-group">
|
|
||||||
{!! Form::label('created_at', 'Created At:') !!}
|
|
||||||
<p>{!! $flight->created_at !!}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Updated At Field -->
|
|
||||||
<div class="form-group">
|
|
||||||
{!! Form::label('updated_at', 'Updated At:') !!}
|
|
||||||
<p>{!! $flight->updated_at !!}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,10 +14,12 @@
|
|||||||
@foreach($flights as $flight)
|
@foreach($flights as $flight)
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
<a href="{!! route('admin.flights.show', [$flight->id]) !!}">
|
||||||
{!! $flight->airline->code !!}{!! $flight->flight_number !!}
|
{!! $flight->airline->code !!}{!! $flight->flight_number !!}
|
||||||
@if($flight->route_code)
|
@if($flight->route_code)
|
||||||
(C: {!! $flight->route_code !!} L: {!! $flight->route_leg !!})
|
(C: {!! $flight->route_code !!} L: {!! $flight->route_leg !!})
|
||||||
@endif
|
@endif
|
||||||
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{!! $flight->dpt_airport->icao !!}</td>
|
<td>{!! $flight->dpt_airport->icao !!}</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
Reference in New Issue
Block a user