-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad23b2a
commit 5a9fea9
Showing
153 changed files
with
5,326 additions
and
2,228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\Roster; | ||
|
||
use App\Models\NetworkData\Atc; | ||
use App\Models\Roster; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Carbon; | ||
|
||
class UpdateRoster extends Command | ||
{ | ||
protected $signature = 'roster:update {fromDate} {toDate}'; | ||
|
||
protected $description = 'Update the ATC roster based on ATC session data.'; | ||
|
||
protected int $minimumHours = 3; | ||
|
||
protected Carbon $fromDate; | ||
|
||
protected Carbon $toDate; | ||
|
||
public function handle() | ||
{ | ||
$this->fromDate = Carbon::parse($this->argument('fromDate'))->startOfDay(); | ||
$this->toDate = Carbon::parse($this->argument('toDate'))->endOfDay(); | ||
|
||
$eligible = Atc::with(['account.states']) | ||
->select(['networkdata_atc.account_id']) | ||
->whereBetween('disconnected_at', [$this->fromDate, $this->toDate]) | ||
->accountIsPartOfUk() | ||
->positionIsWithinUk() | ||
->groupBy('account_id') | ||
->havingRaw("SUM(minutes_online) / 60 > {$this->minimumHours}") | ||
->pluck('account_id'); | ||
|
||
// On the roster, do not need to be on... | ||
Roster::withoutGlobalScopes() | ||
->whereNotIn('account_id', $eligible) | ||
->get() | ||
->each | ||
->remove(); | ||
|
||
// Not on the roster, need to be on... | ||
Roster::upsert( | ||
$eligible->map(fn ($value) => ['account_id' => $value])->toArray(), | ||
['account_id'] | ||
); | ||
|
||
$this->comment('✅ Roster updated!'); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/Console/Commands/Roster/UpdateRosterGanderControllers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\Roster; | ||
|
||
use App\Models\Atc\PositionGroup; | ||
use App\Models\Mship\Account\Endorsement; | ||
use App\Models\Roster; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
class UpdateRosterGanderControllers extends Command | ||
{ | ||
protected $signature = 'roster:gander'; | ||
|
||
protected $description = 'Update the ATC roster based on those within the Gander roster.'; | ||
|
||
public function handle() | ||
{ | ||
$gander = Http::get('https://ganderoceanic.ca/api/roster') | ||
->collect() | ||
->where('active', true) | ||
->pluck('cid'); | ||
|
||
DB::transaction(function () use ($gander) { | ||
Roster::upsert( | ||
$gander->map(fn ($value) => ['account_id' => $value])->toArray(), | ||
['account_id'] | ||
); | ||
|
||
$positionGroup = PositionGroup::where('name', 'Shanwick Oceanic (EGGX)')->firstOrFail(); | ||
|
||
$gander->reject(function ($value) use ($positionGroup) { | ||
return Endorsement::where([ | ||
'account_id' => $value, | ||
'endorsable_id' => $positionGroup->id, | ||
'endorsable_type' => PositionGroup::class, | ||
])->exists(); | ||
})->each(function ($value) use ($positionGroup) { | ||
Endorsement::create([ | ||
'account_id' => $value, | ||
'endorsable_id' => $positionGroup->id, | ||
'endorsable_type' => PositionGroup::class, | ||
]); | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Events\Training; | ||
|
||
use App\Models\Mship\Account\EndorsementRequest; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
|
||
class EndorsementRequestApproved | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
/** | ||
* Create a new event instance. | ||
*/ | ||
public function __construct( | ||
private EndorsementRequest $endorsementRequest, | ||
private ?int $days | ||
) { | ||
} | ||
|
||
public function getEndorsementRequest(): EndorsementRequest | ||
{ | ||
return $this->endorsementRequest; | ||
} | ||
|
||
public function getExpiryDate() | ||
{ | ||
if ($this->days === null) { | ||
return null; | ||
} | ||
|
||
return now()->addDays($this->days)->endOfDay(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
app/Filament/Resources/AccountResource/RelationManagers/EndorsementsRelationManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\AccountResource\RelationManagers; | ||
|
||
use App\Models\Atc\PositionGroup; | ||
use App\Models\Mship\Account\Endorsement; | ||
use Filament\Forms; | ||
use Filament\Forms\Form; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
|
||
class EndorsementsRelationManager extends RelationManager | ||
{ | ||
protected static string $relationship = 'endorsements'; | ||
|
||
protected static ?string $inverseRelationship = 'account'; | ||
|
||
protected static ?string $recordTitleAttribute = 'endorsable.name'; | ||
|
||
public function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\Select::make('position_group_id') | ||
->label('Endorsement') | ||
->required() | ||
->options(PositionGroup::unassignedFor($this->ownerRecord)->mapWithKeys(function (PositionGroup $model) { | ||
return [$model->getKey() => str($model->name)]; | ||
})) | ||
->hiddenOn('edit'), | ||
|
||
// TODO: determine maximum time in advance. | ||
Forms\Components\DatePicker::make('expires_at') | ||
->native(false) | ||
->label('Expires') | ||
->minDate(now()), | ||
|
||
Forms\Components\Hidden::make('created_by') | ||
->afterStateHydrated(fn ($component, $state) => $component->state(auth()->user()->getKey())), | ||
]); | ||
} | ||
|
||
public function isReadOnly(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->recordTitle(fn ($record) => "{$record->endorsable->name} endorsement") | ||
->columns([ | ||
Tables\Columns\TextColumn::make('endorsable.name')->label('Name'), | ||
// TODO: color on type | ||
Tables\Columns\TextColumn::make('type')->label('Type')->badge(), | ||
Tables\Columns\TextColumn::make('created_at')->label('Granted')->date(), | ||
Tables\Columns\TextColumn::make('expires_at')->label('Expires')->date()->default(''), | ||
]) | ||
->headerActions([ | ||
// Tables\Actions\CreateAction::make()->label('Add endorsement'), | ||
]) | ||
->actions([ | ||
// TODO: define permissions for both actions | ||
// Tables\Actions\EditAction::make() | ||
// ->visible(fn ($record) => $record->type == 'Temporary'), | ||
// Tables\Actions\DeleteAction::make() | ||
// ->visible(fn ($record) => $record->type == 'Permanent'), | ||
]); | ||
} | ||
|
||
public static function createEndorsement(array $data, self $livewire) | ||
{ | ||
$creator = auth()->user(); | ||
|
||
Endorsement::create([ | ||
'account_id' => $livewire->ownerRecord->id, | ||
'position_group_id' => $data['position_group_id'], | ||
'expires_at' => $data['expires_at'], | ||
'created_by' => $creator->id, | ||
]); | ||
} | ||
} |
Oops, something went wrong.