diff --git a/app/Concerns/HasSortOrder.php b/app/Concerns/HasSortOrder.php new file mode 100644 index 00000000..320e94fd --- /dev/null +++ b/app/Concerns/HasSortOrder.php @@ -0,0 +1,20 @@ +fillable[] = 'sort'; + } + + protected static function bootHasSortOrder(): void + { + static::addGlobalScope(new SortOrder); + } +} diff --git a/app/Filament/Admin/Resources/BenefitResource.php b/app/Filament/Admin/Resources/BenefitResource.php index ee29da9a..ba2f3d47 100644 --- a/app/Filament/Admin/Resources/BenefitResource.php +++ b/app/Filament/Admin/Resources/BenefitResource.php @@ -16,6 +16,7 @@ use Filament\Forms\Components\Toggle; use Filament\Forms\Form; use Filament\Resources\Resource; +use Filament\Tables\Actions\Action as TableAction; use Filament\Tables\Actions\CreateAction; use Filament\Tables\Actions\ViewAction; use Filament\Tables\Columns\TextColumn; @@ -87,6 +88,15 @@ public static function table(Table $table): Table ->url(self::getUrl('create')), ]) ->heading(__('nomenclature.headings.benefit_table')) + ->reorderable('sort') + ->defaultSort('sort') + ->reorderRecordsTriggerAction( + fn (TableAction $action) => $action + ->icon(null) + ->button() + ->outlined() + ->color('primary') + ) ->columns([ TextColumn::make('name') ->label(__('nomenclature.labels.benefit')), diff --git a/app/Filament/Admin/Resources/ResultResource.php b/app/Filament/Admin/Resources/ResultResource.php index a501dce3..56429538 100644 --- a/app/Filament/Admin/Resources/ResultResource.php +++ b/app/Filament/Admin/Resources/ResultResource.php @@ -13,6 +13,7 @@ use Filament\Forms\Components\TextInput; use Filament\Forms\Form; use Filament\Resources\Resource; +use Filament\Tables\Actions\Action as TableAction; use Filament\Tables\Actions\CreateAction; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Table; @@ -48,6 +49,15 @@ public static function table(Table $table): Table CreateAction::make() ->label(__('nomenclature.actions.add_result')), ]) + ->reorderable('sort') + ->defaultSort('sort') + ->reorderRecordsTriggerAction( + fn (TableAction $action) => $action + ->icon(null) + ->button() + ->outlined() + ->color('primary') + ) ->columns([ TextColumn::make('name') ->label(__('nomenclature.labels.result_name')), diff --git a/app/Filament/Admin/Resources/RoleResource.php b/app/Filament/Admin/Resources/RoleResource.php index 859dcd05..0b8bdaad 100644 --- a/app/Filament/Admin/Resources/RoleResource.php +++ b/app/Filament/Admin/Resources/RoleResource.php @@ -18,6 +18,7 @@ use Filament\Forms\Components\Toggle; use Filament\Forms\Form; use Filament\Resources\Resource; +use Filament\Tables\Actions\Action as TableAction; use Filament\Tables\Actions\CreateAction; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Filters\SelectFilter; @@ -81,6 +82,15 @@ public static function table(Table $table): Table ->label(__('nomenclature.actions.add_role')), ]) + ->reorderable('sort') + ->defaultSort('sort') + ->reorderRecordsTriggerAction( + fn (TableAction $action) => $action + ->icon(null) + ->button() + ->outlined() + ->color('primary') + ) ->columns([ TextColumn::make('name') ->label(__('nomenclature.labels.role_name')), diff --git a/app/Filament/Admin/Resources/ServiceResource.php b/app/Filament/Admin/Resources/ServiceResource.php index 2b1524a6..353f2bf2 100644 --- a/app/Filament/Admin/Resources/ServiceResource.php +++ b/app/Filament/Admin/Resources/ServiceResource.php @@ -21,6 +21,7 @@ use Filament\Forms\Form; use Filament\Forms\Get; use Filament\Resources\Resource; +use Filament\Tables\Actions\Action as TableAction; use Filament\Tables\Actions\CreateAction; use Filament\Tables\Actions\ViewAction; use Filament\Tables\Columns\TextColumn; @@ -141,6 +142,15 @@ public static function table(Table $table): Table { return $table ->modifyQueryUsing(fn (Builder $query) => $query->withCount(['organizationServices'])) + ->reorderable('sort') + ->defaultSort('sort') + ->reorderRecordsTriggerAction( + fn (TableAction $action) => $action + ->icon(null) + ->button() + ->outlined() + ->color('primary') + ) ->columns([ TextColumn::make('name') ->label(__('nomenclature.labels.name')) diff --git a/app/Models/Benefit.php b/app/Models/Benefit.php index 0e36d7c9..714e25d8 100644 --- a/app/Models/Benefit.php +++ b/app/Models/Benefit.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Concerns\HasGeneralStatus; +use App\Concerns\HasSortOrder; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -14,6 +15,7 @@ class Benefit extends Model { use HasFactory; use HasGeneralStatus; + use HasSortOrder; protected $fillable = [ 'name', diff --git a/app/Models/BenefitType.php b/app/Models/BenefitType.php index c916462f..ea24f6bb 100644 --- a/app/Models/BenefitType.php +++ b/app/Models/BenefitType.php @@ -5,7 +5,7 @@ namespace App\Models; use App\Concerns\HasGeneralStatus; -use App\Models\Scopes\SortOrder; +use App\Concerns\HasSortOrder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -14,19 +14,13 @@ class BenefitType extends Model { use HasFactory; use HasGeneralStatus; + use HasSortOrder; 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/Result.php b/app/Models/Result.php index 48596f5a..dd5c2d40 100644 --- a/app/Models/Result.php +++ b/app/Models/Result.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Concerns\HasGeneralStatus; +use App\Concerns\HasSortOrder; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -14,6 +15,7 @@ class Result extends Model { use HasFactory; use HasGeneralStatus; + use HasSortOrder; protected $fillable = [ 'name', diff --git a/app/Models/Role.php b/app/Models/Role.php index 0781891e..55755fcf 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Concerns\HasGeneralStatus; +use App\Concerns\HasSortOrder; use App\Enums\AdminPermission; use App\Enums\CasePermission; use Illuminate\Database\Eloquent\Casts\AsEnumCollection; @@ -16,6 +17,7 @@ class Role extends Model { use HasFactory; use HasGeneralStatus; + use HasSortOrder; protected $fillable = [ 'name', diff --git a/app/Models/Service.php b/app/Models/Service.php index f7763688..469dae8c 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -5,6 +5,7 @@ namespace App\Models; use App\Concerns\HasGeneralStatus; +use App\Concerns\HasSortOrder; use App\Enums\CounselingSheet; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -15,6 +16,7 @@ class Service extends Model { use HasFactory; use HasGeneralStatus; + use HasSortOrder; protected $fillable = [ 'name', diff --git a/app/Models/ServiceIntervention.php b/app/Models/ServiceIntervention.php index cc5e45e1..e217f50c 100644 --- a/app/Models/ServiceIntervention.php +++ b/app/Models/ServiceIntervention.php @@ -5,7 +5,7 @@ namespace App\Models; use App\Concerns\HasGeneralStatus; -use App\Models\Scopes\SortOrder; +use App\Concerns\HasSortOrder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -16,19 +16,13 @@ class ServiceIntervention extends Model { use HasFactory; use HasGeneralStatus; + use HasSortOrder; 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_10_004906_add_sort_column_in_services_table.php b/database/migrations/2025_01_10_004906_add_sort_column_in_services_table.php new file mode 100644 index 00000000..25a977ad --- /dev/null +++ b/database/migrations/2025_01_10_004906_add_sort_column_in_services_table.php @@ -0,0 +1,17 @@ +integer('sort')->default(0); + }); + } +}; diff --git a/database/migrations/2025_01_10_005052_add_sort_column_in_benefits_table.php b/database/migrations/2025_01_10_005052_add_sort_column_in_benefits_table.php new file mode 100644 index 00000000..647e475d --- /dev/null +++ b/database/migrations/2025_01_10_005052_add_sort_column_in_benefits_table.php @@ -0,0 +1,17 @@ +integer('sort')->default(0); + }); + } +}; diff --git a/database/migrations/2025_01_10_005204_add_sort_column_in_results_table.php b/database/migrations/2025_01_10_005204_add_sort_column_in_results_table.php new file mode 100644 index 00000000..0199c89b --- /dev/null +++ b/database/migrations/2025_01_10_005204_add_sort_column_in_results_table.php @@ -0,0 +1,17 @@ +integer('sort')->default(0); + }); + } +}; diff --git a/database/migrations/2025_01_10_005232_add_sort_column_in_roles_table.php b/database/migrations/2025_01_10_005232_add_sort_column_in_roles_table.php new file mode 100644 index 00000000..4b4a6133 --- /dev/null +++ b/database/migrations/2025_01_10_005232_add_sort_column_in_roles_table.php @@ -0,0 +1,17 @@ +integer('sort')->default(0); + }); + } +}; diff --git a/lang/vendor/filament-tables/ro/table.php b/lang/vendor/filament-tables/ro/table.php new file mode 100644 index 00000000..6e6ec4e2 --- /dev/null +++ b/lang/vendor/filament-tables/ro/table.php @@ -0,0 +1,16 @@ + [ + + 'disable_reordering' => [ + 'label' => 'Salvează modificările', + ], + + 'enable_reordering' => [ + 'label' => 'Ordonează lista', + ], + ], +]; diff --git a/resources/views/vendor/filament-tables/index.blade.php b/resources/views/vendor/filament-tables/index.blade.php new file mode 100644 index 00000000..01d02307 --- /dev/null +++ b/resources/views/vendor/filament-tables/index.blade.php @@ -0,0 +1,1298 @@ +@php + use Filament\Support\Enums\Alignment; + use Filament\Support\Enums\VerticalAlignment; + use Filament\Support\Facades\FilamentView; + use Filament\Tables\Columns\Column; + use Filament\Tables\Columns\ColumnGroup; + use Filament\Tables\Enums\ActionsPosition; + use Filament\Tables\Enums\FiltersLayout; + use Filament\Tables\Enums\RecordCheckboxPosition; + use Illuminate\Support\Str; + + $actions = $getActions(); + $flatActionsCount = count($getFlatActions()); + $actionsAlignment = $getActionsAlignment(); + $actionsPosition = $getActionsPosition(); + $actionsColumnLabel = $getActionsColumnLabel(); + $activeFiltersCount = $getActiveFiltersCount(); + $columns = $getVisibleColumns(); + $collapsibleColumnsLayout = $getCollapsibleColumnsLayout(); + $columnsLayout = $getColumnsLayout(); + $content = $getContent(); + $contentGrid = $getContentGrid(); + $contentFooter = $getContentFooter(); + $filterIndicators = $getFilterIndicators(); + $hasColumnGroups = $hasColumnGroups(); + $hasColumnsLayout = $hasColumnsLayout(); + $hasSummary = $hasSummary(); + $header = $getHeader(); + $headerActions = array_filter( + $getHeaderActions(), + fn (\Filament\Tables\Actions\Action | \Filament\Tables\Actions\BulkAction | \Filament\Tables\Actions\ActionGroup $action): bool => $action->isVisible(), + ); + $headerActionsPosition = $getHeaderActionsPosition(); + $heading = $getHeading(); + $group = $getGrouping(); + $bulkActions = array_filter( + $getBulkActions(), + fn (\Filament\Tables\Actions\BulkAction | \Filament\Tables\Actions\ActionGroup $action): bool => $action->isVisible(), + ); + $groups = $getGroups(); + $description = $getDescription(); + $isGroupsOnly = $isGroupsOnly() && $group; + $isReorderable = $isReorderable(); + $isReordering = $isReordering(); + $areGroupingSettingsVisible = (! $isReordering) && count($groups) && (! $areGroupingSettingsHidden()); + $isGroupingDirectionSettingHidden = $isGroupingDirectionSettingHidden(); + $isColumnSearchVisible = $isSearchableByColumn(); + $isGlobalSearchVisible = $isSearchable(); + $isSearchOnBlur = $isSearchOnBlur(); + $isSelectionEnabled = $isSelectionEnabled() && (! $isGroupsOnly); + $selectsCurrentPageOnly = $selectsCurrentPageOnly(); + $recordCheckboxPosition = $getRecordCheckboxPosition(); + $isStriped = $isStriped(); + $isLoaded = $isLoaded(); + $hasFilters = $isFilterable(); + $filtersLayout = $getFiltersLayout(); + $filtersTriggerAction = $getFiltersTriggerAction(); + $hasFiltersDialog = $hasFilters && in_array($filtersLayout, [FiltersLayout::Dropdown, FiltersLayout::Modal]); + $hasFiltersAboveContent = $hasFilters && in_array($filtersLayout, [FiltersLayout::AboveContent, FiltersLayout::AboveContentCollapsible]); + $hasFiltersAboveContentCollapsible = $hasFilters && ($filtersLayout === FiltersLayout::AboveContentCollapsible); + $hasFiltersBelowContent = $hasFilters && ($filtersLayout === FiltersLayout::BelowContent); + $hasColumnToggleDropdown = $hasToggleableColumns(); + $hasHeader = $header || $heading || $description || ($headerActions && (! $isReordering)) || $isReorderable || $areGroupingSettingsVisible || $isGlobalSearchVisible || $hasFilters || count($filterIndicators) || $hasColumnToggleDropdown; + $hasHeaderToolbar = $isReorderable || $areGroupingSettingsVisible || $isGlobalSearchVisible || $hasFiltersDialog || $hasColumnToggleDropdown; + $pluralModelLabel = $getPluralModelLabel(); + $records = $isLoaded ? $getRecords() : null; + $searchDebounce = $getSearchDebounce(); + $allSelectableRecordsCount = ($isSelectionEnabled && $isLoaded) ? $getAllSelectableRecordsCount() : null; + $columnsCount = count($columns); + $reorderRecordsTriggerAction = $getReorderRecordsTriggerAction($isReordering); + $toggleColumnsTriggerAction = $getToggleColumnsTriggerAction(); + $page = $this->getTablePage(); + $defaultSortOptionLabel = $getDefaultSortOptionLabel(); + + if (count($actions) && (! $isReordering)) { + $columnsCount++; + } + + if ($isSelectionEnabled || $isReordering) { + $columnsCount++; + } + + if ($group) { + $groupedSummarySelectedState = $this->getTableSummarySelectedState($this->getAllTableSummaryQuery(), modifyQueryUsing: fn (\Illuminate\Database\Query\Builder $query) => $group->groupQuery($query, model: $getQuery()->getModel())); + } + + $getHiddenClasses = function (Column | ColumnGroup $column): ?string { + if ($breakpoint = $column->getHiddenFrom()) { + return match ($breakpoint) { + 'sm' => 'sm:hidden', + 'md' => 'md:hidden', + 'lg' => 'lg:hidden', + 'xl' => 'xl:hidden', + '2xl' => '2xl:hidden', + }; + } + + if ($breakpoint = $column->getVisibleFrom()) { + return match ($breakpoint) { + 'sm' => 'hidden sm:table-cell', + 'md' => 'hidden md:table-cell', + 'lg' => 'hidden lg:table-cell', + 'xl' => 'hidden xl:table-cell', + '2xl' => 'hidden 2xl:table-cell', + }; + } + + return null; + }; +@endphp + +