Rework frontend
This commit is contained in:
@@ -3,41 +3,27 @@
|
||||
namespace App\Filament\Resources\DepartmentResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DepartmentResource;
|
||||
use App\Services\Filament\Traits\SeoGenerate;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateDepartment extends CreateRecord
|
||||
{
|
||||
use SeoGenerate;
|
||||
|
||||
protected static string $resource = DepartmentResource::class;
|
||||
|
||||
protected array $seoData;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$this->seoData = $this->generateSeo($data);
|
||||
$data['search_data'] = $this->generateSearchData($data['content']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
{
|
||||
$this->record->seo()->create($this->seoData);
|
||||
}
|
||||
|
||||
private function generateSeo(array $data) : array
|
||||
{
|
||||
$title = $data['title'];
|
||||
$rowData = $this->getFirstBlockByName('paragraph', $data['content']);
|
||||
if ($rowData !== null) {
|
||||
$description = strip_tags($rowData['data']['content']);
|
||||
} else {
|
||||
$description = null;
|
||||
}
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160),
|
||||
];
|
||||
$this->createSeo($this->record);
|
||||
}
|
||||
|
||||
private function generateSearchData(array $data) : string
|
||||
@@ -52,15 +38,6 @@ class CreateDepartment extends CreateRecord
|
||||
|
||||
return strtolower($result);
|
||||
}
|
||||
private function getFirstBlockByName(string $name, array $content) : array|null
|
||||
{
|
||||
$data = null;
|
||||
foreach ($content as $block) {
|
||||
$data = ($block['type'] === $name) ? $block : null;
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
private function getDataFromBlocks($block) : string
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
namespace App\Filament\Resources\DepartmentResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DepartmentResource;
|
||||
use App\Services\Filament\Traits\SeoGenerate;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EditDepartment extends EditRecord
|
||||
{
|
||||
protected static string $resource = DepartmentResource::class;
|
||||
use SeoGenerate;
|
||||
|
||||
protected array $seoData;
|
||||
protected static string $resource = DepartmentResource::class;
|
||||
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$this->seoData = $this->generateSeo($data);
|
||||
$data['search_data'] = $this->generateSearchData($data['content']);
|
||||
|
||||
return $data;
|
||||
@@ -24,24 +24,7 @@ class EditDepartment extends EditRecord
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
$this->record->seo()->update($this->seoData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function generateSeo(array $data) : array
|
||||
{
|
||||
$title = $data['title'];
|
||||
$rowData = $this->getFirstBlockByName('paragraph', $data['content']);
|
||||
if ($rowData !== null) {
|
||||
$description = strip_tags($rowData['data']['content']);
|
||||
} else {
|
||||
$description = null;
|
||||
}
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => Str::limit(htmlspecialchars($description, ENT_QUOTES, 'UTF-8'), 160),
|
||||
];
|
||||
$this->updateSeo($this->record);
|
||||
}
|
||||
|
||||
private function getDataFromBlocks($block) : string
|
||||
|
||||
+61
-12
@@ -15,14 +15,22 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
class ProgramsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'programs';
|
||||
protected static ?string $title = 'Образовательные программы кафедры';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
Forms\Components\Section::make('Основная информация')
|
||||
->description('Связь образовательной программы с кафедрой')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label('Название программы')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->placeholder('Например: Информатика и вычислительная техника')
|
||||
->helperText('Полное название образовательной программы'),
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -31,24 +39,65 @@ class ProgramsRelationManager extends RelationManager
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name'),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Название программы')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->wrap(),
|
||||
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->label('Статус')
|
||||
->badge()
|
||||
->formatStateUsing(fn($state): string => EducationalProgramStatus::tryFrom($state)->getLabel())
|
||||
->color(fn($state): string => EducationalProgramStatus::tryFrom($state)->getColor())
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
Tables\Filters\SelectFilter::make('status')
|
||||
->label('Статус программы')
|
||||
->options(EducationalProgramStatus::class)
|
||||
->default(EducationalProgramStatus::PUBLISHED->value),
|
||||
])
|
||||
->headerActions([
|
||||
AttachAction::make()
|
||||
->recordSelectOptionsQuery(fn (Builder $query) => $query->where('status', EducationalProgramStatus::PUBLISHED)),
|
||||
|
||||
->label('Добавить программу')
|
||||
->modalHeading('Добавление программы к кафедре')
|
||||
->modalSubmitActionLabel('Добавить')
|
||||
->preloadRecordSelect()
|
||||
->recordSelectOptionsQuery(fn(Builder $query) => $query->where('status', EducationalProgramStatus::PUBLISHED))
|
||||
->recordSelect(
|
||||
fn(Forms\Components\Select $select) => $select
|
||||
->placeholder('Выберите программу')
|
||||
->label('Образовательная программа')
|
||||
->helperText('Только опубликованные программы')
|
||||
->searchable()
|
||||
->columnSpanFull()
|
||||
)
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DetachAction::make(),
|
||||
|
||||
Tables\Actions\DetachAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Открепить программу')
|
||||
->modalHeading('Открепление программы')
|
||||
->modalSubmitActionLabel('Открепить')
|
||||
->modalDescription('Вы уверены, что хотите открепить эту программу от кафедры?'),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DetachBulkAction::make(),
|
||||
Tables\Actions\DetachBulkAction::make()
|
||||
->label('Открепить выбранные')
|
||||
->modalHeading('Открепление программ')
|
||||
->modalSubmitActionLabel('Открепить')
|
||||
->modalDescription('Вы уверены, что хотите открепить выбранные программы от кафедры?'),
|
||||
]),
|
||||
]);
|
||||
])
|
||||
->emptyStateActions([
|
||||
AttachAction::make()
|
||||
->label('Добавить программу'),
|
||||
])
|
||||
->defaultSort('name')
|
||||
->deferLoading()
|
||||
->persistFiltersInSession();
|
||||
}
|
||||
}
|
||||
}
|
||||
+123
-20
@@ -14,21 +14,48 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
class TeachersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'teachers';
|
||||
|
||||
protected static ?string $inverseRelationship = 'departments_teach';
|
||||
|
||||
|
||||
protected static ?string $title = 'Преподаватели кафедры';
|
||||
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('teaching_position')->label('Преподавательская должность')->required(),
|
||||
Forms\Components\TextInput::make('service_email')->label('Служебная почта'),
|
||||
Forms\Components\TextInput::make('service_phone')->label('Служебный телефон'),
|
||||
Forms\Components\TextInput::make('cabinet')->label('Кабинет'),
|
||||
Forms\Components\Section::make('Информация о преподавателе')
|
||||
->description('Основные данные о работе преподавателя на кафедре')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('teaching_position')
|
||||
->label('Преподавательская должность')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->placeholder('Например: Профессор')
|
||||
->helperText('Официальная преподавательская должность'),
|
||||
|
||||
Forms\Components\TextInput::make('service_email')
|
||||
->label('Служебная почта')
|
||||
->email()
|
||||
->maxLength(255)
|
||||
->placeholder('example@university.edu')
|
||||
->helperText('Корпоративная электронная почта'),
|
||||
|
||||
Forms\Components\TextInput::make('service_phone')
|
||||
->label('Служебный телефон')
|
||||
->tel()
|
||||
->maxLength(20)
|
||||
->placeholder('+7 (XXX) XXX-XX-XX')
|
||||
->helperText('Формат: +7 (XXX) XXX-XX-XX')
|
||||
->regex('/^\+?[0-9\s\-\(\)]{7,}$/')
|
||||
->validationMessages([
|
||||
'regex' => 'Пожалуйста, введите корректный номер телефона. Допустимые форматы: +7 (XXX) XXX-XX-XX или XXX-XX-XX',
|
||||
]),
|
||||
|
||||
Forms\Components\TextInput::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->maxLength(10)
|
||||
->placeholder('Например: 305а')
|
||||
->helperText('Номер кабинета преподавателя'),
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -37,29 +64,105 @@ class TeachersRelationManager extends RelationManager
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name'),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('ФИО')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('teaching_position')
|
||||
->label('Должность')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->wrap(),
|
||||
|
||||
Tables\Columns\TextColumn::make('service_email')
|
||||
->label('Почта')
|
||||
->searchable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
Tables\Columns\TextColumn::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->sortable()
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
AttachAction::make()
|
||||
->preloadRecordSelect()
|
||||
->recordSelectOptionsQuery(fn (Builder $query) => $query->has('userDetail'))
|
||||
->form(fn (AttachAction $action): array => [
|
||||
$action->getRecordSelect(),
|
||||
Forms\Components\TextInput::make('teaching_position')->label('Преподавательская должность')->required(),
|
||||
Forms\Components\TextInput::make('service_email')->label('Служебная почта'),
|
||||
Forms\Components\TextInput::make('service_phone')->label('Служебный телефон'),
|
||||
Forms\Components\TextInput::make('cabinet')->label('Кабинет'),
|
||||
Forms\Components\Section::make('')
|
||||
->schema([
|
||||
$action->getRecordSelect()
|
||||
->placeholder('Выбрать преподавателя')
|
||||
->columnSpanFull()
|
||||
->searchable()
|
||||
->preload()
|
||||
->helperText('Выберите преподавателя')
|
||||
->required(),
|
||||
|
||||
Forms\Components\TextInput::make('teaching_position')
|
||||
->label('Преподавательская должность')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->placeholder('Например: Профессор')
|
||||
->helperText('Официальная преподавательская должность'),
|
||||
|
||||
Forms\Components\TextInput::make('service_email')
|
||||
->label('Служебная почта')
|
||||
->email()
|
||||
->maxLength(255)
|
||||
->placeholder('example@university.edu')
|
||||
->helperText('Корпоративная электронная почта'),
|
||||
|
||||
Forms\Components\TextInput::make('service_phone')
|
||||
->label('Служебный телефон')
|
||||
->tel()
|
||||
->maxLength(20)
|
||||
->placeholder('+7 (XXX) XXX-XX-XX')
|
||||
->helperText('Формат: +7 (XXX) XXX-XX-XX')
|
||||
->regex('/^\+?[0-9\s\-\(\)]{7,}$/')
|
||||
->validationMessages([
|
||||
'regex' => 'Пожалуйста, введите корректный номер телефона. Допустимые форматы: +7 (XXX) XXX-XX-XX или XXX-XX-XX',
|
||||
]),
|
||||
|
||||
Forms\Components\TextInput::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->maxLength(10)
|
||||
->placeholder('Например: 305а')
|
||||
->helperText('Номер кабинета преподавателя'),
|
||||
])
|
||||
->columns(1),
|
||||
])
|
||||
->modalSubmitActionLabel('Добавить')
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DetachAction::make(),
|
||||
Tables\Actions\EditAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Редактировать'),
|
||||
|
||||
Tables\Actions\DetachAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Убрать с кафедры')
|
||||
->modalHeading('Удаление связи')
|
||||
->modalSubmitActionLabel('Убрать')
|
||||
->modalDescription('Вы уверены, что хотите убрать этого преподавателя с кафедры?'),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DetachBulkAction::make(),
|
||||
Tables\Actions\DetachBulkAction::make()
|
||||
->label('Убрать выбранных')
|
||||
->modalHeading('Удаление связей')
|
||||
->modalSubmitActionLabel('Убрать')
|
||||
->modalDescription('Вы уверены, что хотите убрать выбранных преподавателей с кафедры?'),
|
||||
]),
|
||||
]);
|
||||
])
|
||||
->emptyStateActions([
|
||||
AttachAction::make()
|
||||
->label('Добавить преподавателя'),
|
||||
])
|
||||
->defaultSort('name')
|
||||
->deferLoading();
|
||||
}
|
||||
}
|
||||
}
|
||||
+123
-20
@@ -14,20 +14,48 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
class WorkersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'workers';
|
||||
|
||||
protected static ?string $inverseRelationship = 'departments_work';
|
||||
|
||||
protected static ?string $title = 'Сотрудники кафедры';
|
||||
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('position')->label('Должность')->required(),
|
||||
Forms\Components\TextInput::make('service_email')->label('Служебная почта'),
|
||||
Forms\Components\TextInput::make('service_phone')->label('Служебный телефон'),
|
||||
Forms\Components\TextInput::make('cabinet')->label('Кабинет'),
|
||||
Forms\Components\Section::make('Информация о должности')
|
||||
->description('Основные данные о работе сотрудника на кафедре')
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('position')
|
||||
->label('Должность')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->placeholder('Например: Заведующий кафедрой')
|
||||
->helperText('Официальная должность сотрудника на кафедре'),
|
||||
|
||||
Forms\Components\TextInput::make('service_email')
|
||||
->label('Служебная почта')
|
||||
->email()
|
||||
->maxLength(255)
|
||||
->placeholder('example@university.edu')
|
||||
->helperText('Корпоративная электронная почта'),
|
||||
|
||||
Forms\Components\TextInput::make('service_phone')
|
||||
->label('Служебный телефон')
|
||||
->tel()
|
||||
->maxLength(20)
|
||||
->placeholder('+7 (XXX) XXX-XX-XX')
|
||||
->helperText('Формат: +7 (XXX) XXX-XX-XX')
|
||||
->regex('/^\+?[0-9\s\-\(\)]{7,}$/') // Разрешаем +, цифры, пробелы, дефисы, скобки
|
||||
->validationMessages([
|
||||
'regex' => 'Пожалуйста, введите корректный номер телефона. Допустимые форматы: +7 (XXX) XXX-XX-XX или XXX-XX-XX',
|
||||
]),
|
||||
|
||||
Forms\Components\TextInput::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->maxLength(10)
|
||||
->placeholder('Например: 305а')
|
||||
->helperText('Номер кабинета сотрудника'),
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -36,30 +64,105 @@ class WorkersRelationManager extends RelationManager
|
||||
return $table
|
||||
->recordTitleAttribute('name')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name'),
|
||||
Tables\Columns\TextColumn::make('position'),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('ФИО')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('position')
|
||||
->label('Должность')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->wrap(),
|
||||
|
||||
Tables\Columns\TextColumn::make('service_email')
|
||||
->label('Почта')
|
||||
->searchable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
Tables\Columns\TextColumn::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->sortable()
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
AttachAction::make()
|
||||
->preloadRecordSelect()
|
||||
->recordSelectOptionsQuery(fn (Builder $query) => $query->has('userDetail'))
|
||||
->form(fn (AttachAction $action): array => [
|
||||
$action->getRecordSelect(),
|
||||
Forms\Components\TextInput::make('position')->label('Должность')->required(),
|
||||
Forms\Components\TextInput::make('service_email')->label('Служебная почта'),
|
||||
Forms\Components\TextInput::make('service_phone')->label('Служебный телефон'),
|
||||
Forms\Components\TextInput::make('cabinet')->label('Кабинет'),
|
||||
Forms\Components\Section::make('')
|
||||
->schema([
|
||||
$action->getRecordSelect()
|
||||
->placeholder('Выбрать сотрудника')
|
||||
->columnSpanFull()
|
||||
->searchable()
|
||||
->preload()
|
||||
->helperText('Выберите сотрудника')
|
||||
->required(),
|
||||
|
||||
Forms\Components\TextInput::make('position')
|
||||
->label('Должность')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->placeholder('Например: Заведующий кафедрой')
|
||||
->helperText('Официальная должность сотрудника на кафедре'),
|
||||
|
||||
Forms\Components\TextInput::make('service_email')
|
||||
->label('Служебная почта')
|
||||
->email()
|
||||
->maxLength(255)
|
||||
->placeholder('example@university.edu')
|
||||
->helperText('Корпоративная электронная почта'),
|
||||
|
||||
Forms\Components\TextInput::make('service_phone')
|
||||
->label('Служебный телефон')
|
||||
->tel()
|
||||
->maxLength(20)
|
||||
->placeholder('+7 (XXX) XXX-XX-XX')
|
||||
->helperText('Формат: +7 (XXX) XXX-XX-XX')
|
||||
->regex('/^\+?[0-9\s\-\(\)]{7,}$/') // Разрешаем +, цифры, пробелы, дефисы, скобки
|
||||
->validationMessages([
|
||||
'regex' => 'Пожалуйста, введите корректный номер телефона. Допустимые форматы: +7 (XXX) XXX-XX-XX или XXX-XX-XX',
|
||||
]),
|
||||
|
||||
Forms\Components\TextInput::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->maxLength(10)
|
||||
->placeholder('Например: 305а')
|
||||
->helperText('Номер кабинета сотрудника'),
|
||||
])
|
||||
->columns(2),
|
||||
])
|
||||
->modalSubmitActionLabel('Добавить')
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DetachAction::make(),
|
||||
Tables\Actions\EditAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Редактировать'),
|
||||
|
||||
Tables\Actions\DetachAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Убрать с кафедры')
|
||||
->modalHeading('Удаление связи')
|
||||
->modalSubmitActionLabel('Убрать')
|
||||
->modalDescription('Вы уверены, что хотите убрать этого сотрудника с кафедры?'),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DetachBulkAction::make(),
|
||||
Tables\Actions\DetachBulkAction::make()
|
||||
->label('Убрать выбранных')
|
||||
->modalHeading('Удаление связей')
|
||||
->modalSubmitActionLabel('Убрать')
|
||||
->modalDescription('Вы уверены, что хотите убрать выбранных сотрудников с кафедры?'),
|
||||
]),
|
||||
]);
|
||||
])
|
||||
->emptyStateActions([
|
||||
AttachAction::make()
|
||||
->label('Добавить сотрудника'),
|
||||
])
|
||||
->defaultSort('name')
|
||||
->deferLoading();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user