Rework frontend
This commit is contained in:
@@ -3,18 +3,21 @@
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\AdditionalEducationCategoryResource\Pages;
|
||||
use App\Filament\Resources\AdditionalEducationCategoryResource\RelationManagers;
|
||||
use App\Models\AdditionalEducationCategory;
|
||||
use App\Models\DirectionAdditionalEducation;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\BadgeColumn;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class AdditionalEducationCategoryResource extends Resource
|
||||
@@ -27,27 +30,57 @@ class AdditionalEducationCategoryResource extends Resource
|
||||
protected static ?string $pluralLabel = 'Категории дополнительного образования';
|
||||
protected static ?string $navigationParentItem = 'Дополнительное Образование';
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
protected static ?string $navigationIcon = 'heroicon-o-tag';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Section::make()->schema([
|
||||
Forms\Components\Grid::make('2')->schema([
|
||||
TextInput::make('title')->label('Заголовок')->required()
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(function (string $operation, string|null $state, Forms\Set $set) {
|
||||
$set('slug', Str::slug($state));
|
||||
$set('seo.title', $state);
|
||||
}),
|
||||
TextInput::make('slug')->label('Slug')->unique(ignoreRecord: true)->readOnly()->required(),
|
||||
Forms\Components\Select::make('dir_addit_educat_id')->required()->label('Направление доп. образования')
|
||||
->preload()
|
||||
->options(DirectionAdditionalEducation::where('is_active', true)->pluck('title', 'id'))
|
||||
Section::make('Основная информация')
|
||||
->description('Заполните данные о категории программ ДПО')
|
||||
->collapsible()
|
||||
->schema([
|
||||
Grid::make(2)
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->label('Название категории')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->placeholder('Например: "Профессиональная переподготовка"')
|
||||
->live(onBlur: true)
|
||||
->afterStateUpdated(function (string $operation, ?string $state, Forms\Set $set) {
|
||||
$set('slug', Str::slug($state));
|
||||
})
|
||||
->helperText('Укажите понятное название категории'),
|
||||
|
||||
TextInput::make('slug')
|
||||
->label('URL-идентификатор')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->unique(ignoreRecord: true)
|
||||
->helperText('Человеко-понятный URL для категории'),
|
||||
|
||||
Select::make('dir_addit_educat_id')
|
||||
->label('Направление ДПО')
|
||||
->options(
|
||||
DirectionAdditionalEducation::where('is_active', true)
|
||||
->orderBy('title')
|
||||
->pluck('title', 'id')
|
||||
)
|
||||
->required()
|
||||
->preload()
|
||||
->searchable()
|
||||
->placeholder('Выберите направление')
|
||||
->helperText('К какому направлению относится категория'),
|
||||
]),
|
||||
|
||||
Toggle::make('is_active')
|
||||
->label('Активная категория')
|
||||
->inline(false)
|
||||
->default(true)
|
||||
->helperText('Отображать ли категорию на сайте')
|
||||
->columnSpanFull(),
|
||||
]),
|
||||
Forms\Components\Toggle::make('is_active')->label('Активно')->columnSpanFull()->inline(false)->default(true),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -55,30 +88,77 @@ class AdditionalEducationCategoryResource extends Resource
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')->label('ID')->sortable(),
|
||||
TextColumn::make('title')->label('Название')->sortable()->searchable(),
|
||||
TextColumn::make('created_at')->label('Дата создания')->sortable(),
|
||||
Tables\Columns\BadgeColumn::make('direction.title')->label('Направление')->sortable(),
|
||||
Tables\Columns\ToggleColumn::make('is_active')->label('Активно')->sortable(),
|
||||
TextColumn::make('title')
|
||||
->label('Название')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->description(fn ($record) => $record->direction->title ?? '')
|
||||
->limit(50),
|
||||
|
||||
BadgeColumn::make('direction.title')
|
||||
->label('Направление')
|
||||
->sortable()
|
||||
->searchable()
|
||||
->color('primary'),
|
||||
|
||||
IconColumn::make('is_active')
|
||||
->label('Активна')
|
||||
->boolean()
|
||||
->trueIcon('heroicon-o-check-circle')
|
||||
->falseIcon('heroicon-o-x-circle')
|
||||
->trueColor('success')
|
||||
->falseColor('danger')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('updated_at')
|
||||
->label('Обновлено')
|
||||
->dateTime('d.m.Y H:i')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
Tables\Filters\SelectFilter::make('dir_addit_educat_id')
|
||||
->label('Направление ДПО')
|
||||
->options(
|
||||
DirectionAdditionalEducation::where('is_active', true)
|
||||
->orderBy('title')
|
||||
->pluck('title', 'id')
|
||||
)
|
||||
->searchable(),
|
||||
|
||||
Tables\Filters\TernaryFilter::make('is_active')
|
||||
->label('Только активные')
|
||||
->placeholder('Все')
|
||||
->trueLabel('Активные')
|
||||
->falseLabel('Неактивные'),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\EditAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Редактировать'),
|
||||
|
||||
Tables\Actions\ViewAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Просмотреть'),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\DeleteBulkAction::make()
|
||||
->label('Удалить выбранные')
|
||||
->modalHeading('Удаление категорий')
|
||||
->modalDescription('Вы уверены, что хотите удалить выбранные категории ДПО?'),
|
||||
]),
|
||||
]);
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make()
|
||||
->label('Добавить категорию'),
|
||||
])
|
||||
->defaultSort('title');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
@@ -89,4 +169,4 @@ class AdditionalEducationCategoryResource extends Resource
|
||||
'edit' => Pages\EditAdditionalEducationCategory::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user