Skip to content

Commit

Permalink
Merge pull request #3 from IBEC-BOX/navigation
Browse files Browse the repository at this point in the history
Navigation
  • Loading branch information
ast21 authored Jul 19, 2023
2 parents 316ddf9 + 77a316a commit c1abd6f
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 6 additions & 4 deletions database/migrations/create_admin_kit_pages_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
11 changes: 11 additions & 0 deletions resources/lang/en/page-navigation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'attributes' => [
'page' => 'Page',
'page_id' => 'Page',
'created_at' => 'Created at',
'updated_at' => 'Updated at',

],
];
11 changes: 11 additions & 0 deletions resources/lang/ru/page-navigation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'attributes' => [
'page' => 'Страница',
'page_id' => 'Страница',
'created_at' => 'Создано',
'updated_at' => 'Изменено',

],
];
17 changes: 13 additions & 4 deletions src/Models/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/PagesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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),
]);
}
}
63 changes: 50 additions & 13 deletions src/UI/Filament/Resources/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,83 @@

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(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]);
}

Expand All @@ -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,
]);
}
}
15 changes: 0 additions & 15 deletions src/UI/Filament/Resources/PageResource/Pages/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
3 changes: 0 additions & 3 deletions src/UI/Filament/Resources/PageResource/Pages/EditPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}
Expand Down
3 changes: 0 additions & 3 deletions src/UI/Filament/Resources/PageResource/Pages/ListPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];
}
Expand Down

0 comments on commit c1abd6f

Please sign in to comment.