diff --git a/app/Filament/Resources/RoleTemplates/Pages/CreateRoleTemplate.php b/app/Filament/Resources/RoleTemplates/Pages/CreateRoleTemplate.php new file mode 100644 index 0000000..7e1e187 --- /dev/null +++ b/app/Filament/Resources/RoleTemplates/Pages/CreateRoleTemplate.php @@ -0,0 +1,11 @@ +value; + protected static ?int $navigationSort = 90; + + protected static ?string $modelLabel = 'Mẫu phân quyền'; + protected static ?string $pluralModelLabel = 'Mẫu phân quyền'; + + public static function form(Schema $schema): Schema + { + return RoleTemplateForm::configure($schema); + } + + public static function table(Table $table): Table + { + return RoleTemplatesTable::configure($table); + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListRoleTemplates::route('/'), + 'create' => Pages\CreateRoleTemplate::route('/create'), + 'edit' => Pages\EditRoleTemplate::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Resources/RoleTemplates/Schemas/RoleTemplateForm.php b/app/Filament/Resources/RoleTemplates/Schemas/RoleTemplateForm.php new file mode 100644 index 0000000..1970c04 --- /dev/null +++ b/app/Filament/Resources/RoleTemplates/Schemas/RoleTemplateForm.php @@ -0,0 +1,66 @@ +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), + ]), + ]); + } +} diff --git a/app/Filament/Resources/RoleTemplates/Tables/RoleTemplatesTable.php b/app/Filament/Resources/RoleTemplates/Tables/RoleTemplatesTable.php new file mode 100644 index 0000000..ecbfddb --- /dev/null +++ b/app/Filament/Resources/RoleTemplates/Tables/RoleTemplatesTable.php @@ -0,0 +1,47 @@ +columns([ + TextColumn::make('name') + ->label('Tên nhóm') + ->searchable() + ->sortable(), + + TextColumn::make('description') + ->label('Mô tả') + ->limit(50) + ->toggleable(), + + IconColumn::make('is_active') + ->label('Kích hoạt') + ->boolean() + ->alignCenter(), + + TextColumn::make('users_count') + ->label('Số user') + ->counts('users') + ->alignCenter(), + + TextColumn::make('created_at') + ->label('Ngày tạo') + ->dateTime('d/m/Y') + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + Tables\Filters\TernaryFilter::make('is_active') + ->label('Trạng thái'), + ]) + ->defaultSort('created_at', 'desc'); + } +} diff --git a/app/Filament/Resources/Users/Pages/CreateUser.php b/app/Filament/Resources/Users/Pages/CreateUser.php new file mode 100644 index 0000000..125b3ff --- /dev/null +++ b/app/Filament/Resources/Users/Pages/CreateUser.php @@ -0,0 +1,11 @@ +components([ + Grid::make(2) + ->schema([ + Section::make('Thông tin tài khoản') + ->columnSpan(1) + ->schema([ + TextInput::make('name') + ->label('Họ tên') + ->required(), + TextInput::make('email') + ->label('Email') + ->email() + ->required() + ->unique(ignoreRecord: true), + ]), + + Section::make('Phân quyền') + ->columnSpan(1) + ->schema([ + Select::make('role_template_id') + ->label('Nhóm quyền (Mẫu)') + ->relationship('roleTemplate', 'name') + ->searchable() + ->preload() + ->placeholder('Không theo mẫu nào'), + + TagsInput::make('extra_permissions') + ->label('Thêm quyền (vượt cấp)') + ->placeholder('ví dụ: contracts.export, payments.delete') + ->helperText('Nhập quyền muốn thêm cho user này, bất chấp mẫu nhóm') + ->separator(',') + ->splitKeys([',', 'Enter']), + + TagsInput::make('excluded_permissions') + ->label('Bớt quyền (hạn chế)') + ->placeholder('ví dụ: contracts.delete') + ->helperText('Nhập quyền muốn tắt cho user này, bất chấp mẫu nhóm') + ->separator(',') + ->splitKeys([',', 'Enter']), + ]), + ]), + ]); + } +} diff --git a/app/Filament/Resources/Users/Tables/UsersTable.php b/app/Filament/Resources/Users/Tables/UsersTable.php new file mode 100644 index 0000000..19d58bd --- /dev/null +++ b/app/Filament/Resources/Users/Tables/UsersTable.php @@ -0,0 +1,43 @@ +columns([ + TextColumn::make('name') + ->label('Họ tên') + ->searchable() + ->sortable(), + + TextColumn::make('email') + ->label('Email') + ->searchable() + ->sortable(), + + TextColumn::make('roleTemplate.name') + ->label('Nhóm quyền') + ->placeholder('Không có') + ->badge() + ->color('primary'), + + TextColumn::make('created_at') + ->label('Ngày tạo') + ->dateTime('d/m/Y') + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + Tables\Filters\SelectFilter::make('role_template_id') + ->label('Nhóm quyền') + ->relationship('roleTemplate', 'name'), + ]) + ->defaultSort('created_at', 'desc'); + } +} diff --git a/app/Filament/Resources/Users/UserResource.php b/app/Filament/Resources/Users/UserResource.php new file mode 100644 index 0000000..6b52022 --- /dev/null +++ b/app/Filament/Resources/Users/UserResource.php @@ -0,0 +1,42 @@ +value; + protected static ?int $navigationSort = 100; + + protected static ?string $modelLabel = 'Ngườ dùng'; + protected static ?string $pluralModelLabel = 'Ngườ dùng'; + + public static function form(Schema $schema): Schema + { + return UserForm::configure($schema); + } + + public static function table(Table $table): Table + { + return UsersTable::configure($table); + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListUsers::route('/'), + 'create' => Pages\CreateUser::route('/create'), + 'edit' => Pages\EditUser::route('/{record}/edit'), + ]; + } +}