From 528a7c7440a2b6e78fd3421cfb4427e98f69bdc0 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sun, 31 Dec 2017 09:42:31 -0600 Subject: [PATCH] allow marking of airport as hub and restrict to hubs at registration #86 --- .../2017_06_11_135707_create_airports_table.php | 2 +- app/Database/seeds/dev.yml | 1 + app/Database/seeds/prod.yml | 1 + app/Database/seeds/sample.yml | 2 ++ app/Http/Controllers/Auth/RegisterController.php | 2 +- app/Repositories/AirportRepository.php | 10 ++++++++-- resources/views/admin/airports/fields.blade.php | 10 ++++++++-- resources/views/admin/airports/table.blade.php | 8 ++++++-- .../views/layouts/default/auth/register.blade.php | 2 +- 9 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/Database/migrations/2017_06_11_135707_create_airports_table.php b/app/Database/migrations/2017_06_11_135707_create_airports_table.php index df551639..1a53426e 100644 --- a/app/Database/migrations/2017_06_11_135707_create_airports_table.php +++ b/app/Database/migrations/2017_06_11_135707_create_airports_table.php @@ -15,7 +15,7 @@ class CreateAirportsTable extends Migration $table->string('location', 100)->nullable(); $table->string('country', 64)->nullable(); $table->string('tz', 64)->nullable(); - $table->boolean('hub')->default(true); + $table->boolean('hub')->default(false); $table->unsignedDecimal('fuel_100ll_cost', 19)->default(0); $table->unsignedDecimal('fuel_jeta_cost', 19)->default(0); $table->unsignedDecimal('fuel_mogas_cost', 19)->default(0); diff --git a/app/Database/seeds/dev.yml b/app/Database/seeds/dev.yml index 55836add..fab538a3 100644 --- a/app/Database/seeds/dev.yml +++ b/app/Database/seeds/dev.yml @@ -12,4 +12,5 @@ airports: country: United States lat: 30.1945278 lon: -97.6698889 + hub: 1 tz: America/Chicago diff --git a/app/Database/seeds/prod.yml b/app/Database/seeds/prod.yml index 55836add..fab538a3 100644 --- a/app/Database/seeds/prod.yml +++ b/app/Database/seeds/prod.yml @@ -12,4 +12,5 @@ airports: country: United States lat: 30.1945278 lon: -97.6698889 + hub: 1 tz: America/Chicago diff --git a/app/Database/seeds/sample.yml b/app/Database/seeds/sample.yml index df76b459..a1740c72 100644 --- a/app/Database/seeds/sample.yml +++ b/app/Database/seeds/sample.yml @@ -94,6 +94,7 @@ airports: country: United States lat: 30.1945278 lon: -97.6698889 + hub: 1 tz: America/Chicago - id: KJFK iata: JFK @@ -103,6 +104,7 @@ airports: country: United States lat: 40.6399257 lon: -73.7786950 + hub: 1 tz: America/New_York - id: KBWI iata: BWI diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 71ebd398..442cbbc7 100755 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -48,7 +48,7 @@ class RegisterController extends Controller public function showRegistrationForm() { - $airports = $this->airportRepo->selectBoxList(); + $airports = $this->airportRepo->selectBoxList(false, true); $airlines = $this->airlineRepo->selectBoxList(); return $this->view('auth.register', [ diff --git a/app/Repositories/AirportRepository.php b/app/Repositories/AirportRepository.php index e31a70b8..051e5444 100644 --- a/app/Repositories/AirportRepository.php +++ b/app/Repositories/AirportRepository.php @@ -25,10 +25,16 @@ class AirportRepository extends BaseRepository implements CacheableInterface * Return the list of airports formatted for a select box * @return array */ - public function selectBoxList($add_blank=false): array + public function selectBoxList($add_blank=false, $only_hubs=false): array { $retval = []; - $items = $this->orderBy('icao', 'asc')->all(); + $where = []; + + if($only_hubs) { + $where['hub'] = 1; + } + + $items = $this->orderBy('icao', 'asc')->findWhere($where); if ($add_blank) { $retval[''] = ''; diff --git a/resources/views/admin/airports/fields.blade.php b/resources/views/admin/airports/fields.blade.php index 15b67428..b46359cd 100644 --- a/resources/views/admin/airports/fields.blade.php +++ b/resources/views/admin/airports/fields.blade.php @@ -42,15 +42,21 @@
-
+
{!! Form::label('lat', 'Latitude:') !!} {!! Form::number('lat', null, ['class' => 'form-control', 'step' => '0.000001', 'rv-value' => 'airport.lat']) !!}
-
+
{!! Form::label('lon', 'Longitude:') !!} {!! Form::number('lon', null, ['class' => 'form-control', 'step' => '0.000001', 'rv-value' => 'airport.lon']) !!}
+ +
+ {!! Form::label('hub', 'Hub:') !!} + {!! Form::hidden('hub', 0) !!} + {!! Form::checkbox('hub', null) !!} +
diff --git a/resources/views/admin/airports/table.blade.php b/resources/views/admin/airports/table.blade.php index 0301af9b..4587cd55 100644 --- a/resources/views/admin/airports/table.blade.php +++ b/resources/views/admin/airports/table.blade.php @@ -4,7 +4,7 @@ ICAO Name Location - Timezone + Hub 100LL JetA MOGAS @@ -16,7 +16,11 @@ {!! $airport->icao !!} {!! $airport->name !!} {!! $airport->location !!} - {!! $airport->timezone !!} + + @if($airport->hub == 1) + Hub + @endif + {!! $airport->fuel_100ll_cost !!} diff --git a/resources/views/layouts/default/auth/register.blade.php b/resources/views/layouts/default/auth/register.blade.php index 63cc8a5c..d87c54d4 100644 --- a/resources/views/layouts/default/auth/register.blade.php +++ b/resources/views/layouts/default/auth/register.blade.php @@ -36,7 +36,7 @@
- {!! Form::select('home_airport_id', $airlines, null , ['class' => 'form-control select2']) !!} + {!! Form::select('home_airport_id', $airports, null , ['class' => 'form-control select2']) !!}
@if ($errors->has('home_airport_id'))

{{ $errors->first('home_airport_id') }}