Rework frontend

This commit is contained in:
F4ilji
2025-04-02 18:09:54 +05:00
parent 49072e50c7
commit bd3a4408b1
197 changed files with 9715 additions and 6664 deletions
@@ -3,42 +3,27 @@
namespace App\Filament\Resources\AcademicJournalResource\Pages;
use App\Filament\Resources\AcademicJournalResource;
use App\Services\Filament\Traits\SeoGenerate;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Support\Str;
class CreateAcademicJournal extends CreateRecord
{
protected static string $resource = AcademicJournalResource::class;
use SeoGenerate;
protected array $seoData;
protected static string $resource = AcademicJournalResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
$this->seoData = $this->generateSeo($data);
$data['search_data'] = $this->generateSearchData($data['main_info']);
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['main_info']);
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\AcademicJournalResource\Pages;
use App\Filament\Resources\AcademicJournalResource;
use App\Services\Filament\Traits\SeoGenerate;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\Str;
class EditAcademicJournal extends EditRecord
{
use SeoGenerate;
protected static string $resource = AcademicJournalResource::class;
protected array $seoData;
protected function mutateFormDataBeforeSave(array $data): array
{
$this->seoData = $this->generateSeo($data);
$data['search_data'] = $this->generateSearchData($data['main_info']);
return $data;
@@ -24,24 +25,7 @@ class EditAcademicJournal 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['main_info']);
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
@@ -94,15 +78,6 @@ class EditAcademicJournal extends EditRecord
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;
}
protected function getHeaderActions(): array
{
@@ -4,7 +4,9 @@ namespace App\Filament\Resources\AcademicJournalResource\RelationManagers;
use App\Models\AcademicJournal;
use Filament\Forms;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
@@ -17,27 +19,54 @@ class JournalsRelationManager extends RelationManager
{
protected static string $relationship = 'journals';
protected static ?string $modelLabel = 'выпуск';
protected static ?string $pluralModelLabel = 'выпуски';
public function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('title')->required(),
TextInput::make('title')
->label('Название выпуска')
->required()
->maxLength(255)
->placeholder('Введите название выпуска журнала')
->helperText('Например: "Том 15, №3 (2023)" или специальное название выпуска'),
FileUpload::make('path_file')
->label('Файл выпуска')
->required()
->acceptedFileTypes([
'application/pdf',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/zip'
'application/pdf' => 'PDF',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'DOCX',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'XLSX',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'PPTX',
'application/zip' => 'ZIP',
])
->maxSize(512000)
->disk('public')
->directory('files')
->directory('journals/files')
->downloadable()
->visibility('public'),
Forms\Components\TextInput::make('year_publication')->integer(),
Toggle::make('is_active')->default(true)->label('Активный выпуск')->inline(false),
->visibility('public')
->helperText('Максимальный размер файла: 512MB. Допустимые форматы: PDF, DOCX, XLSX, PPTX, ZIP')
->openable()
->previewable(false),
TextInput::make('year_publication')
->label('Год публикации')
->required()
->numeric()
->minValue(1900)
->maxValue(now()->year + 1)
->placeholder('Укажите год выпуска')
->helperText('Год должен быть в диапазоне от 1900 до '.(now()->year + 1)),
Toggle::make('is_active')
->label('Активный выпуск')
->default(true)
->inline(false)
->helperText('Активные выпуски отображаются на сайте'),
]);
}
@@ -49,22 +78,79 @@ class JournalsRelationManager extends RelationManager
->defaultSort('sort')
->recordTitleAttribute('title')
->columns([
Tables\Columns\TextColumn::make('title'),
Tables\Columns\TextColumn::make('title')
->label('Название выпуска')
->searchable()
->sortable()
->description(fn ($record) => $record->year_publication),
Tables\Columns\IconColumn::make('is_active')
->label('Статус')
->boolean()
->trueIcon('heroicon-o-check-circle')
->falseIcon('heroicon-o-x-circle')
->trueColor('success')
->falseColor('danger'),
Tables\Columns\TextColumn::make('created_at')
->label('Дата добавления')
->dateTime('d.m.Y H:i')
->sortable(),
])
->filters([
//
Tables\Filters\SelectFilter::make('year_publication')
->label('Год выпуска')
->options(
fn () => $this->getOwnerRecord()
->journals()
->select('year_publication')
->distinct()
->orderBy('year_publication', 'desc')
->pluck('year_publication', 'year_publication')
->toArray()
),
Tables\Filters\TernaryFilter::make('is_active')
->label('Только активные')
->trueLabel('Активные')
->falseLabel('Неактивные')
->queries(
true: fn (Builder $query) => $query->where('is_active', true),
false: fn (Builder $query) => $query->where('is_active', false),
),
])
->headerActions([
Tables\Actions\CreateAction::make(),
Tables\Actions\CreateAction::make()
->label('Добавить выпуск')
->modalHeading('Добавление нового выпуска'),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DetachAction::make(),
Tables\Actions\EditAction::make()
->iconButton()
->tooltip('Редактировать'),
Tables\Actions\DeleteAction::make()
->iconButton()
->tooltip('Удалить')
->modalHeading('Удаление выпуска')
->modalDescription('Вы уверены, что хотите удалить этот выпуск?'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DetachBulkAction::make(),
Tables\Actions\DeleteBulkAction::make()
->label('Удалить выбранные')
->modalHeading('Удаление выпусков')
->modalDescription('Вы уверены, что хотите удалить выбранные выпуски?'),
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make()
->label('Добавить выпуск'),
])
->groups([
Tables\Grouping\Group::make('year_publication')
->label('Год публикации')
->collapsible(),
]);
}
}
}