Skip to content

Commit

Permalink
change RepeatableEntry with TableEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
alexPopaCode4 committed Jan 8, 2025
1 parent f2b2e7d commit 255afd0
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 233 deletions.
31 changes: 21 additions & 10 deletions app/Filament/Admin/Resources/BenefitResource/Pages/ViewBenefit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

use App\Actions\BackAction;
use App\Filament\Admin\Resources\BenefitResource;
use App\Filament\Admin\Resources\BenefitResource\Widgets\BenefitTypesWidget;
use App\Infolists\Components\TableEntry;
use Filament\Actions\EditAction;
use Filament\Forms\Form;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Infolist;
use Filament\Resources\Pages\ViewRecord;
use Illuminate\Contracts\Support\Htmlable;

Expand Down Expand Up @@ -45,15 +47,24 @@ public function getTitle(): string|Htmlable
return $this->record->name;
}

public function form(Form $form): Form
public function infolist(Infolist $infolist): Infolist
{
return $form->schema([]);
}
return $infolist->schema([
Section::make()
->maxWidth('3xl')
->schema([
TableEntry::make('benefitTypes')
->hiddenLabel()
->schema([
TextEntry::make('name')
->label(__('nomenclature.labels.benefit_type_name'))
->hiddenLabel(),

protected function getFooterWidgets(): array
{
return [
BenefitTypesWidget::class,
];
TextEntry::make('status')
->label(__('nomenclature.labels.status'))
->hiddenLabel(),
]),
]),
]);
}
}

This file was deleted.

96 changes: 50 additions & 46 deletions app/Filament/Admin/Resources/ServiceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,54 +71,58 @@ public static function form(Form $form): Form
->options(CounselingSheet::options()),

]),
TableRepeater::make('serviceInterventions')
->relationship('serviceInterventions')
->label(__('nomenclature.headings.service_intervention'))
->columnSpanFull()
->addActionLabel(__('nomenclature.actions.add_intervention'))
->schema([
Placeholder::make('id')
->label(__('nomenclature.labels.nr'))
->content(function () {
static $index = 1;

return $index++;
})
->hiddenLabel(),
TextInput::make('name')
->columnSpanFull()
->hiddenLabel()
->maxLength(200)
->label(__('nomenclature.labels.intervention_name')),

Toggle::make('status')
Section::make()
->schema([
TableRepeater::make('serviceInterventions')
->relationship('serviceInterventions')
->label(__('nomenclature.headings.service_intervention'))
->columnSpanFull()
->live()
->default(true)
->afterStateUpdated(function (bool $state) {
if (! $state) {
dd('Modal cu inactivare de hard confirmation');
}
})
->label(fn (Get $get) => $get('status') ? __('nomenclature.labels.active') : __('nomenclature.labels.inactive')),
])
->deleteAction(
fn (Action $action) => $action
->disabled(function (array $arguments, TableRepeater $component): bool {
$items = $component->getState();
$currentItem = $items[$arguments['item']];

$serviceIntervention = ServiceIntervention::where('id', $currentItem['id'])
->withCount('organizationIntervention')
->first();

if (! $serviceIntervention) {
return false;
}

return $serviceIntervention->organization_intervention_count > 0;
})
),
->addActionLabel(__('nomenclature.actions.add_intervention'))
->schema([
Placeholder::make('id')
->label(__('nomenclature.labels.nr'))
->content(function () {
static $index = 1;

return $index++;
})
->hiddenLabel(),
TextInput::make('name')
->columnSpanFull()
->hiddenLabel()
->maxLength(200)
->label(__('nomenclature.labels.intervention_name')),

Toggle::make('status')
->columnSpanFull()
->live()
->default(true)
->afterStateUpdated(function (bool $state) {
if (! $state) {
dd('Modal cu inactivare de hard confirmation');
}
})
->label(fn (Get $get) => $get('status') ? __('nomenclature.labels.active') : __('nomenclature.labels.inactive')),
])
->deleteAction(
fn (Action $action) => $action
->disabled(function (array $arguments, TableRepeater $component): bool {
$items = $component->getState();
$currentItem = $items[$arguments['item']];

$serviceIntervention = ServiceIntervention::where('id', $currentItem['id'])
->withCount('organizationIntervention')
->first();

if (! $serviceIntervention) {
return false;
}

return $serviceIntervention->organization_intervention_count > 0;
})
),
]),
]);
}

Expand Down
37 changes: 25 additions & 12 deletions app/Filament/Admin/Resources/ServiceResource/Pages/ViewService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
use App\Actions\BackAction;
use App\Enums\CounselingSheet;
use App\Filament\Admin\Resources\ServiceResource;
use App\Filament\Admin\Resources\ServiceResource\Widgets\InterventionsWidget;
use App\Filament\Organizations\Resources\InterventionServiceResource\Pages\EditCounselingSheet;
use App\Infolists\Components\Notice;
use App\Infolists\Components\TableEntry;
use Filament\Actions;
use Filament\Actions\StaticAction;
use Filament\Infolists\Components\Actions\Action;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Infolist;
use Filament\Resources\Pages\ViewRecord;
use Illuminate\Contracts\Support\Htmlable;
Expand Down Expand Up @@ -87,18 +88,30 @@ public function infolist(Infolist $infolist): Infolist
->link(),
),
]),
]);
}

protected function hasInfolist(): bool
{
return true;
}
Section::make()
->schema([
TableEntry::make('serviceInterventions')
->hiddenLabel()
->schema([
TextEntry::make('name')
->label(__('nomenclature.labels.intervention_name'))
->hiddenLabel(),

protected function getFooterWidgets(): array
{
return [
InterventionsWidget::class,
];
TextEntry::make('institutions_count')
->label(__('nomenclature.labels.institutions'))
->hiddenLabel(),

TextEntry::make('organizations_count')
->label(__('nomenclature.labels.centers'))
->hiddenLabel(),

TextEntry::make('status')
->label(__('nomenclature.labels.status'))
->hiddenLabel(),

]),
]),
]);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Infolists\Components\Actions\Edit;
use App\Infolists\Components\DateEntry;
use App\Infolists\Components\Location;
use App\Infolists\Components\TableEntry;
use App\Services\Breadcrumb\BeneficiaryBreadcrumb;
use Filament\Infolists\Components\Group;
use Filament\Infolists\Components\RepeatableEntry;
Expand Down Expand Up @@ -295,21 +296,25 @@ public function getPartnerSchema(): array
public function getDetailedEvaluationSchema(): array
{
return [
RepeatableEntry::make('detailedEvaluationSpecialists')
TableEntry::make('detailedEvaluationSpecialists')
->columns(4)
->label(__('beneficiary.section.detailed_evaluation.labels.specialists'))
->schema([
TextEntry::make('full_name')
->label(__('beneficiary.section.detailed_evaluation.labels.full_name')),
->label(__('beneficiary.section.detailed_evaluation.labels.full_name'))
->hiddenLabel(),

TextEntry::make('institution')
->label(__('beneficiary.section.detailed_evaluation.labels.institution')),
->label(__('beneficiary.section.detailed_evaluation.labels.institution'))
->hiddenLabel(),

TextEntry::make('relationship')
->label(__('beneficiary.section.detailed_evaluation.labels.relationship')),
->label(__('beneficiary.section.detailed_evaluation.labels.relationship'))
->hiddenLabel(),

DateEntry::make('date')
->label(__('beneficiary.section.detailed_evaluation.labels.contact_date')),
->label(__('beneficiary.section.detailed_evaluation.labels.contact_date'))
->hiddenLabel(),
]),

RepeatableEntry::make('meetings')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
use App\Filament\Organizations\Resources\InterventionServiceResource\Pages\EditCounselingSheet;
use App\Filament\Organizations\Resources\ServiceResource;
use App\Infolists\Components\Notice;
use App\Infolists\Components\TableEntry;
use App\Models\BeneficiaryIntervention;
use Filament\Actions\EditAction;
use Filament\Actions\StaticAction;
use Filament\Infolists\Components\Actions\Action;
use Filament\Infolists\Components\Section;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Infolist;
use Filament\Resources\Pages\ViewRecord;
use Illuminate\Contracts\Support\Htmlable;
Expand Down Expand Up @@ -47,6 +50,12 @@ protected function getHeaderActions(): array

public function infolist(Infolist $infolist): Infolist
{
$this->getRecord()
->load([
'interventions.serviceInterventionWithoutStatusCondition',
'interventions.beneficiaryInterventions.interventionPlan',
]);

return $infolist->schema([
Section::make()
->visible(fn () => $this->getRecord()->serviceWithoutStatusCondition->counseling_sheet)
Expand Down Expand Up @@ -87,18 +96,30 @@ public function infolist(Infolist $infolist): Infolist
->modalAutofocus(false),
),
]),
]);
}

protected function hasInfolist(): bool
{
return true;
}
TableEntry::make('interventions')
->columnSpanFull()
->hiddenLabel()
->schema([
TextEntry::make('serviceInterventionWithoutStatusCondition.name')
->hiddenLabel()
->label(__('service.labels.interventions')),

protected function getHeaderWidgets(): array
{
return [
ServiceResource\Widgets\ListServiceInterventions::class,
];
TextEntry::make('cases')
->hiddenLabel()
->label(__('service.labels.cases'))
->default(
fn ($record) => $record->beneficiaryInterventions
?->map(fn (BeneficiaryIntervention $beneficiaryIntervention) => $beneficiaryIntervention->interventionPlan->beneficiary_id)
->unique()
->count()
),

TextEntry::make('status')
->hiddenLabel()
->label(__('service.labels.status')),
]),

]);
}
}
Loading

0 comments on commit 255afd0

Please sign in to comment.