From de3b928b0111affc42750fdd156a137f7e13a0f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Ioni=C8=9B=C4=83?= Date: Fri, 22 Dec 2023 18:20:22 +0200 Subject: [PATCH] wip --- .../Pages/ViewBeneficiary.php | 37 +++++- .../Resources/CommunityResource.php | 8 +- app/Tables/Filters/ServicesFilter.php | 115 ++++++++++++++++++ lang/ro/organization.php | 5 +- 4 files changed, 160 insertions(+), 5 deletions(-) create mode 100644 app/Tables/Filters/ServicesFilter.php diff --git a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/ViewBeneficiary.php b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/ViewBeneficiary.php index 5953507e..75ce4a21 100644 --- a/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/ViewBeneficiary.php +++ b/app/Filament/Organizations/Resources/BeneficiaryResource/Pages/ViewBeneficiary.php @@ -4,6 +4,7 @@ namespace App\Filament\Organizations\Resources\BeneficiaryResource\Pages; +use App\Enums\Ternary; use App\Filament\Organizations\Resources\BeneficiaryResource; use App\Infolists\Components\EnumEntry; use Filament\Infolists\Components\Actions\Action; @@ -105,7 +106,41 @@ protected function personalInformationSection(): Section 'class' => 'h-full', ]) ->schema([ - // + EnumEntry::make('presentation_mode') + ->label(__('field.presentation_mode')), + + TextEntry::make('referringInstitution.name') + ->label(__('field.referring_institution')), + + TextEntry::make('family_doctor_name') + ->label(__('field.family_doctor_name')), + + TextEntry::make('family_doctor_contact') + ->label(__('field.family_doctor_contact')) + ->icon('heroicon-o-phone') + ->url(fn ($state) => "tel:{$state}"), + + EnumEntry::make('aggressor.relationship') + ->label(__('field.aggressor_relationship')), + + EnumEntry::make('aggressor.gender') + ->label(__('field.aggressor_gender')), + + EnumEntry::make('aggressor.has_violence_history') + ->label(__('field.aggressor_has_violence_history')), + + EnumEntry::make('has_police_reports') + ->label(__('field.has_police_reports')) + ->suffix(fn ($record) => Ternary::isYes($record->has_police_reports) + ? " ({$record->police_report_count})" : null), + + EnumEntry::make('has_medical_reports') + ->label(__('field.has_medical_reports')) + ->suffix(fn ($record) => Ternary::isYes($record->has_medical_reports) + ? " ({$record->medical_report_count})" : null), + + EnumEntry::make('has_protection_order') + ->label(__('field.has_protection_order')), ]); } } diff --git a/app/Filament/Organizations/Resources/CommunityResource.php b/app/Filament/Organizations/Resources/CommunityResource.php index a6d3e49f..126b80f4 100644 --- a/app/Filament/Organizations/Resources/CommunityResource.php +++ b/app/Filament/Organizations/Resources/CommunityResource.php @@ -7,6 +7,7 @@ use App\Filament\Organizations\Resources\CommunityResource\Pages; use App\Models\CommunityProfile; use App\Tables\Columns\ServiceChipsColumn; +use App\Tables\Filters\ServicesFilter; use Filament\Infolists\Components\Grid; use Filament\Infolists\Components\Section; use Filament\Infolists\Components\SpatieMediaLibraryImageEntry; @@ -80,7 +81,6 @@ public static function infolist(Infolist $infolist): Infolist ]), InfolistSplit::make([ - TextEntry::make('website') ->icon('heroicon-o-link') ->hiddenLabel() @@ -98,7 +98,6 @@ public static function infolist(Infolist $infolist): Infolist ->hiddenLabel() ->url(fn (string $state) => "tel:{$state}") ->openUrlInNewTab(), - ]), ]), ]); @@ -150,11 +149,14 @@ public static function table(Table $table): Table ]) ->from('md'), ]) - ->contentGrid([ 'default' => 1, ]) ->filters([ + ServicesFilter::make('services') + ->label(__('organization.filter.service.label')) + ->columnSpanFull(), + SelectFilter::make('county') ->relationship('counties', 'name') ->label(__('organization.filter.county.label')) diff --git a/app/Tables/Filters/ServicesFilter.php b/app/Tables/Filters/ServicesFilter.php new file mode 100644 index 00000000..1f0376e7 --- /dev/null +++ b/app/Tables/Filters/ServicesFilter.php @@ -0,0 +1,115 @@ +attribute = $attribute; + + return $this; + } + + public function getAttribute(): string + { + return $this->evaluate($this->attribute) ?? $this->getName(); + } + + public function searchable(bool | Closure $condition = true): static + { + $this->isSearchable = $condition; + + return $this; + } + + public function isSearchable(): bool + { + return (bool) $this->evaluate($this->isSearchable); + } + + protected function setUp(): void + { + parent::setUp(); + + $this->options(fn () => $this->getServices()); + + $this->query(function (Builder $query, array $data = []) { + if (blank($data['values'] ?? null)) { + return; + } + + $query->whereHas('services', function (Builder $query) use ($data) { + $query->whereIn('id', $data['values']); + }) + ->dd(); + }); + + $this->indicateUsing(function (ServicesFilter $filter, array $state): array { + if (blank($state['values'] ?? null)) { + return []; + } + + $label = $this->getServices() + ->filter(fn ($value, $key) => \in_array($key, $state['values'])) + ->values() + ->join(', ', ' & '); + + $indicator = $filter->getIndicator(); + + if (! $indicator instanceof Indicator) { + $indicator = Indicator::make("{$indicator}: {$label}"); + } + + return [$indicator]; + }); + } + + public function getFormField(): CheckboxList + { + $field = CheckboxList::make('values') + ->label($this->getLabel()) + ->searchable($this->isSearchable()) + ->options($this->getOptions()) + ->columns([ + 'sm' => 2, + 'lg' => 3, + 'xl' => 4, + ]); + + if (filled($defaultState = $this->getDefaultState())) { + $field->default($defaultState); + } + + return $field; + } + + private function getServices(): Collection + { + return Cache::driver('array') + ->remember( + MINUTE_IN_SECONDS, + 'all-services-name-id', + fn () => Service::pluck('name', 'id') + ); + } +} diff --git a/lang/ro/organization.php b/lang/ro/organization.php index 1dfc4415..c6c94fd5 100644 --- a/lang/ro/organization.php +++ b/lang/ro/organization.php @@ -29,8 +29,11 @@ ], 'filter' => [ + 'service' => [ + 'label' => 'Servicii', + ], 'county' => [ - 'label' => 'Filtrează după locație', + 'label' => 'Locație', 'placeholder' => 'Național', ], ],