Launch ACARS link on the simbrief page #1272 (#1276)

This commit is contained in:
Nabeel S 2021-08-09 12:01:27 -04:00 committed by GitHub
parent 6eb883de73
commit 4125cdd373
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 31 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\Frontend;
use App\Exceptions\AssetNotFound;
use App\Models\Aircraft;
use App\Models\Bid;
use App\Models\Enums\AircraftState;
use App\Models\Enums\AircraftStatus;
use App\Models\Enums\FareType;
@ -14,6 +15,7 @@ use App\Models\SimBrief;
use App\Models\User;
use App\Repositories\FlightRepository;
use App\Services\FareService;
use App\Services\ModuleService;
use App\Services\SimBriefService;
use App\Services\UserService;
use Exception;
@ -24,17 +26,20 @@ class SimBriefController
{
private $fareSvc;
private $flightRepo;
private $moduleSvc;
private $simBriefSvc;
private $userSvc;
public function __construct(
FareService $fareSvc,
FlightRepository $flightRepo,
ModuleService $moduleSvc,
SimBriefService $simBriefSvc,
UserService $userSvc
) {
$this->fareSvc = $fareSvc;
$this->flightRepo = $flightRepo;
$this->moduleSvc = $moduleSvc;
$this->simBriefSvc = $simBriefSvc;
$this->userSvc = $userSvc;
}
@ -106,6 +111,7 @@ class SimBriefController
if (setting('simbrief.block_aircraft')) {
// Build a list of aircraft_id's being used for active sb packs
$sb_aircraft = SimBrief::whereNotNull('flight_id')->pluck('aircraft_id');
// Filter aircraft list to non used/blocked ones
$aircrafts = $aircrafts->whereNotIn('id', $sb_aircraft);
}
@ -225,7 +231,7 @@ class SimBriefController
// Show the main simbrief form
return view('flights.simbrief_form', [
'user' => Auth::user(),
'user' => $user,
'flight' => $flight,
'aircraft' => $aircraft,
'pax_weight' => $pax_weight,
@ -253,7 +259,11 @@ class SimBriefController
*/
public function briefing($id)
{
$simbrief = SimBrief::find($id);
/** @var User $user */
$user = Auth::user();
/** @var SimBrief $simbrief */
$simbrief = SimBrief::with(['flight'])->find($id);
if (!$simbrief) {
flash()->error('SimBrief briefing not found');
return redirect(route('frontend.flights.index'));
@ -266,11 +276,18 @@ class SimBriefController
$equipment = substr($str, $wc + 1, $tr - 2);
$transponder = substr($str, $tr + 1);
// See if a bid exists for this flight
$bid = Bid::where(['user_id' => $user->id, 'flight_id' => $simbrief->flight_id])->first();
return view('flights.simbrief_briefing', [
'user' => $user,
'simbrief' => $simbrief,
'wakecat' => $wakecat,
'equipment' => $equipment,
'transponder' => $transponder,
'bid' => $bid,
'flight' => $simbrief->flight,
'acars_plugin' => $this->moduleSvc->isModuleActive('VMSAcars'),
]);
}

View File

@ -195,22 +195,22 @@ class Pirep extends Model
/**
* Create a new PIREP from a SimBrief instance
*
* @param \App\Models\SimBrief $simBrief
* @param \App\Models\SimBrief $simbrief
*
* @return \App\Models\Pirep
*/
public static function fromSimBrief(SimBrief $simBrief): self
public static function fromSimBrief(SimBrief $simbrief): self
{
return new self([
'flight_id' => $simBrief->flight->id,
'airline_id' => $simBrief->flight->airline_id,
'flight_number' => $simBrief->flight->flight_number,
'route_code' => $simBrief->flight->route_code,
'route_leg' => $simBrief->flight->route_leg,
'dpt_airport_id' => $simBrief->flight->dpt_airport_id,
'arr_airport_id' => $simBrief->flight->arr_airport_id,
'route' => $simBrief->xml->getRouteString(),
'level' => $simBrief->xml->getFlightLevel(),
'flight_id' => $simbrief->flight->id,
'airline_id' => $simbrief->flight->airline_id,
'flight_number' => $simbrief->flight->flight_number,
'route_code' => $simbrief->flight->route_code,
'route_leg' => $simbrief->flight->route_leg,
'dpt_airport_id' => $simbrief->flight->dpt_airport_id,
'arr_airport_id' => $simbrief->flight->arr_airport_id,
'route' => $simbrief->xml->getRouteString(),
'level' => $simbrief->xml->getFlightLevel(),
]);
}

View File

@ -92,14 +92,13 @@ class SimBrief extends Model
public function flight()
{
if (!empty($this->attributes['flight_id'])) {
return $this->belongsTo(Flight::class, 'flight_id');
}
if (!empty($this->attributes['pirep_id'])) {
public function pirep()
{
return $this->belongsTo(Pirep::class, 'pirep_id');
}
}
public function user()
{

View File

@ -7,26 +7,39 @@
<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-2">
<div class="col">
@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-2">
@if (!empty($simbrief->xml->params->static_id) && Auth::id() == $simbrief->user_id)
<a class="btn btn-secondary pull-right btn-lg"
@if (!empty($simbrief->xml->params->static_id) && $user === $simbrief->user_id)
<div class="col">
<a class="btn btn-secondary 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"
@endif
<div class="col">
<a class="btn btn-primary btn-lg"
style="margin-top: -10px; margin-bottom: 5px"
href="{{ url(route('frontend.simbrief.generate_new', [$simbrief->id])) }}">Generate New OFP</a>
</div>
<div class="col">
@if ($acars_plugin)
@if ($bid)
<a href="vmsacars:bid/{{$bid->id}}"
style="margin-top: -10px; margin-bottom: 5px"
class="btn btn-info btn-lg">Load in vmsACARS</a>
@else
<a href="vmsacars:flight/{{$flight->id}}"
style="margin-top: -10px; margin-bottom: 5px"
class="btn btn-info btn-lg">Load in vmsACARS</a>
@endif
@endif
</div>
</div>
<div class="row">