Skip to content

Commit

Permalink
Merge pull request #113 from vatsimnetwork/development
Browse files Browse the repository at this point in the history
  • Loading branch information
williammck authored Oct 27, 2023
2 parents a343d52 + eec4ce1 commit 2422447
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
35 changes: 35 additions & 0 deletions app/Http/Controllers/Api/PluginDataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ public function allRclMessages(Request $request)
);
}

public function allClxMessages(Request $request)
{
$track = null;
if ($trackIdent = $request->get('track')) {
$track = Track::active()->whereIdentifier($trackIdent)->first();
if (! $track) {
abort(400, "Track with identifier $trackIdent not active at present time.");
}
}

return Cache::remember(
'clx-messages:'.($track->id ?? 'all'),
60,
fn () => ClxMessage::with('rclMessage')
->when($track, fn (Builder $q) => $q->whereBelongsTo($track))
->get()
->map(self::serializeClxMessage(...))
);
}

public function detailedClxMessages(Request $request)
{
$trackToSortBy = null;
Expand Down Expand Up @@ -113,6 +133,21 @@ private static function serializeRclMessage(RclMessage $msg): array
];
}

private static function serializeClxMessage(ClxMessage $msg): array
{
return [
'callsign' => $msg->callsign,
'status' => 'CLEARED',
'nat' => $msg->track->identifier ?? 'RR',
'fix' => $msg->entry_fix,
'level' => $msg->flight_level,
'mach' => '0.'.substr($msg->mach, 1),
'estimating_time' => self::formatTime($msg->rclMessage?->entry_time ?? '00:00'),
'clearance_issued' => $msg->created_at,
'extra_info' => $msg->rclMessage?->free_text,
];
}

private static function formatTime($time)
{
return substr($time, 0, 2).':'.substr($time, 2, 2);
Expand Down
16 changes: 9 additions & 7 deletions app/Http/Livewire/Pilots/NotifyNewEta.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class NotifyNewEta extends Component
{
public RclMessage $rclMessage;
public ClxMessage|null $latestClxMessage;
public ?ClxMessage $latestClxMessage = null;
public $entryTime;
public bool $reject = false;

Expand Down Expand Up @@ -42,7 +42,7 @@ public function submit()

DB::transaction(function(): void {
$this->rclMessage->update([
'previous_clx_message' => $this->latestClxMessage->toArray(),
'previous_clx_message' => $this->latestClxMessage?->toArray(),
'new_entry_time' => true,
'new_entry_time_notified_at' => now(),
'previous_entry_time' => $this->rclMessage->entry_time,
Expand All @@ -51,11 +51,13 @@ public function submit()
$this->rclMessage->clx_message_id = null;
$this->rclMessage->save();

$this->latestClxMessage->update([
'cancelled' => true,
'cancellation_reason' => ClxCancellationReasons::NewEta
]);
$this->latestClxMessage->save();
if ($this->latestClxMessage) {
$this->latestClxMessage->update([
'cancelled' => true,
'cancellation_reason' => ClxCancellationReasons::NewEta
]);
$this->latestClxMessage->save();
}
});

flashAlert(type: 'success', title: 'Success!', message: 'New ETA submitted. Keep an eye on your message history page!', toast: false, timer: false);
Expand Down
3 changes: 2 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
return $request->user();
});

Route::get('/plugins', [PluginDataController::class, 'allRclMessages']);
Route::get('/plugins', [PluginDataController::class, 'allClxMessages']);
Route::get('/plugins-rcl', [PluginDataController::class, 'allRclMessages']);

Route::get('/clx-messages', [PluginDataController::class, 'detailedClxMessages']);

Expand Down

0 comments on commit 2422447

Please sign in to comment.