Add link to download ACARS config from profile (#539)

* Add link to download ACARS config from profile

* Formatting
This commit is contained in:
Nabeel S
2020-02-07 13:29:43 -05:00
committed by GitHub
parent 94cfbd4748
commit dd9fbdb6f1
4 changed files with 50 additions and 6 deletions

View File

@@ -18,10 +18,8 @@ use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Intervention\Image\Facades\Image; use Intervention\Image\Facades\Image;
use Laracasts\Flash\Flash; use Laracasts\Flash\Flash;
use Nwidart\Modules\Facades\Module;
/**
* Class ProfileController
*/
class ProfileController extends Controller class ProfileController extends Controller
{ {
private $airlineRepo; private $airlineRepo;
@@ -45,6 +43,21 @@ class ProfileController extends Controller
$this->userRepo = $userRepo; $this->userRepo = $userRepo;
} }
/**
* Return whether the vmsACARS module is enabled or not
*/
private function acarsEnabled(): bool
{
// Is the ACARS module enabled?
$acars_enabled = false;
$acars = Module::find('VMSACARS');
if ($acars) {
$acars_enabled = $acars->isEnabled();
}
return $acars_enabled;
}
/** /**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/ */
@@ -57,6 +70,7 @@ class ProfileController extends Controller
} }
return view('profile.index', [ return view('profile.index', [
'acars' => $this->acarsEnabled(),
'user' => Auth::user(), 'user' => Auth::user(),
'airports' => $airports, 'airports' => $airports,
]); ]);
@@ -119,7 +133,7 @@ class ProfileController extends Controller
* *
* @throws \Prettus\Validator\Exceptions\ValidatorException * @throws \Prettus\Validator\Exceptions\ValidatorException
* *
* @return $this * @return mixed
*/ */
public function update(Request $request) public function update(Request $request)
{ {
@@ -200,4 +214,24 @@ class ProfileController extends Controller
return redirect(route('frontend.profile.index')); return redirect(route('frontend.profile.index'));
} }
/**
* Generate the ACARS config and send it to download
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response
*/
public function acars(Request $request)
{
$user = Auth::user();
$config = view('system.acars.config', ['user' => $user])->render();
return response($config)->withHeaders([
'Content-Type' => 'text/xml',
'Content-Length' => strlen($config),
'Cache-Control' => 'no-store, no-cache',
'Content-Disposition' => 'attachment; filename="settings.xml',
]);
}
} }

View File

@@ -48,8 +48,9 @@ Route::group([
Route::get('pireps/fares', 'PirepController@fares'); Route::get('pireps/fares', 'PirepController@fares');
Route::post('pireps/{id}/submit', 'PirepController@submit')->name('pireps.submit'); Route::post('pireps/{id}/submit', 'PirepController@submit')->name('pireps.submit');
Route::get('profile/regen_apikey', 'ProfileController@regen_apikey') Route::get('profile/acars', 'ProfileController@acars')->name('profile.acars');
->name('profile.regen_apikey'); Route::get('profile/regen_apikey', 'ProfileController@regen_apikey')->name('profile.regen_apikey');
Route::resource('profile', 'ProfileController'); Route::resource('profile', 'ProfileController');
}); });

View File

@@ -94,6 +94,11 @@
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-12">
<div class="text-right"> <div class="text-right">
@if ($acars)
<a href="{{ route('frontend.profile.acars') }}" class="btn btn-primary"
onclick="alert('Save to \'My Documents/phpVMS\'')">ACARS Config</a>
&nbsp;
@endif
<a href="{{ route('frontend.profile.regen_apikey') }}" class="btn btn-warning" <a href="{{ route('frontend.profile.regen_apikey') }}" class="btn btn-warning"
onclick="return confirm({{ __('Are you sure? This will reset your API key.') }})">@lang('profile.newapikey')</a> onclick="return confirm({{ __('Are you sure? This will reset your API key.') }})">@lang('profile.newapikey')</a>
&nbsp; &nbsp;

View File

@@ -0,0 +1,4 @@
<AcarsConfiguration xmlns="http://schemas.phpvms.net/acars/config">
<AirlineUrl>{{ config('app.url') }}</AirlineUrl>
<ApiKey>{{ $user->api_key }}</ApiKey>
</AcarsConfiguration>