From 7261bc52928ffce34dd286212923b71469bc69ff Mon Sep 17 00:00:00 2001 From: "B.Fatih KOZ" Date: Wed, 27 Sep 2023 23:00:19 +0300 Subject: [PATCH] Elevation and Region (#1618) * Elevation and Region Add elevation and region data to model, which is already being returned during lookup. Provide export/import for these new fields Implement sortable columns to admin airports table. * Improve import test (airport) * Update airports > show.blade.php Added elevation to the title --- ...9_26_190028_add_new_fields_to_airports.php | 17 ++++++++++ .../Controllers/Admin/AirportController.php | 4 +-- app/Models/Airport.php | 17 ++++++++-- app/Services/ImportExport/AirportImporter.php | 2 ++ .../views/admin/airports/fields.blade.php | 32 +++++++++---------- .../views/admin/airports/table.blade.php | 18 +++++++---- .../layouts/default/airports/show.blade.php | 11 ++++--- tests/ImporterTest.php | 5 +-- tests/data/airports.csv | 8 ++--- tests/data/airports_special_chars.csv | 20 ++++++------ 10 files changed, 86 insertions(+), 48 deletions(-) create mode 100644 app/Database/migrations/2023_09_26_190028_add_new_fields_to_airports.php diff --git a/app/Database/migrations/2023_09_26_190028_add_new_fields_to_airports.php b/app/Database/migrations/2023_09_26_190028_add_new_fields_to_airports.php new file mode 100644 index 000000000..c5841e21b --- /dev/null +++ b/app/Database/migrations/2023_09_26_190028_add_new_fields_to_airports.php @@ -0,0 +1,17 @@ +integer('elevation')->nullable()->after('lon'); + $table->string('region', 150)->nullable()->after('location'); + }); + } + } +}; diff --git a/app/Http/Controllers/Admin/AirportController.php b/app/Http/Controllers/Admin/AirportController.php index f11f204e8..81645d666 100644 --- a/app/Http/Controllers/Admin/AirportController.php +++ b/app/Http/Controllers/Admin/AirportController.php @@ -54,9 +54,7 @@ public function index(Request $request): View } $this->airportRepo->pushCriteria(new WhereCriteria($request, $where)); - $airports = $this->airportRepo - ->orderBy('icao', 'asc') - ->paginate(); + $airports = $this->airportRepo->sortable('icao')->paginate(); return view('admin.airports.index', [ 'airports' => $airports, diff --git a/app/Models/Airport.php b/app/Models/Airport.php index 06cd4dc2f..0c699223a 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -21,6 +21,7 @@ * @property string full_name * @property string description * @property string location + * @property string region * @property string country * @property string timezone * @property string notes @@ -30,6 +31,7 @@ * @property float fuel_mogas_cost * @property float lat * @property float lon + * @property int elevation */ class Airport extends Model { @@ -53,9 +55,11 @@ class Airport extends Model 'icao', 'name', 'location', + 'region', 'country', 'lat', 'lon', + 'elevation', 'hub', 'timezone', 'tz', @@ -84,8 +88,11 @@ class Airport extends Model 'iata' => 'sometimes|nullable', 'name' => 'required', 'location' => 'sometimes', + 'region' => 'sometimes', + 'country' => 'sometimes', 'lat' => 'required|numeric', 'lon' => 'required|numeric', + 'elevation' => 'nullable|numeric', 'ground_handling_cost' => 'nullable|numeric', 'fuel_100ll_cost' => 'nullable|numeric', 'fuel_jeta_cost' => 'nullable|numeric', @@ -97,7 +104,11 @@ class Airport extends Model 'iata', 'icao', 'name', + 'hub', + 'notes', + 'elevation', 'location', + 'region', 'country', ]; @@ -126,7 +137,7 @@ public function iata(): Attribute /** * Return full name like: - * KJFK/JFK - John F Kennedy + * KJFK - John F Kennedy * * @return string */ @@ -138,8 +149,8 @@ public function fullName(): Attribute } /** - * Return full name like: - * KJFK/JFK - John F Kennedy + * Return full description like: + * KJFK/JFK - John F Kennedy (hub) * * @return Attribute */ diff --git a/app/Services/ImportExport/AirportImporter.php b/app/Services/ImportExport/AirportImporter.php index a4e0afdf2..a786c5575 100644 --- a/app/Services/ImportExport/AirportImporter.php +++ b/app/Services/ImportExport/AirportImporter.php @@ -21,11 +21,13 @@ class AirportImporter extends ImportExport 'iata' => 'nullable', 'name' => 'required', 'location' => 'nullable', + 'region' => 'nullable', 'country' => 'nullable', 'timezone' => 'nullable', 'hub' => 'nullable|boolean', 'lat' => 'required|numeric', 'lon' => 'required|numeric', + 'elevation' => 'nullable|numeric', 'ground_handling_cost' => 'nullable|numeric', 'fuel_100ll_cost' => 'nullable|numeric', 'fuel_jeta_cost' => 'nullable|numeric', diff --git a/resources/views/admin/airports/fields.blade.php b/resources/views/admin/airports/fields.blade.php index 37591c044..3c0c4e517 100644 --- a/resources/views/admin/airports/fields.blade.php +++ b/resources/views/admin/airports/fields.blade.php @@ -10,13 +10,11 @@ ]) }}

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

-
{{ Form::label('iata', 'IATA:') }} {{ Form::text('iata', null, ['class' => 'form-control']) }}

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

-
@@ -25,35 +23,41 @@ {{ Form::text('name', null, ['class' => 'form-control']) }}

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

-
+
{{ Form::label('lat', 'Latitude:') }} * {{ Form::text('lat', null, ['class' => 'form-control', 'rv-value' => 'airport.lat']) }}

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

- -
+
{{ Form::label('lon', 'Longitude:') }} * {{ Form::text('lon', null, ['class' => 'form-control', 'rv-value' => 'airport.lon']) }}

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

+
+ {{ Form::label('elevation', 'Elevation:') }} + {{ Form::text('elevation', null, ['class' => 'form-control', 'rv-value' => 'airport.elevation']) }} +

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

+
- -
+
{{ Form::label('country', 'Country:') }} {{ Form::text('country', null, ['class' => 'form-control']) }}

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

- -
+
{{ Form::label('location', 'Location:') }} {{ Form::text('location', null, ['class' => 'form-control']) }}

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

- -
- {{ Form::label('timezone', 'Timezone:') }} +
+ {{ Form::label('region', 'Region:') }} + {{ Form::text('region', null, ['class' => 'form-control']) }} +

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

+
+
+ {{ Form::label('timezone', 'Timezone:') }}
{{ Form::select('timezone', $timezones, null, ['id' => 'timezone', 'class' => 'select2']) }}

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

@@ -64,7 +68,6 @@ {{ Form::label('ground_handling_cost', 'Ground Handling Cost:') }} {{ Form::number('ground_handling_cost', null, ['class' => 'form-control', 'step' => '0.01']) }}

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

- @component('admin.components.info') This is the base rate per-flight. A multiplier for this rate can be set in the subfleet, so you can modulate those costs from there. @@ -75,7 +78,6 @@ {{ Form::label('fuel_jeta_cost', 'Jet A Fuel Cost:') }} {{ Form::number('fuel_jeta_cost', null, ['class' => 'form-control', 'step' => '0.01']) }}

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

- @component('admin.components.info') This is the cost per {{ config('phpvms.internal_units.fuel') }} @endcomponent @@ -85,7 +87,6 @@ {{ Form::label('fuel_100ll_cost', '100LL Fuel Cost:') }} {{ Form::number('fuel_100ll_cost', null, ['class' => 'form-control', 'step' => '0.01']) }}

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

- @component('admin.components.info') This is the cost per {{ config('phpvms.internal_units.fuel') }} @endcomponent @@ -95,7 +96,6 @@ {{ Form::label('fuel_mogas_cost', 'MOGAS Fuel Cost:') }} {{ Form::number('fuel_mogas_cost', null, ['class' => 'form-control', 'step' => '0.01']) }}

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

- @component('admin.components.info') This is the cost per {{ config('phpvms.internal_units.fuel') }} @endcomponent diff --git a/resources/views/admin/airports/table.blade.php b/resources/views/admin/airports/table.blade.php index 4f289fdef..bc1af21ef 100644 --- a/resources/views/admin/airports/table.blade.php +++ b/resources/views/admin/airports/table.blade.php @@ -1,12 +1,15 @@
- - - - - - + + + + + + + + + @@ -20,6 +23,9 @@ + + +
ICAOIATANameLocationHubNotes@sortablelink('icao', 'ICAO')@sortablelink('iata', 'IATA')@sortablelink('name', 'Name')@sortablelink('location', 'Location')@sortablelink('region', 'Region')@sortablelink('country', 'Country')@sortablelink('elevation', 'Elevation')@sortablelink('hub', 'Hub')@sortablelink('notes', 'Notes') GH Cost JetA 100LL{{ $airport->iata }} {{ $airport->name }} {{ $airport->location }}{{ $airport->region }}{{ $airport->country }}{{ $airport->elevation }} @if($airport->hub === true) Hub diff --git a/resources/views/layouts/default/airports/show.blade.php b/resources/views/layouts/default/airports/show.blade.php index b5efcffbe..1a36f4d7a 100644 --- a/resources/views/layouts/default/airports/show.blade.php +++ b/resources/views/layouts/default/airports/show.blade.php @@ -4,14 +4,17 @@ @section('content')
-

{{ $airport->full_name }}

+

+ {{ $airport->full_name }} + @if(filled($airport->elevation)) + {{'| '.$airport->elevation.'ft'}} + @endif +

{{-- Show the weather widget in one column --}}
- {{ Widget::Weather([ - 'icao' => $airport->icao, - ]) }} + {{ Widget::Weather(['icao' => $airport->icao]) }}
{{-- Show the airspace map in the other column --}} diff --git a/tests/ImporterTest.php b/tests/ImporterTest.php index 506a03747..34b99dccf 100644 --- a/tests/ImporterTest.php +++ b/tests/ImporterTest.php @@ -664,8 +664,9 @@ public function testAirportImporter(): void $this->assertEquals('AUS', $airport->iata); $this->assertEquals('KAUS', $airport->icao); $this->assertEquals('Austin-Bergstrom', $airport->name); - $this->assertEquals('Austin, Texas, USA', $airport->location); - $this->assertEquals('United States', $airport->country); + $this->assertEquals('Austin', $airport->location); + $this->assertEquals('Texas', $airport->region); + $this->assertEquals('US', $airport->country); $this->assertEquals('America/Chicago', $airport->timezone); $this->assertEquals(true, $airport->hub); $this->assertEquals('30.1945', $airport->lat); diff --git a/tests/data/airports.csv b/tests/data/airports.csv index 94633aa7d..b9f697aaa 100644 --- a/tests/data/airports.csv +++ b/tests/data/airports.csv @@ -1,4 +1,4 @@ -icao,iata,name,location,country,timezone,hub,lat,lon,ground_handling_cost,fuel_100ll_cost,fuel_jeta_cost,fuel_mogas_cost,notes -KAUS,AUS,Austin-Bergstrom,"Austin, Texas, USA", United States,America/Chicago,1,30.1945,-97.6699,0,,,,"Test Note" -KSFO,SFO,San Francisco,"San Francisco, California, USA", United States,America/California,1,30.1945,-97.6699,,,0.9,, -KJFK,JFK,Kennedy,"Queens, New York, USA", United States,America/New_York,0,30.1945,abcd,150,,0.8,,"Busy Airport" +icao,iata,name,location,region,country,timezone,hub,lat,lon,elevation,ground_handling_cost,fuel_100ll_cost,fuel_jeta_cost,fuel_mogas_cost,notes +KAUS,AUS,Austin-Bergstrom,"Austin","Texas",US,America/Chicago,1,30.1945,-97.6699,148,0,,,,"Test Note" +KSFO,SFO,San Francisco,"San Francisco","California",US,America/California,1,30.1945,-97.6699,,,,0.9,, +KJFK,JFK,Kennedy,"Queens","New York",US,America/New_York,0,30.1945,abcd,58,150,,0.8,,"Busy Airport" diff --git a/tests/data/airports_special_chars.csv b/tests/data/airports_special_chars.csv index c6ae0f0b8..adf493787 100755 --- a/tests/data/airports_special_chars.csv +++ b/tests/data/airports_special_chars.csv @@ -1,10 +1,10 @@ -icao,iata,name,location,country,timezone,hub,lat,lon,ground_handling_cost,fuel_100ll_cost,fuel_jeta_cost,fuel_mogas_cost,notes -EGLL,LHR,"London Heathrow","London, England",,Europe/London,,51.4775,-0.4614,500,0,0,0, -KAUS,AUS,Austin-Bergstrom,"Austin, Texas, USA","United States",America/Chicago,1,30.1945,-97.6699,0,0,0,0,"Test Note" -KJFK,JFK,"John F Kennedy","New York, New York, USA","United States",America/New_York,1,40.6399,-73.7787,250,0,0,0,"Busy Airport" -KPAE,PAE,"Snohomish County (Paine Field) Airport",Everett,"United States",America/Los_Angeles,,47.9063,-122.282,0,0,0,0, -KSEA,SEA,"Seattle Tacoma International Airport",Seattle,"United States",America/Los_Angeles,,47.449,-122.309,0,0,0,0, -LEMD,MAD,"Adolfo Suárez Madrid–Barajas Airport",Madrid,Spain,Europe/Madrid,,40.4719,-3.5626,,0,0,0, -MKJP,KIN,"Norman Manley International Airport","Kingston, Jamaica",,America/Jamaica,,17.9357,-76.7875,50,0,0,0, -MWCR,GCM,"Owen Roberts International Airport",Georgetown,Cayman,America/Cayman,,19.2928,-81.3577,50,0,0,0, -OMDB,DXB,"Dubai International Airport","Dubai, UAE",,Asia/Dubai,,25.2528,55.3644,50,0,0,0, +icao,iata,name,location,region,country,timezone,hub,lat,lon,elevation,ground_handling_cost,fuel_100ll_cost,fuel_jeta_cost,fuel_mogas_cost,notes +EGLL,LHR,"London Heathrow","London, England",,,Europe/London,,51.4775,-0.4614,-156,500,0,0,0, +KAUS,AUS,Austin-Bergstrom,"Austin, Texas, USA","Texas","United States",America/Chicago,1,30.1945,-97.6699,,0,0,0,0,"Test Note" +KJFK,JFK,"John F Kennedy","New York, New York, USA","New York","United States",America/New_York,1,40.6399,-73.7787,,250,0,0,0,"Busy Airport" +KPAE,PAE,"Snohomish County (Paine Field) Airport",Everett,,"United States",America/Los_Angeles,,47.9063,-122.282,,0,0,0,0, +KSEA,SEA,"Seattle Tacoma International Airport",Seattle,,"United States",America/Los_Angeles,,47.449,-122.309,,0,0,0,0, +LEMD,MAD,"Adolfo Suárez Madrid–Barajas Airport",Madrid,,Spain,Europe/Madrid,,40.4719,-3.5626,,,0,0,0, +MKJP,KIN,"Norman Manley International Airport","Kingston, Jamaica",,,America/Jamaica,,17.9357,-76.7875,98,50,0,0,0, +MWCR,GCM,"Owen Roberts International Airport",Georgetown,,Cayman,America/Cayman,,19.2928,-81.3577,459,50,0,0,0, +OMDB,DXB,"Dubai International Airport","Dubai, UAE",,,Asia/Dubai,,25.2528,55.3644,,50,0,0,0,