wip: article AI polish, category SEO fields, cover generator, membership plan seeder
This commit is contained in:
@@ -10,8 +10,10 @@ use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Support\Enums\Alignment;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use UnitEnum;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class ManagePlugins extends Page
|
||||
{
|
||||
@@ -69,19 +71,45 @@ class ManagePlugins extends Page
|
||||
|
||||
public function showDocs(string $name, PluginManager $manager): void
|
||||
{
|
||||
$docs = $manager->readDocs($name);
|
||||
if ($docs === null || trim($docs) === '') {
|
||||
if ($manager->readDocs($name) === null) {
|
||||
Notification::make()->title(__('admin.messages.plugin_docs_missing'))->warning()->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title(__('admin.pages.plugin_docs'))
|
||||
->body(str($docs)->limit(1800)->toString())
|
||||
->persistent()
|
||||
->info()
|
||||
->send();
|
||||
$this->mountAction('viewDocs', ['name' => $name]);
|
||||
}
|
||||
|
||||
public function viewDocsAction(): Action
|
||||
{
|
||||
return Action::make('viewDocs')
|
||||
->label(__('admin.pages.plugin_docs'))
|
||||
->modalHeading(function (array $arguments): string {
|
||||
$name = (string) ($arguments['name'] ?? '');
|
||||
$plugin = collect($this->plugins)->firstWhere('name', $name);
|
||||
$title = is_array($plugin) ? (string) ($plugin['title'] ?? $name) : $name;
|
||||
|
||||
return __('admin.pages.plugin_docs').($title !== '' ? ' · '.$title : '');
|
||||
})
|
||||
->modalContent(function (array $arguments): View {
|
||||
return view('filament.partials.plugin-docs', [
|
||||
'html' => app(PluginManager::class)->readDocsHtml((string) ($arguments['name'] ?? '')) ?? '',
|
||||
]);
|
||||
})
|
||||
->modalAlignment(Alignment::Center)
|
||||
->modalWidth(Width::FiveExtraLarge)
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelAction(fn (Action $action): Action => $action
|
||||
->label(__('admin.actions.close'))
|
||||
->color('primary')
|
||||
->close()
|
||||
)
|
||||
->modalFooterActionsAlignment(Alignment::End)
|
||||
->closeModalByClickingAway()
|
||||
->closeModalByEscaping()
|
||||
->stickyModalHeader()
|
||||
->stickyModalFooter()
|
||||
->extraModalWindowAttributes(['class' => 'lb-plugin-docs-modal']);
|
||||
}
|
||||
|
||||
protected function reload(PluginManager $manager): void
|
||||
|
||||
@@ -22,4 +22,10 @@ class MembershipPluginPage extends PluginSkeletonPage
|
||||
{
|
||||
return 'membership';
|
||||
}
|
||||
|
||||
public static function shouldRegisterNavigation(): bool
|
||||
{
|
||||
// UI is owned by plugins/larablog/membership Filament resources.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Articles;
|
||||
|
||||
use App\Filament\Concerns\HasTranslatedLabels;
|
||||
use App\Filament\Resources\Articles\Pages\CreateArticle;
|
||||
use App\Filament\Resources\Articles\Pages\EditArticle;
|
||||
use App\Filament\Resources\Articles\Pages\ListArticles;
|
||||
use App\Filament\Resources\Articles\RelationManagers\CommentsRelationManager;
|
||||
use App\Filament\Resources\Articles\Schemas\ArticleForm;
|
||||
use App\Filament\Resources\Articles\Tables\ArticlesTable;
|
||||
use App\Models\Article;
|
||||
@@ -15,8 +17,6 @@ use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
use App\Filament\Concerns\HasTranslatedLabels;
|
||||
|
||||
class ArticleResource extends Resource
|
||||
{
|
||||
@@ -24,9 +24,6 @@ class ArticleResource extends Resource
|
||||
|
||||
protected static ?string $model = Article::class;
|
||||
|
||||
|
||||
|
||||
|
||||
protected static function navKey(): string
|
||||
{
|
||||
return 'articles';
|
||||
@@ -57,7 +54,7 @@ class ArticleResource extends Resource
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
CommentsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,14 @@ class CreateArticle extends CreateRecord
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
{
|
||||
$filtered = Hook::filter('filament.article.mutate_before_save', $data, null);
|
||||
$data = is_array($filtered) ? $filtered : $data;
|
||||
|
||||
return is_array($filtered) ? $filtered : $data;
|
||||
$validated = Hook::filter('filament.article.validate_access_restrictions', $data, null);
|
||||
$data = is_array($validated) ? $validated : $data;
|
||||
|
||||
unset($data['paid_content'], $data['membership']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterCreate(): void
|
||||
|
||||
@@ -4,9 +4,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Articles\Pages;
|
||||
|
||||
use App\Domain\Ai\Jobs\GenerateArticleCoverJob;
|
||||
use App\Domain\Ai\Jobs\OptimizeArticleContentJob;
|
||||
use App\Domain\Plugin\Hook;
|
||||
use App\Filament\Resources\Articles\ArticleResource;
|
||||
use App\Settings\AiSettings;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Notifications\Notification;
|
||||
@@ -21,6 +23,13 @@ class EditArticle extends EditRecord
|
||||
return [
|
||||
Action::make('aiOptimize')
|
||||
->label(__('admin.messages.ai_optimize'))
|
||||
->visible(function (): bool {
|
||||
try {
|
||||
return (bool) app(AiSettings::class)->content_optimization_enabled;
|
||||
} catch (\Throwable) {
|
||||
return false;
|
||||
}
|
||||
})
|
||||
->action(function (): void {
|
||||
OptimizeArticleContentJob::dispatch($this->record->getKey());
|
||||
Notification::make()
|
||||
@@ -29,6 +38,55 @@ class EditArticle extends EditRecord
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
Action::make('applyAiPolish')
|
||||
->label(__('admin.messages.ai_apply_polish'))
|
||||
->color('gray')
|
||||
->requiresConfirmation()
|
||||
->modalHeading(__('admin.messages.ai_apply_polish'))
|
||||
->modalDescription(__('admin.messages.ai_apply_polish_confirm'))
|
||||
->visible(fn (): bool => filled($this->record->ai_polished_content))
|
||||
->action(function (): void {
|
||||
$polished = (string) $this->record->ai_polished_content;
|
||||
|
||||
if ($polished === '') {
|
||||
Notification::make()
|
||||
->title(__('admin.messages.ai_polish_missing'))
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->record->forceFill(['content' => $polished])->save();
|
||||
$this->refreshFormData(['content', 'ai_polished_content', 'ai_summary', 'description']);
|
||||
|
||||
Notification::make()
|
||||
->title(__('admin.messages.ai_apply_polish_done'))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
Action::make('autoCover')
|
||||
->label(__('admin.messages.auto_cover'))
|
||||
->color('gray')
|
||||
->action(function (): void {
|
||||
GenerateArticleCoverJob::dispatch($this->record->getKey(), 'auto');
|
||||
Notification::make()
|
||||
->title(__('admin.messages.auto_cover_queued'))
|
||||
->body(__('admin.messages.ai_optimize_queue_hint'))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
Action::make('generateCover')
|
||||
->label(__('admin.messages.generate_cover'))
|
||||
->color('gray')
|
||||
->action(function (): void {
|
||||
GenerateArticleCoverJob::dispatch($this->record->getKey(), 'generate');
|
||||
Notification::make()
|
||||
->title(__('admin.messages.generate_cover_queued'))
|
||||
->body(__('admin.messages.ai_optimize_queue_hint'))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
DeleteAction::make(),
|
||||
...Hook::collect('filament.article.actions'),
|
||||
];
|
||||
@@ -40,6 +98,13 @@ class EditArticle extends EditRecord
|
||||
*/
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$items = is_array($this->record->ai_suggestions) ? $this->record->ai_suggestions : [];
|
||||
$data['ai_suggestions_text'] = collect($items)
|
||||
->filter(fn ($item) => filled($item))
|
||||
->values()
|
||||
->map(fn ($item, $index) => ($index + 1).'. '.$item)
|
||||
->implode("\n");
|
||||
|
||||
$filtered = Hook::filter('filament.article.mutate_before_fill', $data, $this->record);
|
||||
|
||||
return is_array($filtered) ? $filtered : $data;
|
||||
@@ -51,9 +116,26 @@ class EditArticle extends EditRecord
|
||||
*/
|
||||
protected function mutateFormDataBeforeSave(array $data): array
|
||||
{
|
||||
$filtered = Hook::filter('filament.article.mutate_before_save', $data, $this->record);
|
||||
if (filled($data['cover_path'] ?? null)) {
|
||||
$path = (string) $data['cover_path'];
|
||||
$data['cover_status'] = 'ready';
|
||||
$data['cover_source'] = str_starts_with($path, 'http://') || str_starts_with($path, 'https://')
|
||||
? 'content_image'
|
||||
: 'manual';
|
||||
$data['cover_disk'] = ($data['cover_source'] === 'content_image')
|
||||
? 'url'
|
||||
: ($this->record->cover_disk ?: config('larablog.attachments_disk', 'attachments'));
|
||||
}
|
||||
|
||||
return is_array($filtered) ? $filtered : $data;
|
||||
$filtered = Hook::filter('filament.article.mutate_before_save', $data, $this->record);
|
||||
$data = is_array($filtered) ? $filtered : $data;
|
||||
|
||||
$validated = Hook::filter('filament.article.validate_access_restrictions', $data, $this->record);
|
||||
$data = is_array($validated) ? $validated : $data;
|
||||
|
||||
unset($data['paid_content'], $data['membership']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function afterSave(): void
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Filament\Resources\Articles\Pages;
|
||||
|
||||
use App\Filament\Resources\Articles\ArticleResource;
|
||||
use App\Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListArticles extends ListRecords
|
||||
{
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Articles\RelationManagers;
|
||||
|
||||
use App\Filament\Support\AdminTable;
|
||||
use App\Models\Comment;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CommentsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'comments';
|
||||
|
||||
public static function getTitle(Model $ownerRecord, string $pageClass): string
|
||||
{
|
||||
return __('admin.nav.comments');
|
||||
}
|
||||
|
||||
public function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('author')
|
||||
->label(__('admin.fields.author'))
|
||||
->required(),
|
||||
TextInput::make('url')
|
||||
->label(__('admin.fields.url'))
|
||||
->url(),
|
||||
Textarea::make('content')
|
||||
->label(__('admin.fields.content'))
|
||||
->required()
|
||||
->columnSpanFull(),
|
||||
Select::make('moderation_status')
|
||||
->label(__('admin.fields.moderation_status'))
|
||||
->options([
|
||||
Comment::STATUS_PENDING => __('admin.options.moderation.pending'),
|
||||
Comment::STATUS_PENDING_AI => __('admin.options.moderation.pending_ai'),
|
||||
Comment::STATUS_APPROVED => __('admin.options.moderation.approved'),
|
||||
Comment::STATUS_REJECTED => __('admin.options.moderation.rejected'),
|
||||
Comment::STATUS_NEEDS_HUMAN => __('admin.options.moderation.needs_human'),
|
||||
])
|
||||
->required()
|
||||
->default(Comment::STATUS_PENDING),
|
||||
DateTimePicker::make('published_at')
|
||||
->label(__('admin.fields.published_at')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('author')
|
||||
->columns([
|
||||
TextColumn::make('author')
|
||||
->label(__('admin.fields.author'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('content')
|
||||
->label(__('admin.fields.content'))
|
||||
->html()
|
||||
->formatStateUsing(fn (?string $state): string => trim(html_entity_decode(strip_tags((string) $state), ENT_QUOTES | ENT_HTML5, 'UTF-8'))),
|
||||
),
|
||||
TextColumn::make('moderation_status')
|
||||
->label(__('admin.fields.moderation_status'))
|
||||
->badge(),
|
||||
TextColumn::make('published_at')
|
||||
->label(__('admin.fields.published_at'))
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('moderation_status')
|
||||
->label(__('admin.fields.moderation_status'))
|
||||
->options([
|
||||
Comment::STATUS_PENDING => __('admin.options.moderation.pending'),
|
||||
Comment::STATUS_PENDING_AI => __('admin.options.moderation.pending_ai'),
|
||||
Comment::STATUS_APPROVED => __('admin.options.moderation.approved'),
|
||||
Comment::STATUS_REJECTED => __('admin.options.moderation.rejected'),
|
||||
Comment::STATUS_NEEDS_HUMAN => __('admin.options.moderation.needs_human'),
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
CreateAction::make()
|
||||
->mutateFormDataUsing(function (array $data): array {
|
||||
$data['published_at'] ??= now();
|
||||
$data['moderation_status'] ??= Comment::STATUS_PENDING;
|
||||
|
||||
return $data;
|
||||
})
|
||||
->after(function (): void {
|
||||
$this->getOwnerRecord()->increment('comments_count');
|
||||
}),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make()
|
||||
->after(function (): void {
|
||||
$this->getOwnerRecord()->decrement('comments_count');
|
||||
}),
|
||||
])
|
||||
->toolbarActions([
|
||||
DeleteBulkAction::make()
|
||||
->after(function (): void {
|
||||
$this->getOwnerRecord()->forceFill([
|
||||
'comments_count' => $this->getOwnerRecord()->comments()->count(),
|
||||
])->save();
|
||||
}),
|
||||
])
|
||||
->defaultSort('published_at', 'desc');
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,8 @@ use App\Domain\Plugin\Hook;
|
||||
use App\Settings\GeneralSettings;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Schema;
|
||||
@@ -78,8 +78,33 @@ class ArticleForm
|
||||
TextInput::make('read_password')
|
||||
->label(__('admin.fields.read_password'))
|
||||
->password(),
|
||||
TextInput::make('cover_path')
|
||||
->label(__('admin.fields.cover_path'))
|
||||
->helperText(__('admin.helpers.cover_path'))
|
||||
->columnSpanFull(),
|
||||
TextInput::make('cover_source')
|
||||
->label(__('admin.fields.cover_source'))
|
||||
->disabled()
|
||||
->dehydrated(false),
|
||||
TextInput::make('cover_status')
|
||||
->label(__('admin.fields.cover_status'))
|
||||
->disabled()
|
||||
->dehydrated(false),
|
||||
Textarea::make('ai_summary')
|
||||
->label(__('admin.fields.ai_summary'))
|
||||
->rows(3)
|
||||
->columnSpanFull(),
|
||||
Textarea::make('ai_polished_content')
|
||||
->label(__('admin.fields.ai_polished_content'))
|
||||
->helperText(__('admin.helpers.ai_polished_content'))
|
||||
->rows(12)
|
||||
->columnSpanFull(),
|
||||
Textarea::make('ai_suggestions_text')
|
||||
->label(__('admin.fields.ai_suggestions'))
|
||||
->helperText(__('admin.helpers.ai_suggestions'))
|
||||
->rows(4)
|
||||
->disabled()
|
||||
->dehydrated(false)
|
||||
->columnSpanFull(),
|
||||
...Hook::collect('filament.article.form'),
|
||||
]);
|
||||
|
||||
@@ -5,12 +5,16 @@ declare(strict_types=1);
|
||||
namespace App\Filament\Resources\Articles\Tables;
|
||||
|
||||
use App\Domain\Plugin\Hook;
|
||||
use App\Filament\Support\AdminTable;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ArticlesTable
|
||||
{
|
||||
@@ -18,21 +22,32 @@ class ArticlesTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
AdminTable::stickyStart(
|
||||
TextColumn::make('id')
|
||||
->label(__('admin.fields.id'))
|
||||
->sortable(),
|
||||
),
|
||||
TextColumn::make('category.name')
|
||||
->label(__('admin.fields.category'))
|
||||
->searchable(),
|
||||
TextColumn::make('user.name')
|
||||
->label(__('admin.fields.author'))
|
||||
->searchable(),
|
||||
TextColumn::make('title')
|
||||
->label(__('admin.fields.title'))
|
||||
->searchable(),
|
||||
TextColumn::make('description')
|
||||
->label(__('admin.fields.description'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('title')
|
||||
->label(__('admin.fields.title'))
|
||||
->searchable(),
|
||||
),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('description')
|
||||
->label(__('admin.fields.description'))
|
||||
->searchable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
),
|
||||
TextColumn::make('keywords')
|
||||
->label(__('admin.fields.keywords'))
|
||||
->searchable(),
|
||||
->searchable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('published_at')
|
||||
->label(__('admin.fields.published_at'))
|
||||
->dateTime()
|
||||
@@ -66,15 +81,33 @@ class ArticlesTable
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('slug')
|
||||
->label(__('admin.fields.slug'))
|
||||
->searchable(),
|
||||
->searchable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('content_format')
|
||||
->label(__('admin.fields.content_format'))
|
||||
->searchable(),
|
||||
->searchable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
...Hook::collect('filament.article.table.columns'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
SelectFilter::make('category_id')
|
||||
->label(__('admin.fields.category'))
|
||||
->relationship('category', 'name')
|
||||
->searchable()
|
||||
->preload(),
|
||||
TernaryFilter::make('visible')
|
||||
->label(__('admin.fields.visible')),
|
||||
TernaryFilter::make('stick')
|
||||
->label(__('admin.fields.stick')),
|
||||
TernaryFilter::make('close_comment')
|
||||
->label(__('admin.fields.close_comment')),
|
||||
...Hook::collect('filament.article.table.filters'),
|
||||
])
|
||||
->modifyQueryUsing(function (Builder $query): Builder {
|
||||
$modified = Hook::filter('filament.article.table.query', $query);
|
||||
|
||||
return $modified instanceof Builder ? $modified : $query;
|
||||
})
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
...Hook::collect('filament.article.actions'),
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Filament\Resources\Attachments\Pages;
|
||||
|
||||
use App\Filament\Resources\Attachments\AttachmentResource;
|
||||
use App\Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAttachments extends ListRecords
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Attachments\Tables;
|
||||
|
||||
use App\Filament\Support\AdminTable;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
@@ -16,21 +17,28 @@ class AttachmentsTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('article.title')
|
||||
->label(__('admin.fields.article'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('article.title')
|
||||
->label(__('admin.fields.article'))
|
||||
->searchable(),
|
||||
),
|
||||
TextColumn::make('disk')
|
||||
->label(__('admin.fields.disk'))
|
||||
->searchable(),
|
||||
TextColumn::make('path')
|
||||
->label(__('admin.fields.path'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('path')
|
||||
->label(__('admin.fields.path'))
|
||||
->searchable(),
|
||||
),
|
||||
TextColumn::make('thumb_path')
|
||||
->label(__('admin.fields.thumb_path'))
|
||||
->searchable(),
|
||||
TextColumn::make('filename')
|
||||
->label(__('admin.fields.filename'))
|
||||
->searchable(),
|
||||
->searchable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('filename')
|
||||
->label(__('admin.fields.filename'))
|
||||
->searchable(),
|
||||
),
|
||||
TextColumn::make('mime')
|
||||
->label(__('admin.fields.mime'))
|
||||
->searchable(),
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Filament\Resources\Categories\Pages;
|
||||
|
||||
use App\Filament\Resources\Categories\CategoryResource;
|
||||
use App\Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListCategories extends ListRecords
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Categories\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
@@ -16,16 +17,25 @@ class CategoryForm
|
||||
TextInput::make('name')
|
||||
->label(__('admin.fields.name'))
|
||||
->required(),
|
||||
TextInput::make('description')
|
||||
->label(__('admin.fields.description'))
|
||||
->maxLength(255)
|
||||
->helperText(__('admin.helpers.category_description')),
|
||||
Textarea::make('intro')
|
||||
->label(__('admin.fields.intro'))
|
||||
->rows(5)
|
||||
->columnSpanFull()
|
||||
->helperText(__('admin.helpers.category_intro')),
|
||||
TextInput::make('keywords')
|
||||
->label(__('admin.fields.keywords')),
|
||||
TextInput::make('cover_path')
|
||||
->label(__('admin.fields.cover_path'))
|
||||
->helperText(__('admin.helpers.category_cover')),
|
||||
TextInput::make('display_order')
|
||||
->label(__('admin.fields.display_order'))
|
||||
->required()
|
||||
->numeric()
|
||||
->default(0),
|
||||
TextInput::make('articles_count')
|
||||
->label(__('admin.fields.articles_count'))
|
||||
->required()
|
||||
->numeric()
|
||||
->default(0),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Categories\Tables;
|
||||
|
||||
use App\Filament\Resources\Articles\ArticleResource;
|
||||
use App\Filament\Support\AdminTable;
|
||||
use App\Models\Category;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
@@ -16,9 +19,11 @@ class CategoriesTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.fields.name'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.fields.name'))
|
||||
->searchable(),
|
||||
),
|
||||
TextColumn::make('display_order')
|
||||
->label(__('admin.fields.display_order'))
|
||||
->numeric()
|
||||
@@ -26,7 +31,17 @@ class CategoriesTable
|
||||
TextColumn::make('articles_count')
|
||||
->label(__('admin.fields.articles_count'))
|
||||
->numeric()
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->url(fn (Category $record): string => ArticleResource::getUrl('index', [
|
||||
'filters' => [
|
||||
'category_id' => ['value' => $record->id],
|
||||
],
|
||||
])),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('description')
|
||||
->label(__('admin.fields.description'))
|
||||
->toggleable(),
|
||||
),
|
||||
TextColumn::make('created_at')
|
||||
->label(__('admin.fields.created_at'))
|
||||
->dateTime()
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Filament\Resources\Comments\Pages;
|
||||
|
||||
use App\Filament\Resources\Comments\CommentResource;
|
||||
use App\Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListComments extends ListRecords
|
||||
{
|
||||
|
||||
@@ -4,11 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Comments\Schemas;
|
||||
|
||||
use App\Domain\Blog\ArticleExcerpt;
|
||||
use App\Models\Comment;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class CommentForm
|
||||
@@ -20,7 +21,22 @@ class CommentForm
|
||||
Select::make('article_id')
|
||||
->label(__('admin.fields.article'))
|
||||
->relationship('article', 'title')
|
||||
->required(),
|
||||
->required()
|
||||
->live(),
|
||||
Textarea::make('article_excerpt_preview')
|
||||
->label(__('admin.fields.article_excerpt'))
|
||||
->disabled()
|
||||
->dehydrated(false)
|
||||
->rows(3)
|
||||
->columnSpanFull()
|
||||
->visible(fn (?Comment $record): bool => $record?->article !== null)
|
||||
->afterStateHydrated(function (Textarea $component, mixed $state, ?Comment $record): void {
|
||||
if ($record?->article === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$component->state(app(ArticleExcerpt::class)->forList($record->article, 240));
|
||||
}),
|
||||
TextInput::make('author')
|
||||
->label(__('admin.fields.author'))
|
||||
->required(),
|
||||
|
||||
@@ -4,10 +4,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Comments\Tables;
|
||||
|
||||
use App\Domain\Blog\ArticleExcerpt;
|
||||
use App\Filament\Support\AdminTable;
|
||||
use App\Models\Comment;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class CommentsTable
|
||||
@@ -15,16 +19,32 @@ class CommentsTable
|
||||
public static function configure(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->modifyQueryUsing(fn ($query) => $query->with('article'))
|
||||
->columns([
|
||||
TextColumn::make('article.title')
|
||||
->label(__('admin.fields.article'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('article.title')
|
||||
->label(__('admin.fields.article'))
|
||||
->searchable(),
|
||||
),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('article_excerpt')
|
||||
->label(__('admin.fields.article_excerpt'))
|
||||
->getStateUsing(function (Comment $record): string {
|
||||
if ($record->article === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return app(ArticleExcerpt::class)->forList($record->article, 80);
|
||||
}),
|
||||
),
|
||||
TextColumn::make('author')
|
||||
->label(__('admin.fields.author'))
|
||||
->searchable(),
|
||||
TextColumn::make('url')
|
||||
->label(__('admin.fields.url'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('url')
|
||||
->label(__('admin.fields.url'))
|
||||
->searchable(),
|
||||
),
|
||||
TextColumn::make('ip')
|
||||
->label(__('admin.fields.ip'))
|
||||
->searchable(),
|
||||
@@ -47,7 +67,15 @@ class CommentsTable
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
SelectFilter::make('moderation_status')
|
||||
->label(__('admin.fields.moderation_status'))
|
||||
->options([
|
||||
Comment::STATUS_PENDING => __('admin.options.moderation.pending'),
|
||||
Comment::STATUS_PENDING_AI => __('admin.options.moderation.pending_ai'),
|
||||
Comment::STATUS_APPROVED => __('admin.options.moderation.approved'),
|
||||
Comment::STATUS_REJECTED => __('admin.options.moderation.rejected'),
|
||||
Comment::STATUS_NEEDS_HUMAN => __('admin.options.moderation.needs_human'),
|
||||
]),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
|
||||
@@ -5,8 +5,8 @@ declare(strict_types=1);
|
||||
namespace App\Filament\Resources\Links\Pages;
|
||||
|
||||
use App\Filament\Resources\Links\LinkResource;
|
||||
use App\Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListLinks extends ListRecords
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Links\Tables;
|
||||
|
||||
use App\Filament\Support\AdminTable;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
@@ -17,12 +18,16 @@ class LinksTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.fields.name'))
|
||||
->searchable(),
|
||||
TextColumn::make('url')
|
||||
->label(__('admin.fields.url'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.fields.name'))
|
||||
->searchable(),
|
||||
),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('url')
|
||||
->label(__('admin.fields.url'))
|
||||
->searchable(),
|
||||
),
|
||||
TextColumn::make('display_order')
|
||||
->label(__('admin.fields.display_order'))
|
||||
->numeric()
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Pages;
|
||||
|
||||
use Filament\Resources\Pages\ListRecords as FilamentListRecords;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
/**
|
||||
* Admin list pages: never open view/edit by clicking the row.
|
||||
*/
|
||||
class ListRecords extends FilamentListRecords
|
||||
{
|
||||
protected function makeTable(): Table
|
||||
{
|
||||
return parent::makeTable()
|
||||
->recordUrl(null)
|
||||
->recordAction(null);
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Plugins\Pages;
|
||||
|
||||
use App\Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\Plugins\PluginResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPlugins extends ListRecords
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Plugins\Tables;
|
||||
|
||||
use App\Filament\Support\AdminTable;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
@@ -17,9 +18,11 @@ class PluginsTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.fields.name'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.fields.name'))
|
||||
->searchable(),
|
||||
),
|
||||
TextColumn::make('version')
|
||||
->label(__('admin.fields.version'))
|
||||
->searchable(),
|
||||
|
||||
@@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Stylevars\Pages;
|
||||
|
||||
use App\Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\Stylevars\StylevarResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListStylevars extends ListRecords
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Stylevars\Tables;
|
||||
|
||||
use App\Filament\Support\AdminTable;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
@@ -17,16 +18,21 @@ class StylevarsTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label(__('admin.fields.id'))
|
||||
->sortable(),
|
||||
TextColumn::make('title')
|
||||
->label(__('admin.fields.title'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('value')
|
||||
->label(__('admin.fields.value'))
|
||||
->limit(60),
|
||||
AdminTable::stickyStart(
|
||||
TextColumn::make('id')
|
||||
->label(__('admin.fields.id'))
|
||||
->sortable(),
|
||||
),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('title')
|
||||
->label(__('admin.fields.title'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('value')
|
||||
->label(__('admin.fields.value')),
|
||||
),
|
||||
IconColumn::make('visible')
|
||||
->label(__('admin.fields.visible'))
|
||||
->boolean(),
|
||||
|
||||
@@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Tags\Pages;
|
||||
|
||||
use App\Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\Tags\TagResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListTags extends ListRecords
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Tags\Tables;
|
||||
|
||||
use App\Filament\Support\AdminTable;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
@@ -16,9 +17,11 @@ class TagsTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.fields.name'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.fields.name'))
|
||||
->searchable(),
|
||||
),
|
||||
TextColumn::make('use_count')
|
||||
->label(__('admin.fields.use_count'))
|
||||
->numeric()
|
||||
|
||||
@@ -4,9 +4,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Users\Pages;
|
||||
|
||||
use App\Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\Users\UserResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListUsers extends ListRecords
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\Users\Tables;
|
||||
|
||||
use App\Filament\Support\AdminTable;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
@@ -16,19 +17,25 @@ class UsersTable
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label(__('admin.fields.id'))
|
||||
->sortable(),
|
||||
AdminTable::stickyStart(
|
||||
TextColumn::make('id')
|
||||
->label(__('admin.fields.id'))
|
||||
->sortable(),
|
||||
),
|
||||
TextColumn::make('username')
|
||||
->label(__('admin.fields.username'))
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.fields.display_name'))
|
||||
->searchable(),
|
||||
TextColumn::make('email')
|
||||
->label(__('admin.fields.email'))
|
||||
->searchable(),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('name')
|
||||
->label(__('admin.fields.display_name'))
|
||||
->searchable(),
|
||||
),
|
||||
AdminTable::ellipsis(
|
||||
TextColumn::make('email')
|
||||
->label(__('admin.fields.email'))
|
||||
->searchable(),
|
||||
),
|
||||
TextColumn::make('roles.name')
|
||||
->badge()
|
||||
->label(__('admin.fields.roles')),
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Support;
|
||||
|
||||
use Filament\Tables\Columns\Column;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Enums\FiltersResetActionPosition;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
/**
|
||||
* Shared Filament table defaults for the admin panel.
|
||||
*/
|
||||
final class AdminTable
|
||||
{
|
||||
public static function configureUsing(Table $table): void
|
||||
{
|
||||
$table
|
||||
->filtersLayout(FiltersLayout::AboveContent)
|
||||
->filtersResetActionPosition(FiltersResetActionPosition::Footer)
|
||||
->filtersFormSchema(function (array $filters): array {
|
||||
return collect($filters)
|
||||
->map(fn ($group) => $group->inlineLabel())
|
||||
->values()
|
||||
->all();
|
||||
})
|
||||
->extraAttributes(['class' => 'lb-admin-table'], merge: true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opt-in sticky column (typically id), pinned after the selection checkbox.
|
||||
*/
|
||||
public static function stickyStart(Column $column): Column
|
||||
{
|
||||
return $column
|
||||
->extraHeaderAttributes(['class' => 'lb-sticky-col-start'], merge: true)
|
||||
->extraCellAttributes(['class' => 'lb-sticky-col-start'], merge: true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Long text: single-line CSS ellipsis (hover via native title when limited).
|
||||
*/
|
||||
public static function ellipsis(TextColumn $column, int $clamp = 1): TextColumn
|
||||
{
|
||||
return $column
|
||||
->wrap()
|
||||
->lineClamp($clamp)
|
||||
->tooltip(function (mixed $state): ?string {
|
||||
if (! is_string($state) || $state === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $state;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user