finished the upgrade to filament 4. completely revamped the frontend with codex, now it looks great!

This commit is contained in:
2025-11-13 17:42:43 +01:00
parent f59fda588b
commit b311188bc1
138 changed files with 5440 additions and 4105 deletions

View File

@@ -1,10 +1,11 @@
<?php
namespace App\Filament\Resources;
namespace App\Filament\Resources\Styles;
use App\Filament\Resources\StyleResource\Pages;
use BackedEnum;
use App\Filament\Resources\Styles\Pages;
use App\Models\Style;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Schemas;
use Filament\Schemas\Schema;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
@@ -17,70 +18,68 @@ use Filament\Tables\Columns\ImageColumn;
use Filament\Forms\Components\Toggle;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Tabs;
use Filament\Schemas\Components\Tabs\Tab;
use Filament\Actions\Action;
use Filament\Actions\BulkAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\CreateAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
class StyleResource extends Resource
{
protected static ?string $model = Style::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-rectangle-stack';
public static function form(Form $form): Form
public static function form(Schema $schema): Schema
{
return $form
->columns('full')
->schema([
Forms\Components\Tabs::make('Style Details')
return $schema
->columns(1)
->components([
Tabs::make('Style Details')
->tabs([
Forms\Components\Tabs\Tab::make('General')
->schema([
Forms\Components\Grid::make(2)
->schema([
Tab::make('General')
->components([
Grid::make(2)
->columnSpanFull()
->components([
TextInput::make('title')
->label(__('filament.resource.style.form.title'))
->required()
->maxLength(255),
Toggle::make('enabled')
->label(__('filament.resource.style.form.enabled'))
->default(true),
]),
Forms\Components\Grid::make(2)
->schema([
->required()
->maxLength(255),
Toggle::make('enabled')
->default(true),
]),
Grid::make(2)
->columnSpanFull()
->components([
Textarea::make('prompt')
->label(__('filament.resource.style.form.prompt'))
->required()
->rows(5),
Textarea::make('description')
->label(__('filament.resource.style.form.description'))
->required()
->rows(5),
]),
]),
Select::make('ai_model_id')
->relationship('aiModel', 'name')
->label(__('filament.resource.style.form.ai_model'))
->required(),
FileUpload::make('preview_image')
->label(__('filament.resource.style.form.preview_image'))
->disk('public')
->directory('style_previews')
->image()
->imageEditor()
->required()
->rules(['mimes:jpeg,png,bmp,gif,webp']),
->required(),
]),
Forms\Components\Tabs\Tab::make('Details')
->schema([
Forms\Components\TextInput::make('sort_order')
Tab::make('Details')
->components([
TextInput::make('sort_order')
->numeric()
->default(0)
->label(__('filament.resource.style.form.sort_order')),
->default(0),
Textarea::make('parameters')
->label(__('filament.resource.style.form.parameters'))
->nullable()
->rows(15)
->json()
->helperText(__('filament.resource.style.form.parameters_help'))
->formatStateUsing(fn (?array $state): ?string => $state ? json_encode($state, JSON_PRETTY_PRINT) : null),
->rows(15),
]),
]),
]);
@@ -90,45 +89,42 @@ class StyleResource extends Resource
{
return $table
->defaultSort('sort_order')
->reorderable('sort_order')
->columns([
TextColumn::make('title')->label(__('filament.resource.style.table.title'))->searchable()->sortable(),
TextColumn::make('title')->searchable()->sortable(),
IconColumn::make('enabled')
->label(__('filament.resource.style.table.enabled'))
->boolean(),
TextColumn::make('aiModel.name')->label(__('filament.resource.style.table.ai_model'))->searchable()->sortable(),
ImageColumn::make('preview_image')->label(__('filament.resource.style.table.preview_image'))->disk('public'),
TextColumn::make('sort_order')->label(__('filament.resource.style.table.sort_order'))->sortable(),
TextColumn::make('aiModel.name')->searchable()->sortable(),
ImageColumn::make('preview_image')->disk('public'),
TextColumn::make('sort_order')->sortable(),
])
->filters([
SelectFilter::make('ai_model')
->relationship('aiModel', 'name')
->label(__('filament.resource.style.table.ai_model')),
->relationship('aiModel', 'name'),
])
->deferFilters(false)
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('duplicate')
->label(__('filament.resource.style.action.duplicate'))
EditAction::make(),
Action::make('duplicate')
->label('Duplicate')
->icon('heroicon-o-document-duplicate')
->action(function (\App\Models\Style $record) {
$newStyle = $record->replicate();
$newStyle->title = $record->title . ' (Kopie)';
$newStyle->save();
return redirect()->to(StyleResource::getUrl('edit', ['record' => $newStyle->id]));
return redirect()->to(\App\Filament\Resources\Styles\StyleResource::getUrl('edit', ['record' => $newStyle->id]));
}),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\BulkAction::make('enable')
->label(__('filament.resource.style.action.enable_selected'))
BulkActionGroup::make([
DeleteBulkAction::make(),
BulkAction::make('enable')
->label('Enable Selected')
->icon('heroicon-o-check-circle')
->action(function (\Illuminate\Support\Collection $records) {
$records->each->update(['enabled' => true]);
}),
Tables\Actions\BulkAction::make('disable')
->label(__('filament.resource.style.action.disable_selected'))
BulkAction::make('disable')
->label('Disable Selected')
->icon('heroicon-o-x-circle')
->action(function (\Illuminate\Support\Collection $records) {
$records->each->update(['enabled' => false]);
@@ -136,7 +132,7 @@ class StyleResource extends Resource
]),
])
->emptyStateActions([
Tables\Actions\CreateAction::make(),
CreateAction::make(),
]);
}
@@ -155,4 +151,4 @@ class StyleResource extends Resource
'edit' => Pages\EditStyle::route('/{record}/edit'),
];
}
}
}