Skip to content

Commit

Permalink
Merge pull request #160 from vatsimnetwork/development
Browse files Browse the repository at this point in the history
1.8.4
  • Loading branch information
lieselwd authored Nov 5, 2024
2 parents 25cb9b7 + c35a04f commit c562820
Show file tree
Hide file tree
Showing 18 changed files with 417 additions and 60 deletions.
37 changes: 19 additions & 18 deletions app/Http/Controllers/ClxMessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Events\ClxIssuedEvent;
use App\Http\Requests\ClxMessageRequest;
use App\Models\ClxMessage;
use App\Models\DatalinkAuthority;
use App\Models\RclMessage;
use App\Models\Track;
use App\Services\CpdlcService;
Expand Down Expand Up @@ -99,9 +100,9 @@ public function showRclMessage(RclMessage $rclMessage)

return view('controllers.clx.rcl-messages.show', [
'message' => $rclMessage,
'dlAuthorities' => DatalinkAuthorities::cases(),
'dlAuthorities' => DatalinkAuthority::notSystem()->get(),
'tracks' => $rclMessage->is_concorde ? Track::concorde()->get() : Track::active()->get(),
'activeDlAuthority' => $this->dataService->getActiveControllerAuthority(Auth::user()) ?? DatalinkAuthorities::NAT,
'activeDlAuthority' => $this->dataService->getActiveControllerAuthority(Auth::user()) ?? DatalinkAuthority::find('NAT'),
'_pageTitle' => $rclMessage->callsign,
]);
}
Expand Down Expand Up @@ -160,7 +161,7 @@ public function transmit(RclMessage $rclMessage, ClxMessageRequest $request)
'entry_time_restriction' => $entryRequirement ?? null,
'raw_entry_time_restriction' => $request->get('entry_time_requirement'),
'free_text' => $isReclearance ? '** RECLEARANCE '.now()->format('Hi').' ** '.$request->get('free_text') : $request->get('free_text'),
'datalink_authority' => DatalinkAuthorities::from($request->get('datalink_authority')),
'datalink_authority_id' => $request->get('datalink_authority_id'),
'is_concorde' => $rclMessage->is_concorde,
]);

Expand All @@ -179,7 +180,7 @@ public function transmit(RclMessage $rclMessage, ClxMessageRequest $request)
* Create datalink messages
*/
$array = [
'CLX '.now()->format('Hi dmy').' '.$clxMessage->datalink_authority->name.' CLRNCE '.$clxMessage->id,
'CLX '.now()->format('Hi dmy').' '.$clxMessage->datalinkAuthority->id.' CLRNCE '.$clxMessage->id,
$rclMessage->callsign.' CLRD TO '.$rclMessage->destination.' VIA '.$clxMessage->entry_fix,
$clxMessage->track ? 'NAT '.$clxMessage->track->identifier : 'RANDOM ROUTE',
$clxMessage->track ? $clxMessage->track->last_routeing : $clxMessage->random_routeing,
Expand Down Expand Up @@ -213,9 +214,9 @@ public function transmit(RclMessage $rclMessage, ClxMessageRequest $request)
$clxMessage->datalink_message = $array;
$msg = '';
if ($clxMessage->track) {
$msg = "{$clxMessage->datalink_authority->name} clears {$rclMessage->callsign} to {$rclMessage->destination} via {$clxMessage->entry_fix}, track {$clxMessage->track->identifier}. From {$clxMessage->entry_fix} maintain Flight Level {$clxMessage->flight_level}, Mach {$clxMessage->mach}.";
$msg = "{$clxMessage->datalinkAuthority->name} clears {$rclMessage->callsign} to {$rclMessage->destination} via {$clxMessage->entry_fix}, track {$clxMessage->track->identifier}. From {$clxMessage->entry_fix} maintain Flight Level {$clxMessage->flight_level}, Mach {$clxMessage->mach}.";
} else {
$msg = "{$clxMessage->datalink_authority->name} clears {$rclMessage->callsign} to {$rclMessage->destination} via {$clxMessage->entry_fix}, random routeing {$clxMessage->random_routeing}. From {$clxMessage->entry_fix} maintain Flight Level {$clxMessage->flight_level}, Mach {$clxMessage->mach}.";
$msg = "{$clxMessage->datalinkAuthority->name} clears {$rclMessage->callsign} to {$rclMessage->destination} via {$clxMessage->entry_fix}, random routeing {$clxMessage->random_routeing}. From {$clxMessage->entry_fix} maintain Flight Level {$clxMessage->flight_level}, Mach {$clxMessage->mach}.";
}
// Only show crossing restriction if entry time =/= the restriction due to the bodge
if ($clxMessage->entry_time_restriction && ($clxMessage->raw_entry_time_restriction != $rclMessage->entry_time)) {
Expand Down Expand Up @@ -259,7 +260,7 @@ public function transmit(RclMessage $rclMessage, ClxMessageRequest $request)
->causedBy($clxMessage->vatsimAccount)
->performedOn($rclMessage)
->withProperties(['datalink' => $clxMessage->data_link_message])
->log('CLX Message Transmitted By '.$clxMessage->datalink_authority->name);
->log('CLX Message Transmitted By '.$clxMessage->datalinkAuthority->id);

flashAlert(type: 'success', title: null, message: 'Clearance transmitted.', toast: true, timer: true);

Expand All @@ -280,7 +281,7 @@ public function deleteRclMessage(Request $request, RclMessage $rclMessage)

public function revertToVoice(Request $request, RclMessage $rclMessage)
{
$datalinkAuthority = $this->dataService->getActiveControllerAuthority ?? DatalinkAuthorities::NAT;
$datalinkAuthority = $this->dataService->getActiveControllerAuthority ?? DatalinkAuthority::find('NAT');
$this->cpdlcService->sendMessage(
author: $datalinkAuthority,
recipient: $rclMessage->callsign,
Expand All @@ -296,14 +297,14 @@ public function revertToVoice(Request $request, RclMessage $rclMessage)

public function moveToProcessed(Request $request, RclMessage $rclMessage)
{
$datalinkAuthority = $this->dataService->getActiveControllerAuthority ?? DatalinkAuthorities::NAT;
$this->cpdlcService->sendMessage(
author: $datalinkAuthority,
recipient: $rclMessage->callsign,
recipientAccount: $rclMessage->vatsimAccount,
message: sprintf(RclResponsesEnum::AcknowledgeMoved->value, strtoupper($datalinkAuthority->description())),
caption: RclResponsesEnum::Acknowledge->text()
);
$datalinkAuthority = $this->dataService->getActiveControllerAuthority ?? DatalinkAuthority::find('NAT');
// $this->cpdlcService->sendMessage(
// author: $datalinkAuthority,
// recipient: $rclMessage->callsign,
// recipientAccount: $rclMessage->vatsimAccount,
// message: sprintf(RclResponsesEnum::AcknowledgeMoved->value, strtoupper($datalinkAuthority->description())),
// caption: RclResponsesEnum::Acknowledge->text()
// );

$clxMessage = new ClxMessage([
'vatsim_account_id' => $request->user()->id,
Expand Down Expand Up @@ -349,7 +350,7 @@ public function moveToProcessed(Request $request, RclMessage $rclMessage)
->causedBy($clxMessage->vatsimAccount)
->performedOn($rclMessage)
->withProperties(['datalink' => $clxMessage->data_link_message])
->log('CLX Message Transmitted By '.$clxMessage->datalink_authority->name);
->log('CLX Message Transmitted By '.$clxMessage->datalinkAuthority->name);

flashAlert(type: 'success', title: null, message: 'Clearance moved.', toast: true, timer: true);

Expand All @@ -361,7 +362,7 @@ public function create()
return view('controllers.clx.rcl-messages.create', [
'dlAuthorities' => DatalinkAuthorities::cases(),
'tracks' => Track::where('active', true)->orWhere('concorde', true)->get(),
'activeDlAuthority' => $this->dataService->getActiveControllerAuthority(Auth::user()) ?? DatalinkAuthorities::NAT,
'activeDlAuthority' => $this->dataService->getActiveControllerAuthority(Auth::user()) ?? DatalinkAuthority::find('NAT'),
'_pageTitle' => 'Create Manual Clearance',
]);
}
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/RclMessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Enums\DatalinkAuthorities;
use App\Enums\RclResponsesEnum;
use App\Http\Requests\RclMessageRequest;
use App\Models\DatalinkAuthority;
use App\Models\RclMessage;
use App\Models\Track;
use App\Services\CpdlcService;
Expand Down Expand Up @@ -39,6 +40,7 @@ public function create()
'flight_level' => substr($data?->flight_plan?->altitude, 0, 3) ?? null,
'arrival_icao' => $data?->flight_plan?->arrival ?? null,
'tracks' => Track::whereActive(true)->when($isConcorde, fn ($query) => $query->orWhere('concorde', true))->get(),
'datalinkAuthorities' => DatalinkAuthority::whereValidRclTarget(true)->pluck('name', 'id'),
'isConcorde' => $isConcorde,
'_pageTitle' => 'Request Oceanic Clearance',
]);
Expand All @@ -59,12 +61,12 @@ public function store(RclMessageRequest $request)
$rclMessage->save();

// If RCL auto acknowledgement enabled, send CPDLC acknowledgement
if (config('app.rcl_auto_acknowledgement_enabled')) {
if (config('app.rcl_auto_acknowledgement_enabled') && $rclMessage->targetDatalinkAuthority->auto_acknowledge_participant) {
$rclMessage->acknowledged_at = now();
$rclMessage->is_acknowledged = true;
$rclMessage->save();
$this->cpdlcService->sendMessage(
author: DatalinkAuthorities::SYS,
author: $rclMessage->targetDatalinkAuthority,
recipient: $rclMessage->callsign,
recipientAccount: $rclMessage->vatsimAccount,
message: sprintf(RclResponsesEnum::Acknowledge->value, strtoupper(DatalinkAuthorities::SYS->description())),
Expand Down
13 changes: 8 additions & 5 deletions app/Http/Livewire/Controllers/CreateManualClx.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Enums\RclResponsesEnum;
use App\Events\ClxIssuedEvent;
use App\Models\ClxMessage;
use App\Models\DatalinkAuthority;
use App\Models\RclMessage;
use App\Models\Track;
use App\Models\VatsimAccount;
Expand Down Expand Up @@ -36,6 +37,8 @@ class CreateManualClx extends Component

public function mount()
{
$dataService = new VatsimDataService();
$this->activeDlAuthority = $dataService->getActiveControllerAuthority(Auth::user()) ?? DatalinkAuthority::find('NAT');
$this->tmi = current_tmi();
}
public function render()
Expand Down Expand Up @@ -164,7 +167,7 @@ public function submit()
'entry_time_restriction' => null, //TODO implement
'raw_entry_time_restriction' => $rclMessage->entry_time,
'free_text' => '** RCL/CLX MANUALLY ENTERED BY ATC **',
'datalink_authority' => $this->activeDlAuthority,
'datalink_authority_id' => $this->activeDlAuthority->id,
'is_concorde' => $rclMessage->is_concorde,
]);
if ($rclMessage->trac) {
Expand All @@ -176,7 +179,7 @@ public function submit()
}

$array = [
'CLX '.now()->format('Hi dmy').' '.$clxMessage->datalink_authority->name.' CLRNCE '.$clxMessage->id,
'CLX '.now()->format('Hi dmy').' '.$clxMessage->datalinkAuthority->id.' CLRNCE '.$clxMessage->id,
$rclMessage->callsign.' CLRD TO '.$rclMessage->destination.' VIA '.$clxMessage->entry_fix,
$clxMessage->track ? 'NAT '.$clxMessage->track->identifier : 'RANDOM ROUTE',
$clxMessage->track ? $clxMessage->track->last_routeing : $clxMessage->random_routeing,
Expand Down Expand Up @@ -210,9 +213,9 @@ public function submit()
$clxMessage->datalink_message = $array;
$msg = '';
if ($clxMessage->track) {
$msg = "{$clxMessage->datalink_authority->name} clears {$rclMessage->callsign} to {$rclMessage->destination} via {$clxMessage->entry_fix}, track {$clxMessage->track->identifier}. From {$clxMessage->entry_fix} maintain Flight Level {$clxMessage->flight_level}, Mach {$clxMessage->mach}.";
$msg = "{$clxMessage->datalinkAuthority->name} clears {$rclMessage->callsign} to {$rclMessage->destination} via {$clxMessage->entry_fix}, track {$clxMessage->track->identifier}. From {$clxMessage->entry_fix} maintain Flight Level {$clxMessage->flight_level}, Mach {$clxMessage->mach}.";
} else {
$msg = "{$clxMessage->datalink_authority->name} clears {$rclMessage->callsign} to {$rclMessage->destination} via {$clxMessage->entry_fix}, random routeing {$clxMessage->random_routeing}. From {$clxMessage->entry_fix} maintain Flight Level {$clxMessage->flight_level}, Mach {$clxMessage->mach}.";
$msg = "{$clxMessage->datalinkAuthority->name} clears {$rclMessage->callsign} to {$rclMessage->destination} via {$clxMessage->entry_fix}, random routeing {$clxMessage->random_routeing}. From {$clxMessage->entry_fix} maintain Flight Level {$clxMessage->flight_level}, Mach {$clxMessage->mach}.";
}
// Only show crossing restriction if entry time =/= the restriction due to the bodge
if ($clxMessage->entry_time_restriction && ($clxMessage->raw_entry_time_restriction != $rclMessage->entry_time)) {
Expand Down Expand Up @@ -256,7 +259,7 @@ public function submit()
->causedBy($clxMessage->vatsimAccount)
->performedOn($rclMessage)
->withProperties(['datalink' => $clxMessage->data_link_message])
->log('CLX Message Transmitted By '.$clxMessage->datalink_authority->name);
->log('CLX Message Transmitted By '.$clxMessage->datalinkAuthority->name);

flashAlert(type: 'success', title: null, message: 'Clearance transmitted.', toast: true, timer: true);

Expand Down
32 changes: 24 additions & 8 deletions app/Http/Livewire/Controllers/LtNewPending.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Http\Livewire\Controllers;

use App\Enums\DatalinkAuthorities;
use App\Http\Controllers\ClxMessagesController;
use App\Models\DatalinkAuthority;
use App\Models\Track;
use Illuminate\Database\Eloquent\Builder;
use phpDocumentor\Reflection\Types\Boolean;
Expand Down Expand Up @@ -60,6 +62,10 @@ public function columns(): array
->sortable(),
Column::make("Request time", "request_time")
->sortable(),
Column::make("Target")
->label(function ($row, Column $column) {
return Rclmessage::whereId($row->id)->first()->targetDatalinkAuthority->id ?? 'N/A';
}),
LinkColumn::make('View') // make() has no effect in this case but needs to be set anyway
->title(fn($row) => 'View ' . $row->callsign)
->location(function($row) {
Expand Down Expand Up @@ -93,23 +99,27 @@ private function scopeWhereRandomRouteing($query)

public function filters(): array
{
$options = Track::query()
$trackOptions = Track::query()
->orderBy('identifier')
->get()
->keyBy('id')
->map(fn($track) => $track->identifier)
->toArray();
$options[100] = 'RR';
$trackOptions[100] = 'RR';
$authorityOptions = DatalinkAuthority::query()
->orderBy('id')
->get()
->keyBy('id')
->map(fn($authority) => $authority->name)
->toArray();
return [
MultiSelectDropdownFilter::make('Track')
->options(
$options
)
MultiSelectFilter::make('Track')
->options($trackOptions)
->setFirstOption('All')
->filter(function(Builder $builder, array $value) use ($options) {
->filter(function(Builder $builder, array $value) use ($trackOptions) {
$selections = [];
foreach ($value as $selection) {
$selections[] = $options[$selection];
$selections[] = $trackOptions[$selection];
}
if (in_array('RR', $selections)) {
unset($value[array_search('100', $value)]);
Expand All @@ -123,6 +133,12 @@ public function filters(): array
$builder->whereIn('track_id', array_values($value));
}
}),
MultiSelectFilter::make('Target OCA')
->options($authorityOptions)
->setFirstOption('All')
->filter(function(Builder $builder, array $value) {
$builder->whereIn('target_datalink_authority_id', array_values($value));
}),
SelectFilter::make('Acknowledged')
->options([
'' => 'All',
Expand Down
7 changes: 5 additions & 2 deletions app/Http/Requests/RclMessageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Enums\DatalinkAuthorities;
use App\Enums\RclResponsesEnum;
use App\Models\DatalinkAuthority;
use App\Models\Track;
use App\Services\CpdlcService;
use Carbon\Carbon;
Expand Down Expand Up @@ -34,6 +35,7 @@ public function rules(): array
'tmi' => 'required|numeric|min:001|max:366',
'random_routeing' => 'nullable|regex:/^[A-Z\/0-9 _]*[A-Z\/0-9][A-Z\/0-9 _]*$/',
'is_concorde' => 'nullable',
'target_datalink_authority_id' => 'required',
];
}

Expand All @@ -42,6 +44,7 @@ public function rules(): array
'flight_level.max' => 'You must file a valid flight level.',
'max_flight_level.max' => 'You must file a valid maximum flight level.',
'callsign.alpha_num' => 'Your callsign must be valid with no spaces as you would enter it into your pilot client. E.g. BAW14LA, AAL134',
'target_datalink_authority_id.required' => 'You must select the first oceanic sector you will be flying through.'
];

public function prepareForValidation()
Expand Down Expand Up @@ -88,8 +91,8 @@ public function withValidator($validator)
/** Entry fix time requirement */
if (config('app.rcl_time_constraints_enabled') && strlen($this->entry_time) == 4) {
if (!$this->entryTimeWithinRange($this->entry_time)) {
if (config('app.rcl_auto_acknowledgement_enabled')) {
$this->cpdlcService->sendMessage(author: DatalinkAuthorities::SYS, recipient: $this->callsign, recipientAccount: Auth::user(), message: sprintf(RclResponsesEnum::Contact->value, strtoupper(DatalinkAuthorities::OCEN->description())), caption: RclResponsesEnum::Contact->text());
if (config('app.rcl_auto_acknowledgement_enabled') && DatalinkAuthority::find($this->target_datalink_authority_id)->auto_acknowledge_participant) {
$this->cpdlcService->sendMessage(author: DatalinkAuthority::find('SYST'), recipient: $this->callsign, recipientAccount: Auth::user(), message: sprintf(RclResponsesEnum::Contact->value, strtoupper(DatalinkAuthorities::OCEN->description())), caption: RclResponsesEnum::Contact->text());
}
$lower = config('app.rcl_lower_limit') + 1;
$upper = config('app.rcl_upper_limit') - 1;
Expand Down
Loading

0 comments on commit c562820

Please sign in to comment.