Airport lookup from vaCentral API; changes to Airports tables

This commit is contained in:
Nabeel Shahzad
2017-12-07 17:22:15 -06:00
parent ec8b2e8242
commit ddb8a6f5e9
19 changed files with 429 additions and 65 deletions

17
.gitignore vendored
View File

@@ -30,8 +30,6 @@ tmp/
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
@@ -39,12 +37,23 @@ tmp/
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/gradle.xml
.idea/**/libraries
cmake-build-debug/
.idea/**/mongoSettings.xml
*.iws
out/
.idea_modules/
atlassian-ide-plugin.xml
.idea/replstate.xml
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
phpvms_next.iml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
public/info.php
local.conf.php

View File

@@ -10,13 +10,13 @@ all: install
.PHONY: clean
clean:
@find bootstrap/cache -type f -not -name '.gitignore' -print0 | xargs -0 -r rm --
@find storage/app/public -type f -not -name '.gitignore' -print0 | xargs -0 -r rm --
@find storage/app -type f -not -name '.gitignore' -not -name public -print0 | xargs -0 -r rm --
@find storage/framework/cache -type f -not -name '.gitignore' -print0 | xargs -0 -r rm --
@find storage/framework/sessions -type f -not -name '.gitignore' -print0 | xargs -0 -r rm --
@find storage/framework/views -type f -not -name '.gitignore' -print0 | xargs -0 -r rm --
@find storage/logs -type f -not -name '.gitignore' -print0 | xargs -0 -r rm --
@find bootstrap/cache -type f -not -name '.gitignore' -print0 -delete
@find storage/app/public -type f -not -name '.gitignore' -print0 -delete
@find storage/app -type f -not -name '.gitignore' -not -name public -print0 -delete
@find storage/framework/cache -type f -not -name '.gitignore' -print0 -delete
@find storage/framework/sessions -type f -not -name '.gitignore' -print0 -delete
@find storage/framework/views -type f -not -name '.gitignore' -print0 -delete
@find storage/logs -type f -not -name '.gitignore' -print0 -delete
@php artisan route:clear
@php artisan config:clear
@@ -32,7 +32,7 @@ install: build
@echo "Done!"
.PHONY: update
update: clean build
update: build
@php artisan migrate
@echo "Done!"
@@ -40,7 +40,7 @@ update: clean build
reset: clean
@php artisan database:create --reset
@php artisan migrate:refresh --seed
@make install
@make update
.PHONY: tests
tests: test

View File

@@ -27,6 +27,7 @@ class AirportController extends BaseController
*
* @param Request $request
* @return Response
* @throws \Prettus\Repository\Exceptions\RepositoryException
*/
public function index(Request $request)
{
@@ -46,13 +47,16 @@ class AirportController extends BaseController
*/
public function create()
{
return view('admin.airports.create');
return view('admin.airports.create', [
'timezones' => Timezonelist::toArray(),
]);
}
/**
* Store a newly created Airport in storage.
* @param CreateAirportRequest $request
* @return Response
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function store(CreateAirportRequest $request)
{
@@ -104,9 +108,10 @@ class AirportController extends BaseController
/**
* Update the specified Airport in storage.
* @param int $id
* @param int $id
* @param UpdateAirportRequest $request
* @return Response
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function update($id, UpdateAirportRequest $request)
{

View File

@@ -23,7 +23,7 @@ class DashboardController extends BaseController
/*Feed::$cacheDir = storage_path('app');
Feed::$cacheExpire = '5 hours';
$feed = Feed::loadRss(config('phpvms.feed_url'));*/
$feed = Feed::loadRss(config('phpvms.news_feed_url'));*/
$feed = [];
return view('admin.dashboard.index', [
'feed' => $feed,

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Controllers\Api;
use App\Repositories\AirportRepository;
use App\Http\Controllers\AppBaseController;
use App\Http\Resources\Airport as AirportResource;
use VaCentral\Airport as AirportLookup;
class AirportController extends AppBaseController
{
protected $airportRepo;
public function __construct(
AirportRepository $airportRepo
) {
$this->airportRepo = $airportRepo;
}
/**
* Do a lookup, via vaCentral, for the airport information
* @param $id
* @return AirportResource
*/
public function lookup($id)
{
$airport = AirportLookup::get($id);
return new AirportResource(collect($airport));
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\Resource;
class Airport extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return parent::toArray($request);
}
}

View File

@@ -15,9 +15,14 @@ class AppServiceProvider extends ServiceProvider
{
Schema::defaultStringLength(191);
//\VaCentral\VaCentral::setVaCentralUrl(config('phpvms.vacentral_api_url'));
if(!empty(config('phpvms.vacentral_api_key'))) {
\VaCentral\VaCentral::setApiKey(config('phpvms.vacentral_api_key'));
}
# if there's a local.conf.php in the root, then merge that in
if(file_exists(base_path('local.conf.php'))) {
$local_conf = include(base_path('local.conf.php'));
$local_conf = include base_path('local.conf.php');
$config = $this->app['config']->get('phpvms', []);
$this->app['config']->set(
'phpvms',

View File

@@ -5,7 +5,7 @@
"keywords": ["phpvms", "virtual", "airlines"],
"license": "MIT",
"type": "project",
"minimum-stability": "stable",
"prefer-stable": true,
"url": "https://github.com/nabeelio/phpvms.git",
"require": {
"php": ">=7.0",
@@ -45,11 +45,12 @@
"scriptfusion/phpunit-immediate-exception-printer": "1.3.0",
"nwidart/laravel-modules": "2.6.0",
"sebastiaanluca/laravel-helpers": "1.0.2",
"nabeel/laravel-installer": "dev-master",
"tivie/php-os-detector": "1.1.0",
"jackiedo/timezonelist": "^5.0",
"nesbot/carbon": "^1.22",
"tremby/laravel-git-version": "^1.1"
"tremby/laravel-git-version": "^1.1",
"nabeel/laravel-installer": "dev-master",
"nabeel/vacentral": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "6.4.0",

224
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "2f361a73a9d21108cf1e05a2bbfb1626",
"content-hash": "459233f5328b1d32bc905cdf05d8b523",
"packages": [
{
"name": "anlutro/l4-settings",
@@ -985,6 +985,187 @@
],
"time": "2017-11-14T20:44:03+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.3.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699",
"reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.4",
"php": ">=5.5"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^4.0 || ^5.0",
"psr/log": "^1.0"
},
"suggest": {
"psr/log": "Required for using the Log middleware"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "6.2-dev"
}
},
"autoload": {
"files": [
"src/functions_include.php"
],
"psr-4": {
"GuzzleHttp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle is a PHP HTTP client library",
"homepage": "http://guzzlephp.org/",
"keywords": [
"client",
"curl",
"framework",
"http",
"http client",
"rest",
"web service"
],
"time": "2017-06-22T18:50:49+00:00"
},
{
"name": "guzzlehttp/promises",
"version": "v1.3.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/promises.git",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646",
"shasum": ""
},
"require": {
"php": ">=5.5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Promise\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "Guzzle promises library",
"keywords": [
"promise"
],
"time": "2016-12-20T10:07:11+00:00"
},
{
"name": "guzzlehttp/psr7",
"version": "1.4.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"request",
"response",
"stream",
"uri",
"url"
],
"time": "2017-03-20T17:10:46+00:00"
},
{
"name": "hashids/hashids",
"version": "2.0.4",
@@ -2126,6 +2307,42 @@
"description": "Laravel web installer",
"time": "2017-12-04T19:05:57+00:00"
},
{
"name": "nabeel/vacentral",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/nabeelio/vacentral-library.git",
"reference": "79093ce128b791755a787a420d344b8adb05e8a4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nabeelio/vacentral-library/zipball/79093ce128b791755a787a420d344b8adb05e8a4",
"reference": "79093ce128b791755a787a420d344b8adb05e8a4",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "6.3.0",
"php": ">= 7.0.0",
"symfony/lts": "v3"
},
"require-dev": {
"doctrine/instantiator": "v1.0.5",
"phpunit/phpunit": "5.7.25",
"phpunit/phpunit-mock-objects": "3.4.4"
},
"type": "library",
"autoload": {
"psr-4": {
"VaCentral\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"time": "2017-12-07T20:57:37+00:00"
},
{
"name": "nesbot/carbon",
"version": "1.22.1",
@@ -7172,9 +7389,10 @@
"infyomlabs/adminlte-templates": 20,
"zizaco/entrust": 20,
"makinacorpus/php-bloom": 20,
"nabeel/laravel-installer": 20
"nabeel/laravel-installer": 20,
"nabeel/vacentral": 20
},
"prefer-stable": false,
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": ">=7.0"

View File

@@ -63,7 +63,7 @@ return [
SebastiaanLuca\Helpers\Methods\GlobalHelpersServiceProvider::class,
SebastiaanLuca\Helpers\Collections\CollectionMacrosServiceProvider::class,
Toin0u\Geotools\GeotoolsServiceProvider::class,
//Jackiedo\Timezonelist\TimezonelistServiceProvider::class,
Jackiedo\Timezonelist\TimezonelistServiceProvider::class,
/*
* Application Service Providers...

View File

@@ -35,8 +35,18 @@ return [
*/
'only_flights_from_current' => false,
/**
* Your vaCentral API key
*/
'vacentral_api_key' => '',
/**
* vaCentral API URL. You likely don't need to change this
*/
'vacentral_api_url' => 'https://api.vacentral.net',
/**
* Misc Settings
*/
'feed_url' => 'http://forum.phpvms.net/rss/1-announcements-feed.xml/?',
'news_feed_url' => 'http://forum.phpvms.net/rss/1-announcements-feed.xml/?',
];

View File

@@ -21,7 +21,7 @@ class CreateAirportsTable extends Migration
$table->string('name', 100);
$table->string('location', 100)->nullable();
$table->string('country', 48)->nullable();
$table->string('timezone', 64)->nullable();
$table->string('tz', 64)->nullable();
$table->double('fuel_100ll_cost', 19, 2)->default(0);
$table->double('fuel_jeta_cost', 19, 2)->default(0);
$table->double('fuel_mogas_cost', 19, 2)->default(0);

View File

@@ -95,7 +95,7 @@ airports:
location: Austin, Texas, USA
lat: 30.1945278
lon: -97.6698889
timezone: America/Chicago
tz: America/Chicago
- id: KJFK
iata: JFK
icao: KJFK
@@ -103,7 +103,7 @@ airports:
location: New York, New York, USA
lat: 40.6399257
lon: -73.7786950
timezone: America/New_York
tz: America/New_York
- id: EGLL
iata: LHR
icao: EGLL
@@ -111,7 +111,7 @@ airports:
location: London, England
lat: 51.4775
lon: -0.4614
timezone: Europe/London
tz: Europe/London
#
aircraft:

View File

@@ -2,7 +2,18 @@
* admin functions, mostly map/mapping related
*/
function phpvms_render_airspace_map(opts) {
function phpvms_vacentral_airport_lookup(icao, callback)
{
$.ajax({
url: '/api/airports/' + icao + '/lookup',
method: 'GET'
}).done(function (data, status) {
callback(data.data);
});
}
function phpvms_render_airspace_map(opts)
{
opts = __parse_opts(opts);
var map = __draw_base_map(opts);
if(opts.set_marker == true) { L.marker(coords).addTo(map); }
@@ -13,7 +24,7 @@ function __parse_opts(opts) {
_.defaults(opts, {
render_elem: 'map',
overlay_elem: '',
lat: 0,
lat: 0,
lon: 0,
zoom: 12,
layers: [],
@@ -24,7 +35,7 @@ function __parse_opts(opts) {
}
function __draw_base_map(opts) {
var coords = [opts.lat, opts.lon];
/*var openaip_airspace_labels = new L.TileLayer.WMS(

View File

@@ -1,12 +1,13 @@
@extends('admin.app')
@section('title', "Add Airport")
@section('title', 'Add Airport')
@section('content')
<div class="card border-blue-bottom">
<div class="content">
@include('adminlte-templates::common.errors')
{!! Form::open(['route' => 'admin.airports.store']) !!}
{!! Form::open(['route' => 'admin.airports.store', 'id' => 'airportForm']) !!}
@include('admin.airports.fields')
{!! Form::close() !!}
</div>
</div>
@endsection
@include('admin.airports.script')

View File

@@ -4,9 +4,10 @@
<div class="card border-blue-bottom">
<div class="content">
@include('adminlte-templates::common.errors')
{!! Form::model($airport, ['route' => ['admin.airports.update', $airport->id], 'method' => 'patch']) !!}
{!! Form::model($airport, ['route' => ['admin.airports.update', $airport->id], 'method' => 'patch', 'id' => 'airportForm']) !!}
@include('admin.airports.fields')
{!! Form::close() !!}
</div>
</div>
@endsection
@include('admin.airports.script')

View File

@@ -1,40 +1,66 @@
<div class="row">
<!-- Icao Field -->
<div class="form-group col-sm-6">
{!! Form::label('icao', 'ICAO:') !!}
{!! Form::text('icao', null, ['class' => 'form-control']) !!}
</div>
<div class="col-lg-12">
<!-- Icao Field -->
<div class="row">
<div class="form-group col-sm-6">
{!! Form::label('icao', 'ICAO:') !!}
<a href="#" class="airport_data_lookup">Lookup</a>
{!! Form::text('icao', null, [
'id' => 'airport_icao', 'class' => 'form-control',
'rv-value' => 'airport.icao'
]) !!}
</div>
<div class="form-group col-sm-6">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group col-sm-6">
{!! Form::label('iata', 'IATA:') !!}
{!! Form::text('iata', null, ['class' => 'form-control', 'rv-value' => 'airport.iata']) !!}
</div>
</div>
<div class="form-group col-sm-6">
{!! Form::label('location', 'Location:') !!}
{!! Form::text('location', null, ['class' => 'form-control']) !!}
</div>
<div class="row">
<div class="form-group col-sm-6">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control', 'rv-value' => 'airport.name']) !!}
</div>
<div class="form-group col-sm-6">
{!! Form::label('lat', 'Latitude:') !!}
{!! Form::number('lat', null, ['class' => 'form-control', 'step' => '0.000001']) !!}
</div>
<div class="form-group col-sm-6">
{!! Form::label('location', 'Location:') !!}
{!! Form::text('location', null, ['class' => 'form-control', 'rv-value' => 'airport.city']) !!}
</div>
</div>
<div class="form-group col-sm-6">
{!! Form::label('lon', 'Longitude:') !!}
{!! Form::number('lon', null, ['class' => 'form-control', 'step' => '0.000001']) !!}
</div>
<div class="row">
<div class="form-group col-sm-6">
{!! Form::label('country', 'Country:') !!}
{!! Form::text('country', null, ['class' => 'form-control', 'rv-value' => 'airport.country']) !!}
</div>
<div class="form-group col-sm-6">
{!! Form::label('timezone', 'Timezone:') !!}
{!! Form::select('timezone', $timezones, null, ['id' => 'timezone', 'class' => 'select2' ]); !!}
</div>
<div class="form-group col-sm-6">
{!! Form::label('tz', 'Timezone:') !!}
{!! Form::select('tz', $timezones, null, ['class' => 'select2']); !!}
</div>
</div>
<!-- Submit Field -->
<div class="form-group col-sm-12">
<div class="pull-right">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<a href="{!! route('admin.airports.index') !!}" class="btn btn-default">Cancel</a>
<div class="row">
<div class="form-group col-sm-6">
{!! Form::label('lat', 'Latitude:') !!}
{!! Form::number('lat', null, ['class' => 'form-control', 'step' => '0.000001', 'rv-value' => 'airport.lat']) !!}
</div>
<div class="form-group col-sm-6">
{!! Form::label('lon', 'Longitude:') !!}
{!! Form::number('lon', null, ['class' => 'form-control', 'step' => '0.000001', 'rv-value' => 'airport.lon']) !!}
</div>
</div>
<div class="row">
<!-- Submit Field -->
<div class="form-group col-sm-12">
<div class="pull-right">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<a href="{!! route('admin.airports.index') !!}" class="btn btn-default">Cancel</a>
</div>
</div>
</div>
</div>
</div>

View File

@@ -1,6 +1,8 @@
@section('scripts')
<script>
$(document).ready(function() {
$('#airports-table a.inline').editable({
type: 'text',
mode: 'inline',
@@ -16,6 +18,29 @@ $(document).ready(function() {
}
}
});
$('a.airport_data_lookup').click(function(e) {
e.preventDefault();
var icao = $("input#airport_icao").val();
if(icao === '') {
return;
}
phpvms_vacentral_airport_lookup(icao, function(data) {
console.log('lookup data', data);
_.forEach(data, function(value, key) {
if(key === 'city') {
key = 'location';
}
$("#" + key).val(value);
if(key === 'tz') {
$("#tz").trigger('change');
}
});
});
});
});
</script>
@endsection

View File

@@ -17,6 +17,8 @@ Route::group([], function () {
Route::match(['get'], 'status', 'BaseController@status');
Route::match(['get'], 'airports/{id}/lookup', 'AirportController@lookup');
Route::match(['get'], 'flight/{id}', 'FlightController@get');
Route::match(['get'], 'flights/search', 'FlightController@search');