Files

117 lines
4.1 KiB
PHP
Raw Permalink Normal View History

2022-12-08 03:48:20 +08:00
<?php
namespace App\Filament\Resources\Torrent;
2025-09-21 18:07:38 +08:00
use Filament\Schemas\Schema;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Filters\SelectFilter;
use App\Filament\Resources\Torrent\TorrentOperationLogResource\Pages\ManageTorrentOperationLogs;
2022-12-08 03:48:20 +08:00
use App\Filament\Resources\Torrent\TorrentOperationLogResource\Pages;
use App\Filament\Resources\Torrent\TorrentOperationLogResource\RelationManagers;
use App\Models\Torrent;
use App\Models\TorrentOperationLog;
use Filament\Forms;
use Filament\Resources\Resource;
2024-12-25 23:09:07 +08:00
use Filament\Tables\Table;
2022-12-08 03:48:20 +08:00
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class TorrentOperationLogResource extends Resource
{
protected static ?string $model = TorrentOperationLog::class;
2025-09-21 18:07:38 +08:00
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-rectangle-stack';
2022-12-08 03:48:20 +08:00
2025-09-21 18:07:38 +08:00
protected static string | \UnitEnum | null $navigationGroup = 'Torrent';
2022-12-08 03:48:20 +08:00
protected static ?int $navigationSort = 4;
2024-12-25 23:09:07 +08:00
public static function getNavigationLabel(): string
2022-12-08 03:48:20 +08:00
{
return __('admin.sidebar.torrent_operation_log');
}
public static function getBreadcrumb(): string
{
return self::getNavigationLabel();
}
2025-09-21 18:07:38 +08:00
public static function form(Schema $schema): Schema
2022-12-08 03:48:20 +08:00
{
2025-09-21 18:07:38 +08:00
return $schema
->components([
2022-12-08 03:48:20 +08:00
//
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
2025-09-21 18:07:38 +08:00
TextColumn::make('id')->sortable(),
TextColumn::make('user.username')
2022-12-08 03:48:20 +08:00
->formatStateUsing(fn ($record) => username_for_admin($record->uid))
->label(__('label.user.label'))
,
2025-09-21 18:07:38 +08:00
TextColumn::make('torrent.name')
2022-12-08 03:48:20 +08:00
->formatStateUsing(fn ($record) => torrent_name_for_admin($record->torrent))
->label(__('label.torrent.label'))
,
2025-09-21 18:07:38 +08:00
TextColumn::make('action_type_text')
2022-12-08 03:48:20 +08:00
->label(__('torrent-operation-log.fields.action_type'))
,
2025-09-21 18:07:38 +08:00
TextColumn::make('comment')
2022-12-08 03:48:20 +08:00
->label(__('label.comment'))
,
2025-09-21 18:07:38 +08:00
TextColumn::make('created_at')
2022-12-08 03:48:20 +08:00
->formatStateUsing(fn ($state) => format_datetime($state))
->label(__('label.created_at'))
,
])
->defaultSort('id', 'desc')
2022-12-08 03:48:20 +08:00
->filters([
2025-09-21 18:07:38 +08:00
Filter::make('uid')
->schema([
TextInput::make('uid')
2022-12-08 03:48:20 +08:00
->placeholder('UID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['uid'], fn (Builder $query, $value) => $query->where("uid", $value));
})
,
2025-09-21 18:07:38 +08:00
Filter::make('torrent_id')
->schema([
TextInput::make('torrent_id')
2022-12-08 03:48:20 +08:00
->placeholder('Torrent ID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['torrent_id'], fn (Builder $query, $value) => $query->where("torrent_id", $value));
})
,
2025-09-21 18:07:38 +08:00
SelectFilter::make('action_type')
2022-12-08 03:48:20 +08:00
->options(TorrentOperationLog::listStaticProps(TorrentOperationLog::$actionTypes, 'torrent.operation_log.%s.type_text', true))
->label(__('torrent-operation-log.fields.action_type'))
->multiple()
,
])
2025-09-21 18:07:38 +08:00
->recordActions([
2022-12-08 03:48:20 +08:00
// Tables\Actions\EditAction::make(),
// Tables\Actions\DeleteAction::make(),
])
2025-09-21 18:07:38 +08:00
->toolbarActions([
2022-12-08 03:48:20 +08:00
// Tables\Actions\DeleteBulkAction::make(),
]);
}
public static function getPages(): array
{
return [
2025-09-21 18:07:38 +08:00
'index' => ManageTorrentOperationLogs::route('/'),
2022-12-08 03:48:20 +08:00
];
}
}