Skip to content

Commit 98faf6b

Browse files
committed
wip
1 parent e420c2d commit 98faf6b

126 files changed

Lines changed: 800 additions & 663 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/Filament/Actions/ActionGroup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace App\Filament\Actions;
66

7-
use Filament\Pages\Actions\ActionGroup as BaseActionGroup;
7+
use Filament\Actions\ActionGroup as BaseActionGroup;
88

99
class ActionGroup extends BaseActionGroup
1010
{

app/Filament/Actions/ConvertOcasionalBeneficiaryAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use App\Models\Intervention\InterventionableIndividualService;
1414
use App\Models\Intervention\OcasionalIntervention;
1515
use App\Models\Service\Service;
16-
use Filament\Pages\Actions\Action;
16+
use Filament\Actions\Action;
1717

1818
class ConvertOcasionalBeneficiaryAction extends Action
1919
{

app/Filament/Forms/Components/Subsection.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

app/Filament/Resources/AppointmentResource.php

Lines changed: 8 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,27 @@
44

55
namespace App\Filament\Resources;
66

7-
use App\Filament\Forms\Components\Subsection;
87
use App\Filament\Resources\AppointmentResource\Pages;
98
use App\Filament\Resources\AppointmentResource\RelationManagers\ServicesRelationManager;
10-
use App\Filament\Tables\Columns\TextColumn;
9+
use App\Filament\Resources\AppointmentResource\Schemas\AppointmentForm;
10+
use App\Filament\Resources\AppointmentResource\Schemas\AppointmentInfolist;
1111
use App\Models\Appointment;
12-
use Carbon\CarbonImmutable;
13-
use Filament\Forms\Components\DatePicker;
14-
use Filament\Forms\Components\Grid;
15-
use Filament\Forms\Components\RichEditor;
16-
use Filament\Forms\Components\Section;
17-
use Filament\Forms\Components\Select;
18-
use Filament\Forms\Components\TextInput;
12+
use App\Tables\Columns\TextColumn;
1913
use Filament\Forms\Form;
2014
use Filament\Infolists\Infolist;
2115
use Filament\Resources\Resource;
2216
use Filament\Tables;
2317
use Filament\Tables\Filters\SelectFilter;
2418
use Filament\Tables\Table;
25-
use Illuminate\Database\Eloquent\Builder;
2619

2720
class AppointmentResource extends Resource
2821
{
2922
protected static ?string $model = Appointment::class;
3023

3124
protected static ?int $navigationSort = 3;
3225

26+
protected static ?string $navigationIcon = 'heroicon-m-calendar-date-range';
27+
3328
public static function getModelLabel(): string
3429
{
3530
return __('appointment.label.singular');
@@ -43,120 +38,13 @@ public static function getPluralModelLabel(): string
4338
public static function form(Form $form): Form
4439
{
4540
return $form
46-
->columns(1)
47-
->schema([
48-
Section::make()
49-
->schema(static::getAppointmentFormSchema()),
50-
]);
41+
->schema(AppointmentForm::getSchema());
5142
}
5243

5344
public static function infolist(Infolist $infolist): Infolist
5445
{
55-
return $infolist;
56-
}
57-
58-
public static function getAppointmentFormSchema(): array
59-
{
60-
return [
61-
Subsection::make()
62-
->title(__('appointment.section.mandatory'))
63-
->icon('heroicon-o-document-text')
64-
->columns(3)
65-
->schema([
66-
Select::make('beneficiary_id')
67-
->label(__('field.beneficiary'))
68-
->relationship('beneficiary', 'full_name', fn (Builder $query) => $query->onlyRegular())
69-
->searchable()
70-
->required()
71-
->preload(),
72-
73-
Grid::make(6)
74-
->columnSpanFull()
75-
->schema([
76-
DatePicker::make('date')
77-
->label(__('field.date'))
78-
->required()
79-
->columnSpan(2),
80-
81-
TextInput::make('start_time')
82-
->label(__('field.start_time'))
83-
->type('time')
84-
->rule('date_format:H:i')
85-
->reactive()
86-
->required()
87-
->afterStateUpdated(function ($old, $state, callable $get, callable $set) {
88-
if (blank($state)) {
89-
return;
90-
}
91-
92-
/** @var CarbonImmutable */
93-
$oldStartTime = rescue(
94-
fn () => CarbonImmutable::createFromFormat('H:i', $old),
95-
report: false
96-
);
97-
98-
/** @var CarbonImmutable */
99-
$endTime = rescue(
100-
fn () => CarbonImmutable::createFromFormat('H:i', $get('end_time')),
101-
report: false
102-
);
103-
104-
$offset = $endTime instanceof CarbonImmutable
105-
? $endTime->diffInMinutes($oldStartTime)
106-
: 60;
107-
108-
$set(
109-
'end_time',
110-
CarbonImmutable::createFromFormat('H:i', $state)
111-
->addUnitNoOverflow('minute', $offset, 'day')
112-
->format('H:i')
113-
);
114-
}),
115-
116-
TextInput::make('end_time')
117-
->label(__('field.end_time'))
118-
->type('time')
119-
->after('start_time')
120-
->required()
121-
->disabled(fn (callable $get) => $get('start_time') === null),
122-
]),
123-
]),
124-
125-
Subsection::make()
126-
->title(__('appointment.section.additional'))
127-
->icon('heroicon-o-information-circle')
128-
->columns(3)
129-
->schema([
130-
TextInput::make('type')
131-
->label(__('field.type'))
132-
->columnSpan(2)
133-
->nullable()
134-
->maxLength(100),
135-
136-
TextInput::make('location')
137-
->label(__('field.location'))
138-
->columnSpan(2)
139-
->nullable()
140-
->maxLength(100),
141-
142-
TextInput::make('attendant')
143-
->label(__('field.attendant'))
144-
->columnSpan(2)
145-
->nullable()
146-
->maxLength(100),
147-
]),
148-
149-
Subsection::make()
150-
->title(__('appointment.section.notes'))
151-
->icon('heroicon-o-chat-bubble-bottom-center-text')
152-
->schema([
153-
RichEditor::make('notes')
154-
->disableLabel()
155-
->toolbarButtons(['bold', 'italic', 'strike', 'bulletList', 'orderedList', 'redo', 'undo'])
156-
->nullable()
157-
->maxLength(65535),
158-
]),
159-
];
46+
return $infolist
47+
->schema(AppointmentInfolist::getSchema());
16048
}
16149

16250
public static function table(Table $table): Table

app/Filament/Resources/AppointmentResource/Pages/ViewAppointment.php

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@
44

55
namespace App\Filament\Resources\AppointmentResource\Pages;
66

7-
use App\Filament\Forms\Components\Subsection;
8-
use App\Filament\Forms\Components\Value;
97
use App\Filament\Resources\AppointmentResource;
10-
use App\Filament\Resources\BeneficiaryResource;
11-
use App\Models\Appointment;
12-
use Filament\Forms\Components\Grid;
13-
use Filament\Forms\Components\Section;
14-
use Filament\Forms\Form;
15-
use Filament\Pages\Actions\DeleteAction;
16-
use Filament\Pages\Actions\EditAction;
8+
use Filament\Actions\DeleteAction;
9+
use Filament\Actions\EditAction;
1710
use Filament\Resources\Pages\ViewRecord;
1811

1912
class ViewAppointment extends ViewRecord
@@ -36,63 +29,4 @@ protected function getHeaderActions(): array
3629
DeleteAction::make(),
3730
];
3831
}
39-
40-
public function form(Form $form): Form
41-
{
42-
return $form
43-
->columns(1)
44-
->schema([
45-
Section::make()
46-
->schema([
47-
Subsection::make()
48-
->title(__('appointment.section.mandatory'))
49-
->icon('heroicon-o-document-text')
50-
->columns(4)
51-
->schema([
52-
Value::make('id')
53-
->label(__('field.id')),
54-
55-
Value::make('beneficiary.full_name')
56-
->label(__('field.beneficiary'))
57-
->url(fn (Appointment $record) => BeneficiaryResource::geturl('view', $record->beneficiary)),
58-
59-
Grid::make(4)
60-
->columnSpanFull()
61-
->schema([
62-
Value::make('date')
63-
->label(__('field.date')),
64-
65-
Value::make('interval')
66-
->label(__('field.interval_hours')),
67-
]),
68-
]),
69-
70-
Subsection::make()
71-
->title(__('appointment.section.additional'))
72-
->icon('heroicon-o-information-circle')
73-
->columns(3)
74-
->schema([
75-
Value::make('type')
76-
->label(__('field.type'))
77-
->columnSpan(2),
78-
79-
Value::make('location')
80-
->label(__('field.location'))
81-
->columnSpan(2),
82-
83-
Value::make('attendant')
84-
->label(__('field.attendant'))
85-
->columnSpan(2),
86-
]),
87-
88-
Subsection::make()
89-
->title(__('appointment.section.notes'))
90-
->icon('heroicon-o-chat-bubble-bottom-center-text')
91-
->schema([
92-
Value::make('notes')
93-
->disableLabel(),
94-
]),
95-
]),
96-
]);
97-
}
9832
}

app/Filament/Resources/AppointmentResource/RelationManagers/ServicesRelationManager.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66

77
use App\Enums\Intervention\Status;
88
use App\Filament\Resources\BeneficiaryResource;
9-
use App\Filament\Tables\Columns\TextColumn;
109
use App\Models\Appointment;
1110
use App\Models\Intervention;
12-
use Filament\Forms;
11+
use App\Tables\Columns\TextColumn;
1312
use Filament\Forms\Components\Select;
13+
use Filament\Forms\Components\TextInput;
1414
use Filament\Forms\Form;
1515
use Filament\Resources\RelationManagers\RelationManager;
16-
use Filament\Tables;
16+
use Filament\Tables\Actions\AssociateAction;
17+
use Filament\Tables\Actions\DissociateAction;
18+
use Filament\Tables\Actions\ViewAction;
1719
use Filament\Tables\Columns\SelectColumn;
1820
use Filament\Tables\Table;
1921
use Illuminate\Database\Eloquent\Builder;
@@ -23,8 +25,6 @@ class ServicesRelationManager extends RelationManager
2325
{
2426
protected static string $relationship = 'interventions';
2527

26-
protected static ?string $recordTitleAttribute = 'service_name';
27-
2828
public static function getTitle(Model $ownerRecord, string $pageClass): string
2929
{
3030
return __('intervention.services');
@@ -34,21 +34,18 @@ public function form(Form $form): Form
3434
{
3535
return $form
3636
->schema([
37-
Forms\Components\TextInput::make('name')
37+
TextInput::make('name')
3838
->required()
3939
->maxLength(200),
4040
]);
4141
}
4242

43-
protected function getTableQuery(): Builder
44-
{
45-
return parent::getTableQuery()
46-
->with(['vulnerability', 'parent']);
47-
}
48-
4943
public function table(Table $table): Table
5044
{
5145
return $table
46+
->recordTitleAttribute('service_name')
47+
->inverseRelationship('appointment')
48+
->modifyQueryUsing(fn (Builder $query) => $query->with(['vulnerability', 'parent']))
5249
->columns([
5350
TextColumn::make('id')
5451
->label(__('field.id'))
@@ -78,7 +75,7 @@ public function table(Table $table): Table
7875
//
7976
])
8077
->headerActions([
81-
Tables\Actions\AssociateAction::make()
78+
AssociateAction::make()
8279
->label(__('intervention.action.add_service'))
8380
->modalHeading(__('intervention.action.add_service'))
8481
->icon('heroicon-o-plus-circle')
@@ -113,25 +110,20 @@ public function table(Table $table): Table
113110
'services.name as service_name',
114111
]);
115112
})
116-
->inverseRelationshipName('appointment')
117113
->preloadRecordSelect(),
118114
])
119115
->actions([
120-
Tables\Actions\ViewAction::make()
116+
ViewAction::make()
121117
->url(fn (self $livewire, Intervention $record) => BeneficiaryResource::getUrl('interventions.view', [
122118
'beneficiary' => $livewire->getOwnerRecord()->beneficiary,
123119
'record' => $record,
124120
]))
125121
->iconButton(),
126122

127-
Tables\Actions\DissociateAction::make()
123+
DissociateAction::make()
128124
->modalHeading(__('intervention.action.dissociate_service'))
129-
->inverseRelationshipName('appointment')
130125
->iconButton(),
131126
])
132-
->bulkActions([
133-
//
134-
])
135127
->defaultSort('id', 'desc');
136128
}
137129
}

0 commit comments

Comments
 (0)