Files
nexusphp/app/Filament/Resources/User/HitAndRunResource.php

161 lines
6.3 KiB
PHP
Raw Normal View History

2022-06-27 01:39:01 +08:00
<?php
namespace App\Filament\Resources\User;
use App\Filament\Resources\User\HitAndRunResource\Pages;
use App\Filament\Resources\User\HitAndRunResource\RelationManagers;
use App\Models\HitAndRun;
2025-01-27 14:07:44 +08:00
use App\Models\User;
2022-06-27 01:39:01 +08:00
use App\Repositories\HitAndRunRepository;
use Filament\Forms;
2024-12-25 23:09:07 +08:00
use Filament\Forms\Form;
2025-01-27 14:07:44 +08:00
use Filament\Infolists\Infolist;
2022-06-27 01:39:01 +08:00
use Filament\Resources\Resource;
2024-12-25 23:09:07 +08:00
use Filament\Tables\Table;
2022-06-27 01:39:01 +08:00
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\HtmlString;
2025-01-27 14:07:44 +08:00
use Filament\Infolists\Components;
use Filament\Infolists;
2022-06-27 01:39:01 +08:00
class HitAndRunResource extends Resource
{
protected static ?string $model = HitAndRun::class;
protected static ?string $navigationIcon = 'heroicon-o-beaker';
protected static ?string $navigationGroup = 'User';
2022-07-02 15:08:23 +08:00
protected static ?int $navigationSort = 3;
2024-12-25 23:09:07 +08:00
public static function getNavigationLabel(): string
2022-06-27 01:39:01 +08:00
{
return __('admin.sidebar.hit_and_runs');
}
2022-06-29 17:00:15 +08:00
public static function getBreadcrumb(): string
{
return self::getNavigationLabel();
}
2022-06-27 01:39:01 +08:00
public static function table(Table $table): Table
{
return $table
->columns([
2022-07-02 16:36:44 +08:00
Tables\Columns\TextColumn::make('id')->sortable(),
Tables\Columns\TextColumn::make('uid')->searchable(),
Tables\Columns\TextColumn::make('user.username')
->searchable()
->label(__('label.username'))
2022-10-07 02:51:52 +08:00
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->uid, false, true, true, true)))
,
2022-07-05 16:09:43 +08:00
Tables\Columns\TextColumn::make('torrent.name')->limit(30)->label(__('label.torrent.label')),
Tables\Columns\TextColumn::make('snatch.uploadText')->label(__('label.uploaded')),
Tables\Columns\TextColumn::make('snatch.downloadText')->label(__('label.downloaded')),
Tables\Columns\TextColumn::make('snatch.shareRatio')->label(__('label.ratio')),
Tables\Columns\TextColumn::make('seedTimeRequired')->label(__('label.seed_time_required')),
Tables\Columns\TextColumn::make('inspectTimeLeft')->label(__('label.inspect_time_left')),
Tables\Columns\TextColumn::make('statusText')->label(__('label.status')),
2024-12-24 01:10:48 +08:00
Tables\Columns\TextColumn::make('created_at')->label(__('label.created_at')),
2022-06-27 01:39:01 +08:00
])
2022-07-02 16:36:44 +08:00
->defaultSort('id', 'desc')
2022-06-27 01:39:01 +08:00
->filters([
Tables\Filters\Filter::make('uid')
->form([
Forms\Components\TextInput::make('uid')
->label('UID')
->placeholder('UID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['uid'], fn (Builder $query, $uid) => $query->where("uid", $uid));
})
,
Tables\Filters\SelectFilter::make('status')->options(HitAndRun::listStatus(true))->label(__('label.status')),
2022-06-27 01:39:01 +08:00
])
->actions([
Tables\Actions\ViewAction::make(),
])
->groupedBulkActions([
2022-06-27 01:39:01 +08:00
Tables\Actions\BulkAction::make('Pardon')->action(function (Collection $records) {
$idArr = $records->pluck('id')->toArray();
$rep = new HitAndRunRepository();
$rep->bulkPardon(['id' => $idArr], Auth::user());
})
->deselectRecordsAfterCompletion()
2022-07-02 15:08:23 +08:00
->label(__('admin.resources.hit_and_run.bulk_action_pardon'))
2024-12-25 23:09:07 +08:00
->icon('heroicon-o-x-mark')
2022-06-27 01:39:01 +08:00
]);
}
2025-01-27 14:07:44 +08:00
public static function infolist(Infolist $infolist): Infolist
{
return $infolist
->schema([
Infolists\Components\TextEntry::make('id'),
Infolists\Components\TextEntry::make('statusText')
->label(__("label.status"))
,
Infolists\Components\TextEntry::make('uid')
->formatStateUsing(fn ($record) => username_for_admin($record->uid))
->label(__("label.username"))
,
Infolists\Components\TextEntry::make('torrent_id')
->formatStateUsing(fn ($record) => $record->torrent->name)
->label(__("label.torrent.label"))
,
Infolists\Components\TextEntry::make('snatch.uploadedText')
->label(__("label.uploaded"))
,
Infolists\Components\TextEntry::make('snatch.downloadedText')
->label(__("label.downloaded"))
,
Infolists\Components\TextEntry::make('snatch.shareRatio')
->label(__("label.ratio"))
,
Infolists\Components\TextEntry::make('seedTimeRequired')
->label(__("label.seed_time_required"))
,
Infolists\Components\TextEntry::make('inspectTimeLeft')
->label(__("label.inspect_time_left"))
,
Infolists\Components\TextEntry::make('comment')
->formatStateUsing(fn ($record) => nl2br($record->comment))
->label(__("label.comment"))
,
Infolists\Components\TextEntry::make('created_at')
->label(__("label.created_at"))
,
Infolists\Components\TextEntry::make('updated_at')
->label(__("label.updated_at"))
,
])->columns(4);
}
2022-07-02 16:58:07 +08:00
public static function getEloquentQuery(): Builder
{
2022-10-01 01:58:18 +08:00
return parent::getEloquentQuery()->with(['user', 'torrent', 'snatch', 'torrent.basic_category']);
2022-07-02 16:58:07 +08:00
}
2022-06-27 01:39:01 +08:00
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListHitAndRuns::route('/'),
// 'create' => Pages\CreateHitAndRun::route('/create'),
// 'edit' => Pages\EditHitAndRun::route('/{record}/edit'),
'view' => Pages\ViewHitAndRun::route('/{record}'),
];
}
}