feat: RoleTemplateResource + UserResource UI for Permission System
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\RoleTemplates\Schemas;
|
||||
|
||||
use App\Models\PermissionModule;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class RoleTemplateForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
$modules = PermissionModule::orderBy('label')->get();
|
||||
|
||||
$permissionComponents = [];
|
||||
foreach ($modules as $module) {
|
||||
$options = [];
|
||||
foreach ($module->actions as $action) {
|
||||
$label = match ($action) {
|
||||
'view' => 'Xem',
|
||||
'create' => 'Thêm',
|
||||
'update' => 'Sửa',
|
||||
'delete' => 'Xóa',
|
||||
'restore' => 'Khôi phục',
|
||||
'forceDelete' => 'Xóa vĩnh viễn',
|
||||
'export' => 'Xuất Excel',
|
||||
default => $action,
|
||||
};
|
||||
$options[$action] = $label;
|
||||
}
|
||||
|
||||
$permissionComponents[] = CheckboxList::make("permissions.{$module->module}")
|
||||
->label($module->label)
|
||||
->options($options)
|
||||
->columns(4)
|
||||
->columnSpanFull();
|
||||
}
|
||||
|
||||
return $schema
|
||||
->components([
|
||||
Grid::make(2)
|
||||
->schema([
|
||||
Section::make('Thông tin nhóm')
|
||||
->columnSpan(1)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label('Tên nhóm')
|
||||
->required(),
|
||||
TextInput::make('description')
|
||||
->label('Mô tả'),
|
||||
Toggle::make('is_active')
|
||||
->label('Kích hoạt')
|
||||
->default(true),
|
||||
]),
|
||||
|
||||
Section::make('Phân quyền theo module')
|
||||
->columnSpan(1)
|
||||
->schema($permissionComponents),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user