Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Dec 22, 2023
1 parent 9e963ea commit de3b928
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')),
]);
}
}
8 changes: 5 additions & 3 deletions app/Filament/Organizations/Resources/CommunityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,7 +81,6 @@ public static function infolist(Infolist $infolist): Infolist
]),

InfolistSplit::make([

TextEntry::make('website')
->icon('heroicon-o-link')
->hiddenLabel()
Expand All @@ -98,7 +98,6 @@ public static function infolist(Infolist $infolist): Infolist
->hiddenLabel()
->url(fn (string $state) => "tel:{$state}")
->openUrlInNewTab(),

]),
]),
]);
Expand Down Expand Up @@ -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'))
Expand Down
115 changes: 115 additions & 0 deletions app/Tables/Filters/ServicesFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

declare(strict_types=1);

namespace App\Tables\Filters;

use App\Models\Service;
use Closure;
use Filament\Forms\Components\CheckboxList;
use Filament\Tables\Filters\BaseFilter;
use Filament\Tables\Filters\Concerns;
use Filament\Tables\Filters\Indicator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;

class ServicesFilter extends BaseFilter
{
use Concerns\HasOptions;
use Concerns\HasRelationship;

protected string | Closure | null $attribute = null;

protected bool | Closure $isSearchable = false;

public function attribute(string | Closure | null $attribute): static
{
$this->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')
);
}
}
5 changes: 4 additions & 1 deletion lang/ro/organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
],

'filter' => [
'service' => [
'label' => 'Servicii',
],
'county' => [
'label' => 'Filtrează după locație',
'label' => 'Locație',
'placeholder' => 'Național',
],
],
Expand Down

0 comments on commit de3b928

Please sign in to comment.