Skip to content

Commit 6ac469b

Browse files
authored
Display and allow editing of waiting list configuration options (#4097)
* Replace references to Member Services * More options when creating waiting list * Option to display manual flags in waiting list table * lint all * Generic Improvements Make settings collapsible, improve readability, enable/disable roster flag, load flags to avoid multiple calls * Display the Code instead of name Better solution for those with the same name such as having multiple "Senior Controller" qualifications * User friendly labels
1 parent e26853b commit 6ac469b

File tree

6 files changed

+139
-6
lines changed

6 files changed

+139
-6
lines changed

app/Filament/Resources/WaitingListResource.php

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
use App\Filament\Resources\WaitingListResource\Pages;
66
use App\Filament\Resources\WaitingListResource\RelationManagers\AccountsRelationManager;
77
use App\Models\Training\WaitingList;
8-
use Filament\Forms;
8+
use Filament\Forms\Components\Section;
9+
use Filament\Forms\Components\Select;
10+
use Filament\Forms\Components\TextInput;
11+
use Filament\Forms\Components\Toggle;
912
use Filament\Forms\Form;
1013
use Filament\Resources\RelationManagers\RelationGroup;
1114
use Filament\Resources\Resource;
@@ -27,14 +30,68 @@ public static function form(Form $form): Form
2730
{
2831
return $form
2932
->schema([
30-
Forms\Components\TextInput::make('name')->autofocus()->required()->live(onBlur: true)
33+
TextInput::make('name')->autofocus()->required()->live(onBlur: true)
3134
->afterStateUpdated(fn ($state, callable $set) => $set('slug', Str::slug($state))),
32-
Forms\Components\TextInput::make('slug')->required(),
35+
TextInput::make('slug')->required(),
3336

34-
Forms\Components\Select::make('department')->options([
37+
Select::make('department')->options([
3538
'atc' => 'ATC Training',
3639
'pilot' => 'Pilot Training',
3740
])->required(),
41+
42+
Section::make('Additional Settings')
43+
->schema([
44+
Toggle::make('feature_toggles.check_atc_hours')
45+
->label('Check ATC Hours')
46+
->default(true),
47+
48+
Toggle::make('feature_toggles.display_on_roster')
49+
->label('Display Roster Membership')
50+
->default(true),
51+
52+
Toggle::make('feature_toggles.check_cts_theory_exam')
53+
->label('Display CTS Theory Exam')
54+
->default(true),
55+
56+
Toggle::make('requires_roster_membership')
57+
->label('Require Roster Membership')
58+
->default(true),
59+
60+
Toggle::make('self_enrolment_enabled')
61+
->label('Enable Self-Enrolment')
62+
->default(false)
63+
->live(),
64+
65+
])
66+
->collapsible()
67+
->collapsed(),
68+
69+
Section::make('Self-Enrolment Requirements')
70+
->schema([
71+
Select::make('self_enrolment_minimum_qualification_id')
72+
->label('Minimum Rating')
73+
->helperText('If the member has a rating lower than this, they cannot self-enrol.')
74+
->relationship('minimumQualification', 'code')
75+
->searchable()
76+
->preload(),
77+
Select::make('self_enrolment_maximum_qualification_id')
78+
->label('Maximum Rating')
79+
->helperText('If the member has a rating higher than this, they cannot self-enrol.')
80+
->relationship('maximumQualification', 'code')
81+
->searchable()
82+
->preload(),
83+
Select::make('self_enrolment_hours_at_qualification_id')
84+
->label('Rating for Hour Check')
85+
->helperText('Check if the member has a certain number of hours at this rating.')
86+
->relationship('hoursAtQualification', 'code')
87+
->searchable()
88+
->preload(),
89+
TextInput::make('self_enrolment_hours_at_qualification_minimum_hours')
90+
->label('Minimum Hours')
91+
->helperText('Minimum hours required at the above rating to self-enrol.')
92+
->integer()
93+
->minValue(0),
94+
])->collapsible()->collapsed()->visible(fn (callable $get) => $get('self_enrolment_enabled') === true),
3895
]);
3996
}
4097

app/Filament/Resources/WaitingListResource/Pages/ViewWaitingList.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Filament\Forms\Components\DatePicker;
1414
use Filament\Forms\Components\Select;
1515
use Filament\Forms\Components\TextInput;
16+
use Filament\Forms\Components\Toggle;
1617
use Filament\Resources\Pages\ViewRecord;
1718
use Illuminate\Database\Eloquent\ModelNotFoundException;
1819
use Illuminate\Support\Arr;
@@ -76,6 +77,7 @@ protected function getHeaderActions(): array
7677
$flag = WaitingListFlag::create([
7778
'name' => $data['name'],
7879
'position_group_id' => $data['position_group_id'],
80+
'display_in_table' => $data['display_in_table'] ?? false,
7981
]);
8082

8183
$this->record->addFlag($flag);
@@ -89,6 +91,10 @@ protected function getHeaderActions(): array
8991
Select::make('position_group_id')->label('Position Group')->options(fn () => PositionGroup::all()->mapWithKeys(function ($item) {
9092
return [$item['id'] => $item['name']];
9193
}))->hint('If an option is chosen here, this will be an automated flag. This cannot be reversed.'),
94+
95+
Toggle::make('display_in_table')
96+
->label('Display in Waiting List Table')
97+
->default(false),
9298
])
9399
->visible(fn () => auth()->user()->can('addFlags', $this->record)),
94100
];

app/Filament/Resources/WaitingListResource/RelationManagers/AccountsRelationManager.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@ public function form(Form $form): Form
8585
public function table(Table $table): Table
8686
{
8787
return $table
88-
->modifyQueryUsing(fn (Builder $query) => $query->with(['account', 'account.roster', 'waitingList']))
88+
->modifyQueryUsing(fn (Builder $query) => $query->with(['account', 'account.roster', 'waitingList', 'flags']))
8989
->columns([
9090
Tables\Columns\TextColumn::make('position')->getStateUsing(fn (WaitingListAccount $record) => $this->ownerRecord->positionOf($record) ?? '-')->label('Position'),
9191
Tables\Columns\TextColumn::make('account_id')->label('CID')->searchable(),
9292
Tables\Columns\TextColumn::make('account.name')->label('Name')->searchable(['name_first', 'name_last']),
9393
Tables\Columns\IconColumn::make('on_roster')->boolean()->label('On Roster')->getStateUsing(fn (WaitingListAccount $record) => $record->account->onRoster())->visible(fn () => $this->ownerRecord->feature_toggles['display_on_roster'] ?? true),
9494
Tables\Columns\TextColumn::make('created_at')->label('Added On')->dateTime('d/m/Y H:i:s'),
9595
Tables\Columns\IconColumn::make('cts_theory_exam')->boolean()->label('CTS Theory Exam')->getStateUsing(fn (WaitingListAccount $record) => $record->theory_exam_passed)->visible(fn () => $this->ownerRecord->feature_toggles['check_cts_theory_exam'] ?? true),
96+
...$this->getFlagColumns(),
9697
])
9798
->actions([
9899
Tables\Actions\EditAction::make()
@@ -182,4 +183,22 @@ public static function removalReasonOptions(): array
182183
{
183184
return WaitingList\RemovalReason::formOptions();
184185
}
186+
187+
// Display All Manual Flags where display option is enabled
188+
protected function getFlagColumns(): array
189+
{
190+
return $this->ownerRecord->flags()
191+
->where('display_in_table', true)
192+
->get()
193+
->map(function ($flag) {
194+
return Tables\Columns\IconColumn::make("flag_{$flag->id}")
195+
->label($flag->name)
196+
->boolean()
197+
->getStateUsing(function (WaitingListAccount $record) use ($flag) {
198+
$flagRecord = $record->flags->firstWhere('id', $flag->id);
199+
200+
return $flagRecord?->pivot?->marked_at !== null;
201+
});
202+
})->all();
203+
}
185204
}

app/Models/Training/WaitingList.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected static function boot()
8787

8888
public $table = 'training_waiting_list';
8989

90-
protected $fillable = ['name', 'slug', 'department', 'feature_toggles'];
90+
protected $fillable = ['name', 'slug', 'department', 'feature_toggles', 'requires_roster_membership', 'self_enrolment_enabled', 'self_enrolment_minimum_qualification_id', 'self_enrolment_maximum_qualification_id', 'self_enrolment_hours_at_qualification_id', 'self_enrolment_hours_at_qualification_minimum_hours'];
9191

9292
const ATC_DEPARTMENT = 'atc';
9393

@@ -103,6 +103,10 @@ protected static function boot()
103103
'deleted_at' => 'datetime',
104104
'requires_roster_membership' => 'boolean',
105105
'self_enrolment_enabled' => 'boolean',
106+
'self_enrolment_minimum_qualification_id' => 'integer',
107+
'self_enrolment_maximum_qualification_id' => 'integer',
108+
'self_enrolment_hours_at_qualification_id' => 'integer',
109+
'self_enrolment_hours_at_qualification_minimum_hours' => 'integer',
106110
];
107111

108112
/**
@@ -285,6 +289,21 @@ public function getFeatureTogglesFormattedAttribute(): object
285289
];
286290
}
287291

292+
public function minimumQualification()
293+
{
294+
return $this->belongsTo(\App\Models\Mship\Qualification::class, 'self_enrolment_minimum_qualification_id');
295+
}
296+
297+
public function maximumQualification()
298+
{
299+
return $this->belongsTo(\App\Models\Mship\Qualification::class, 'self_enrolment_maximum_qualification_id');
300+
}
301+
302+
public function hoursAtQualification()
303+
{
304+
return $this->belongsTo(\App\Models\Mship\Qualification::class, 'self_enrolment_hours_at_qualification_id');
305+
}
306+
288307
public function __toString()
289308
{
290309
return (string) $this->name;

app/Models/Training/WaitingList/WaitingListFlag.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ class WaitingListFlag extends Model
1414

1515
protected $table = 'training_waiting_list_flags';
1616

17+
protected $casts = [
18+
'display_in_table' => 'boolean',
19+
];
20+
1721
protected static function boot()
1822
{
1923
parent::boot();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('training_waiting_list_flags', function (Blueprint $table) {
15+
$table->boolean('display_in_table')->default(false)->after('deleted_at');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('training_waiting_list_flags', function (Blueprint $table) {
25+
$table->dropColumn('display_in_table');
26+
});
27+
}
28+
};

0 commit comments

Comments
 (0)