Rework admin panel and other
This commit is contained in:
@@ -3,42 +3,27 @@
|
||||
namespace App\Filament\Resources\DivisionResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DivisionResource;
|
||||
use App\Services\Filament\Traits\SeoGenerate;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateDivision extends CreateRecord
|
||||
{
|
||||
protected static string $resource = DivisionResource::class;
|
||||
use SeoGenerate;
|
||||
|
||||
protected array $seoData;
|
||||
protected static string $resource = DivisionResource::class;
|
||||
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$this->seoData = $this->generateSeo($data);
|
||||
$data['search_data'] = $this->generateSearchData($data['description']);
|
||||
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['description']);
|
||||
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
|
||||
|
||||
@@ -3,20 +3,21 @@
|
||||
namespace App\Filament\Resources\DivisionResource\Pages;
|
||||
|
||||
use App\Filament\Resources\DivisionResource;
|
||||
use App\Services\Filament\Traits\SeoGenerate;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EditDivision extends EditRecord
|
||||
{
|
||||
use SeoGenerate;
|
||||
|
||||
protected static string $resource = DivisionResource::class;
|
||||
|
||||
protected array $seoData;
|
||||
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$this->seoData = $this->generateSeo($data);
|
||||
$data['search_data'] = $this->generateSearchData($data['description']);
|
||||
|
||||
return $data;
|
||||
@@ -24,25 +25,11 @@ class EditDivision extends EditRecord
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
$this->record->seo()->update($this->seoData);
|
||||
$this->updateSeo($this->record);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function generateSeo(array $data) : array
|
||||
{
|
||||
$title = $data['title'];
|
||||
$rowData = $this->getFirstBlockByName('paragraph', $data['description']);
|
||||
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),
|
||||
];
|
||||
}
|
||||
|
||||
private function getDataFromBlocks($block) : string
|
||||
{
|
||||
|
||||
+133
-20
@@ -14,17 +14,48 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
class WorkersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'workers';
|
||||
|
||||
protected static ?string $title = 'Сотрудники';
|
||||
protected static ?string $title = 'Сотрудники подразделения';
|
||||
protected static ?string $inverseRelationship = 'divisions';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('administrativePosition')->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('administrativePosition')
|
||||
->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' => 'Пожалуйста, введите корректный номер телефона',
|
||||
]),
|
||||
|
||||
Forms\Components\TextInput::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->maxLength(10)
|
||||
->placeholder('Например: 305а')
|
||||
->helperText('Номер кабинета в подразделении'),
|
||||
])
|
||||
->columns(2),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -35,32 +66,114 @@ class WorkersRelationManager extends RelationManager
|
||||
->reorderable('sort')
|
||||
->defaultSort('sort')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name'),
|
||||
Tables\Columns\TextColumn::make('administrativePosition'),
|
||||
Tables\Columns\TextColumn::make('sort')
|
||||
->label('№')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('ФИО')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->weight('medium')
|
||||
->description(fn ($record) => $record->service_email),
|
||||
|
||||
Tables\Columns\TextColumn::make('administrativePosition')
|
||||
->label('Должность')
|
||||
->searchable()
|
||||
->wrap()
|
||||
->description(fn ($record) => $record->cabinet),
|
||||
|
||||
Tables\Columns\TextColumn::make('service_phone')
|
||||
->label('Телефон')
|
||||
->searchable()
|
||||
->toggleable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
AttachAction::make()
|
||||
->label('Добавить сотрудника')
|
||||
->modalHeading('Добавление сотрудника')
|
||||
->modalSubmitActionLabel('Добавить')
|
||||
->preloadRecordSelect()
|
||||
->recordSelectOptionsQuery(fn (Builder $query) => $query->has('userDetail'))
|
||||
->form(fn (AttachAction $action): array => [
|
||||
$action->getRecordSelect(),
|
||||
Forms\Components\TextInput::make('administrativePosition')->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()
|
||||
->label('Сотрудник')
|
||||
->placeholder('Выберите сотрудника')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
|
||||
Forms\Components\TextInput::make('administrativePosition')
|
||||
->label('Административная должность')
|
||||
->required()
|
||||
->columnSpanFull()
|
||||
->maxLength(255)
|
||||
->placeholder('Например: Руководитель отдела')
|
||||
->helperText('Официальная должность в подразделении'),
|
||||
|
||||
Forms\Components\TextInput::make('service_email')
|
||||
->label('Служебная почта')
|
||||
->email()
|
||||
->columnSpanFull()
|
||||
->maxLength(255)
|
||||
->placeholder('example@university.edu')
|
||||
->helperText('Корпоративная электронная почта в подразделении'),
|
||||
|
||||
Forms\Components\TextInput::make('service_phone')
|
||||
->label('Служебный телефон')
|
||||
->tel()
|
||||
->columnSpanFull()
|
||||
->maxLength(20)
|
||||
->placeholder('+7 (XXX) XXX-XX-XX')
|
||||
->helperText('Формат: +7 (XXX) XXX-XX-XX')
|
||||
->regex('/^\+?[0-9\s\-\(\)]{7,}$/')
|
||||
->validationMessages([
|
||||
'regex' => 'Пожалуйста, введите корректный номер телефона',
|
||||
]),
|
||||
|
||||
Forms\Components\TextInput::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->columnSpanFull()
|
||||
->maxLength(10)
|
||||
->placeholder('Например: 305а')
|
||||
->helperText('Номер кабинета в подразделении'),
|
||||
])
|
||||
->columns(2),
|
||||
]),
|
||||
])
|
||||
->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('Добавить сотрудника'),
|
||||
])
|
||||
->persistFiltersInSession()
|
||||
->paginated([10, 25, 50, 100])
|
||||
->striped();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user