#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\UpdateFlightRequest;
|
||||
use App\Repositories\FlightRepository;
|
||||
use App\Repositories\AircraftRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Flash;
|
||||
use Prettus\Repository\Criteria\RequestCriteria;
|
||||
@@ -13,11 +14,30 @@ use Response;
|
||||
class FlightController extends BaseController
|
||||
{
|
||||
/** @var FlightRepository */
|
||||
private $flightRepository;
|
||||
private $flightRepository, $aircraftRepository;
|
||||
|
||||
public function __construct(FlightRepository $flightRepo)
|
||||
public function __construct(
|
||||
FlightRepository $flightRepo,
|
||||
AircraftRepository $aircraftRepository
|
||||
)
|
||||
{
|
||||
$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 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'));
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
$id = $request->id;
|
||||
print_r($request->toArray());
|
||||
|
||||
$flight = $this->flightRepository->findWithoutFail($id);
|
||||
|
||||
if (empty($flight)) {
|
||||
Flash::error('Flight not found');
|
||||
return redirect(route('admin.flights.index'));
|
||||
@@ -165,14 +196,11 @@ class FlightController extends BaseController
|
||||
// add
|
||||
}
|
||||
|
||||
// update the pivot table with overrides for the fares
|
||||
elseif ($request->isMethod('put')) {
|
||||
// update
|
||||
}
|
||||
|
||||
// dissassociate fare from teh aircraft
|
||||
elseif ($request->isMethod('delete')) {
|
||||
// del
|
||||
}
|
||||
|
||||
return $this->return_aircraft_view($flight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,3 +123,7 @@ flights:
|
||||
dpt_airport_id: 1
|
||||
arr_airport_id: 2
|
||||
route: KAUS KJFK
|
||||
|
||||
flight_aircraft:
|
||||
- flight_id: 1
|
||||
aircraft_id: 1
|
||||
|
||||
@@ -61,8 +61,8 @@
|
||||
</table>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col-xs-12" style="text-align: right;">
|
||||
<div class="input-group input-group-lg">
|
||||
<div class="col-xs-12">
|
||||
<div class="input-group input-group-lg pull-right">
|
||||
{!! Form::open(['url' => '/admin/aircraft/'.$aircraft->id.'/fares',
|
||||
'method' => 'post',
|
||||
'class' => 'rm_fare form-inline'
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1 class="pull-left">{!! $aircraft->name !!}</h1></section>
|
||||
<h1 class="pull-left">{!! $aircraft->name !!}</h1>
|
||||
<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>
|
||||
</h1>
|
||||
</section>
|
||||
</h1>
|
||||
</section>
|
||||
<section class="content">
|
||||
<div class="clearfix"></div>
|
||||
<div class="row">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1 class="pull-left">$MODEL_NAME_PLURAL_HUMAN$</h1>
|
||||
<h1 class="pull-left">Airports</h1>
|
||||
<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>
|
||||
</h1>
|
||||
|
||||
51
resources/views/admin/flights/aircraft.blade.php
Normal file
51
resources/views/admin/flights/aircraft.blade.php
Normal file
@@ -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')
|
||||
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1>Flights</h1>
|
||||
</section>
|
||||
<div class="content">
|
||||
<div class="box box-primary">
|
||||
<div class="box-body">
|
||||
<div class="row" style="padding-left: 20px">
|
||||
@include('admin.flights.show_fields')
|
||||
<a href="{!! route('admin.flights.index') !!}" class="btn btn-default">Back</a>
|
||||
<section class="content-header">
|
||||
<h1 class="pull-left">{!! $flight->airline->code !!}{!! $flight->flight_number !!}</h1>
|
||||
<h1 class="pull-right">
|
||||
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px"
|
||||
href="{!! route('admin.flights.edit', $flight->id) !!}">Edit</a>
|
||||
</h1>
|
||||
</section>
|
||||
<section class="content">
|
||||
<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>
|
||||
</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
|
||||
|
||||
@@ -1,90 +1,81 @@
|
||||
<!-- Id Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('id', 'Id:') !!}
|
||||
<p>{!! $flight->id !!}</p>
|
||||
<div class="form-group col-sm-6">
|
||||
<div class="box box-solid">
|
||||
<div class="box-header with-border">
|
||||
{{--<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>
|
||||
|
||||
<!-- Airline Id Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('airline_id', 'Airline Id:') !!}
|
||||
<p>{!! $flight->airline_id !!}</p>
|
||||
<div class="form-group col-sm-6">
|
||||
<div class="box box-solid">
|
||||
<div class="box-header with-border">
|
||||
{{--<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>
|
||||
|
||||
<!-- 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">
|
||||
{!! Form::label('route_code', 'Route Code:') !!}
|
||||
<p>{!! $flight->route_code !!}</p>
|
||||
</div>
|
||||
<div class="form-group col-sm-12">
|
||||
<div class="box box-primary">
|
||||
<div class="box-body">
|
||||
<!-- Route Code Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('route_code', 'Route Code:') !!}
|
||||
{!! $flight->route_code !!}
|
||||
</div>
|
||||
|
||||
<!-- Route Leg Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('route_leg', 'Route Leg:') !!}
|
||||
<p>{!! $flight->route_leg !!}</p>
|
||||
</div>
|
||||
<!-- Route Leg Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('route_leg', 'Route Leg:') !!}
|
||||
{!! $flight->route_leg !!}
|
||||
</div>
|
||||
|
||||
<!-- Dpt Airport Id Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('dpt_airport_id', 'Dpt Airport Id:') !!}
|
||||
<p>{!! $flight->dpt_airport_id !!}</p>
|
||||
</div>
|
||||
<!-- Alt Airport Id Field -->
|
||||
@if($flight->alt_airport_id)
|
||||
<div class="form-group">
|
||||
{!! Form::label('alt_airport_id', 'Alt Airport Id:') !!}
|
||||
<p>{!! $flight->alt_airport->icao !!}</p>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<!-- Arr Airport Id Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('arr_airport_id', 'Arr Airport Id:') !!}
|
||||
<p>{!! $flight->arr_airport_id !!}</p>
|
||||
</div>
|
||||
<!-- Route Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('route', 'Route:') !!}
|
||||
<p>{!! $flight->route !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Alt Airport Id Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('alt_airport_id', 'Alt Airport Id:') !!}
|
||||
<p>{!! $flight->alt_airport_id !!}</p>
|
||||
</div>
|
||||
<!-- Dpt Time Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('dpt_time', 'Departure Time:') !!}
|
||||
{!! $flight->dpt_time !!}
|
||||
</div>
|
||||
|
||||
<!-- Route Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('route', 'Route:') !!}
|
||||
<p>{!! $flight->route !!}</p>
|
||||
</div>
|
||||
<!-- Arr Time Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('arr_time', 'Arrival Time:') !!}
|
||||
{!! $flight->arr_time !!}
|
||||
</div>
|
||||
|
||||
<!-- Dpt Time Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('dpt_time', 'Dpt Time:') !!}
|
||||
<p>{!! $flight->dpt_time !!}</p>
|
||||
</div>
|
||||
<!-- Notes Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('notes', 'Notes:') !!}
|
||||
<p>{!! $flight->notes !!}</p>
|
||||
</div>
|
||||
|
||||
<!-- Arr Time Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('arr_time', 'Arr Time:') !!}
|
||||
<p>{!! $flight->arr_time !!}</p>
|
||||
<!-- Active Field -->
|
||||
<div class="form-group">
|
||||
{!! Form::label('active', 'Active:') !!}
|
||||
<p>{!! $flight->active !!}</p>
|
||||
</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)
|
||||
<tr>
|
||||
<td>
|
||||
<a href="{!! route('admin.flights.show', [$flight->id]) !!}">
|
||||
{!! $flight->airline->code !!}{!! $flight->flight_number !!}
|
||||
@if($flight->route_code)
|
||||
(C: {!! $flight->route_code !!} L: {!! $flight->route_leg !!})
|
||||
@endif
|
||||
</a>
|
||||
</td>
|
||||
<td>{!! $flight->dpt_airport->icao !!}</td>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user