Cleaned up select box stuff, moved to repositories
This commit is contained in:
@@ -18,6 +18,11 @@ use Response;
|
||||
|
||||
class FlightController extends BaseController
|
||||
{
|
||||
private $airlineRepo,
|
||||
$airportRepo,
|
||||
$flightRepo,
|
||||
$subfleetRepo;
|
||||
|
||||
public function __construct(
|
||||
AirlineRepository $airlineRepo,
|
||||
AirportRepository $airportRepo,
|
||||
@@ -46,10 +51,9 @@ class FlightController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the Flight.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
* @throws \Prettus\Repository\Exceptions\RepositoryException
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
@@ -67,15 +71,17 @@ class FlightController extends BaseController
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('admin.flights.create');
|
||||
return view('admin.flights.create', [
|
||||
'flight' => null,
|
||||
'airlines' => $this->airlineRepo->selectBoxList(),
|
||||
'airports' => $this->airportRepo->selectBoxList(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created Flight in storage.
|
||||
*
|
||||
* @param CreateFlightRequest $request
|
||||
*
|
||||
* @return Response
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*/
|
||||
public function store(CreateFlightRequest $request)
|
||||
{
|
||||
@@ -84,15 +90,12 @@ class FlightController extends BaseController
|
||||
$flight = $this->flightRepo->create($input);
|
||||
|
||||
Flash::success('Flight saved successfully.');
|
||||
return redirect(route('admin.flights.index'));
|
||||
return redirect(route('admin.flights.edit', $flight->id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified Flight.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Response
|
||||
* @param $id
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
@@ -111,11 +114,8 @@ class FlightController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified Flight.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Response
|
||||
* @param $id
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
@@ -129,19 +129,17 @@ class FlightController extends BaseController
|
||||
$avail_subfleets = $this->getAvailSubfleets($flight);
|
||||
return view('admin.flights.edit', [
|
||||
'flight' => $flight,
|
||||
'airlines' => $this->airlineRepo->all()->pluck('name', 'id'),
|
||||
'airports' => $this->airportRepo->all()->pluck('icao', 'icao'),
|
||||
'airlines' => $this->airlineRepo->selectBoxList(),
|
||||
'airports' => $this->airportRepo->selectBoxList(),
|
||||
'avail_subfleets' => $avail_subfleets,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified Flight in storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param $id
|
||||
* @param UpdateFlightRequest $request
|
||||
*
|
||||
* @return Response
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*/
|
||||
public function update($id, UpdateFlightRequest $request)
|
||||
{
|
||||
@@ -159,11 +157,8 @@ class FlightController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified Flight from storage.
|
||||
*
|
||||
* @param int $id
|
||||
*
|
||||
* @return Response
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
@@ -180,6 +175,10 @@ class FlightController extends BaseController
|
||||
return redirect(route('admin.flights.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $flight
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
protected function return_fields_view($flight)
|
||||
{
|
||||
$flight->refresh();
|
||||
@@ -188,6 +187,10 @@ class FlightController extends BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function fields(Request $request)
|
||||
{
|
||||
$id = $request->id;
|
||||
@@ -222,6 +225,10 @@ class FlightController extends BaseController
|
||||
return $this->return_fields_view($flight);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $flight
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
protected function return_subfleet_view($flight)
|
||||
{
|
||||
$avail_subfleets = $this->getAvailSubfleets($flight);
|
||||
@@ -231,6 +238,10 @@ class FlightController extends BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
public function subfleets(Request $request)
|
||||
{
|
||||
$id = $request->id;
|
||||
|
||||
@@ -18,6 +18,12 @@ use App\Repositories\PirepFieldRepository;
|
||||
|
||||
class PirepController extends Controller
|
||||
{
|
||||
private $airlineRepo,
|
||||
$aircraftRepo,
|
||||
$pirepRepo,
|
||||
$airportRepo,
|
||||
$pirepFieldRepo;
|
||||
|
||||
public function __construct(
|
||||
AirlineRepository $airlineRepo,
|
||||
PirepRepository $pirepRepo,
|
||||
@@ -33,30 +39,6 @@ class PirepController extends Controller
|
||||
$this->pirepFieldRepo = $pirepFieldRepo;
|
||||
}
|
||||
|
||||
public function airportList()
|
||||
{
|
||||
# TODO: Cache
|
||||
$retval = [];
|
||||
$airports = $this->airportRepo->all();
|
||||
foreach($airports as $airport) {
|
||||
$retval[$airport->icao] = $airport->icao.' - '.$airport->name;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
public function aircraftList()
|
||||
{
|
||||
$retval = [];
|
||||
$aircraft = $this->aircraftRepo->all();
|
||||
|
||||
foreach ($aircraft as $ac) {
|
||||
$retval[$ac->id] = $ac->subfleet->name.' - '.$ac->name.' ('.$ac->registration.')';
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
@@ -74,12 +56,11 @@ class PirepController extends Controller
|
||||
public function create()
|
||||
{
|
||||
$aircraft = $this->aircraftList();
|
||||
$airports = $this->airportList();
|
||||
|
||||
return $this->view('pireps.create', [
|
||||
'airports' => $airports,
|
||||
'airports' => $this->airportRepo->selectBoxList(),
|
||||
'airlines' => $this->airlineRepo->all()->pluck('name', 'id'),
|
||||
'aircraft' => $aircraft,
|
||||
'aircraft' => $this->aircraftRepo->selectBoxList(),
|
||||
'pirepfields' => $this->pirepFieldRepo->all(),
|
||||
'fieldvalues' => [],
|
||||
]);
|
||||
|
||||
@@ -20,4 +20,20 @@ class AircraftRepository extends BaseRepository implements CacheableInterface
|
||||
{
|
||||
return Aircraft::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of aircraft formatted for a select box
|
||||
* @return array
|
||||
*/
|
||||
public function selectBoxList()
|
||||
{
|
||||
$retval = [];
|
||||
$items = $this->all();
|
||||
|
||||
foreach ($items as $i) {
|
||||
$retval[$i->id] = $i->subfleet->name . ' - ' . $i->name . ' (' . $i->registration . ')';
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,20 @@ class AirlineRepository extends BaseRepository implements CacheableInterface
|
||||
{
|
||||
return Airline::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of airline formatted for a select box
|
||||
* @return array
|
||||
*/
|
||||
public function selectBoxList()
|
||||
{
|
||||
$retval = [];
|
||||
$items = $this->all();
|
||||
|
||||
foreach ($items as $i) {
|
||||
$retval[$i->id] = $i->name;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,4 +20,19 @@ class AirportRepository extends BaseRepository implements CacheableInterface
|
||||
{
|
||||
return Airport::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of airports formatted for a select box
|
||||
* @return array
|
||||
*/
|
||||
public function selectBoxList()
|
||||
{
|
||||
$retval = [];
|
||||
$items = $this->all();
|
||||
foreach ($items as $i) {
|
||||
$retval[$i->icao] = $i->icao . ' - ' . $i->name;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,12 @@
|
||||
@extends('admin.app')
|
||||
|
||||
@section('title', 'Edit Flight')
|
||||
@section('content')
|
||||
<section class="content-header">
|
||||
<h1>Create Flight</h1>
|
||||
</section>
|
||||
<div class="content">
|
||||
<div class="card border-blue-bottom">
|
||||
@include('adminlte-templates::common.errors')
|
||||
<div class="box box-primary">
|
||||
|
||||
<div class="box-body">
|
||||
<div class="row">
|
||||
{!! Form::open(['route' => 'admin.flights.store']) !!}
|
||||
|
||||
@include('admin.flights.fields')
|
||||
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
{!! Form::model($flight, ['route' => ['admin.flights.store']]) !!}
|
||||
@include('admin.flights.fields')
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
<!-- Active Field -->
|
||||
<div class="form-group col-sm-2">
|
||||
{!! Form::label('active', 'Active:') !!}
|
||||
{!! Form::checkbox('active', $flight->active, ['class' => 'form-control icheck']) !!}
|
||||
@if($flight!==null)
|
||||
{!! Form::checkbox('active', $flight->active, ['class' => 'form-control icheck']) !!}
|
||||
@else
|
||||
{!! Form::checkbox('active', null, ['class' => 'form-control icheck']) !!}
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user