diff --git a/app/Filament/Admin/Resources/BenefitResource.php b/app/Filament/Admin/Resources/BenefitResource.php index 3159533f..ee29da9a 100644 --- a/app/Filament/Admin/Resources/BenefitResource.php +++ b/app/Filament/Admin/Resources/BenefitResource.php @@ -10,6 +10,7 @@ use App\Models\Benefit; use App\Models\BenefitService; use Filament\Forms\Components\Actions\Action; +use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Section; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Toggle; @@ -41,10 +42,15 @@ public static function form(Form $form): Form TableRepeater::make('benefitTypes') ->relationship('benefitTypes') ->label(__('nomenclature.headings.benefit_types')) + ->helperText(__('nomenclature.helper_texts.benefit_types')) + ->reorderable() + ->orderColumn() ->columnSpanFull() ->hideLabels() ->addActionLabel(__('nomenclature.actions.add_benefit_type')) ->schema([ + Hidden::make('sort'), + TextInput::make('name') ->label(__('nomenclature.labels.benefit_type_name')) ->maxLength(200), diff --git a/app/Filament/Admin/Resources/ServiceResource.php b/app/Filament/Admin/Resources/ServiceResource.php index c4eb6513..2b1524a6 100644 --- a/app/Filament/Admin/Resources/ServiceResource.php +++ b/app/Filament/Admin/Resources/ServiceResource.php @@ -13,6 +13,7 @@ use App\Models\Service; use App\Models\ServiceIntervention; use Filament\Forms\Components\Actions\Action; +use Filament\Forms\Components\Hidden; use Filament\Forms\Components\Placeholder; use Filament\Forms\Components\Section; use Filament\Forms\Components\TextInput; @@ -77,10 +78,15 @@ public static function form(Form $form): Form TableRepeater::make('serviceInterventions') ->relationship('serviceInterventions') ->label(__('nomenclature.headings.service_intervention')) + ->helperText(__('nomenclature.helper_texts.service_interventions')) + ->reorderable() + ->orderColumn() ->columnSpanFull() ->addActionLabel(__('nomenclature.actions.add_intervention')) ->schema([ - Placeholder::make('id') + Hidden::make('sort'), + + Placeholder::make('index') ->label(__('nomenclature.labels.nr')) ->content(function () { static $index = 1; @@ -88,6 +94,7 @@ public static function form(Form $form): Form return $index++; }) ->hiddenLabel(), + TextInput::make('name') ->columnSpanFull() ->hiddenLabel() @@ -107,7 +114,11 @@ public static function form(Form $form): Form ]) ->deleteAction( fn (Action $action) => $action - ->disabled(function (array $arguments, TableRepeater $component): bool { + ->disabled(function (array $arguments, TableRepeater $component, string $operation): bool { + if ($operation === 'create') { + return false; + } + $items = $component->getState(); $currentItem = $items[$arguments['item']]; diff --git a/app/Models/BenefitType.php b/app/Models/BenefitType.php index 8aa0df50..c916462f 100644 --- a/app/Models/BenefitType.php +++ b/app/Models/BenefitType.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Concerns\HasGeneralStatus; +use App\Models\Scopes\SortOrder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -17,8 +18,15 @@ class BenefitType extends Model protected $fillable = [ 'benefit_id', 'name', + 'sort', ]; + protected static function booted() + { + parent::booted(); + static::addGlobalScope(new SortOrder); + } + public function benefit(): BelongsTo { return $this->belongsTo(Benefit::class); diff --git a/app/Models/Scopes/SortOrder.php b/app/Models/Scopes/SortOrder.php new file mode 100644 index 00000000..a801c21a --- /dev/null +++ b/app/Models/Scopes/SortOrder.php @@ -0,0 +1,34 @@ +column = $column; + $this->direction = $direction; + } + + /** + * Apply the scope to a given Eloquent query builder. + * + * @param Builder $builder + * @param Model $model + * @return void + */ + public function apply(Builder $builder, Model $model): void + { + $builder->orderBy($this->column, $this->direction); + } +} diff --git a/app/Models/ServiceIntervention.php b/app/Models/ServiceIntervention.php index 4c1fcf93..cc5e45e1 100644 --- a/app/Models/ServiceIntervention.php +++ b/app/Models/ServiceIntervention.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Concerns\HasGeneralStatus; +use App\Models\Scopes\SortOrder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -19,8 +20,15 @@ class ServiceIntervention extends Model protected $fillable = [ 'service_id', 'name', + 'sort', ]; + protected static function booted() + { + parent::booted(); + static::addGlobalScope(new SortOrder); + } + public function service(): BelongsTo { return $this->belongsTo(Service::class); diff --git a/database/migrations/2025_01_09_221922_add_sort_column_in_service_interventions_table.php b/database/migrations/2025_01_09_221922_add_sort_column_in_service_interventions_table.php new file mode 100644 index 00000000..34ec2791 --- /dev/null +++ b/database/migrations/2025_01_09_221922_add_sort_column_in_service_interventions_table.php @@ -0,0 +1,17 @@ +integer('sort')->default(0); + }); + } +}; diff --git a/database/migrations/2025_01_10_002445_add_sort_column_in_benefit_types_table.php b/database/migrations/2025_01_10_002445_add_sort_column_in_benefit_types_table.php new file mode 100644 index 00000000..c9647576 --- /dev/null +++ b/database/migrations/2025_01_10_002445_add_sort_column_in_benefit_types_table.php @@ -0,0 +1,17 @@ +integer('sort')->default(0); + }); + } +}; diff --git a/lang/ro/nomenclature.php b/lang/ro/nomenclature.php index 2b74e9c6..b9577f6d 100644 --- a/lang/ro/nomenclature.php +++ b/lang/ro/nomenclature.php @@ -66,6 +66,8 @@ 'inactivate_result_modal' => 'Prin inactivarea rezultatului, acesta nu va mai fi disponibil pentru fi adăugat în nomenclatoarele de rezultate ale organizațiilor Sunrise. Pentru organizațiile care au folosit deja acest rezultat, acesta va fi retras din nomenclatoare, fără să se șteargă din istoricul planului de interventie pentru care a fost folosit.', 'delete_benefit' => 'Beneficiile sociale utilizate deja în fișe de beneficiar nu mai pot fi șterse. Aveți doar opțiunea de a le deactiva.', 'result' => 'Definește un rezultat care va deveni disponibil pentru a fi inclus în nomenclatoarele tuturor organizațiilor Sunrise.', + 'service_interventions' => 'Ordinea intervențiilor din această listă va fi păstrată în platforma Sunrise pentru afișarea opțiunilor în selectorul de intervenții', + 'benefit_types' => 'Ordinea beneficiilor din această listă va fi păstrată în platforma Sunrise pentru afișarea opțiunilor în selectorul de beneficii sociale.', ], 'actions' => [