From 4a14e83c8842685e0ae734d5ff73c1c3708570b4 Mon Sep 17 00:00:00 2001 From: Nabeel S Date: Sun, 1 Mar 2020 15:51:00 -0500 Subject: [PATCH] Performance improvements #602 (#607) * Update gitignore * Save theme to the session to avoid a lookup #602 * Formatting * Move routes into main service provider * Move Observers into their own service provider --- .gitignore | 1 + app/Http/Kernel.php | 2 +- app/Http/Middleware/SetActiveTheme.php | 23 +- app/Http/Routes/admin.php | 223 ---------- app/Http/Routes/api.php | 93 ---- app/Http/Routes/web.php | 60 --- app/Providers/AppServiceProvider.php | 46 -- app/Providers/ObserverServiceProviders.php | 48 ++ app/Providers/RouteServiceProvider.php | 415 +++++++++++++++++- app/helpers.php | 3 +- config/app.php | 1 + resources/docker/.gitignore | 4 + .../layouts/default/dashboard/index.blade.php | 10 +- .../default/dashboard/pirep_card.blade.php | 66 +++ .../default/pireps/pirep_card.blade.php | 68 --- .../layouts/default/pireps/show.blade.php | 2 +- .../layouts/default/pireps/table.blade.php | 4 +- 17 files changed, 557 insertions(+), 512 deletions(-) delete mode 100644 app/Http/Routes/admin.php delete mode 100755 app/Http/Routes/api.php delete mode 100755 app/Http/Routes/web.php create mode 100644 app/Providers/ObserverServiceProviders.php create mode 100755 resources/docker/.gitignore create mode 100644 resources/views/layouts/default/dashboard/pirep_card.blade.php delete mode 100644 resources/views/layouts/default/pireps/pirep_card.blade.php diff --git a/.gitignore b/.gitignore index a694dcf6..2cd78d74 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ env.php #Homestead.yaml Homestead.json LocalValetDriver.php +docker-compose-profiler.yml # Rocketeer PHP task runner and deployment package. https://github.com/rocketeers/rocketeer .rocketeer/ diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 4fc5cadb..579f0e8f 100755 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -35,13 +35,13 @@ class Kernel extends HttpKernel 'json', ], 'web' => [ - InstalledCheck::class, EncryptCookies::class, AddQueuedCookiesToResponse::class, StartSession::class, ShareErrorsFromSession::class, // VerifyCsrfToken::class, SubstituteBindings::class, + InstalledCheck::class, ], ]; diff --git a/app/Http/Middleware/SetActiveTheme.php b/app/Http/Middleware/SetActiveTheme.php index c549fbd1..ace8abec 100644 --- a/app/Http/Middleware/SetActiveTheme.php +++ b/app/Http/Middleware/SetActiveTheme.php @@ -15,16 +15,23 @@ class SetActiveTheme implements Middleware { public function handle(Request $request, Closure $next) { - try { - $theme = setting('general.theme'); - } catch (\Exception $e) { - Log::error($e->getMessage()); - $theme = 'default'; + if (!$request->session()->has('theme')) { + try { + $theme = setting('general.theme'); + if (empty($theme)) { + $theme = 'default'; + } + } catch (\Exception $e) { + Log::error($e->getMessage()); + $theme = 'default'; + } + + $request->session()->put('theme', $theme); + } else { + $theme = $request->session()->get('theme', 'default'); } - if (!empty($theme)) { - Theme::set($theme); - } + Theme::set($theme); return $next($request); } diff --git a/app/Http/Routes/admin.php b/app/Http/Routes/admin.php deleted file mode 100644 index 79a7ee1c..00000000 --- a/app/Http/Routes/admin.php +++ /dev/null @@ -1,223 +0,0 @@ - 'Admin', - 'prefix' => 'admin', - 'as' => 'admin.', - 'middleware' => ['auth', 'ability:admin,admin-access'], - ], - static function () { - // CRUD for airlines - Route::resource('airlines', 'AirlinesController')->middleware('ability:admin,airlines'); - - // CRUD for roles - Route::resource('roles', 'RolesController')->middleware('role:admin'); - - Route::get('airports/export', 'AirportController@export') - ->name('airports.export') - ->middleware('ability:admin,airports'); - - Route::match(['get', 'post', 'put'], 'airports/fuel', 'AirportController@fuel') - ->middleware('ability:admin,airports'); - - Route::match(['get', 'post'], 'airports/import', 'AirportController@import') - ->name('airports.import')->middleware('ability:admin,airports'); - - Route::match( - ['get', 'post', 'put', 'delete'], - 'airports/{id}/expenses', - 'AirportController@expenses' - )->middleware('ability:admin,airports'); - - Route::resource('airports', 'AirportController')->middleware('ability:admin,airports'); - - // Awards - Route::resource('awards', 'AwardController')->middleware('ability:admin,awards'); - - // aircraft and fare associations - Route::get('aircraft/export', 'AircraftController@export') - ->name('aircraft.export') - ->middleware('ability:admin,aircraft'); - - Route::match(['get', 'post'], 'aircraft/import', 'AircraftController@import') - ->name('aircraft.import')->middleware('ability:admin,aircraft'); - - Route::match( - ['get', 'post', 'put', 'delete'], - 'aircraft/{id}/expenses', - 'AircraftController@expenses' - )->middleware('ability:admin,aircraft'); - - Route::resource('aircraft', 'AircraftController')->middleware('ability:admin,aircraft'); - - // expenses - Route::get('expenses/export', 'ExpenseController@export') - ->name('expenses.export') - ->middleware('ability:admin,finances'); - - Route::match(['get', 'post'], 'expenses/import', 'ExpenseController@import') - ->name('expenses.import') - ->middleware('ability:admin,finances'); - - Route::resource('expenses', 'ExpenseController')->middleware('ability:admin,finances'); - - // fares - Route::get('fares/export', 'FareController@export') - ->name('fares.export') - ->middleware('ability:admin,finances'); - - Route::match(['get', 'post'], 'fares/import', 'FareController@import') - ->name('fares.import')->middleware('ability:admin,finances'); - - Route::resource('fares', 'FareController')->middleware('ability:admin,finances'); - - // files - Route::post('files', 'FileController@store') - ->name('files.store') - ->middleware('ability:admin,files'); - - Route::delete('files/{id}', 'FileController@destroy') - ->name('files.delete') - ->middleware('ability:admin,files'); - - // finances - Route::resource('finances', 'FinanceController')->middleware('ability:admin,finances'); - - // flights and aircraft associations - Route::get('flights/export', 'FlightController@export') - ->name('flights.export') - ->middleware('ability:admin,flights'); - - Route::match(['get', 'post'], 'flights/import', 'FlightController@import') - ->name('flights.import') - ->middleware('ability:admin,flights'); - - Route::match( - ['get', 'post', 'put', 'delete'], - 'flights/{id}/fares', - 'FlightController@fares' - )->middleware('ability:admin,flights'); - - Route::match( - ['get', 'post', 'put', 'delete'], - 'flights/{id}/fields', - 'FlightController@field_values' - )->middleware('ability:admin,flights'); - - Route::match( - ['get', 'post', 'put', 'delete'], - 'flights/{id}/subfleets', - 'FlightController@subfleets' - )->middleware('ability:admin,flights'); - - Route::resource('flights', 'FlightController') - ->middleware('ability:admin,flights'); - - Route::resource('flightfields', 'FlightFieldController') - ->middleware('ability:admin,flights'); - - // pirep related routes - Route::get('pireps/fares', 'PirepController@fares')->middleware('ability:admin,pireps'); - Route::get('pireps/pending', 'PirepController@pending')->middleware('ability:admin,pireps'); - Route::resource('pireps', 'PirepController')->middleware('ability:admin,pireps'); - - Route::match(['get', 'post', 'delete'], 'pireps/{id}/comments', 'PirepController@comments') - ->middleware('ability:admin,pireps'); - - Route::match(['post', 'put'], 'pireps/{id}/status', 'PirepController@status') - ->name('pirep.status') - ->middleware('ability:admin,pireps'); - - Route::resource('pirepfields', 'PirepFieldController') - ->middleware('ability:admin,pireps'); - - // rankings - Route::resource('ranks', 'RankController')->middleware('ability:admin,ranks'); - Route::match( - ['get', 'post', 'put', 'delete'], - 'ranks/{id}/subfleets', - 'RankController@subfleets' - )->middleware('ability:admin,ranks'); - - // settings - Route::match(['get'], 'settings', 'SettingsController@index') - ->middleware('ability:admin,settings'); - - Route::match(['post', 'put'], 'settings', 'SettingsController@update') - ->name('settings.update') - ->middleware('ability:admin,settings'); - - // maintenance - Route::match(['get'], 'maintenance', 'MaintenanceController@index') - ->name('maintenance.index') - ->middleware('ability:admin,maintenance'); - - Route::match(['post'], 'maintenance/cache', 'MaintenanceController@cache') - ->name('maintenance.cache') - ->middleware('ability:admin,maintenance'); - - Route::match(['post'], 'maintenance/update', 'MaintenanceController@update') - ->name('maintenance.update') - ->middleware('ability:admin,maintenance'); - - Route::match(['post'], 'maintenance/forcecheck', 'MaintenanceController@forcecheck') - ->name('maintenance.forcecheck') - ->middleware('ability:admin,maintenance'); - - // subfleet - Route::get('subfleets/export', 'SubfleetController@export') - ->name('subfleets.export') - ->middleware('ability:admin,fleet'); - - Route::match(['get', 'post'], 'subfleets/import', 'SubfleetController@import') - ->name('subfleets.import') - ->middleware('ability:admin,fleet'); - - Route::match( - ['get', 'post', 'put', 'delete'], - 'subfleets/{id}/expenses', - 'SubfleetController@expenses' - )->middleware('ability:admin,fleet'); - - Route::match( - ['get', 'post', 'put', 'delete'], - 'subfleets/{id}/fares', - 'SubfleetController@fares' - )->middleware('ability:admin,fleet'); - - Route::match( - ['get', 'post', 'put', 'delete'], - 'subfleets/{id}/ranks', - 'SubfleetController@ranks' - )->middleware('ability:admin,fleet'); - - Route::resource('subfleets', 'SubfleetController')->middleware('ability:admin,fleet'); - - Route::resource('users', 'UserController')->middleware('ability:admin,users'); - Route::get( - 'users/{id}/regen_apikey', - 'UserController@regen_apikey' - )->name('users.regen_apikey')->middleware('ability:admin,users'); - - // defaults - Route::get('', ['uses' => 'DashboardController@index']) - ->middleware('update_pending', 'ability:admin,admin-access'); - - Route::get('/', ['uses' => 'DashboardController@index']) - ->middleware('update_pending', 'ability:admin,admin-access'); - - Route::get('dashboard', ['uses' => 'DashboardController@index', 'name' => 'dashboard']) - ->middleware('update_pending', 'ability:admin,admin-access'); - - Route::match( - ['get', 'post', 'delete'], - 'dashboard/news', - ['uses' => 'DashboardController@news'] - )->name('dashboard.news')->middleware('update_pending', 'ability:admin,admin-access'); - } -); diff --git a/app/Http/Routes/api.php b/app/Http/Routes/api.php deleted file mode 100755 index 4069059f..00000000 --- a/app/Http/Routes/api.php +++ /dev/null @@ -1,93 +0,0 @@ - ['api.auth']], function () { - Route::get('airlines', 'AirlineController@index'); - Route::get('airlines/{id}', 'AirlineController@get'); - - Route::get('airports', 'AirportController@index'); - Route::get('airports/hubs', 'AirportController@index_hubs'); - Route::get('airports/{id}', 'AirportController@get'); - Route::get('airports/{id}/lookup', 'AirportController@lookup'); - Route::get('airports/{id}/distance/{to}', 'AirportController@distance'); - - Route::get('fleet', 'FleetController@index'); - Route::get('fleet/aircraft/{id}', 'FleetController@get_aircraft'); - - Route::get('flights', 'FlightController@index'); - Route::get('flights/search', 'FlightController@search'); - Route::get('flights/{id}', 'FlightController@get'); - Route::get('flights/{id}/route', 'FlightController@route'); - - Route::get('pireps', 'UserController@pireps'); - Route::put('pireps/{pirep_id}', 'PirepController@update'); - - /* - * ACARS related - */ - Route::post('pireps/prefile', 'PirepController@prefile'); - Route::post('pireps/{pirep_id}', 'PirepController@update'); - Route::patch('pireps/{pirep_id}', 'PirepController@update'); - Route::post('pireps/{pirep_id}/update', 'PirepController@update'); - Route::post('pireps/{pirep_id}/file', 'PirepController@file'); - Route::post('pireps/{pirep_id}/comments', 'PirepController@comments_post'); - Route::put('pireps/{pirep_id}/cancel', 'PirepController@cancel'); - Route::delete('pireps/{pirep_id}/cancel', 'PirepController@cancel'); - - Route::get('pireps/{pirep_id}/fields', 'PirepController@fields_get'); - Route::post('pireps/{pirep_id}/fields', 'PirepController@fields_post'); - - Route::get('pireps/{pirep_id}/finances', 'PirepController@finances_get'); - Route::post('pireps/{pirep_id}/finances/recalculate', 'PirepController@finances_recalculate'); - - Route::get('pireps/{pirep_id}/route', 'PirepController@route_get'); - Route::post('pireps/{pirep_id}/route', 'PirepController@route_post'); - Route::delete('pireps/{pirep_id}/route', 'PirepController@route_delete'); - - Route::get('pireps/{pirep_id}/comments', 'PirepController@comments_get'); - - Route::get('pireps/{pirep_id}/acars/position', 'AcarsController@acars_get'); - Route::post('pireps/{pirep_id}/acars/position', 'AcarsController@acars_store'); - Route::post('pireps/{pirep_id}/acars/positions', 'AcarsController@acars_store'); - - Route::post('pireps/{pirep_id}/acars/events', 'AcarsController@acars_events'); - Route::post('pireps/{pirep_id}/acars/logs', 'AcarsController@acars_logs'); - - Route::get('settings', 'SettingsController@index'); - - // This is the info of the user whose token is in use - Route::get('user', 'UserController@index'); - Route::get('user/fleet', 'UserController@fleet'); - Route::get('user/pireps', 'UserController@pireps'); - - Route::get('user/bids', 'UserController@bids'); - Route::put('user/bids', 'UserController@bids'); - Route::post('user/bids', 'UserController@bids'); - Route::delete('user/bids', 'UserController@bids'); - - Route::get('users/{id}', 'UserController@get'); - Route::get('users/{id}/fleet', 'UserController@fleet'); - Route::get('users/{id}/pireps', 'UserController@pireps'); - - Route::get('users/{id}/bids', 'UserController@bids'); - Route::put('users/{id}/bids', 'UserController@bids'); -}); diff --git a/app/Http/Routes/web.php b/app/Http/Routes/web.php deleted file mode 100755 index c1fe3292..00000000 --- a/app/Http/Routes/web.php +++ /dev/null @@ -1,60 +0,0 @@ - 'Frontend', 'prefix' => '', 'as' => 'frontend.', - 'middleware' => ['auth', SetActiveTheme::class], -], function () { - Route::resource('dashboard', 'DashboardController'); - - Route::get('airports/{id}', 'AirportController@show')->name('airports.show'); - - // Download a file - Route::get('downloads', 'DownloadController@index')->name('downloads.index'); - Route::get('downloads/{id}', 'DownloadController@show')->name('downloads.download'); - - Route::get('flights/bids', 'FlightController@bids')->name('flights.bids'); - Route::get('flights/search', 'FlightController@search')->name('flights.search'); - Route::resource('flights', 'FlightController'); - - Route::get('pireps/fares', 'PirepController@fares'); - Route::post('pireps/{id}/submit', 'PirepController@submit')->name('pireps.submit'); - - Route::resource('pireps', 'PirepController', [ - 'except' => ['show'], - ]); - - Route::get('profile/acars', 'ProfileController@acars')->name('profile.acars'); - Route::get('profile/regen_apikey', 'ProfileController@regen_apikey')->name('profile.regen_apikey'); - - Route::resource('profile', 'ProfileController'); -}); - -/** - * These are publically available routes - */ -Route::group([ - 'namespace' => 'Frontend', 'prefix' => '', 'as' => 'frontend.', - 'middleware' => [SetActiveTheme::class], -], function () { - Route::get('/', 'HomeController@index')->name('home'); - Route::get('r/{id}', 'PirepController@show')->name('pirep.show.public'); - Route::get('pireps/{id}', 'PirepController@show')->name('pireps.show'); - - Route::get('p/{id}', 'ProfileController@show')->name('profile.show.public'); - Route::get('users', 'UserController@index')->name('users.index'); - Route::get('pilots', 'UserController@index')->name('pilots.index'); - - Route::get('livemap', 'LiveMapController@index')->name('livemap.index'); -}); - -Auth::routes(['verify' => true]); -Route::get('/logout', 'Auth\LoginController@logout')->name('logout'); - -require app_path('Http/Routes/admin.php'); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 2605280a..99a11adc 100755 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,28 +2,6 @@ namespace App\Providers; -use App\Models\Aircraft; -use App\Models\Airport; -use App\Models\Flight; -use App\Models\FlightField; -use App\Models\FlightFieldValue; -use App\Models\Journal; -use App\Models\JournalTransaction; -use App\Models\Observers\AircraftObserver; -use App\Models\Observers\AirportObserver; -use App\Models\Observers\FlightObserver; -use App\Models\Observers\JournalObserver; -use App\Models\Observers\JournalTransactionObserver; -use App\Models\Observers\SettingObserver; -use App\Models\Observers\Sluggable; -use App\Models\Observers\SubfleetObserver; -use App\Models\Observers\UserObserver; -use App\Models\PirepField; -use App\Models\PirepFieldValue; -use App\Models\Setting; -use App\Models\Subfleet; -use App\Models\User; -use App\Repositories\SettingRepository; use App\Services\ModuleService; use App\Support\Utils; use Illuminate\Support\Facades\Schema; @@ -35,31 +13,7 @@ class AppServiceProvider extends ServiceProvider public function boot(): void { Schema::defaultStringLength(191); - - /*Carbon::serializeUsing(function ($carbon) { - return $carbon->format('U'); - });*/ - - $this->app->bind('setting', SettingRepository::class); - View::share('moduleSvc', app(ModuleService::class)); - - // Model observers - Aircraft::observe(AircraftObserver::class); - Airport::observe(AirportObserver::class); - Journal::observe(JournalObserver::class); - JournalTransaction::observe(JournalTransactionObserver::class); - - Flight::observe(FlightObserver::class); - FlightField::observe(Sluggable::class); - FlightFieldValue::observe(Sluggable::class); - - PirepField::observe(Sluggable::class); - PirepFieldValue::observe(Sluggable::class); - - Setting::observe(SettingObserver::class); - Subfleet::observe(SubfleetObserver::class); - User::observe(UserObserver::class); } /** diff --git a/app/Providers/ObserverServiceProviders.php b/app/Providers/ObserverServiceProviders.php new file mode 100644 index 00000000..7a7d4d3b --- /dev/null +++ b/app/Providers/ObserverServiceProviders.php @@ -0,0 +1,48 @@ +mapWebRoutes(); + $this->mapAdminRoutes(); $this->mapApiRoutes(); } @@ -34,13 +37,332 @@ class RouteServiceProvider extends ServiceProvider * * @return void */ - protected function mapWebRoutes() + private function mapWebRoutes() { Route::group([ 'middleware' => 'web', 'namespace' => $this->namespace, ], function ($router) { - require app_path('Http/Routes/web.php'); + Route::group([ + 'namespace' => 'Frontend', + 'prefix' => '', + 'as' => 'frontend.', + 'middleware' => ['auth', SetActiveTheme::class], + ], function () { + Route::resource('dashboard', 'DashboardController'); + + Route::get('airports/{id}', 'AirportController@show')->name('airports.show'); + + // Download a file + Route::get('downloads', 'DownloadController@index')->name('downloads.index'); + Route::get('downloads/{id}', 'DownloadController@show')->name('downloads.download'); + + Route::get('flights/bids', 'FlightController@bids')->name('flights.bids'); + Route::get('flights/search', 'FlightController@search')->name('flights.search'); + Route::resource('flights', 'FlightController'); + + Route::get('pireps/fares', 'PirepController@fares'); + Route::post('pireps/{id}/submit', 'PirepController@submit')->name('pireps.submit'); + + Route::resource('pireps', 'PirepController', [ + 'except' => ['show'], + ]); + + Route::get('profile/acars', 'ProfileController@acars')->name('profile.acars'); + Route::get('profile/regen_apikey', 'ProfileController@regen_apikey')->name('profile.regen_apikey'); + + Route::resource('profile', 'ProfileController'); + }); + + Route::group([ + 'namespace' => 'Frontend', + 'prefix' => '', + 'as' => 'frontend.', + 'middleware' => [SetActiveTheme::class], + ], function () { + Route::get('/', 'HomeController@index')->name('home'); + Route::get('r/{id}', 'PirepController@show')->name('pirep.show.public'); + Route::get('pireps/{id}', 'PirepController@show')->name('pireps.show'); + + Route::get('p/{id}', 'ProfileController@show')->name('profile.show.public'); + Route::get('users', 'UserController@index')->name('users.index'); + Route::get('pilots', 'UserController@index')->name('pilots.index'); + + Route::get('livemap', 'LiveMapController@index')->name('livemap.index'); + }); + + Auth::routes(['verify' => true]); + Route::get('/logout', 'Auth\LoginController@logout')->name('logout'); + }); + } + + private function mapAdminRoutes() + { + Route::group([ + 'namespace' => $this->namespace.'\\Admin', + 'prefix' => 'admin', + 'as' => 'admin.', + 'middleware' => ['web', 'auth', 'ability:admin,admin-access'], + ], static function () { + // CRUD for airlines + Route::resource('airlines', 'AirlinesController') + ->middleware('ability:admin,airlines'); + + // CRUD for roles + Route::resource('roles', 'RolesController') + ->middleware('role:admin'); + + Route::get('airports/export', 'AirportController@export') + ->name('airports.export') + ->middleware('ability:admin,airports'); + + Route::match([ + 'get', + 'post', + 'put', + ], 'airports/fuel', 'AirportController@fuel') + ->middleware('ability:admin,airports'); + + Route::match([ + 'get', + 'post', + ], 'airports/import', 'AirportController@import') + ->name('airports.import') + ->middleware('ability:admin,airports'); + + Route::match([ + 'get', + 'post', + 'put', + 'delete', + ], 'airports/{id}/expenses', 'AirportController@expenses') + ->middleware('ability:admin,airports'); + + Route::resource('airports', 'AirportController')->middleware('ability:admin,airports'); + + // Awards + Route::resource('awards', 'AwardController')->middleware('ability:admin,awards'); + + // aircraft and fare associations + Route::get('aircraft/export', 'AircraftController@export') + ->name('aircraft.export') + ->middleware('ability:admin,aircraft'); + + Route::match([ + 'get', + 'post', + ], 'aircraft/import', 'AircraftController@import') + ->name('aircraft.import') + ->middleware('ability:admin,aircraft'); + + Route::match([ + 'get', + 'post', + 'put', + 'delete', + ], 'aircraft/{id}/expenses', 'AircraftController@expenses') + ->middleware('ability:admin,aircraft'); + + Route::resource('aircraft', 'AircraftController') + ->middleware('ability:admin,aircraft'); + + // expenses + Route::get('expenses/export', 'ExpenseController@export') + ->name('expenses.export') + ->middleware('ability:admin,finances'); + + Route::match([ + 'get', + 'post', + ], 'expenses/import', 'ExpenseController@import') + ->name('expenses.import') + ->middleware('ability:admin,finances'); + + Route::resource('expenses', 'ExpenseController') + ->middleware('ability:admin,finances'); + + // fares + Route::get('fares/export', 'FareController@export') + ->name('fares.export') + ->middleware('ability:admin,finances'); + + Route::match([ + 'get', + 'post', + ], 'fares/import', 'FareController@import') + ->name('fares.import') + ->middleware('ability:admin,finances'); + + Route::resource('fares', 'FareController')->middleware('ability:admin,finances'); + + // files + Route::post('files', 'FileController@store') + ->name('files.store') + ->middleware('ability:admin,files'); + + Route::delete('files/{id}', 'FileController@destroy') + ->name('files.delete') + ->middleware('ability:admin,files'); + + // finances + Route::resource('finances', 'FinanceController') + ->middleware('ability:admin,finances'); + + // flights and aircraft associations + Route::get('flights/export', 'FlightController@export') + ->name('flights.export') + ->middleware('ability:admin,flights'); + + Route::match([ + 'get', + 'post', + ], 'flights/import', 'FlightController@import') + ->name('flights.import') + ->middleware('ability:admin,flights'); + + Route::match([ + 'get', + 'post', + 'put', + 'delete', + ], 'flights/{id}/fares', 'FlightController@fares') + ->middleware('ability:admin,flights'); + + Route::match([ + 'get', + 'post', + 'put', + 'delete', + ], 'flights/{id}/fields', 'FlightController@field_values') + ->middleware('ability:admin,flights'); + + Route::match([ + 'get', + 'post', + 'put', + 'delete', + ], 'flights/{id}/subfleets', 'FlightController@subfleets') + ->middleware('ability:admin,flights'); + + Route::resource('flights', 'FlightController') + ->middleware('ability:admin,flights'); + + Route::resource('flightfields', 'FlightFieldController') + ->middleware('ability:admin,flights'); + + // pirep related routes + Route::get('pireps/fares', 'PirepController@fares') + ->middleware('ability:admin,pireps'); + + Route::get('pireps/pending', 'PirepController@pending') + ->middleware('ability:admin,pireps'); + + Route::resource('pireps', 'PirepController') + ->middleware('ability:admin,pireps'); + + Route::match([ + 'get', + 'post', + 'delete', + ], 'pireps/{id}/comments', 'PirepController@comments') + ->middleware('ability:admin,pireps'); + + Route::match([ + 'post', + 'put', + ], 'pireps/{id}/status', 'PirepController@status') + ->name('pirep.status') + ->middleware('ability:admin,pireps'); + + Route::resource('pirepfields', 'PirepFieldController') + ->middleware('ability:admin,pireps'); + + // rankings + Route::resource('ranks', 'RankController')->middleware('ability:admin,ranks'); + Route::match([ + 'get', + 'post', + 'put', + 'delete', + ], 'ranks/{id}/subfleets', 'RankController@subfleets')->middleware('ability:admin,ranks'); + + // settings + Route::match(['get'], 'settings', 'SettingsController@index')->middleware('ability:admin,settings'); + + Route::match([ + 'post', + 'put', + ], 'settings', 'SettingsController@update') + ->name('settings.update')->middleware('ability:admin,settings'); + + // maintenance + Route::match(['get'], 'maintenance', 'MaintenanceController@index') + ->name('maintenance.index')->middleware('ability:admin,maintenance'); + + Route::match(['post'], 'maintenance/cache', 'MaintenanceController@cache') + ->name('maintenance.cache')->middleware('ability:admin,maintenance'); + + Route::match(['post'], 'maintenance/update', 'MaintenanceController@update') + ->name('maintenance.update')->middleware('ability:admin,maintenance'); + + Route::match(['post'], 'maintenance/forcecheck', 'MaintenanceController@forcecheck') + ->name('maintenance.forcecheck')->middleware('ability:admin,maintenance'); + + // subfleet + Route::get('subfleets/export', 'SubfleetController@export') + ->name('subfleets.export')->middleware('ability:admin,fleet'); + + Route::match([ + 'get', + 'post', + ], 'subfleets/import', 'SubfleetController@import') + ->name('subfleets.import')->middleware('ability:admin,fleet'); + + Route::match([ + 'get', + 'post', + 'put', + 'delete', + ], 'subfleets/{id}/expenses', 'SubfleetController@expenses')->middleware('ability:admin,fleet'); + + Route::match([ + 'get', + 'post', + 'put', + 'delete', + ], 'subfleets/{id}/fares', 'SubfleetController@fares')->middleware('ability:admin,fleet'); + + Route::match([ + 'get', + 'post', + 'put', + 'delete', + ], 'subfleets/{id}/ranks', 'SubfleetController@ranks')->middleware('ability:admin,fleet'); + + Route::resource('subfleets', 'SubfleetController')->middleware('ability:admin,fleet'); + + Route::resource('users', 'UserController')->middleware('ability:admin,users'); + Route::get('users/{id}/regen_apikey', 'UserController@regen_apikey') + ->name('users.regen_apikey')->middleware('ability:admin,users'); + + // defaults + Route::get('', ['uses' => 'DashboardController@index']) + ->middleware('update_pending', 'ability:admin,admin-access'); + + Route::get('/', ['uses' => 'DashboardController@index']) + ->middleware('update_pending', 'ability:admin,admin-access'); + + Route::get('dashboard', [ + 'uses' => 'DashboardController@index', + 'name' => 'dashboard', + ])->middleware('update_pending', 'ability:admin,admin-access'); + + Route::match([ + 'get', + 'post', + 'delete', + ], 'dashboard/news', ['uses' => 'DashboardController@news']) + ->name('dashboard.news')->middleware('update_pending', 'ability:admin,admin-access'); }); } @@ -51,7 +373,7 @@ class RouteServiceProvider extends ServiceProvider * * @return void */ - protected function mapApiRoutes() + private function mapApiRoutes() { Route::group([ 'middleware' => ['api'], @@ -59,7 +381,92 @@ class RouteServiceProvider extends ServiceProvider 'prefix' => 'api', 'as' => 'api.', ], function ($router) { - require app_path('Http/Routes/api.php'); + Route::group([], function () { + Route::get('acars', 'AcarsController@live_flights'); + Route::get('acars/geojson', 'AcarsController@pireps_geojson'); + + Route::get('pireps/{pirep_id}', 'PirepController@get'); + Route::get('pireps/{pirep_id}/acars/geojson', 'AcarsController@acars_geojson'); + + Route::get('news', 'NewsController@index'); + Route::get('status', 'StatusController@status'); + Route::get('version', 'StatusController@status'); + }); + + /* + * These need to be authenticated with a user's API key + */ + Route::group(['middleware' => ['api.auth']], function () { + Route::get('airlines', 'AirlineController@index'); + Route::get('airlines/{id}', 'AirlineController@get'); + + Route::get('airports', 'AirportController@index'); + Route::get('airports/hubs', 'AirportController@index_hubs'); + Route::get('airports/{id}', 'AirportController@get'); + Route::get('airports/{id}/lookup', 'AirportController@lookup'); + Route::get('airports/{id}/distance/{to}', 'AirportController@distance'); + + Route::get('fleet', 'FleetController@index'); + Route::get('fleet/aircraft/{id}', 'FleetController@get_aircraft'); + + Route::get('flights', 'FlightController@index'); + Route::get('flights/search', 'FlightController@search'); + Route::get('flights/{id}', 'FlightController@get'); + Route::get('flights/{id}/route', 'FlightController@route'); + + Route::get('pireps', 'UserController@pireps'); + Route::put('pireps/{pirep_id}', 'PirepController@update'); + + /* + * ACARS related + */ + Route::post('pireps/prefile', 'PirepController@prefile'); + Route::post('pireps/{pirep_id}', 'PirepController@update'); + Route::patch('pireps/{pirep_id}', 'PirepController@update'); + Route::post('pireps/{pirep_id}/update', 'PirepController@update'); + Route::post('pireps/{pirep_id}/file', 'PirepController@file'); + Route::post('pireps/{pirep_id}/comments', 'PirepController@comments_post'); + Route::put('pireps/{pirep_id}/cancel', 'PirepController@cancel'); + Route::delete('pireps/{pirep_id}/cancel', 'PirepController@cancel'); + + Route::get('pireps/{pirep_id}/fields', 'PirepController@fields_get'); + Route::post('pireps/{pirep_id}/fields', 'PirepController@fields_post'); + + Route::get('pireps/{pirep_id}/finances', 'PirepController@finances_get'); + Route::post('pireps/{pirep_id}/finances/recalculate', 'PirepController@finances_recalculate'); + + Route::get('pireps/{pirep_id}/route', 'PirepController@route_get'); + Route::post('pireps/{pirep_id}/route', 'PirepController@route_post'); + Route::delete('pireps/{pirep_id}/route', 'PirepController@route_delete'); + + Route::get('pireps/{pirep_id}/comments', 'PirepController@comments_get'); + + Route::get('pireps/{pirep_id}/acars/position', 'AcarsController@acars_get'); + Route::post('pireps/{pirep_id}/acars/position', 'AcarsController@acars_store'); + Route::post('pireps/{pirep_id}/acars/positions', 'AcarsController@acars_store'); + + Route::post('pireps/{pirep_id}/acars/events', 'AcarsController@acars_events'); + Route::post('pireps/{pirep_id}/acars/logs', 'AcarsController@acars_logs'); + + Route::get('settings', 'SettingsController@index'); + + // This is the info of the user whose token is in use + Route::get('user', 'UserController@index'); + Route::get('user/fleet', 'UserController@fleet'); + Route::get('user/pireps', 'UserController@pireps'); + + Route::get('user/bids', 'UserController@bids'); + Route::put('user/bids', 'UserController@bids'); + Route::post('user/bids', 'UserController@bids'); + Route::delete('user/bids', 'UserController@bids'); + + Route::get('users/{id}', 'UserController@get'); + Route::get('users/{id}/fleet', 'UserController@fleet'); + Route::get('users/{id}/pireps', 'UserController@pireps'); + + Route::get('users/{id}/bids', 'UserController@bids'); + Route::put('users/{id}/bids', 'UserController@bids'); + }); }); } } diff --git a/app/helpers.php b/app/helpers.php index 379fcc37..ba6aa286 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,6 +1,7 @@ retrieve($key); diff --git a/config/app.php b/config/app.php index 897753bc..7e75aea4 100755 --- a/config/app.php +++ b/config/app.php @@ -82,6 +82,7 @@ return [ App\Providers\DirectiveServiceProvider::class, App\Providers\EventServiceProvider::class, App\Providers\MeasurementsProvider::class, + App\Providers\ObserverServiceProviders::class, App\Providers\RouteServiceProvider::class, ], diff --git a/resources/docker/.gitignore b/resources/docker/.gitignore new file mode 100755 index 00000000..c2f1693e --- /dev/null +++ b/resources/docker/.gitignore @@ -0,0 +1,4 @@ +* +!nginx/ +!php/ +!.gitignore diff --git a/resources/views/layouts/default/dashboard/index.blade.php b/resources/views/layouts/default/dashboard/index.blade.php index 1af6252b..8ab2b3ac 100644 --- a/resources/views/layouts/default/dashboard/index.blade.php +++ b/resources/views/layouts/default/dashboard/index.blade.php @@ -60,17 +60,17 @@ -
- + +
@if($last_pirep === null)
@lang('dashboard.noreportsyet') @lang('dashboard.fileonenow')
@else - @include('pireps.pirep_card', ['pirep' => $last_pirep]) + @include('dashboard.pirep_card', ['pirep' => $last_pirep]) @endif
diff --git a/resources/views/layouts/default/dashboard/pirep_card.blade.php b/resources/views/layouts/default/dashboard/pirep_card.blade.php new file mode 100644 index 00000000..012a3635 --- /dev/null +++ b/resources/views/layouts/default/dashboard/pirep_card.blade.php @@ -0,0 +1,66 @@ +
+
+
+

+ @lang('common.edit') +

+
+ + {{ $pirep->airline->code }}{{ $pirep->ident }} + - + {{ $pirep->dpt_airport->name }} + ({{$pirep->dpt_airport->icao}}) + to + {{ $pirep->arr_airport->name }} + ({{$pirep->arr_airport->icao}}) +
+
+
+
+ @if($pirep->state === PirepState::PENDING) +
+ @elseif($pirep->state === PirepState::ACCEPTED) +
+ @elseif($pirep->state === PirepState::REJECTED) +
+ @else +
+ @endif + {{ PirepState::label($pirep->state) }}
+
+
+
+
+
+ + + + + + + + + + @if($pirep->level) + + + + + @endif + + + + +
@lang('pireps.flighttime') @minutestotime($pirep->flight_time)
@lang('common.aircraft') {{ $pirep->aircraft->name }} + ({{ $pirep->aircraft->registration }}) +
@lang('pireps.flightlevel') {{ $pirep->level }}
@lang('pireps.filedon'): {{ show_datetime($pirep->created_at) }}
+
+
+
+
+
diff --git a/resources/views/layouts/default/pireps/pirep_card.blade.php b/resources/views/layouts/default/pireps/pirep_card.blade.php deleted file mode 100644 index 29d588a5..00000000 --- a/resources/views/layouts/default/pireps/pirep_card.blade.php +++ /dev/null @@ -1,68 +0,0 @@ -
-
-
-
-

- @lang('common.edit') -

-
- - {{ $pirep->airline->code }}{{ $pirep->ident }} - - - {{ $pirep->dpt_airport->name }} - ({{$pirep->dpt_airport->icao}}) - to - {{ $pirep->arr_airport->name }} - ({{$pirep->arr_airport->icao}}) -
-
-
-
- @if($pirep->state === PirepState::PENDING) -
- @elseif($pirep->state === PirepState::ACCEPTED) -
- @elseif($pirep->state === PirepState::REJECTED) -
- @else -
- @endif - {{ PirepState::label($pirep->state) }}
-
-
-
-
-
- - - - - - - - - - @if($pirep->level) - - - - - @endif - - - - -
@lang('pireps.flighttime') @minutestotime($pirep->flight_time)
@lang('common.aircraft') {{ $pirep->aircraft->name }} - ({{ $pirep->aircraft->registration }}) -
@lang('pireps.flightlevel') {{ $pirep->level }}
@lang('pireps.filedon'): {{ show_datetime($pirep->created_at) }}
-
-
-
-
-
-
diff --git a/resources/views/layouts/default/pireps/show.blade.php b/resources/views/layouts/default/pireps/show.blade.php index 158a41d6..2fca0fdf 100644 --- a/resources/views/layouts/default/pireps/show.blade.php +++ b/resources/views/layouts/default/pireps/show.blade.php @@ -91,7 +91,7 @@
@endif - +
diff --git a/resources/views/layouts/default/pireps/table.blade.php b/resources/views/layouts/default/pireps/table.blade.php index 4337d380..373589b8 100644 --- a/resources/views/layouts/default/pireps/table.blade.php +++ b/resources/views/layouts/default/pireps/table.blade.php @@ -1,5 +1,5 @@
-
@lang('common.state')
+
@@ -36,7 +36,7 @@ @endif
{{ trans_choice('common.flight', 1) }} - {{ (new \App\Support\Units\Time($pirep->flight_time)) }} + @minutestotime($pirep->flight_time) @if($pirep->state === PirepState::PENDING)