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

View File

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

View File

@ -22,9 +22,9 @@
"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 (!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
{{ in_array($flight->id, $saved, true) ? 'btn-info':'' }}"
{{ isset($saved[$flight->id]) ? 'btn-info':'' }}"
x-id="{{ $flight->id }}"
x-saved-class="btn-info"
type="button"
@ -39,16 +39,12 @@
{{--<table class="table-condensed"></table>--}}
<span class="title">{{ strtoupper(__('flights.dep')) }}&nbsp;</span>
{{ optional($flight->dpt_airport)->name ?? $flight->dpt_airport_id }}
(<a href="{{route('frontend.airports.show', [
'id' => $flight->dpt_airport_id
])}}">{{$flight->dpt_airport_id}}</a>)
(<a href="{{route('frontend.airports.show', ['id' => $flight->dpt_airport_id])}}">{{$flight->dpt_airport_id}}</a>)
@if($flight->dpt_time), {{ $flight->dpt_time }}@endif
<br/>
<span class="title">{{ strtoupper(__('flights.arr')) }}&nbsp;</span>
{{ optional($flight->arr_airport)->name ?? $flight->arr_airport_id }}
(<a href="{{route('frontend.airports.show', [
'id' => $flight->arr_airport_id
])}}">{{$flight->arr_airport_id}}</a>)
(<a href="{{route('frontend.airports.show', ['id' => $flight->arr_airport_id])}}">{{$flight->arr_airport_id}}</a>)
@if($flight->arr_time), {{ $flight->arr_time }}@endif
<br/>
@if(filled($flight->callsign))
@ -76,6 +72,13 @@
</div>
<div class="row">
<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 -->
@if ($simbrief !== false)
<!-- If this flight has a briefing, show the link to view it-->
@ -86,7 +89,7 @@
</a>
@else
<!-- 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 }}"
class="btn btn-sm btn-outline-primary">
Create Simbrief Flight Plan
@ -94,7 +97,6 @@
@endif
@endif
@endif
<a href="{{ route('frontend.pireps.create') }}?flight_id={{ $flight->id }}"
class="btn btn-sm btn-outline-info">
{{ __('pireps.newpirep') }}