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
This commit is contained in:
Nabeel S 2020-03-01 15:51:00 -05:00 committed by GitHub
parent 21e2e48a6e
commit 4a14e83c88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 557 additions and 512 deletions

1
.gitignore vendored
View File

@ -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/

View File

@ -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,
],
];

View File

@ -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);
}

View File

@ -1,223 +0,0 @@
<?php
/**
* Admin Routes
*/
use Illuminate\Support\Facades\Route;
Route::group(
[
'namespace' => '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');
}
);

View File

@ -1,93 +0,0 @@
<?php
/**
* Public routes
*/
use Illuminate\Support\Facades\Route;
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');
});

View File

@ -1,60 +0,0 @@
<?php
use App\Http\Middleware\SetActiveTheme;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
/*
* These are only visible to a logged in user
*/
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');
});
/**
* 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');

View File

@ -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);
}
/**

View File

@ -0,0 +1,48 @@
<?php
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 Illuminate\Support\ServiceProvider;
class ObserverServiceProviders extends ServiceProvider
{
public function boot(): void
{
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);
}
}

View File

@ -2,7 +2,9 @@
namespace App\Providers;
use App\Http\Middleware\SetActiveTheme;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
@ -24,6 +26,7 @@ class RouteServiceProvider extends ServiceProvider
public function map()
{
$this->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');
});
});
}
}

View File

@ -1,6 +1,7 @@
<?php
use App\Exceptions\SettingNotFound;
use App\Repositories\SettingRepository;
use Carbon\Carbon;
use Illuminate\Contracts\View\Factory;
@ -157,7 +158,7 @@ if (!function_exists('setting')) {
*/
function setting($key, $default = null)
{
$settingRepo = app('setting');
$settingRepo = app(SettingRepository::class);
try {
$value = $settingRepo->retrieve($key);

View File

@ -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,
],

4
resources/docker/.gitignore vendored Executable file
View File

@ -0,0 +1,4 @@
*
!nginx/
!php/
!.gitignore

View File

@ -60,17 +60,17 @@
</div>
<div class="card">
<div class="nav nav-tabs" role="tablist" style="background: #067ec1; color: #FFF;">
@lang('dashboard.yourlastreport')
</div>
<div class="nav nav-tabs" role="tablist" style="background: #067ec1; color: #FFF;">
@lang('dashboard.yourlastreport')
</div>
<div class="card border-blue-bottom">
@if($last_pirep === null)
<div class="card-body" style="text-align:center;">
@lang('dashboard.noreportsyet') <a
href="{{ route('frontend.pireps.create') }}">@lang('dashboard.fileonenow')</a>
</div>
@else
@include('pireps.pirep_card', ['pirep' => $last_pirep])
@include('dashboard.pirep_card', ['pirep' => $last_pirep])
@endif
</div>

View File

@ -0,0 +1,66 @@
<div class="card-body" style="min-height: 0px">
<div class="row">
<div class="col-12">
<p class="float-right">
<a href="{{ route('frontend.pireps.edit', [$pirep->id]) }}"
class="btn btn-sm btn-info">@lang('common.edit')</a>
</p>
<h5>
<a href="{{ route('frontend.pireps.show', [$pirep->id]) }}">
{{ $pirep->airline->code }}{{ $pirep->ident }}</a>
-
{{ $pirep->dpt_airport->name }}
(<a href="{{route('frontend.airports.show', [
'id' => $pirep->dpt_airport->icao
])}}">{{$pirep->dpt_airport->icao}}</a>)
<span class="description">to</span>
{{ $pirep->arr_airport->name }}
(<a href="{{route('frontend.airports.show', [
'id' => $pirep->arr_airport->icao
])}}">{{$pirep->arr_airport->icao}}</a>)
</h5>
</div>
<div class="col-sm-2 text-center">
<div>
@if($pirep->state === PirepState::PENDING)
<div class="badge badge-warning">
@elseif($pirep->state === PirepState::ACCEPTED)
<div class="badge badge-success">
@elseif($pirep->state === PirepState::REJECTED)
<div class="badge badge-danger">
@else
<div class="badge badge-info">
@endif
{{ PirepState::label($pirep->state) }}</div>
</div>
</div>
<div class="col-sm-10">
<div class="row">
<div class="col-sm-12">
<table class="table-condensed" width="100%">
<tr>
<td nowrap><span class="title">@lang('pireps.flighttime')&nbsp;</span></td>
<td>@minutestotime($pirep->flight_time)</td>
</tr>
<tr>
<td nowrap><span class="title">@lang('common.aircraft')&nbsp;</span></td>
<td>{{ $pirep->aircraft->name }}
({{ $pirep->aircraft->registration }})
</td>
</tr>
@if($pirep->level)
<tr>
<td nowrap><span class="title">@lang('pireps.flightlevel')&nbsp;</span></td>
<td>{{ $pirep->level }}</td>
</tr>
@endif
<tr>
<td nowrap><span class="title">@lang('pireps.filedon'):&nbsp;</span></td>
<td>{{ show_datetime($pirep->created_at) }}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>

View File

@ -1,68 +0,0 @@
<div class="card border-blue-bottom">
<div class="card-block" style="min-height: 0px">
<div class="row">
<div class="col-12">
<p class="float-right">
<a href="{{ route('frontend.pireps.edit', [$pirep->id]) }}"
class="btn btn-sm btn-info">@lang('common.edit')</a>
</p>
<h5>
<a href="{{ route('frontend.pireps.show', [$pirep->id]) }}">
{{ $pirep->airline->code }}{{ $pirep->ident }}</a>
-
{{ $pirep->dpt_airport->name }}
(<a href="{{route('frontend.airports.show', [
'id' => $pirep->dpt_airport->icao
])}}">{{$pirep->dpt_airport->icao}}</a>)
<span class="description">to</span>
{{ $pirep->arr_airport->name }}
(<a href="{{route('frontend.airports.show', [
'id' => $pirep->arr_airport->icao
])}}">{{$pirep->arr_airport->icao}}</a>)
</h5>
</div>
<div class="col-sm-2 text-center">
<div>
@if($pirep->state === PirepState::PENDING)
<div class="badge badge-warning">
@elseif($pirep->state === PirepState::ACCEPTED)
<div class="badge badge-success">
@elseif($pirep->state === PirepState::REJECTED)
<div class="badge badge-danger">
@else
<div class="badge badge-info">
@endif
{{ PirepState::label($pirep->state) }}</div>
</div>
</div>
<div class="col-sm-10">
<div class="row">
<div class="col-sm-12">
<table class="table-condensed" width="100%">
<tr>
<td nowrap><span class="title">@lang('pireps.flighttime')&nbsp;</span></td>
<td>@minutestotime($pirep->flight_time)</td>
</tr>
<tr>
<td nowrap><span class="title">@lang('common.aircraft')&nbsp;</span></td>
<td>{{ $pirep->aircraft->name }}
({{ $pirep->aircraft->registration }})
</td>
</tr>
@if($pirep->level)
<tr>
<td nowrap><span class="title">@lang('pireps.flightlevel')&nbsp;</span></td>
<td>{{ $pirep->level }}</td>
</tr>
@endif
<tr>
<td nowrap><span class="title">@lang('pireps.filedon'):&nbsp;</span></td>
<td>{{ show_datetime($pirep->created_at) }}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</div>

View File

@ -91,7 +91,7 @@
</form>
</div>
@endif
<table class="table table-striped table-condensed">
<table class="table table-striped">
<tr>
<td width="30%">@lang('common.state')</td>

View File

@ -1,5 +1,5 @@
<div class="table-responsive">
<table class="table table-sm table-hover table-striped">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>{{ trans_choice('common.flight', 1) }}</th>
@ -36,7 +36,7 @@
@endif
</td>
<td class="text-center">
{{ (new \App\Support\Units\Time($pirep->flight_time)) }}
@minutestotime($pirep->flight_time)
</td>
<td class="text-center">
@if($pirep->state === PirepState::PENDING)