migrate custom field management to filament

fix xss
This commit is contained in:
NekoCH
2025-12-28 22:36:52 +08:00
parent f18fa80eac
commit 00ec3d5e8d
11 changed files with 235 additions and 10 deletions

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\TorrentCustomFields\Pages;
use App\Filament\Resources\TorrentCustomFields\TorrentCustomFieldResource;
use Filament\Actions\CreateAction;
use Filament\Resources\Pages\ListRecords;
class ListTorrentCustomFields extends ListRecords
{
protected static string $resource = TorrentCustomFieldResource::class;
protected function getHeaderActions(): array
{
return [
CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Filament\Resources\TorrentCustomFields\Schemas;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
use Nexus\Field\Field;
class TorrentCustomFieldForm
{
public static function configure(Schema $schema): Schema
{
return $schema
->components([
TextInput::make('name')
->label(__('label.field.name'))
->helperText(__('label.field.name_help'))
->alphaDash()
->required(),
TextInput::make('label')
->label(__('label.field.field_label'))
->required(),
Select::make('type')
->options((new Field())->getTypeRadioOptions())
->label(__('label.field.type'))
->required(),
Checkbox::make('required')
->label(__('label.field.required')),
Textarea::make('help')
->label(__('label.field.help'))
->rows(3),
Textarea::make('options')
->label(__('label.field.options'))
->rows(3)
->hiddenJs("\$get('type') !== 'radio' && \$get('type') !== 'checkbox' && \$get('type') !== 'select'")
->helperText(__('label.field.options_help')),
Checkbox::make('is_single_row')
->label(__('label.field.is_single_row')),
TextInput::make('priority')
->label(__('label.priority'))
->numeric(),
Textarea::make('display')
->label(__('label.field.display'))
->rows(3)
->helperText(__('label.search_box.custom_fields_display_help')),
])
->columns(1);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Filament\Resources\TorrentCustomFields\Tables;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteAction;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class TorrentCustomFieldsTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('id'),
TextColumn::make('name')->label(__('label.field.name')),
TextColumn::make('label')->label(__('label.field.field_label')),
TextColumn::make('type')->label(__('label.field.type')),
IconColumn::make('required')->boolean()->label(__('label.field.required')),
IconColumn::make('is_single_row')->boolean()->label(__('label.field.is_single_row')),
TextColumn::make('priority')->label(__('label.priority')),
])
->filters([
//
])
->recordActions([
EditAction::make(),
DeleteAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
]),
]);
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Filament\Resources\TorrentCustomFields;
use App\Filament\Resources\TorrentCustomFields\Pages\ListTorrentCustomFields;
use App\Filament\Resources\TorrentCustomFields\Schemas\TorrentCustomFieldForm;
use App\Filament\Resources\TorrentCustomFields\Tables\TorrentCustomFieldsTable;
use App\Models\TorrentCustomField;
use BackedEnum;
use Filament\Resources\Resource;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Table;
use UnitEnum;
class TorrentCustomFieldResource extends Resource
{
protected static ?string $model = TorrentCustomField::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
protected static string|null|UnitEnum $navigationGroup = 'Section';
protected static ?int $navigationSort = 12;
public static function getNavigationLabel(): string
{
return __('label.field.label');
}
public static function getBreadcrumb(): string
{
return self::getNavigationLabel();
}
public static function form(Schema $schema): Schema
{
return TorrentCustomFieldForm::configure($schema);
}
public static function table(Table $table): Table
{
return TorrentCustomFieldsTable::configure($table);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => ListTorrentCustomFields::route('/'),
];
}
}

View File

@@ -16,6 +16,7 @@ use App\Models\SecondIcon;
use App\Models\Source;
use App\Models\Standard;
use App\Models\Team;
use App\Models\TorrentCustomField;
use App\Models\User;
use App\Policies\CodecPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
@@ -34,6 +35,7 @@ class AuthServiceProvider extends ServiceProvider
Category::class => CodecPolicy::class,
Icon::class => CodecPolicy::class,
SecondIcon::class => CodecPolicy::class,
TorrentCustomField::class => CodecPolicy::class,
Codec::class => CodecPolicy::class,
AudioCodec::class => CodecPolicy::class,