Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

479 reorder nomenclature items #489

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions app/Concerns/HasSortOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace App\Concerns;

use App\Models\Scopes\SortOrder;

trait HasSortOrder
{
public function initializeHasSortOrder(): void
{
$this->fillable[] = 'sort';
}

protected static function bootHasSortOrder(): void
{
static::addGlobalScope(new SortOrder);
}
}
16 changes: 16 additions & 0 deletions app/Filament/Admin/Resources/BenefitResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
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;
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;
Expand All @@ -41,10 +43,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),
Expand Down Expand Up @@ -81,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')),
Expand Down
10 changes: 10 additions & 0 deletions app/Filament/Admin/Resources/ResultResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')),
Expand Down
10 changes: 10 additions & 0 deletions app/Filament/Admin/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')),
Expand Down
25 changes: 23 additions & 2 deletions app/Filament/Admin/Resources/ServiceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
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;
use Filament\Forms\Components\Toggle;
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;
Expand Down Expand Up @@ -77,17 +79,23 @@ 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;

return $index++;
})
->hiddenLabel(),

TextInput::make('name')
->columnSpanFull()
->hiddenLabel()
Expand All @@ -107,7 +115,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']];

Expand All @@ -130,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'))
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Benefit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +15,7 @@ class Benefit extends Model
{
use HasFactory;
use HasGeneralStatus;
use HasSortOrder;

protected $fillable = [
'name',
Expand Down
2 changes: 2 additions & 0 deletions app/Models/BenefitType.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Models;

use App\Concerns\HasGeneralStatus;
use App\Concerns\HasSortOrder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -13,6 +14,7 @@ class BenefitType extends Model
{
use HasFactory;
use HasGeneralStatus;
use HasSortOrder;

protected $fillable = [
'benefit_id',
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +15,7 @@ class Result extends Model
{
use HasFactory;
use HasGeneralStatus;
use HasSortOrder;

protected $fillable = [
'name',
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,6 +17,7 @@ class Role extends Model
{
use HasFactory;
use HasGeneralStatus;
use HasSortOrder;

protected $fillable = [
'name',
Expand Down
34 changes: 34 additions & 0 deletions app/Models/Scopes/SortOrder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace App\Models\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;

class SortOrder implements Scope
{
private string $column;

private string $direction;

public function __construct(string $column = 'sort', string $direction = 'asc')
{
$this->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);
}
}
2 changes: 2 additions & 0 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,7 @@ class Service extends Model
{
use HasFactory;
use HasGeneralStatus;
use HasSortOrder;

protected $fillable = [
'name',
Expand Down
2 changes: 2 additions & 0 deletions app/Models/ServiceIntervention.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\Models;

use App\Concerns\HasGeneralStatus;
use App\Concerns\HasSortOrder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -15,6 +16,7 @@ class ServiceIntervention extends Model
{
use HasFactory;
use HasGeneralStatus;
use HasSortOrder;

protected $fillable = [
'service_id',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('roles', function (Blueprint $table) {
$table->integer('sort')->default(0);
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('service_interventions', function (Blueprint $table) {
$table->integer('sort')->default(0);
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('benefit_types', function (Blueprint $table) {
$table->integer('sort')->default(0);
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::table('services', function (Blueprint $table) {
$table->integer('sort')->default(0);
});
}
};
Loading
Loading