From bd8e13e78fd5bdb891c4a3c3bf0d2ed567167a15 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sun, 17 Jan 2021 21:52:22 -0500 Subject: [PATCH] Cleanup Simbrief Briefing pages --- .../Frontend/SimBriefController.php | 48 +- app/Providers/RouteServiceProvider.php | 2 +- .../layouts/default/flights/search.blade.php | 2 +- .../flights/simbrief_aircraft.blade.php | 47 ++ .../flights/simbrief_briefing.blade.php | 6 +- .../default/flights/simbrief_form.blade.php | 790 +++++++++--------- 6 files changed, 466 insertions(+), 429 deletions(-) create mode 100644 resources/views/layouts/default/flights/simbrief_aircraft.blade.php diff --git a/app/Http/Controllers/Frontend/SimBriefController.php b/app/Http/Controllers/Frontend/SimBriefController.php index bd51c000..33bdd8e4 100644 --- a/app/Http/Controllers/Frontend/SimBriefController.php +++ b/app/Http/Controllers/Frontend/SimBriefController.php @@ -57,16 +57,13 @@ class SimBriefController return redirect(route('frontend.flights.index')); } - if (!$aircraft_id) { - flash()->error('Aircraft not selected ! Please select an Aircraft to Proceed ...'); - } - $apiKey = setting('simbrief.api_key'); if (empty($apiKey)) { flash()->error('Invalid SimBrief API key!'); return redirect(route('frontend.flights.index')); } + // Check if a Simbrief profile already exists $simbrief = SimBrief::select('id')->where([ 'flight_id' => $flight_id, 'user_id' => $user->id, @@ -76,6 +73,7 @@ class SimBriefController return redirect(route('frontend.simbrief.briefing', [$simbrief->id])); } + // Simbrief Profile doesn't exist; prompt the user to create a new one $aircraft = Aircraft::select('registration', 'name', 'icao', 'iata', 'subfleet_id') ->where('id', $aircraft_id) ->get(); @@ -92,11 +90,22 @@ class SimBriefController $pax_weight = 208; } + // No aircraft selected, show that form + if (!$aircraft_id) { + return view('flights.simbrief_aircraft', [ + 'flight' => $flight, + 'aircraft' => $aircraft, + 'subfleets' => $subfleets, + 'pax_weight' => $pax_weight, + ]); + } + + // Show the main simbrief form return view('flights.simbrief_form', [ 'flight' => $flight, 'aircraft' => $aircraft, 'subfleets' => $subfleets, - 'pax_weight' => $pax_weight, // TODO: Replace with a setting + 'pax_weight' => $pax_weight, ]); } @@ -136,21 +145,30 @@ class SimBriefController * * @param \Illuminate\Http\Request $request * + * @throws \Exception + * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ - public function remove(Request $request) + public function generate_new(Request $request) { - $sb_pack = SimBrief::find($request->id); - if ($sb_pack) { - if (!$sb_pack->pirep_id) { - $sb_pack->delete(); - } else { - $sb_pack->flight_id = null; - $sb_pack->save(); - } + $simbrief = SimBrief::find($request->id); + + // Invalid Simbrief ID/profile, go back to the main flight index + if (!$simbrief) { + return redirect(route('frontend.flights.index')); } - return redirect(route('frontend.flights.index')); + // Cleanup the current Simbrief entry and redirect to the new generation form + // If there isn't a PIREP ID, then delete the entry, otherwise, remove the flight + $flight_id = $simbrief->flight_id; + if (!$simbrief->pirep_id) { + $simbrief->delete(); + } else { + $simbrief->flight_id = null; + $simbrief->save(); + } + + return redirect(route('frontend.simbrief.generate').'?flight_id='.$flight_id); } /** diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 2cdd142c..aff100a3 100755 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -147,7 +147,7 @@ class RouteServiceProvider extends ServiceProvider 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'); - Route::get('simbrief/{id}/remove', 'SimBriefController@remove')->name('simbrief.remove'); + Route::get('simbrief/{id}/generate_new', 'SimBriefController@generate_new')->name('simbrief.generate_new'); }); Route::group([ diff --git a/resources/views/layouts/default/flights/search.blade.php b/resources/views/layouts/default/flights/search.blade.php index fe842e08..7f505777 100644 --- a/resources/views/layouts/default/flights/search.blade.php +++ b/resources/views/layouts/default/flights/search.blade.php @@ -10,7 +10,7 @@

@lang('common.airline')

- {{ Form::select('airline_id', $airlines, null , ['class' => 'form-control form-control-sm select2']) }} + {{ Form::select('airline_id', $airlines, null , ['class' => 'form-control select2']) }}
diff --git a/resources/views/layouts/default/flights/simbrief_aircraft.blade.php b/resources/views/layouts/default/flights/simbrief_aircraft.blade.php new file mode 100644 index 00000000..aef5dfb6 --- /dev/null +++ b/resources/views/layouts/default/flights/simbrief_aircraft.blade.php @@ -0,0 +1,47 @@ +@extends('app') +@section('title', 'SimBrief Flight Planning') + +@section('content') +
+
+

Select Aircraft for Flight

+
+
+ +
+
+ +
+ +
+@endsection +@section('scripts') + +@endsection diff --git a/resources/views/layouts/default/flights/simbrief_briefing.blade.php b/resources/views/layouts/default/flights/simbrief_briefing.blade.php index ebc3f415..61663d7d 100644 --- a/resources/views/layouts/default/flights/simbrief_briefing.blade.php +++ b/resources/views/layouts/default/flights/simbrief_briefing.blade.php @@ -10,14 +10,14 @@
@if (empty($simbrief->pirep_id)) Prefile PIREP @endif
Generate New OFP + style="margin-top: -10px; margin-bottom: 5px" + href="{{ url(route('frontend.simbrief.generate_new', [$simbrief->id])) }}">Generate New OFP
diff --git a/resources/views/layouts/default/flights/simbrief_form.blade.php b/resources/views/layouts/default/flights/simbrief_form.blade.php index 372b61f9..4575f4b9 100644 --- a/resources/views/layouts/default/flights/simbrief_form.blade.php +++ b/resources/views/layouts/default/flights/simbrief_form.blade.php @@ -2,365 +2,337 @@ @section('title', 'SimBrief Flight Planning') @section('content') + @php + $loadmin = $flight->load_factor - $flight->load_factor_variance; + $loadmax = $flight->load_factor + $flight->load_factor_variance; + if($loadmin < 1) { $loadmin = 1; } + if($loadmax > 100) { $loadmax = 100; } + @endphp - @if(empty(request()->get('aircraft_id'))) -
-
-

Aircraft Selection

-
-
- -
-
- -
- -
- @else - + @foreach($aircraft as $acdetails) @php - $loadmin = $flight->load_factor - $flight->load_factor_variance; - $loadmax = $flight->load_factor + $flight->load_factor_variance; - if($loadmin < 1) { $loadmin = 1; } - if($loadmax > 100) { $loadmax = 100; } + $simbrieftype = $acdetails->icao ; + $subflid = $acdetails->subfleet_id ; + if($acdetails->icao === 'A20N') { $simbrieftype = 'A320'; } + if($acdetails->icao === 'A21N') { $simbrieftype = 'A321'; } + if($acdetails->icao === 'B77L') { $simbrieftype = 'B77F'; } + if($acdetails->icao === 'B773') { $simbrieftype = 'B77W'; } + if($acdetails->icao === 'E35L') { $simbrieftype = 'E135'; } @endphp + @endforeach - @foreach($aircraft as $acdetails) - @php - $simbrieftype = $acdetails->icao ; - $subflid = $acdetails->subfleet_id ; - if($acdetails->icao === 'A20N') { $simbrieftype = 'A320'; } - if($acdetails->icao === 'A21N') { $simbrieftype = 'A321'; } - if($acdetails->icao === 'B77L') { $simbrieftype = 'B77F'; } - if($acdetails->icao === 'B773') { $simbrieftype = 'B77W'; } - if($acdetails->icao === 'E35L') { $simbrieftype = 'E135'; } - @endphp - @endforeach - -
-
-
-
-

Create Flight Briefing Package

-
-
-
-
-
 Aircraft Details
-
-
- - - -
-
- - - -
+ +
+

Create Simbrief Briefing

+
+
+
+
+
+
+
 Aircraft Details
+
+
+ + + +
+
+ + +
-
+
+
-
-
 @lang('pireps.flightinformations') for - {{ $flight->airline->icao }} {{ $flight->flight_number }}
-
-
- - - -
-
- - - -
-
- - -
+
+
 @lang('pireps.flightinformations') for + {{ $flight->airline->icao }} {{ $flight->flight_number }}
+
+
+ + +
-
-
-
- - -
-
- - -
+
+ + +
-
-
-
- - -
-
- - -
-
- - -
+
+ +
-
+
+
+
+ + +
+
+ + +
+
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
-
- @foreach($subfleets as $subfleet) - @if($subfleet->id == $subflid) -
 Configuration And Load Information For - {{ $subfleet->name }} ; {{ $acdetails->registration }}
- {{-- Generate Load Figures --}} -
- {{-- Create and send some data to the $loadarray for MANUALRMK generation --}} - @php $loadarray = [] ; @endphp - @foreach($subfleet->fares as $fare) - @if($fare->capacity > 0) - @php - $randomloadperfare = ceil(($fare->capacity * (rand($loadmin, $loadmax))) /100); - $loadarray[] = ['SeatType' => $fare->code]; - $loadarray[] = ['SeatLoad' => $randomloadperfare]; - @endphp -
- - -
- @endif - @endforeach - @php - $loadcollection = collect($loadarray) ; - $totalgenload = $loadcollection->sum('SeatLoad') ; - @endphp -
- - @if($totalgenload > 0 && $totalgenload < 900) - -
-
+
+ @foreach($subfleets as $subfleet) + @if($subfleet->id == $subflid) +
 Configuration And Load Information For + {{ $subfleet->name }} ; {{ $acdetails->registration }}
+ {{-- Generate Load Figures --}} +
+ {{-- Create and send some data to the $loadarray for MANUALRMK generation --}} + @php $loadarray = [] ; @endphp + @foreach($subfleet->fares as $fare) + @if($fare->capacity > 0) + @php + $randomloadperfare = ceil(($fare->capacity * (rand($loadmin, $loadmax))) /100); + $loadarray[] = ['SeatType' => $fare->code]; + $loadarray[] = ['SeatLoad' => $randomloadperfare]; + @endphp
- @if(setting('units.weight') === 'kg') - @php $estimatedpayload = number_format(round(($pax_weight * $totalgenload) / 2.2)) ; @endphp - @else - @php $estimatedpayload = number_format(round($pax_weight * $totalgenload)) ; @endphp - @endif - - + +
+ @endif + @endforeach + @php + $loadcollection = collect($loadarray) ; + $totalgenload = $loadcollection->sum('SeatLoad') ; + @endphp +
+ + @if($totalgenload > 0 && $totalgenload < 900) + +
+
+
+ @if(setting('units.weight') === 'kg') + @php $estimatedpayload = number_format(round(($pax_weight * $totalgenload) / 2.2)) ; @endphp + @else + @php $estimatedpayload = number_format(round($pax_weight * $totalgenload)) ; @endphp + @endif + +
- - @elseif($totalgenload > 900) - - - @endif +
+ + @elseif($totalgenload > 900) + + @endif - @endforeach -
+ @endif + @endforeach
- {{-- - Here we generate the MANUALRMK which is sent to SimBrief and displayed in the generated - ofp as Dispatch Remarks. $loadarray is created and filled with data during random load - generation, it holds each fare's code and the generated load then we are imploding that - array to get the fare codes and load counts. +
+ {{-- + Here we generate the MANUALRMK which is sent to SimBrief and displayed in the generated + ofp as Dispatch Remarks. $loadarray is created and filled with data during random load + generation, it holds each fare's code and the generated load then we are imploding that + array to get the fare codes and load counts. - Returned string will be like Load Distribution Y 132 C 12 F 4 - --}} - @if($totalgenload > 0) - @php - $loaddisttxt = "Load Distribution "; - $loaddist = implode(' ', array_map( - function ($v, $k) { - if(is_array($v)){ - return implode('&'.' '.':', $v); - }else{ - return $k.':'.$v; - } - }, - $loadarray, array_keys($loadarray) - )); - @endphp - - @endif - - - - - - - - - - - - - + Returned string will be like Load Distribution Y 132 C 12 F 4 + --}} + @if($totalgenload > 0) + @php + $loaddisttxt = "Load Distribution "; + $loaddist = implode(' ', array_map( + function ($v, $k) { + if(is_array($v)){ + return implode('&'.' '.':', $v); + }else{ + return $k.':'.$v; + } + }, + $loadarray, array_keys($loadarray) + )); + @endphp + + @endif + + + + + + + + + + + + + -
-
-
-
 Planning Options
- - - - - - - - - - - - - - - - - - - - - -
Cont Fuel: - -
Reserve Fuel: - -
SID/STAR Type: - -
Plan Stepclimbs: - -
ETOPS Planning: - -
-
-
-
-
 @lang('stisla.briefingoptions')
- - - - - - - - - - - - - - - - - - - - - - - - - -
Units: - -
Detailed Navlog: - -
Runway Analysis: - -
Include NOTAMS: - -
FIR NOTAMS: - -
Flight Maps: - -
-
-
-
-
-
- -
+
+
+
+
 Planning Options
+ + + + + + + + + + + + + + + + + + + + + +
Cont Fuel: + +
Reserve Fuel: + +
SID/STAR Type: + +
Plan Stepclimbs: + +
ETOPS Planning: + +
+
+
+
+
 @lang('stisla.briefingoptions')
+ + + + + + + + + + + + + + + + + + + + + + + + + +
Units: + +
Detailed Navlog: + +
Runway Analysis: + +
Include NOTAMS: + +
FIR NOTAMS: + +
Flight Maps: + +
+
+
+
+
+
+
@@ -369,83 +341,83 @@
- - @endif +
+ @endsection @section('scripts') - - - + + - - + + + var $selectedac = document.getElementById("aircraftselection").value; + var $newlink = "&aircraft_id=".concat($selectedac); + document.getElementById("mylink").href = $oldlink.concat($newlink); + } + @endsection