diff --git a/README.md b/README.md index 8ba5769..46665c9 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. -## Installation // 1 +## Installation You can install the package via composer: diff --git a/composer.json b/composer.json index 7bb5ae5..ee543a5 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,8 @@ "filament/filament": "^2.0", "filament/spatie-laravel-translatable-plugin": "^2.0", "ibecsystems/admin-kit-core": "^2.0", + "ibecsystems/admin-kit-navigation": "^2.0", + "ibecsystems/admin-kit-seo": "^2.0", "illuminate/contracts": "^10.0", "spatie/laravel-package-tools": "^1.14.0", "spatie/laravel-data": "^3.2", diff --git a/database/migrations/create_admin_kit_pages_table.php.stub b/database/migrations/create_admin_kit_pages_table.php.stub index 2fdfdd6..d28dfcb 100644 --- a/database/migrations/create_admin_kit_pages_table.php.stub +++ b/database/migrations/create_admin_kit_pages_table.php.stub @@ -10,10 +10,12 @@ return new class extends Migration { Schema::create('admin_kit_pages', function (Blueprint $table) { $table->id(); - - // add fields - $table->jsonb('title')->default('{}'); - + $table->jsonb('title'); + $table->jsonb('content'); + $table->jsonb('page_title')->nullable(); + $table->string('slug'); + $table->boolean('site_display')->default(1); + $table->softDeletes(); $table->timestamps(); }); } diff --git a/resources/lang/en/page-navigation.php b/resources/lang/en/page-navigation.php new file mode 100644 index 0000000..3cc4679 --- /dev/null +++ b/resources/lang/en/page-navigation.php @@ -0,0 +1,11 @@ + [ + 'page' => 'Page', + 'page_id' => 'Page', + 'created_at' => 'Created at', + 'updated_at' => 'Updated at', + + ], +]; diff --git a/resources/lang/ru/page-navigation.php b/resources/lang/ru/page-navigation.php new file mode 100644 index 0000000..d5a0c2c --- /dev/null +++ b/resources/lang/ru/page-navigation.php @@ -0,0 +1,11 @@ + [ + 'page' => 'Страница', + 'page_id' => 'Страница', + 'created_at' => 'Создано', + 'updated_at' => 'Изменено', + + ], +]; diff --git a/src/Models/Page.php b/src/Models/Page.php index 25cfe33..8c2f4d4 100644 --- a/src/Models/Page.php +++ b/src/Models/Page.php @@ -4,26 +4,35 @@ use AdminKit\Core\Abstracts\Models\AbstractModel; use AdminKit\Pages\Database\Factories\PageFactory; +use AdminKit\SEO\Traits\HasSEO; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\SoftDeletes; use Spatie\Translatable\HasTranslations; class Page extends AbstractModel { use HasFactory; use HasTranslations; + use HasSEO; + use SoftDeletes; protected $table = 'admin_kit_pages'; protected $fillable = [ 'title', + 'content', + 'slug', + 'position', + 'site_display', ]; - protected $casts = [ - // + public array $translatable = [ + 'title', + 'content', ]; - protected $translatable = [ - 'title', + protected $casts = [ + // ]; protected static function newFactory(): PageFactory diff --git a/src/PagesServiceProvider.php b/src/PagesServiceProvider.php index 077a27c..a96df7f 100644 --- a/src/PagesServiceProvider.php +++ b/src/PagesServiceProvider.php @@ -3,8 +3,12 @@ namespace AdminKit\Pages; use AdminKit\Pages\Commands\PagesCommand; +use AdminKit\Pages\Models\Page; use AdminKit\Pages\Providers\FilamentServiceProvider; use AdminKit\Pages\Providers\RouteServiceProvider; +use Filament\Forms\Components\Select; +use Filament\Forms\Components\TextInput; +use RyanChandler\FilamentNavigation\Facades\FilamentNavigation; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -30,4 +34,20 @@ public function registeringPackage() $this->app->register(FilamentServiceProvider::class); $this->app->register(RouteServiceProvider::class); } + + public function packageBooted() + { + FilamentNavigation::addItemType(__('filament-navigation.attributes.page'), [ + Select::make('page_id') + ->label(__('filament-navigation.attributes.page_id')) + ->searchable() + ->options(function () { + return Page::pluck('title', 'id'); + }), + + TextInput::make('slug') + ->required() + ->unique(Page::class, 'slug', ignoreRecord: true), + ]); + } } diff --git a/src/UI/Filament/Resources/PageResource.php b/src/UI/Filament/Resources/PageResource.php index dd26704..1cc7b71 100644 --- a/src/UI/Filament/Resources/PageResource.php +++ b/src/UI/Filament/Resources/PageResource.php @@ -2,42 +2,74 @@ namespace AdminKit\Pages\UI\Filament\Resources; +use AdminKit\Core\Forms\Components\TranslatableTabs; use AdminKit\Pages\Models\Page; use AdminKit\Pages\UI\Filament\Resources\PageResource\Pages; +use AdminKit\SEO\Forms\Components\SEOComponent; use Filament\Forms; -use Filament\Resources\Concerns\Translatable; +use Filament\Forms\Components\Tabs; use Filament\Resources\Form; use Filament\Resources\Resource; use Filament\Resources\Table; use Filament\Tables; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\SoftDeletingScope; +use Illuminate\Support\Str; class PageResource extends Resource { - use Translatable; - protected static ?string $model = Page::class; - protected static ?string $navigationIcon = 'heroicon-o-x'; + protected static ?string $modelLabel = 'Страницу'; + + protected static ?string $pluralModelLabel = 'Страницы'; + + protected static ?string $navigationGroup = 'Страницы'; + + protected static ?string $navigationIcon = 'heroicon-o-clipboard-list'; public static function form(Form $form): Form { return $form ->schema([ - Forms\Components\TextInput::make('title')->required(), - ]) - ->columns(1); + Forms\Components\Card::make([ + Forms\Components\TextInput::make('page_title') + ->label('Название страницы') + ->required() + ->lazy() + ->afterStateUpdated( + function (string $context, $state, callable $set) { + if ($context === 'create') { + $set('slug', Str::slug($state)); + } + } + ), + Forms\Components\TextInput::make('slug') + ->disabled() + ->required() + ->unique(Page::class, 'slug', ignoreRecord: true), + ])->columns(), + + TranslatableTabs::make(fn ($locale) => Tabs\Tab::make($locale)->schema([ + Forms\Components\TextInput::make('title') + ->label('Название') + ->required(), + + Forms\Components\RichEditor::make('content')->label('Контент')->required()->columnSpan(2), + ]))->columnSpan(2), + + SEOComponent::make(), + ]); } public static function table(Table $table): Table { return $table ->columns([ - Tables\Columns\TextColumn::make('id')->sortable(), - Tables\Columns\TextColumn::make('title'), + Tables\Columns\TextColumn::make('title')->label('Название')->searchable(), ]) - ->defaultSort('id', 'desc') ->filters([ - // + Tables\Filters\TrashedFilter::make(), ]) ->actions([ Tables\Actions\EditAction::make(), @@ -45,6 +77,8 @@ public static function table(Table $table): Table ]) ->bulkActions([ Tables\Actions\DeleteBulkAction::make(), + Tables\Actions\ForceDeleteBulkAction::make(), + Tables\Actions\RestoreBulkAction::make(), ]); } @@ -64,8 +98,11 @@ public static function getPages(): array ]; } - public static function getTranslatableLocales(): array + public static function getEloquentQuery(): Builder { - return config('admin-kit.locales'); + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); } } diff --git a/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php b/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php index 615bc1f..37517f2 100644 --- a/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php +++ b/src/UI/Filament/Resources/PageResource/Pages/CreatePage.php @@ -3,24 +3,9 @@ namespace AdminKit\Pages\UI\Filament\Resources\PageResource\Pages; use AdminKit\Pages\UI\Filament\Resources\PageResource; -use Filament\Pages\Actions; use Filament\Resources\Pages\CreateRecord; class CreatePage extends CreateRecord { - use CreateRecord\Concerns\Translatable; - protected static string $resource = PageResource::class; - - protected function getActions(): array - { - return [ - Actions\LocaleSwitcher::make(), - ]; - } - - protected function getRedirectUrl(): string - { - return PageResource::getUrl(); - } } diff --git a/src/UI/Filament/Resources/PageResource/Pages/EditPage.php b/src/UI/Filament/Resources/PageResource/Pages/EditPage.php index f1a5219..03409da 100644 --- a/src/UI/Filament/Resources/PageResource/Pages/EditPage.php +++ b/src/UI/Filament/Resources/PageResource/Pages/EditPage.php @@ -8,14 +8,11 @@ class EditPage extends EditRecord { - use EditRecord\Concerns\Translatable; - protected static string $resource = PageResource::class; protected function getActions(): array { return [ - Actions\LocaleSwitcher::make(), Actions\DeleteAction::make(), ]; } diff --git a/src/UI/Filament/Resources/PageResource/Pages/ListPage.php b/src/UI/Filament/Resources/PageResource/Pages/ListPage.php index 5648814..7fe684c 100644 --- a/src/UI/Filament/Resources/PageResource/Pages/ListPage.php +++ b/src/UI/Filament/Resources/PageResource/Pages/ListPage.php @@ -8,14 +8,11 @@ class ListPage extends ListRecords { - use ListRecords\Concerns\Translatable; - protected static string $resource = PageResource::class; protected function getActions(): array { return [ - Actions\LocaleSwitcher::make(), Actions\CreateAction::make(), ]; }