diff --git a/app/Console/Commands/AcarsReplay.php b/app/Console/Commands/AcarsReplay.php index 0c46b493..3dcefed9 100644 --- a/app/Console/Commands/AcarsReplay.php +++ b/app/Console/Commands/AcarsReplay.php @@ -73,7 +73,7 @@ class AcarsReplay extends Command $flight_number = substr($flight->callsign, 3); - $response = $this->httpClient->post('/api/pirep/prefile', [ + $response = $this->httpClient->post('/api/pireps/prefile', [ 'json' => [ 'airline_id' => 1, 'flight_number' => $flight_number, @@ -97,7 +97,7 @@ class AcarsReplay extends Command */ protected function filePirep($pirep_id) { - $response = $this->httpClient->post('/api/pirep/'.$pirep_id.'/file', [ + $response = $this->httpClient->post('/api/pireps/'.$pirep_id.'/file', [ 'json'=> [] ]); diff --git a/app/Http/Controllers/Api/PirepController.php b/app/Http/Controllers/Api/PirepController.php index 587e6735..441248e5 100644 --- a/app/Http/Controllers/Api/PirepController.php +++ b/app/Http/Controllers/Api/PirepController.php @@ -151,16 +151,19 @@ class PirepController extends AppBaseController } /** - * Get all of the ACARS updates for a PIREP + * Return the GeoJSON for the ACARS line * @param $id - * @return AcarsResource + * @param Request $request + * @return \Illuminate\Contracts\Routing\ResponseFactory */ - public function acars_get($id) + public function acars_get($id, Request $request) { $pirep = $this->pirepRepo->find($id); + $geodata = $this->geoSvc->getFeatureFromAcars($pirep); - $updates = $this->acarsRepo->forPirep($id); - return new AcarsResource($updates); + return response(\json_encode($geodata), 200, [ + 'Content-Type' => 'application/json', + ]); } /** @@ -187,20 +190,4 @@ class PirepController extends AppBaseController AcarsResource::withoutWrapping(); return new AcarsResource($update); } - - /** - * Return the GeoJSON for the ACARS line - * @param $id - * @param Request $request - * @return \Illuminate\Contracts\Routing\ResponseFactory - */ - public function geojson($id, Request $request) - { - $pirep = $this->pirepRepo->find($id); - $geodata = $this->geoSvc->getFeatureFromAcars($pirep); - - return response(\json_encode($geodata), 200, [ - 'Content-Type' => 'application/json', - ]); - } } diff --git a/app/Models/Pirep.php b/app/Models/Pirep.php index c812b8a0..3f0baceb 100644 --- a/app/Models/Pirep.php +++ b/app/Models/Pirep.php @@ -94,7 +94,7 @@ class Pirep extends BaseModel public function acars() { return $this->hasMany('App\Models\Acars', 'pirep_id') - ->orderBy('created_at', 'desc'); + ->orderBy('created_at', 'asc'); } public function aircraft() diff --git a/app/Routes/api.php b/app/Routes/api.php index e9c8470b..d9416007 100755 --- a/app/Routes/api.php +++ b/app/Routes/api.php @@ -5,14 +5,15 @@ */ Route::group([], function() { - Route::match(['get'], 'acars', 'AcarsController@index'); + Route::get('acars', 'AcarsController@index'); - Route::match(['get'], 'flights/search', 'FlightController@search'); - Route::match(['get'], 'flights/{id}', 'FlightController@get'); + Route::get('flights/search', 'FlightController@search'); + Route::get('flights/{id}', 'FlightController@get'); - Route::match(['post'], 'pirep/{id}/geojson', 'PirepController@file'); + Route::get('pireps/{id}/acars', 'PirepController@acars_get'); + Route::get('pireps/{id}/geojson', 'PirepController@acars_get'); - Route::match(['get'], 'status', 'BaseController@status'); + Route::get('status', 'BaseController@status'); }); /** @@ -20,19 +21,17 @@ Route::group([], function() */ Route::group(['middleware' => ['api.auth']], function () { - Route::match(['get'], 'airports/{id}', 'AirportController@get'); - Route::match(['get'], 'airports/{id}/lookup', 'AirportController@lookup'); + Route::get('airports/{id}', 'AirportController@get'); + Route::get('airports/{id}/lookup', 'AirportController@lookup'); - Route::match(['get'], 'pirep/{id}', 'PirepController@get'); - Route::match(['post'], 'pirep/prefile', 'PirepController@prefile'); - Route::match(['post'], 'pirep/{id}/file', 'PirepController@file'); + Route::get('pireps/{id}', 'PirepController@get'); + Route::post('pireps/prefile', 'PirepController@prefile'); + Route::post('pireps/{id}/file', 'PirepController@file'); - Route::match(['get'], 'pirep/{id}/acars', 'PirepController@acars_get'); - Route::match(['post'], 'pirep/{id}/acars', 'PirepController@acars_store'); + Route::post('pireps/{id}/acars', 'PirepController@acars_store'); # This is the info of the user whose token is in use - Route::match(['get'], 'user', 'UserController@index'); - #Route::match(['get'], 'user/bids', 'UserController@index'); - Route::match(['get'], 'users/{id}', 'UserController@get'); - Route::match(['get'], 'users/{id}/bids', 'UserController@bids'); + Route::get('user', 'UserController@index'); + Route::get('users/{id}', 'UserController@get'); + Route::get('users/{id}/bids', 'UserController@bids'); }); diff --git a/app/Services/GeoService.php b/app/Services/GeoService.php index 2cb4ceea..c1390de9 100644 --- a/app/Services/GeoService.php +++ b/app/Services/GeoService.php @@ -168,34 +168,36 @@ class GeoService extends BaseService /** * Read an array/relationship of ACARS model points * @param Pirep $pirep - * @return FeatureCollection + * @return array */ public function getFeatureFromAcars(Pirep $pirep) { $route_line = []; $route_points = []; - $route_line[] = [$pirep->dpt_airport->lon, $pirep->dpt_airport->lat]; /** * @var $point \App\Models\Acars */ - foreach ($pirep->acars as $point) - { + $counter = 1; + foreach ($pirep->acars as $point) { $route_line[] = [$point->lon, $point->lat]; $route_points[] = new Feature( new Point([$point->lon, $point->lat]), [ - 'pirep_id' => $pirep->id, - 'name' => $point->altitude, - 'popup' => 'GS: ' . $point->gs . '
Alt: ' . $point->altitude, - ]); - } + 'name' => $point->altitude, + 'popup' => $counter . '
GS: ' . $point->gs . '
Alt: ' . $point->altitude, + ]); + $counter += 1; + } # Arrival $route_line[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat]; $route_line = new Feature(new LineString($route_line)); - return new FeatureCollection([$route_line, $route_points]); + return [ + 'line' => new FeatureCollection([$route_line]), + 'points' => new FeatureCollection($route_points) + ]; } /** diff --git a/public/assets/system/js/system.js b/public/assets/system/js/system.js index f416ec82..dc306994 100644 --- a/public/assets/system/js/system.js +++ b/public/assets/system/js/system.js @@ -218,6 +218,7 @@ const phpvms = (function() { opts = _.defaults(opts, { update_uri: '/api/acars', + pirep_uri: '/api/pireps/{id}/acars', positions: null, render_elem: 'map', aircraft_icon: '/assets/img/acars/aircraft.png', diff --git a/resources/views/layouts/default/acars/map.blade.php b/resources/views/layouts/default/acars/map.blade.php index 4475d4b5..8d2274dd 100644 --- a/resources/views/layouts/default/acars/map.blade.php +++ b/resources/views/layouts/default/acars/map.blade.php @@ -13,6 +13,7 @@