Skip to content

Commit

Permalink
Merge pull request vatsimnetwork#159 from vatsimnetwork/154-auto-ackn…
Browse files Browse the repository at this point in the history
…owledgment-from-ctp24e-to-4-december

Auto-acknowledgment from CTP24E to 4 December vatsimnetwork#154
  • Loading branch information
lieselwd authored Oct 23, 2024
2 parents 77e46ec + 55d6b97 commit 624fbfa
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 27 deletions.
14 changes: 7 additions & 7 deletions app/Http/Controllers/ClxMessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,13 @@ public function revertToVoice(Request $request, RclMessage $rclMessage)
public function moveToProcessed(Request $request, RclMessage $rclMessage)
{
$datalinkAuthority = $this->dataService->getActiveControllerAuthority ?? DatalinkAuthority::whereId('NAT')->first();
$this->cpdlcService->sendMessage(
author: $datalinkAuthority,
recipient: $rclMessage->callsign,
recipientAccount: $rclMessage->vatsimAccount,
message: sprintf(RclResponsesEnum::AcknowledgeMoved->value, strtoupper($datalinkAuthority->description())),
caption: RclResponsesEnum::Acknowledge->text()
);
// $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
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
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::whereId($this->target_datalink_authority_id)->first()->auto_acknowledge_participant) {
$this->cpdlcService->sendMessage(author: DatalinkAuthority::whereId('SYST')->first(), 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
21 changes: 16 additions & 5 deletions app/Models/RclMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Enums\DatalinkAuthorities;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand Down Expand Up @@ -103,6 +104,11 @@
* @method static Builder|RclMessage acknowledged()
* @method static Builder|RclMessage notAcknowledged()
* @method static Builder|RclMessage whereTargetDatalinkAuthority($value)
* @property string|null $datalink_authority_id
* @property string|null $target_datalink_authority_id
* @method static Builder|RclMessage whereDatalinkAuthorityId($value)
* @method static Builder|RclMessage whereTargetDatalinkAuthorityId($value)
* @property-read \App\Models\DatalinkAuthority|null $targetDatalinkAuthority
* @mixin \Eloquent
*/
class RclMessage extends Model
Expand Down Expand Up @@ -143,7 +149,7 @@ public function prunable(): Builder
* @var string[]
*/
protected $fillable = [
'vatsim_account_id', 'callsign', 'destination', 'flight_level', 'max_flight_level', 'mach', 'track_id', 'random_routeing', 'entry_fix', 'entry_time', 'tmi', 'request_time', 'free_text', 'atc_rejected', 'upper_flight_level', 'is_concorde', 'previous_entry_time', 'new_entry_time', 'previous_clx_message', 'new_entry_time_notified_at', 'is_acknowledged', 'acknowledged_at'
'vatsim_account_id', 'callsign', 'destination', 'flight_level', 'max_flight_level', 'mach', 'track_id', 'random_routeing', 'entry_fix', 'entry_time', 'tmi', 'request_time', 'free_text', 'atc_rejected', 'upper_flight_level', 'is_concorde', 'previous_entry_time', 'new_entry_time', 'previous_clx_message', 'new_entry_time_notified_at', 'is_acknowledged', 'acknowledged_at', 'target_datalink_authority_id'
];

/**
Expand Down Expand Up @@ -267,15 +273,15 @@ public function getDataLinkMessageAttribute(): string
{
if ($this->is_concorde) {
if ($this->track) {
return "{$this->callsign} REQ CONC CLRNCE {$this->destination} VIA {$this->entry_fix}/{$this->entry_time} CONC TRACK {$this->track->identifier} BLOCK LOWER F{$this->flight_level} UPPER F{$this->upper_flight_level} M{$this->mach} TMI {$this->tmi}";
return "{$this->callsign} TO {$this->targetDatalinkAuthority->name} REQ CONC CLRNCE {$this->destination} VIA {$this->entry_fix}/{$this->entry_time} CONC TRACK {$this->track->identifier} BLOCK LOWER F{$this->flight_level} UPPER F{$this->upper_flight_level} M{$this->mach} TMI {$this->tmi}";
} else {
return "{$this->callsign} REQ CONC CLRNCE {$this->destination} VIA {$this->entry_fix}/{$this->entry_time} {$this->random_routeing} BLOCK LOWER F{$this->flight_level} UPPER F{$this->upper_flight_level} M{$this->mach} TMI {$this->tmi}";
return "{$this->callsign} TO {$this->targetDatalinkAuthority->name} REQ CONC CLRNCE {$this->destination} VIA {$this->entry_fix}/{$this->entry_time} {$this->random_routeing} BLOCK LOWER F{$this->flight_level} UPPER F{$this->upper_flight_level} M{$this->mach} TMI {$this->tmi}";
}
} else {
if ($this->track) {
return "{$this->callsign} REQ CLRNCE {$this->destination} VIA {$this->entry_fix}/{$this->entry_time} TRACK {$this->track->identifier} F{$this->flight_level} M{$this->mach} MAX F{$this->max_flight_level} TMI {$this->tmi}";
return "{$this->callsign} TO {$this->targetDatalinkAuthority->name} REQ CLRNCE {$this->destination} VIA {$this->entry_fix}/{$this->entry_time} TRACK {$this->track->identifier} F{$this->flight_level} M{$this->mach} MAX F{$this->max_flight_level} TMI {$this->tmi}";
} else {
return "{$this->callsign} REQ CLRNCE {$this->destination} VIA {$this->entry_fix}/{$this->entry_time} {$this->random_routeing} F{$this->flight_level} M{$this->mach} MAX F{$this->max_flight_level} TMI {$this->tmi}";
return "{$this->callsign} TO {$this->targetDatalinkAuthority->name} REQ CLRNCE {$this->destination} VIA {$this->entry_fix}/{$this->entry_time} {$this->random_routeing} F{$this->flight_level} M{$this->mach} MAX F{$this->max_flight_level} TMI {$this->tmi}";
}
}
}
Expand All @@ -296,4 +302,9 @@ protected function routeIdentifier(): Attribute
get: fn () => $this->track ? $this->track->id : 'RR'
);
}

public function targetDatalinkAuthority(): BelongsTo
{
return $this->belongsTo(DatalinkAuthority::class, 'target_datalink_authority_id');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up(): void
{
Schema::table('rcl_messages', function (Blueprint $table) {
$table->string('target_datalink_authority_id')->nullable();
$table->foreign('target_datalink_authority_id')->references('id')->on('datalink_authorities')->nullOnDelete();
});
}

public function down(): void
{
Schema::table('rcl_messages', function (Blueprint $table) {
$table->dropForeign('rcl_messages_target_datalink_authority_id_foreign');
$table->dropColumn('target_datalink_authority_id');
});
}
};
6 changes: 5 additions & 1 deletion resources/views/controllers/clx/rcl-messages/show.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@extends('_layouts.main')
@extends('_layouts.main')
@section('page')
<div class="container">
<form method="POST" action="{{ route('controllers.clx.transmit', $message) }}">
Expand Down Expand Up @@ -100,6 +100,10 @@
<td>CID</td>
<td>{{ $message->vatsimAccount->full_name }} {{ $message->vatsimAccount->id }}</td>
</tr>
<tr>
<td>Target OCA</td>
<td>{{ $message->targetDatalinkAuthority->id }}</td>
</tr>
</tbody>
</table>
</div>
Expand Down
15 changes: 13 additions & 2 deletions resources/views/pilots/rcl/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<div class="col-md-6">
<div class="form-floating">
<input required type="text" class="form-control" name="flight_level" id="flight_level" placeholder="e.g. 310" maxlength="3" value="{{ $flight_level ?? old('flight_level') }}">
<label for="flight_level">Requested {{ $isConcorde ? 'lower block' : '' }} flight level (digits only, e.g. 340)</label>
<label for="flight_level">Requested {{ $isConcorde ? 'lower block' : 'oceanic' }} flight level (digits only, e.g. 340)</label>
</div>
@if (config('app.ctp_info_enabled'))
<div class="form-text"><b>Ensure you enter your assigned oceanic flight level as per your booking!</b></div>
Expand All @@ -84,7 +84,7 @@
<div class="col-md-6">
<div class="form-floating">
<input type="text" class="form-control" name="max_flight_level" id="max_flight_level" placeholder="e.g. 390" maxlength="3" value="{{ old('max_flight_level') }}">
<label for="max_flight_level" class="uk-form-label">Maximum flight level</label>
<label for="max_flight_level" class="uk-form-label">Maximum oceanic flight level</label>
</div>
@if (config('app.ctp_info_enabled'))
<div class="form-text"><b>Ensure you enter your max flight level as per your booking!</b></div>
Expand Down Expand Up @@ -126,6 +126,17 @@
</div>
<h5 class="font-display">Oceanic entry</h5>
<div class="row gap-4 mb-4">
<div class="col-md-6">
<div class="form-floating">
<select class="form-select" id="target_datalink_authority_id" name="target_datalink_authority_id">
<option value="" selected>Select one...</option>
@foreach($datalinkAuthorities as $key => $value)
<option data-authority="{{ $key }}" value="{{ $key }}">{{ $key }} ({{ $value }})</option>
@endforeach
</select>
<label for="track_id">First oceanic sector</label>
</div>
</div>
<div class="col-md-6">
<div class="form-floating">
<input value="{{ old('entry_fix') }}" required type="text" class="form-control" name="entry_fix" id="entry_fix" placeholder="e.g. MALOT" maxlength="7" onblur="this.value = this.value.toUpperCase()">
Expand Down

0 comments on commit 624fbfa

Please sign in to comment.