cleaned searching for flights, specific fields in admin

This commit is contained in:
Nabeel Shahzad 2017-12-04 12:05:31 -06:00
parent e032fd2dbf
commit 8d4f1efd52
5 changed files with 43 additions and 13 deletions

View File

@ -11,6 +11,7 @@ use App\Repositories\AirlineRepository;
use App\Repositories\AirportRepository;
use App\Repositories\FlightRepository;
use App\Repositories\SubfleetRepository;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
@ -57,10 +58,11 @@ class FlightController extends BaseController
*/
public function index(Request $request)
{
$this->flightRepo->pushCriteria(new RequestCriteria($request));
$flights = $this->flightRepo->paginate(10);
$flights = $this->flightRepo->searchCriteria($request)->paginate();
return view('admin.flights.index', [
'flights' => $flights,
'airlines' => $this->airlineRepo->selectBoxList(true),
'airports' => $this->airportRepo->selectBoxList(true),
]);
}

View File

@ -25,11 +25,15 @@ class AirlineRepository extends BaseRepository implements CacheableInterface
* Return the list of airline formatted for a select box
* @return array
*/
public function selectBoxList(): array
public function selectBoxList($add_blank=false): array
{
$retval = [];
$items = $this->all();
if($add_blank) {
$retval[] = '';
}
foreach ($items as $i) {
$retval[$i->id] = $i->name;
}

View File

@ -25,10 +25,15 @@ class AirportRepository extends BaseRepository implements CacheableInterface
* Return the list of airports formatted for a select box
* @return array
*/
public function selectBoxList(): array
public function selectBoxList($add_blank=false): array
{
$retval = [];
$items = $this->all();
if ($add_blank) {
$retval[''] = '';
}
foreach ($items as $i) {
$retval[$i->icao] = $i->icao . ' - ' . $i->name;
}

View File

@ -4,6 +4,7 @@ namespace App\Repositories;
use App\Models\Flight;
use App\Repositories\Criteria\WhereCriteria;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use Prettus\Repository\Contracts\CacheableInterface;
use Prettus\Repository\Traits\CacheableRepository;
@ -27,7 +28,7 @@ class FlightRepository extends BaseRepository implements CacheableInterface
/**
* Create the search criteria and return this with the stuff pushed
* @param Request $request
* @param FormRequest $request
* @param bool $only_active
* @return $this
* @throws \Prettus\Repository\Exceptions\RepositoryException
@ -38,16 +39,24 @@ class FlightRepository extends BaseRepository implements CacheableInterface
'active' => $only_active,
];
if ($request->airline) {
$where['airline_id'] = $request->airline;
if ($request->filled('airline_id')) {
$where['airline_id'] = $request->airline_id;
}
if ($request->depICAO) {
$where['dpt_airport_id'] = $request->depICAO;
if($request->filled('flight_number')) {
$where['flight_number'] = $request->flight_number;
}
if ($request->arrICAO) {
$where['dpt_airport_id'] = $request->arrICAO;
if ($request->filled('route_code')) {
$where['route_code'] = $request->route_code;
}
if ($request->filled('dep_icao')) {
$where['dpt_airport_id'] = $request->dep_icao;
}
if ($request->filled('arr_icao')) {
$where['arr_airport_id'] = $request->arr_icao;
}
$this->pushCriteria(new WhereCriteria($request, $where));

View File

@ -3,9 +3,19 @@
<div class="col-sm-12">
<div class="form-group">
{!! Form::open(['route' => 'admin.flights.index', 'method' => 'GET', 'class'=>'form-inline pull-right']) !!}
{!! Form::label('search', 'search:') !!}
{!! Form::text('search', null, ['class' => 'form-control']) !!}
{!! Form::label('flight_number', 'Flight Number:') !!}
{!! Form::text('flight_number', null, ['class' => 'form-control']) !!}
&nbsp;
{!! Form::label('dep_icao', 'Departure:') !!}
{!! Form::select('dep_icao', $airports, null , ['class' => 'form-control']) !!}
&nbsp;
{!! Form::label('arr_icao', 'Arrival:') !!}
{!! Form::select('arr_icao', $airports, null , ['class' => 'form-control']) !!}
&nbsp;
{!! Form::submit('find', ['class' => 'btn btn-primary']) !!}
&nbsp;
<a href="{!! route('admin.flights.index') !!}">clear</a>
{!! Form::close() !!}
</div>
</div>