Skip to content

Commit

Permalink
pint and code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
atmonshi committed Sep 17, 2022
1 parent cda9ca3 commit 4daae9c
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 43 deletions.
3 changes: 2 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Support\Facades\Route;
use LaraZeus\Sky\Http\Livewire\Faq;
use LaraZeus\Sky\Http\Livewire\Page;
use LaraZeus\Sky\Http\Livewire\Post;
use LaraZeus\Sky\Http\Livewire\Posts;
Expand All @@ -22,5 +23,5 @@
});

if (in_array('LaraZeus\Sky\Filament\Resources\FaqResource', config('zeus-sky.enabled_resources'))) {
Route::get(config('zeus-sky.faq_uri_prefix') . '', \LaraZeus\Sky\Http\Livewire\Faq::class)->name('faq');
Route::get(config('zeus-sky.faq_uri_prefix') . '', Faq::class)->name('faq');
}
17 changes: 13 additions & 4 deletions src/Filament/Resources/FaqResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Filament\Forms\Components\Textarea;
use Filament\Resources\Form;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use LaraZeus\Sky\Filament\Resources\FaqResource\Pages;
use LaraZeus\Sky\Models\Faq;

Expand Down Expand Up @@ -45,16 +45,25 @@ public static function form(Form $form): Form
{
return $form
->schema([
Textarea::make('question')->label(__('Question'))->required()->maxLength(65535)->columnSpan(2),
RichEditor::make('answer')->label(__('Answer'))->required()->maxLength(65535)->columnSpan(2),
Textarea::make('question')
->label(__('Question'))
->required()
->maxLength(65535)
->columnSpan(2),

RichEditor::make('answer')
->label(__('Answer'))
->required()
->maxLength(65535)
->columnSpan(2),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('question'),
TextColumn::make('question'),
]);
}

Expand Down
60 changes: 46 additions & 14 deletions src/Filament/Resources/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,44 @@ public static function form(Form $form): Form
->afterStateUpdated(function (Closure $set, $state) {
$set('slug', Str::slug($state));
}),
TinyEditor::make('content')->label(__('Post Content'))->showMenuBar()->required(),

TinyEditor::make('content')
->label(__('Post Content'))
->showMenuBar()
->required(),
]),
])->columnSpan(3),
])
->columnSpan(3),

Grid::make()->schema([
Section::make(__('SEO'))
->description(__('SEO Settings'))
->schema([
Hidden::make('user_id')->default(auth()->user()->id)->required(),
Hidden::make('post_type')->default('page')->required(),
->description(__('SEO Settings'))->schema([
Hidden::make('user_id')
->required()
->default(auth()->user()->id),

Hidden::make('post_type')
->default('page')
->required(),

Textarea::make('description')
->maxLength(255)
->label(__('Description'))
->hint(__('Write an excerpt for your post')),
TextInput::make('slug')->required()->maxLength(255)->label(__('Post Slug')),
Select::make('parent_id')->options(Post::wherePostType('page')->pluck('title', 'id'))->label(__('Parent Page')),
TextInput::make('ordering')->integer()->label(__('Page Order'))->default(1),

TextInput::make('slug')
->required()
->maxLength(255)
->label(__('Post Slug')),

Select::make('parent_id')
->options(Post::wherePostType('page')->pluck('title', 'id'))
->label(__('Parent Page')),

TextInput::make('ordering')
->integer()
->label(__('Page Order'))
->default(1),
])
->collapsible(),

Expand All @@ -80,15 +101,23 @@ public static function form(Form $form): Form
->required()
->reactive()
->options(PostStatus::pluck('label', 'name')),
TextInput::make('password')->label(__('Password'))->reactive()

TextInput::make('password')
->label(__('Password'))
->reactive()
->visible(fn (Closure $get): bool => $get('status') === 'private'),
DateTimePicker::make('published_at')->label(__('published at'))->default(now()),

DateTimePicker::make('published_at')
->label(__('published at'))
->default(now()),
])
->collapsible(),

Section::make(__('Featured Image'))
->schema([
SpatieMediaLibraryFileUpload::make('featured_image')->collection('pages')->label(''),
SpatieMediaLibraryFileUpload::make('featured_image')
->collection('pages')
->label(''),
])
->collapsible(),
])->columnSpan(1),
Expand All @@ -114,9 +143,12 @@ public static function table(Table $table): Table
])
->defaultSort('id', 'desc')
->filters([
MultiSelectFilter::make('status')->options(PostStatus::pluck('label', 'name')),
MultiSelectFilter::make('status')
->label(__('Status'))
->options(PostStatus::pluck('label', 'name')),

Filter::make('password')->label(__('Password Protected'))
Filter::make('password')
->label(__('Password Protected'))
->query(fn (Builder $query): Builder => $query->whereNotNull('password')),
]);
}
Expand Down
86 changes: 64 additions & 22 deletions src/Filament/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,48 @@ public static function form(Form $form): Form
->afterStateUpdated(function (Closure $set, $state) {
$set('slug', Str::slug($state));
}),
TinyEditor::make('content')->label(__('Post Content'))->showMenuBar()->required(),

TinyEditor::make('content')
->label(__('Post Content'))
->showMenuBar()
->required(),
]),
])->columnSpan(3),

Grid::make()->schema([
Section::make(__('SEO'))
->description(__('SEO Settings'))
->schema([
Hidden::make('user_id')->default(auth()->user()->id)->required(),
Hidden::make('post_type')->default('post')->required(),
Hidden::make('user_id')
->default(auth()->user()->id)
->required(),

Hidden::make('post_type')
->default('post')
->required(),

Textarea::make('description')
->maxLength(255)
->label(__('Description'))
->hint(__('Write an excerpt for your post')),
TextInput::make('slug')->required()->maxLength(255)->label(__('Post Slug')),

TextInput::make('slug')
->required()
->maxLength(255)
->label(__('Post Slug')),
])
->collapsible(),

Section::make(__('Tags and Categories'))
->description(__('Tags and Categories Options'))
->schema([
SpatieTagsInput::make('tags')->type('tag')->label(__('Tags')),
SpatieTagsInput::make('category')->type('category')->label(__('Categories')),
SpatieTagsInput::make('tags')
->type('tag')
->label(__('Tags')),

SpatieTagsInput::make('category')
->type('category')
->label(__('Categories')),
])
->collapsible(),

Expand All @@ -86,16 +105,26 @@ public static function form(Form $form): Form
->required()
->reactive()
->options(PostStatus::pluck('label', 'name')),
TextInput::make('password')->label(__('Password'))->reactive()

TextInput::make('password')
->label(__('Password'))
->reactive()
->visible(fn (Closure $get): bool => $get('status') === 'private'),
DateTimePicker::make('published_at')->label(__('published at'))->default(now()),
DateTimePicker::make('sticky_until')->label(__('Sticky Until')),

DateTimePicker::make('published_at')
->label(__('published at'))
->default(now()),

DateTimePicker::make('sticky_until')
->label(__('Sticky Until')),
])
->collapsible(),

Section::make(__('Featured Image'))
->schema([
SpatieMediaLibraryFileUpload::make('featured_image')->collection('posts')->label(''),
SpatieMediaLibraryFileUpload::make('featured_image')
->collection('posts')
->label(''),
])
->collapsible(),
])->columnSpan(1),
Expand All @@ -119,34 +148,47 @@ public static function table(Table $table): Table
->view('zeus-sky::filament.columns.status-desc')
->tooltip(fn (Post $record): string => $record->published_at->format('Y/m/d | H:i A')),

SpatieTagsColumn::make('tags')->label(__('Post Tags'))->type('tag'),
SpatieTagsColumn::make('category')->label(__('Post Category'))->type('category'),
SpatieTagsColumn::make('tags')
->label(__('Post Tags'))
->type('tag'),

SpatieTagsColumn::make('category')
->label(__('Post Category'))
->type('category'),
])
->defaultSort('id', 'desc')
->filters([
MultiSelectFilter::make('status')->options(PostStatus::pluck('label', 'name')),
MultiSelectFilter::make('status')
->label(__('Status'))
->options(PostStatus::pluck('label', 'name')),

Filter::make('password')->label(__('Password Protected'))
Filter::make('password')
->label(__('Password Protected'))
->query(fn (Builder $query): Builder => $query->whereNotNull('password')),

Filter::make('sticky')->label(__('Still Sticky'))
Filter::make('sticky')
->label(__('Still Sticky'))
->query(fn (Builder $query): Builder => $query->sticky()),

Filter::make('not_sticky')->label(__('Not Sticky'))
Filter::make('not_sticky')
->label(__('Not Sticky'))
->query(
fn (Builder $query): Builder => $query
->whereDate('sticky_until', '<=', now())
->orWhereNull('sticky_until')
->whereDate('sticky_until', '<=', now())
->orWhereNull('sticky_until')
),

Filter::make('sticky_only')->label(__('Sticky Only'))
Filter::make('sticky_only')
->label(__('Sticky Only'))
->query(
fn (Builder $query): Builder => $query
->wherePostType('post')
->whereNotNull('sticky_until')
->wherePostType('post')
->whereNotNull('sticky_until')
),

MultiSelectFilter::make('tags')->relationship('tags', 'name')->label(__('Tags')),
MultiSelectFilter::make('tags')
->relationship('tags', 'name')
->label(__('Tags')),
]);
}

Expand Down
10 changes: 8 additions & 2 deletions src/Filament/Resources/TagResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')->required()->maxLength(255)->label(__('Tag.Name'))->reactive()
TextInput::make('name')
->required()
->maxLength(255)
->label(__('Tag.Name'))
->reactive()
->afterStateUpdated(function (Closure $set, $state) {
$set('slug', Str::slug($state));
}),
TextInput::make('slug')->required()->maxLength(255),
TextInput::make('slug')
->required()
->maxLength(255),
Select::make('type')
->options([
'tag' => 'Tag',
Expand Down

0 comments on commit 4daae9c

Please sign in to comment.