155 lines
5.2 KiB
PHP
155 lines
5.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\AiStyles;
|
|
|
|
use App\Filament\Clusters\RareAdmin\RareAdminCluster;
|
|
use App\Filament\Resources\AiStyles\Pages\ManageAiStyles;
|
|
use App\Models\AiStyle;
|
|
use App\Services\Audit\SuperAdminAuditLogger;
|
|
use BackedEnum;
|
|
use Filament\Actions;
|
|
use Filament\Forms\Components\KeyValue;
|
|
use Filament\Forms\Components\Select;
|
|
use Filament\Forms\Components\Textarea;
|
|
use Filament\Forms\Components\TextInput;
|
|
use Filament\Forms\Components\Toggle;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Schemas\Components\Section;
|
|
use Filament\Schemas\Schema;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use UnitEnum;
|
|
|
|
class AiStyleResource extends Resource
|
|
{
|
|
protected static ?string $model = AiStyle::class;
|
|
|
|
protected static ?string $cluster = RareAdminCluster::class;
|
|
|
|
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-paint-brush';
|
|
|
|
protected static UnitEnum|string|null $navigationGroup = null;
|
|
|
|
protected static ?int $navigationSort = 31;
|
|
|
|
public static function getNavigationGroup(): UnitEnum|string|null
|
|
{
|
|
return __('admin.nav.platform');
|
|
}
|
|
|
|
public static function getNavigationLabel(): string
|
|
{
|
|
return 'AI Styles';
|
|
}
|
|
|
|
public static function form(Schema $schema): Schema
|
|
{
|
|
return $schema->schema([
|
|
Section::make('Style Basics')
|
|
->schema([
|
|
TextInput::make('key')
|
|
->required()
|
|
->maxLength(120)
|
|
->unique(ignoreRecord: true),
|
|
TextInput::make('name')
|
|
->required()
|
|
->maxLength(120),
|
|
TextInput::make('category')
|
|
->maxLength(50),
|
|
TextInput::make('sort')
|
|
->numeric()
|
|
->default(0)
|
|
->required(),
|
|
Toggle::make('is_active')
|
|
->default(true),
|
|
Toggle::make('is_premium')
|
|
->default(false),
|
|
Toggle::make('requires_source_image')
|
|
->default(true),
|
|
])
|
|
->columns(3),
|
|
Section::make('Provider Binding')
|
|
->schema([
|
|
Select::make('provider')
|
|
->options([
|
|
'runware' => 'runware.ai',
|
|
])
|
|
->required()
|
|
->default('runware'),
|
|
TextInput::make('provider_model')
|
|
->maxLength(120),
|
|
])
|
|
->columns(2),
|
|
Section::make('Prompts')
|
|
->schema([
|
|
Textarea::make('description')
|
|
->rows(2),
|
|
Textarea::make('prompt_template')
|
|
->rows(5),
|
|
Textarea::make('negative_prompt_template')
|
|
->rows(4),
|
|
]),
|
|
Section::make('Metadata')
|
|
->schema([
|
|
KeyValue::make('metadata')
|
|
->nullable(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->defaultSort('sort')
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('key')
|
|
->searchable()
|
|
->copyable(),
|
|
Tables\Columns\TextColumn::make('name')
|
|
->searchable(),
|
|
Tables\Columns\TextColumn::make('provider')
|
|
->badge(),
|
|
Tables\Columns\TextColumn::make('provider_model')
|
|
->toggleable(),
|
|
Tables\Columns\IconColumn::make('is_active')
|
|
->boolean(),
|
|
Tables\Columns\IconColumn::make('is_premium')
|
|
->boolean(),
|
|
Tables\Columns\TextColumn::make('sort')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('updated_at')
|
|
->since()
|
|
->toggleable(),
|
|
])
|
|
->filters([
|
|
Tables\Filters\TernaryFilter::make('is_active'),
|
|
Tables\Filters\TernaryFilter::make('is_premium'),
|
|
])
|
|
->actions([
|
|
Actions\EditAction::make()
|
|
->after(fn (array $data, AiStyle $record) => app(SuperAdminAuditLogger::class)->recordModelMutation(
|
|
'updated',
|
|
$record,
|
|
SuperAdminAuditLogger::fieldsMetadata(array_keys($data)),
|
|
static::class
|
|
)),
|
|
Actions\DeleteAction::make()
|
|
->after(fn (AiStyle $record) => app(SuperAdminAuditLogger::class)->recordModelMutation(
|
|
'deleted',
|
|
$record,
|
|
source: static::class
|
|
)),
|
|
])
|
|
->bulkActions([
|
|
Actions\DeleteBulkAction::make(),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => ManageAiStyles::route('/'),
|
|
];
|
|
}
|
|
}
|