Rework admin panel and other
This commit is contained in:
@@ -3,42 +3,28 @@
|
||||
namespace App\Filament\Resources\FacultyResource\Pages;
|
||||
|
||||
use App\Filament\Resources\FacultyResource;
|
||||
use App\Services\Filament\Traits\SeoGenerate;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateFaculty extends CreateRecord
|
||||
{
|
||||
use SeoGenerate;
|
||||
|
||||
protected static string $resource = FacultyResource::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
|
||||
|
||||
@@ -3,20 +3,20 @@
|
||||
namespace App\Filament\Resources\FacultyResource\Pages;
|
||||
|
||||
use App\Filament\Resources\FacultyResource;
|
||||
use App\Services\Filament\Traits\SeoGenerate;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class EditFaculty extends EditRecord
|
||||
{
|
||||
protected static string $resource = FacultyResource::class;
|
||||
use SeoGenerate;
|
||||
|
||||
protected array $seoData;
|
||||
protected static string $resource = FacultyResource::class;
|
||||
|
||||
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$this->seoData = $this->generateSeo($data);
|
||||
$data['search_data'] = $this->generateSearchData($data['content']);
|
||||
|
||||
return $data;
|
||||
@@ -24,7 +24,7 @@ class EditFaculty extends EditRecord
|
||||
|
||||
protected function afterSave(): void
|
||||
{
|
||||
$this->record->seo()->update($this->seoData);
|
||||
$this->updateSeo($this->record);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -39,11 +39,11 @@ class DepartmentsRelationManager extends RelationManager
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DetachAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DetachBulkAction::make(),
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
+118
-20
@@ -9,23 +9,47 @@ use Filament\Tables;
|
||||
use Filament\Tables\Actions\AttachAction;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
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 $modelLabel = 'сотрудник';
|
||||
protected static ?string $pluralModelLabel = 'сотрудники';
|
||||
|
||||
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\Grid::make(2)
|
||||
->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.ru')
|
||||
->helperText('Корпоративная электронная почта'),
|
||||
|
||||
Forms\Components\TextInput::make('service_phone')
|
||||
->label('Рабочий телефон')
|
||||
->tel()
|
||||
->maxLength(20)
|
||||
->placeholder('+7 (XXX) XXX-XX-XX')
|
||||
->helperText('Номер рабочего телефона с кодом'),
|
||||
|
||||
Forms\Components\TextInput::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->maxLength(10)
|
||||
->placeholder('Например: 305а')
|
||||
->helperText('Номер кабинета для приема'),
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -36,9 +60,34 @@ class WorkersRelationManager extends RelationManager
|
||||
->reorderable('sort')
|
||||
->defaultSort('sort')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')->label('Имя'),
|
||||
Tables\Columns\TextColumn::make('position')->label('Должность'),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('ФИО')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
|
||||
Tables\Columns\TextColumn::make('position')
|
||||
->label('Должность')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->limit(30),
|
||||
|
||||
Tables\Columns\TextColumn::make('service_email')
|
||||
->label('Почта')
|
||||
->searchable()
|
||||
->icon('heroicon-o-envelope')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
Tables\Columns\TextColumn::make('service_phone')
|
||||
->label('Телефон')
|
||||
->searchable()
|
||||
->icon('heroicon-o-phone')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
Tables\Columns\TextColumn::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->searchable()
|
||||
->icon('heroicon-o-home-modern')
|
||||
->toggleable(isToggledHiddenByDefault: false),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
@@ -46,21 +95,70 @@ class WorkersRelationManager extends RelationManager
|
||||
->headerActions([
|
||||
AttachAction::make()
|
||||
->form(fn (AttachAction $action): array => [
|
||||
$action->getRecordSelect()->preload(),
|
||||
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('Кабинет'),
|
||||
$action->getRecordSelect()
|
||||
->label('Сотрудник')
|
||||
->searchable()
|
||||
->preload()
|
||||
->required()
|
||||
->helperText('Выберите сотрудника из списка'),
|
||||
|
||||
Forms\Components\TextInput::make('position')
|
||||
->label('Должность на факультете')
|
||||
->required()
|
||||
->maxLength(255)
|
||||
->placeholder('Например: Старший преподаватель')
|
||||
->helperText('Укажите должность на этом факультете'),
|
||||
|
||||
Forms\Components\Grid::make(1)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('service_email')
|
||||
->label('Рабочая почта')
|
||||
->email()
|
||||
->maxLength(255)
|
||||
->placeholder('example@university.ru')
|
||||
->helperText('Корпоративная электронная почта'),
|
||||
|
||||
Forms\Components\TextInput::make('service_phone')
|
||||
->label('Рабочий телефон')
|
||||
->tel()
|
||||
->maxLength(20)
|
||||
->placeholder('+7 (XXX) XXX-XX-XX')
|
||||
->helperText('Номер рабочего телефона с кодом'),
|
||||
|
||||
Forms\Components\TextInput::make('cabinet')
|
||||
->label('Кабинет')
|
||||
->maxLength(10)
|
||||
->placeholder('Например: 305а')
|
||||
->helperText('Номер кабинета для приема'),
|
||||
])
|
||||
])
|
||||
->modalHeading('Добавить сотрудника')
|
||||
->modalSubmitActionLabel('Добавить')
|
||||
->modalButton('Добавить')
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DetachAction::make(),
|
||||
Tables\Actions\EditAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Редактировать'),
|
||||
|
||||
Tables\Actions\DetachAction::make()
|
||||
->iconButton()
|
||||
->tooltip('Открепить')
|
||||
->modalHeading('Открепить сотрудника')
|
||||
->modalDescription('Вы уверены, что хотите открепить этого сотрудника от факультета?')
|
||||
->modalSubmitActionLabel('Открепить'),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DetachBulkAction::make(),
|
||||
Tables\Actions\DetachBulkAction::make()
|
||||
->label('Открепить выбранных')
|
||||
->modalHeading('Открепить сотрудников')
|
||||
->modalDescription('Вы уверены, что хотите открепить выбранных сотрудников от факультета?')
|
||||
->modalSubmitActionLabel('Открепить'),
|
||||
]),
|
||||
]);
|
||||
])
|
||||
->emptyStateHeading('Нет сотрудников')
|
||||
->emptyStateDescription('Добавьте сотрудников, используя кнопку выше')
|
||||
->emptyStateIcon('heroicon-o-user-group');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user