Rework admin panel and other
This commit is contained in:
+147
-45
@@ -3,89 +3,191 @@
|
||||
namespace App\Filament\Resources\EducationalProgramResource\RelationManagers;
|
||||
|
||||
use App\Enums\BudgetEducation;
|
||||
use App\Enums\EducationalProgramStatus;
|
||||
use App\Enums\FormEducation;
|
||||
use App\Models\AdmissionCampaign;
|
||||
use App\Models\EducationalProgram;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Grid;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class AdmissionPlansRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'admission_plans';
|
||||
protected static ?string $title = 'Планы приема';
|
||||
protected static ?string $modelLabel = 'план приема';
|
||||
protected static ?string $pluralModelLabel = 'планы приема';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('admission_campaigns_id')
|
||||
->label('Приемная компания')
|
||||
Select::make('admission_campaigns_id')
|
||||
->label('Приемная кампания')
|
||||
->required()
|
||||
->options(AdmissionCampaign::all()->pluck('name', 'id')),
|
||||
Section::make('План приема')->schema([
|
||||
Forms\Components\Repeater::make('exams')->label('Вступительные испытания')->schema([
|
||||
TextInput::make('title')->label('Название-предмета')->required(),
|
||||
Forms\Components\Select::make('type_exam')->label('Тип-ВИ')
|
||||
->options(['ege' => 'ЕГЭ', 'internal_test' => 'ВИ, проводимое организацией самостоятельно'])->required(),
|
||||
TextInput::make('min_score')->label('Минимальный-балл')->integer()->required()
|
||||
])->live()->maxItems(10)->collapsed()->addActionLabel('Добавить вступительное испытание')->columns(3)->required() ->itemLabel(function (Get $get) {
|
||||
static $count = 0;
|
||||
$maxCount = count($get('exams'));
|
||||
$count = ($count++ <= $maxCount) ? $count : 1;
|
||||
return "Вступительное испытание #" . $count;
|
||||
}),
|
||||
Forms\Components\Repeater::make('contests')->label('Условия поступления')->schema([
|
||||
Forms\Components\Grid::make(1)->schema([
|
||||
Forms\Components\Select::make('form_education')->label('Форма образования')
|
||||
->options(FormEducation::class)->required(),
|
||||
]),
|
||||
Forms\Components\Repeater::make('places')->schema([
|
||||
Forms\Components\Select::make('form_budget')->label('Форма финансирования')
|
||||
->options(BudgetEducation::class)->required(),
|
||||
TextInput::make('count')->label('Количество мест')->integer()->required(),
|
||||
])->columnSpanFull()->maxItems(2),
|
||||
])->live()->maxItems(3)->collapsed()->addActionLabel('Добавить группу')->columns(3)->required()
|
||||
->itemLabel(function (Get $get) {
|
||||
static $count = 0;
|
||||
$maxCount = count($get('contests'));
|
||||
$count = ($count++ <= $maxCount) ? $count : 1;
|
||||
return "Группа #" . $count;
|
||||
}),
|
||||
->columnSpanFull()
|
||||
|
||||
]),
|
||||
->options(
|
||||
AdmissionCampaign::query()
|
||||
->orderBy('name')
|
||||
->pluck('name', 'id')
|
||||
)
|
||||
->searchable()
|
||||
->preload()
|
||||
->placeholder('Выберите приемную кампанию')
|
||||
->helperText('Выберите связанную приемную кампанию'),
|
||||
|
||||
Section::make('План приема')
|
||||
->description('Настройка вступительных испытаний и условий поступления')
|
||||
->collapsible()
|
||||
->schema([
|
||||
self::getExamsRepeater(),
|
||||
self::getContestsRepeater(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
protected static function getExamsRepeater(): Repeater
|
||||
{
|
||||
return Repeater::make('exams')
|
||||
->label('Вступительные испытания')
|
||||
->schema([
|
||||
TextInput::make('title')
|
||||
->label('Название предмета')
|
||||
->required()
|
||||
->maxLength(100)
|
||||
->placeholder('Например: Математика')
|
||||
->helperText('Название вступительного испытания'),
|
||||
|
||||
Select::make('type_exam')
|
||||
->label('Тип испытания')
|
||||
->required()
|
||||
->options([
|
||||
'ege' => 'ЕГЭ',
|
||||
'internal_test' => 'Внутреннее испытание',
|
||||
])
|
||||
->native(false)
|
||||
->placeholder('Выберите тип')
|
||||
->helperText('Тип вступительного испытания'),
|
||||
|
||||
TextInput::make('min_score')
|
||||
->label('Минимальный балл')
|
||||
->required()
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->maxValue(100)
|
||||
->placeholder('Укажите минимальный балл')
|
||||
->helperText('Минимальный проходной балл'),
|
||||
])
|
||||
->columns(3)
|
||||
->maxItems(10)
|
||||
->collapsible()
|
||||
->collapsed()
|
||||
->addActionLabel('Добавить испытание')
|
||||
->itemLabel(fn (array $state): ?string => $state['title'] ?? 'Новое испытание')
|
||||
->helperText('Добавьте все необходимые вступительные испытания');
|
||||
}
|
||||
|
||||
protected static function getContestsRepeater(): Repeater
|
||||
{
|
||||
return Repeater::make('contests')
|
||||
->label('Условия поступления')
|
||||
->schema([
|
||||
Select::make('form_education')
|
||||
->label('Форма обучения')
|
||||
->options(FormEducation::class)
|
||||
->required()
|
||||
->native(false)
|
||||
->placeholder('Выберите форму')
|
||||
->columnSpanFull()
|
||||
->helperText('Форма обучения для данной группы'),
|
||||
|
||||
Repeater::make('places')
|
||||
->label('Места')
|
||||
->schema([
|
||||
Select::make('form_budget')
|
||||
->label('Форма финансирования')
|
||||
->options(BudgetEducation::class)
|
||||
->required()
|
||||
->native(false)
|
||||
->placeholder('Выберите тип')
|
||||
->helperText('Бюджетные или платные места'),
|
||||
|
||||
TextInput::make('count')
|
||||
->label('Количество мест')
|
||||
->required()
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->placeholder('Укажите количество')
|
||||
->helperText('Количество доступных мест'),
|
||||
])
|
||||
->columnSpanFull()
|
||||
->maxItems(2)
|
||||
->addActionLabel('Добавить тип мест')
|
||||
])
|
||||
->columns(2)
|
||||
->maxItems(3)
|
||||
->collapsible()
|
||||
->collapsed()
|
||||
->addActionLabel('Добавить группу')
|
||||
->helperText('Добавьте группы с условиями поступления');
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('admissionCampaign.name'),
|
||||
TextColumn::make('admissionCampaign.name')
|
||||
->label('Приемная кампания')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
|
||||
TextColumn::make('exams_count')
|
||||
->label('Испытаний')
|
||||
->getStateUsing(fn ($record) => count($record->exams ?? []))
|
||||
->badge(),
|
||||
|
||||
TextColumn::make('contests_count')
|
||||
->label('Групп')
|
||||
->getStateUsing(fn ($record) => count($record->contests ?? []))
|
||||
->badge(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
Tables\Actions\CreateAction::make()
|
||||
->label('Добавить план')
|
||||
->modalHeading('Создание плана приема'),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
Tables\Actions\EditAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Редактировать'),
|
||||
|
||||
Tables\Actions\DeleteAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Удалить'),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DetachBulkAction::make(),
|
||||
Tables\Actions\DeleteBulkAction::make()
|
||||
->label('Удалить выбранные')
|
||||
->modalHeading('Удаление планов приема')
|
||||
->modalDescription('Вы уверены, что хотите удалить выбранные планы?'),
|
||||
]),
|
||||
]);
|
||||
])
|
||||
->emptyStateActions([
|
||||
Tables\Actions\CreateAction::make()
|
||||
->label('Добавить план приема'),
|
||||
])
|
||||
->defaultSort('admissionCampaign.name');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user