Add ability to launch acars for flight/bid #1272 (#1273)

* Add ability to launch acars for flight/bid #1272

* Check for module active/inactive status

* Just some formatting
This commit is contained in:
Nabeel S 2021-08-06 14:53:04 -04:00 committed by GitHub
parent 95e1df619e
commit 564f9ec06e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 25 deletions

View File

@ -13,6 +13,7 @@ use App\Repositories\FlightRepository;
use App\Repositories\SubfleetRepository; use App\Repositories\SubfleetRepository;
use App\Repositories\UserRepository; use App\Repositories\UserRepository;
use App\Services\GeoService; use App\Services\GeoService;
use App\Services\ModuleService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@ -25,6 +26,7 @@ class FlightController extends Controller
private $airlineRepo; private $airlineRepo;
private $airportRepo; private $airportRepo;
private $flightRepo; private $flightRepo;
private $moduleSvc;
private $subfleetRepo; private $subfleetRepo;
private $geoSvc; private $geoSvc;
private $userRepo; private $userRepo;
@ -34,6 +36,7 @@ class FlightController extends Controller
* @param AirportRepository $airportRepo * @param AirportRepository $airportRepo
* @param FlightRepository $flightRepo * @param FlightRepository $flightRepo
* @param GeoService $geoSvc * @param GeoService $geoSvc
* @param ModuleService $moduleSvc
* @param SubfleetRepository $subfleetRepo * @param SubfleetRepository $subfleetRepo
* @param UserRepository $userRepo * @param UserRepository $userRepo
*/ */
@ -42,6 +45,7 @@ class FlightController extends Controller
AirportRepository $airportRepo, AirportRepository $airportRepo,
FlightRepository $flightRepo, FlightRepository $flightRepo,
GeoService $geoSvc, GeoService $geoSvc,
ModuleService $moduleSvc,
SubfleetRepository $subfleetRepo, SubfleetRepository $subfleetRepo,
UserRepository $userRepo UserRepository $userRepo
) { ) {
@ -49,6 +53,7 @@ class FlightController extends Controller
$this->airportRepo = $airportRepo; $this->airportRepo = $airportRepo;
$this->flightRepo = $flightRepo; $this->flightRepo = $flightRepo;
$this->geoSvc = $geoSvc; $this->geoSvc = $geoSvc;
$this->moduleSvc = $moduleSvc;
$this->subfleetRepo = $subfleetRepo; $this->subfleetRepo = $subfleetRepo;
$this->userRepo = $userRepo; $this->userRepo = $userRepo;
} }
@ -108,7 +113,12 @@ class FlightController extends Controller
// Get only used Flight Types for the search form // Get only used Flight Types for the search form
// And filter according to settings // And filter according to settings
$usedtypes = Flight::select('flight_type')->where($where)->groupby('flight_type')->orderby('flight_type', 'asc')->get(); $usedtypes = Flight::select('flight_type')
->where($where)
->groupby('flight_type')
->orderby('flight_type')
->get();
// Build collection with type codes and labels // Build collection with type codes and labels
$flight_types = collect('', ''); $flight_types = collect('', '');
foreach ($usedtypes as $ftype) { foreach ($usedtypes as $ftype) {
@ -123,12 +133,20 @@ class FlightController extends Controller
'simbrief' => function ($query) use ($user) { 'simbrief' => function ($query) use ($user) {
$query->where('user_id', $user->id); $query->where('user_id', $user->id);
}, ]) }, ])
->orderBy('flight_number', 'asc') ->orderBy('flight_number')
->orderBy('route_leg', 'asc') ->orderBy('route_leg')
->paginate(); ->paginate();
$saved_flights = Bid::where('user_id', Auth::id()) $saved_flights = [];
->pluck('flight_id')->toArray(); $bids = Bid::where('user_id', Auth::id())->get();
foreach ($bids as $bid) {
if (!$bid->flight) {
$bid->delete();
continue;
}
$saved_flights[$bid->flight_id] = $bid->id;
}
return view('flights.index', [ return view('flights.index', [
'user' => $user, 'user' => $user,
@ -145,6 +163,7 @@ class FlightController extends Controller
'subfleet_id' => $request->input('subfleet_id'), 'subfleet_id' => $request->input('subfleet_id'),
'simbrief' => !empty(setting('simbrief.api_key')), 'simbrief' => !empty(setting('simbrief.api_key')),
'simbrief_bids' => setting('simbrief.only_bids'), 'simbrief_bids' => setting('simbrief.only_bids'),
'acars_plugin' => $this->moduleSvc->isModuleActive('VMSAcars'),
]); ]);
} }
@ -171,7 +190,7 @@ class FlightController extends Controller
} }
$flights->add($bid->flight); $flights->add($bid->flight);
$saved_flights[] = $bid->flight->id; $saved_flights[$bid->flight_id] = $bid->id;
} }
return view('flights.bids', [ return view('flights.bids', [
@ -183,6 +202,7 @@ class FlightController extends Controller
'subfleets' => $this->subfleetRepo->selectBoxList(true), 'subfleets' => $this->subfleetRepo->selectBoxList(true),
'simbrief' => !empty(setting('simbrief.api_key')), 'simbrief' => !empty(setting('simbrief.api_key')),
'simbrief_bids' => setting('simbrief.only_bids'), 'simbrief_bids' => setting('simbrief.only_bids'),
'acars_plugin' => $this->moduleSvc->isModuleActive('VMSAcars'),
]); ]);
} }
@ -206,6 +226,7 @@ class FlightController extends Controller
return view('flights.show', [ return view('flights.show', [
'flight' => $flight, 'flight' => $flight,
'map_features' => $map_features, 'map_features' => $map_features,
'acars_plugin' => $this->moduleSvc->isModuleActive('VMSAcars'),
]); ]);
} }
} }

View File

@ -120,13 +120,14 @@ class ModuleService extends Service
* *
* @return bool * @return bool
*/ */
public function moduleActive(string $name): bool public function isModuleActive(string $name): bool
{ {
$module = Module::where('name', $name); $module = Module::where('name', $name)->first();
if (!$module->exists()) { if (empty($module)) {
return false; return false;
} }
/** @var \Nwidart\Modules\Module $moduleInstance */
$moduleInstance = \Nwidart\Modules\Facades\Module::find($module->name); $moduleInstance = \Nwidart\Modules\Facades\Module::find($module->name);
if (empty($moduleInstance)) { if (empty($moduleInstance)) {
return false; return false;
@ -136,7 +137,7 @@ class ModuleService extends Service
return false; return false;
} }
return true; return $moduleInstance->isEnabled();
} }
/** /**
@ -144,7 +145,7 @@ class ModuleService extends Service
* *
* @param $id * @param $id
* *
* @return object * @return Module
*/ */
public function getModule($id): Module public function getModule($id): Module
{ {
@ -190,17 +191,14 @@ class ModuleService extends Service
*/ */
public function installModule(UploadedFile $file): FlashNotifier public function installModule(UploadedFile $file): FlashNotifier
{ {
$file_ext = $file->getClientOriginalExtension(); $file_ext = strtolower($file->getClientOriginalExtension());
$allowed_extensions = ['zip', 'tar', 'gz']; $allowed_extensions = ['zip', 'tar', 'gz'];
if (!in_array($file_ext, $allowed_extensions, true)) { if (!in_array($file_ext, $allowed_extensions, true)) {
throw new ModuleInvalidFileType(); throw new ModuleInvalidFileType();
} }
$module = null;
$new_dir = rand(); $new_dir = rand();
File::makeDirectory( File::makeDirectory(
storage_path('app/tmp/modules/'.$new_dir), storage_path('app/tmp/modules/'.$new_dir),
0777, 0777,

View File

@ -22,9 +22,9 @@
"x-saved-class" is the class to add/remove if the bid exists or not "x-saved-class" is the class to add/remove if the bid exists or not
If you change it, remember to change it in the in-array line as well If you change it, remember to change it in the in-array line as well
--}} --}}
@if (!setting('pilots.only_flights_from_current') || $flight->dpt_airport_id == Auth::user()->current_airport->icao) @if (!setting('pilots.only_flights_from_current') || $flight->dpt_airport_id == $user->current_airport->icao)
<button class="btn btn-round btn-icon btn-icon-mini save_flight <button class="btn btn-round btn-icon btn-icon-mini save_flight
{{ in_array($flight->id, $saved, true) ? 'btn-info':'' }}" {{ isset($saved[$flight->id]) ? 'btn-info':'' }}"
x-id="{{ $flight->id }}" x-id="{{ $flight->id }}"
x-saved-class="btn-info" x-saved-class="btn-info"
type="button" type="button"
@ -39,16 +39,12 @@
{{--<table class="table-condensed"></table>--}} {{--<table class="table-condensed"></table>--}}
<span class="title">{{ strtoupper(__('flights.dep')) }}&nbsp;</span> <span class="title">{{ strtoupper(__('flights.dep')) }}&nbsp;</span>
{{ optional($flight->dpt_airport)->name ?? $flight->dpt_airport_id }} {{ optional($flight->dpt_airport)->name ?? $flight->dpt_airport_id }}
(<a href="{{route('frontend.airports.show', [ (<a href="{{route('frontend.airports.show', ['id' => $flight->dpt_airport_id])}}">{{$flight->dpt_airport_id}}</a>)
'id' => $flight->dpt_airport_id
])}}">{{$flight->dpt_airport_id}}</a>)
@if($flight->dpt_time), {{ $flight->dpt_time }}@endif @if($flight->dpt_time), {{ $flight->dpt_time }}@endif
<br/> <br/>
<span class="title">{{ strtoupper(__('flights.arr')) }}&nbsp;</span> <span class="title">{{ strtoupper(__('flights.arr')) }}&nbsp;</span>
{{ optional($flight->arr_airport)->name ?? $flight->arr_airport_id }} {{ optional($flight->arr_airport)->name ?? $flight->arr_airport_id }}
(<a href="{{route('frontend.airports.show', [ (<a href="{{route('frontend.airports.show', ['id' => $flight->arr_airport_id])}}">{{$flight->arr_airport_id}}</a>)
'id' => $flight->arr_airport_id
])}}">{{$flight->arr_airport_id}}</a>)
@if($flight->arr_time), {{ $flight->arr_time }}@endif @if($flight->arr_time), {{ $flight->arr_time }}@endif
<br/> <br/>
@if(filled($flight->callsign)) @if(filled($flight->callsign))
@ -76,6 +72,13 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-12 text-right"> <div class="col-sm-12 text-right">
@if ($acars_plugin)
@if (isset($saved[$flight->id]))
<a href="vmsacars:bid/{{ $saved[$flight->id] }}" class="btn btn-sm btn-outline-primary">Load in vmsACARS</a>
@else
<a href="vmsacars:flight/{{ $flight->id }}" class="btn btn-sm btn-outline-primary">Load in vmsACARS</a>
@endif
@endif
<!-- Simbrief enabled --> <!-- Simbrief enabled -->
@if ($simbrief !== false) @if ($simbrief !== false)
<!-- If this flight has a briefing, show the link to view it--> <!-- If this flight has a briefing, show the link to view it-->
@ -86,7 +89,7 @@
</a> </a>
@else @else
<!-- Show button if the bids-only is disable, or if bids-only is enabled, they've saved it --> <!-- Show button if the bids-only is disable, or if bids-only is enabled, they've saved it -->
@if ($simbrief_bids === false || ($simbrief_bids === true && in_array($flight->id, $saved, true))) @if ($simbrief_bids === false || ($simbrief_bids === true && isset($saved[$flight->id])))
<a href="{{ route('frontend.simbrief.generate') }}?flight_id={{ $flight->id }}" <a href="{{ route('frontend.simbrief.generate') }}?flight_id={{ $flight->id }}"
class="btn btn-sm btn-outline-primary"> class="btn btn-sm btn-outline-primary">
Create Simbrief Flight Plan Create Simbrief Flight Plan
@ -94,7 +97,6 @@
@endif @endif
@endif @endif
@endif @endif
<a href="{{ route('frontend.pireps.create') }}?flight_id={{ $flight->id }}" <a href="{{ route('frontend.pireps.create') }}?flight_id={{ $flight->id }}"
class="btn btn-sm btn-outline-info"> class="btn btn-sm btn-outline-info">
{{ __('pireps.newpirep') }} {{ __('pireps.newpirep') }}