Rework admin panel and other

This commit is contained in:
F4ilji
2025-04-02 18:37:20 +05:00
parent 49072e50c7
commit 5cd6ff11b5
198 changed files with 9715 additions and 6664 deletions
@@ -4,263 +4,167 @@ namespace App\Filament\Resources;
use App\Enums\EducationalProgramStatus;
use App\Enums\LevelEducational;
use App\Filament\Components\Forms\ItemForm\Pages\ContentBuilderItem;
use App\Filament\Resources\EducationalProgramResource\Pages;
use App\Filament\Resources\EducationalProgramResource\RelationManagers;
use App\Filament\Resources\EducationalProgramResource\RelationManagers\AdmissionPlansRelationManager;
use App\Models\Category;
use App\Models\EducationalProgram;
use Filament\Forms;
use Filament\Forms\Components\Builder;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieTagsInput;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\BadgeColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Str;
use Mohamedsabil83\FilamentFormsTinyeditor\Components\TinyEditor;
class EducationalProgramResource extends Resource
{
protected static ?string $model = EducationalProgram::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationIcon = 'heroicon-o-academic-cap';
protected static ?string $navigationGroup = 'Образование';
protected static ?string $pluralLabel = 'Образовательные программы';
protected static ?string $modelLabel = 'Образовательная программа';
protected static ?string $navigationParentItem = 'Приемная-компания';
public static function form(Form $form): Form
{
return $form
->schema([
Section::make()
->schema([
TextInput::make('name')->label('Название')->required(),
Section::make('О программе')->schema([
Builder::make('about_program')->label('')->blocks([
Builder\Block::make('heading')->label('Заголовок')
Tabs::make('')
->tabs([
Tabs\Tab::make('Основная информация')
->icon('heroicon-o-information-circle')
->schema([
TextInput::make('name')
->label('Название программы')
->required()
->maxLength(255)
->placeholder('Введите полное название программы')
->columnSpanFull()
->helperText('Официальное название программы как в лицензии'),
Grid::make(2)
->schema([
TextInput::make('id')->hidden()->integer()->default(rand(2335235,324634264263426)),
TextInput::make('content')
->label('')
->live(onBlur: true)
->afterStateUpdated(function (string $operation, string $state, Forms\Set $set, $get) {
}),
Select::make('lvl_edu')
->label('Уровень образования')
->options(LevelEducational::class)
->required()
->native(false)
->helperText('Выберите уровень образовательной программы'),
Select::make('status')
->label('Статус программы')
->options(EducationalProgramStatus::class)
->required()
->native(false)
->helperText('Определяет видимость программы на сайте'),
TextInput::make('lang_stud')
->label('Язык обучения')
->required()
->placeholder('Например: русский, английский')
->helperText('Укажите основной язык преподавания')
->columnSpan(2),
]),
Builder\Block::make('paragraph')
->schema([
RichEditor::make('content')
->toolbarButtons([
'blockquote',
'bold',
'bulletList',
'italic',
'link',
'orderedList',
'redo',
'strike',
'underline',
'undo',
])
->label('')
->required()
]),
Builder\Block::make('image')
->schema([
FileUpload::make('url')
->label('Изображение(-я)')
->image()
->multiple()
->reorderable()
->maxFiles(5)
->disk('public')
->directory('images')
->imageEditor()
->required(),
TextInput::make('alt')
->label('Описание')
->placeholder('Необязяательно')
])->label('Изображение(-я)'),
Builder\Block::make('video')
->schema([
Hidden::make('mime'),
]),
TextInput::make('title')
->required()
->maxLength(255)
->autofocus(),
FileUpload::make('path')
->required()
->acceptedFileTypes(['video/mp4','video/ogg','video/webm'])
->maxSize(512000)
->disk('videos')
->visibility('public')
->afterStateUpdated(fn (callable $set, $state) => $set('mime', $state?->getMimeType())),
]),
Builder\Block::make('files')
->schema([
TextInput::make('title')
->required()
->maxLength(255)
->autofocus(),
FileUpload::make('path')
->required()
->acceptedFileTypes([
'application/pdf',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/zip'
])
->maxSize(512000)
->disk('public')
->directory('files')
->downloadable()
->visibility('public')
])
])
->collapsed()
->blockNumbers(false)
->collapsible()
->addActionLabel('Добавить новый блок'),
]),
Section::make('Особенности программы')->schema([
Builder::make('program_features')->label('')->blocks([
Builder\Block::make('heading')->label('Заголовок')
->schema([
TextInput::make('id')->hidden()->integer()->default(rand(2335235,324634264263426)),
TextInput::make('content')
->label('')
->live(onBlur: true)
->afterStateUpdated(function (string $operation, string $state, Forms\Set $set, $get) {
}),
]),
Builder\Block::make('paragraph')
->schema([
RichEditor::make('content')
->toolbarButtons([
'blockquote',
'bold',
'bulletList',
'italic',
'link',
'orderedList',
'redo',
'strike',
'underline',
'undo',
])
->label('')
->required()
]),
Builder\Block::make('image')
->schema([
FileUpload::make('url')
->label('Изображение(-я)')
->image()
->multiple()
->reorderable()
->maxFiles(5)
->disk('public')
->directory('images')
->imageEditor()
->required(),
TextInput::make('alt')
->label('Описание')
->placeholder('Необязяательно')
])->label('Изображение(-я)'),
Builder\Block::make('video')
->schema([
Hidden::make('mime'),
TextInput::make('title')
->required()
->maxLength(255)
->autofocus(),
FileUpload::make('path')
->required()
->acceptedFileTypes(['video/mp4','video/ogg','video/webm'])
->maxSize(512000)
->disk('videos')
->visibility('public')
->afterStateUpdated(fn (callable $set, $state) => $set('mime', $state?->getMimeType())),
]),
Builder\Block::make('files')
->schema([
TextInput::make('title')
->required()
->maxLength(255)
->autofocus(),
FileUpload::make('path')
->required()
->acceptedFileTypes([
'application/pdf',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/zip'
])
->maxSize(512000)
->disk('public')
->directory('files')
->downloadable()
->visibility('public')
])
])
->collapsed()
->blockNumbers(false)
->collapsible()
->addActionLabel('Добавить новый блок'),
]),
Select::make('lvl_edu')->options(LevelEducational::class)->label('Уровень образования')->required(),
Select::make('status')
->options(EducationalProgramStatus::class)
->label('Статус программы')->required(),
TextInput::make('lang_stud')->label('На каком языке ведется образование')->required(),
Tabs\Tab::make('Описание программы')
->icon('heroicon-o-document-text')
->schema([
self::getContentBuilder('about_program', 'О программе')
->columnSpanFull(),
]),
Tabs\Tab::make('Особенности программы')
->icon('heroicon-o-sparkles')
->schema([
self::getContentBuilder('program_features', 'Особенности программы')
->columnSpanFull(),
]),
])
->persistTabInQueryString()
->columnSpanFull(),
]);
}
protected static function getContentBuilder(string $field, string $label): Builder
{
return ContentBuilderItem::getItem($field);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('name')->label('Название программы')->sortable()->searchable(),
Tables\Columns\TextColumn::make('directionStudy.lvl_edu')->label('Уровень образования')->limit(30),
TextColumn::make('name')
->label('Название')
->sortable()
->searchable()
->description(fn ($record) => $record->lang_stud),
BadgeColumn::make('lvl_edu')
->label('Уровень')
->formatStateUsing(fn ($state) => LevelEducational::tryFrom($state->value)?->getLabel())
->color(fn ($state) => LevelEducational::tryFrom($state->value)?->getColor())
->sortable(),
BadgeColumn::make('status')
->label('Статус')
->formatStateUsing(fn ($state) => EducationalProgramStatus::tryFrom($state)?->getLabel())
->color(fn ($state) => EducationalProgramStatus::tryFrom($state)?->getColor())
->sortable(),
TextColumn::make('updated_at')
->label('Обновлено')
->dateTime('d.m.Y H:i')
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
Tables\Filters\SelectFilter::make('lvl_edu')
->label('Уровень образования')
->options(LevelEducational::class),
Tables\Filters\SelectFilter::make('status')
->label('Статус программы')
->options(EducationalProgramStatus::class),
])
->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('name');
}
public static function getRelations(): array
{
return [
AdmissionPlansRelationManager::class
AdmissionPlansRelationManager::class,
];
}
@@ -272,4 +176,4 @@ class EducationalProgramResource extends Resource
'edit' => Pages\EditEducationalProgram::route('/{record}/edit'),
];
}
}
}