Simbrief Edit & Download Latest OFP (#1228)

* SimBrief OFP Edit

Changes aim to have ability of editing generated SimBrief Flight Plans and re-downloading.

* Move url to config

* Blade update and $uri change

* Update simbrief_form.blade.php

Used `$flight->id` along with `$user->ident` to have a more unique static id value. No details given for that fields uniqueness requirements, this will be ok I think though. 
Also we are passing user's simbrief userid with api to find the flight plan, both combined, no chance to get another users plan and/or any other plan of same user.

* Update SimBriefController.php

Move `static_id` to controller

* Update simbrief_form.blade.php

Read `static_id` from controller

* StyleFix

* Update phpvms.php

* Update SimBriefService.php

Co-authored-by: Nabeel S <nabeelio@users.noreply.github.com>
This commit is contained in:
B.Fatih KOZ 2021-06-09 18:38:14 +03:00 committed by GitHub
parent 7481dab012
commit 90344fb6e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 87 additions and 8 deletions

View File

@ -70,6 +70,9 @@ class SimBriefController
return redirect(route('frontend.flights.index'));
}
// Generate SimBrief Static ID
$static_id = $user->ident.'_'.$flight->id;
// No aircraft selected, show selection form
if (!$aircraft_id) {
// If no subfleets defined for flight get them from user
@ -237,6 +240,7 @@ class SimBriefController
'tpayload' => $tpayload,
'tcargoload' => $tcargoload,
'loaddist' => implode(' ', $loaddist),
'static_id' => $static_id,
]);
}
@ -367,6 +371,31 @@ class SimBriefController
]);
}
/**
* Get the latest generated OFP. Pass in two additional items, the Simbrief userid and static_id
* This will get the latest edited/regenerated of from Simbrief and update our records
* We do not need to send the fares again, so used an empty array
*/
public function update_ofp(Request $request)
{
/** @var User $user */
$user = Auth::user();
$ofp_id = $request->input('ofp_id');
$flight_id = $request->input('flight_id');
$aircraft_id = $request->input('aircraft_id');
$sb_userid = $request->input('sb_userid');
$sb_static_id = $request->input('sb_static_id');
$fares = [];
$simbrief = $this->simBriefSvc->downloadOfp($user->id, $ofp_id, $flight_id, $aircraft_id, $fares, $sb_userid, $sb_static_id);
if ($simbrief === null) {
$error = new AssetNotFound(new Exception('Simbrief OFP not found'));
return $error->getResponse();
}
return redirect(route('frontend.simbrief.briefing', [$ofp_id]));
}
/**
* Generate the API code
*

View File

@ -140,6 +140,7 @@ class RouteServiceProvider extends ServiceProvider
Route::get('simbrief/generate', 'SimBriefController@generate')->name('simbrief.generate');
Route::post('simbrief/apicode', 'SimBriefController@api_code')->name('simbrief.api_code');
Route::get('simbrief/check_ofp', 'SimBriefController@check_ofp')->name('simbrief.check_ofp');
Route::get('simbrief/update_ofp', 'SimBriefController@update_ofp')->name('simbrief.update_ofp');
Route::get('simbrief/{id}', 'SimBriefController@briefing')->name('simbrief.briefing');
Route::get('simbrief/{id}/prefile', 'SimBriefController@prefile')->name('simbrief.prefile');
Route::get('simbrief/{id}/cancel', 'SimBriefController@cancel')->name('simbrief.cancel');

View File

@ -26,11 +26,13 @@ class SimBriefService extends Service
* Check to see if the OFP exists server-side. If it does, download it and
* cache it immediately
*
* @param string $user_id User who generated this
* @param string $ofp_id The SimBrief OFP ID
* @param string $flight_id The flight ID
* @param string $ac_id The aircraft ID
* @param array $fares Full list of fares for the flightß
* @param string $user_id User who generated this
* @param string $ofp_id The SimBrief OFP ID
* @param string $flight_id The flight ID
* @param string $ac_id The aircraft ID
* @param array $fares Full list of fares for the flight
* @param string $sb_userid User's Simbrief ID (Used for Update)
* @param string $sb_static_id Static ID for the generated OFP (Used for Update)
*
* @return SimBrief|null
*/
@ -39,10 +41,18 @@ class SimBriefService extends Service
string $ofp_id,
string $flight_id,
string $ac_id,
array $fares = []
array $fares = [],
string $sb_user_id = null,
string $sb_static_id = null
) {
$uri = str_replace('{id}', $ofp_id, config('phpvms.simbrief_url'));
if ($sb_user_id && $sb_static_id) {
// $uri = str_replace('{sb_user_id}', $sb_user_id, config('phpvms.simbrief_update_url'));
// $uri = str_replace('{sb_static_id}', $sb_static_id, $uri);
$uri = 'https://www.simbrief.com/api/xml.fetcher.php?userid='.$sb_user_id.'&static_id='.$sb_static_id;
}
$opts = [
'connect_timeout' => 2, // wait two seconds by default
'allow_redirects' => false,

View File

@ -52,6 +52,11 @@ return [
*/
'simbrief_url' => 'https://www.simbrief.com/ofp/flightplans/xml/{id}.xml',
/*
* URL for fetching an updated Simbrief flight plan via API
*/
'simbrief_update_url' => 'https://www.simbrief.com/api/xml.fetcher.php?userid={sb_user_id}&static_id={sb_static_id}',
/*
* Your vaCentral API key
*/

View File

@ -7,14 +7,22 @@
<h2>{{ $simbrief->xml->general->icao_airline }}{{ $simbrief->xml->general->flight_number }}
: {{ $simbrief->xml->origin->icao_code }} to {{ $simbrief->xml->destination->icao_code }}</h2>
</div>
<div class="col-sm-3">
<div class="col-sm-2">
@if (empty($simbrief->pirep_id))
<a class="btn btn-outline-info pull-right btn-lg"
style="margin-top: -10px; margin-bottom: 5px"
href="{{ url(route('frontend.simbrief.prefile', [$simbrief->id])) }}">Prefile PIREP</a>
@endif
</div>
<div class="col-sm-3">
<div class="col-sm-2">
@if (!empty($simbrief->xml->params->static_id) && Auth::id() == $simbrief->user_id)
<a class="btn btn-secondary pull-right btn-lg"
style="margin-top: -10px; margin-bottom: 5px"
href="#"
data-toggle="modal" data-target="#OFP_Edit">Edit OFP</a>
@endif
</div>
<div class="col-sm-2">
<a class="btn btn-primary pull-right btn-lg"
style="margin-top: -10px; margin-bottom: 5px"
href="{{ url(route('frontend.simbrief.generate_new', [$simbrief->id])) }}">Generate New OFP</a>
@ -284,6 +292,31 @@
@endif
</div>
</div>
{{-- SimBrief Edit Modal --}}
@if(!empty($simbrief->xml->params->static_id))
<div class="modal fade" id="OFP_Edit" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog" style="max-width: 1020px;">
<div class="modal-content p-0" style="border-radius: 5px;">
<div class="modal-header p-1">
<h5 class="modal-title m-1 p-0">SimBrief</h5>
<span class="close"><i class="fas fa-times-circle" data-dismiss="modal" aria-label="Close" aria-hidden="true"></i></span>
</div>
<div class="modal-body p-0">
<iframe src="https://www.simbrief.com/system/dispatch.php?editflight=last&static_id={{ $simbrief->xml->params->static_id }}" style="width: 100%; height: 80vh;" frameBorder="0" title="SimBrief"></iframe>
</div>
<div class="modal-footer text-right p-1">
<a
class="btn btn-success btn-sm m-1 p-1"
href="{{ route('frontend.simbrief.update_ofp') }}?ofp_id={{ $simbrief->id }}&flight_id={{ $simbrief->flight_id }}&aircraft_id={{ $simbrief->aircraft_id }}&sb_userid={{ $simbrief->xml->params->user_id }}&sb_static_id={{ $simbrief->xml->params->static_id }}">
Download Updated OFP & Close
</a>
<button type="button" class="btn btn-danger btn-sm m-1 p-1" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
@endif
@endsection
@section('scripts')

View File

@ -160,6 +160,7 @@
<input type="hidden" name="omit_stars" value="0">
<input type="hidden" name="cruise" value="CI">
<input type="hidden" name="civalue" value="AUTO">
<input type="hidden" name="static_id" value="{{ $static_id }}">
{{-- For more info about form fields and their details check SimBrief Forum / API Support --}}
</div>
<div class="col-4">