2022-07-02 15:08:23 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Filament\Resources\User;
|
|
|
|
|
|
|
|
|
|
use App\Filament\Resources\User\ClaimResource\Pages;
|
|
|
|
|
use App\Filament\Resources\User\ClaimResource\RelationManagers;
|
|
|
|
|
use App\Models\Claim;
|
|
|
|
|
use Filament\Forms;
|
2024-12-25 23:09:07 +08:00
|
|
|
use Filament\Forms\Form;
|
2022-07-02 15:08:23 +08:00
|
|
|
use Filament\Resources\Resource;
|
2024-12-25 23:09:07 +08:00
|
|
|
use Filament\Tables\Table;
|
2022-07-02 15:08:23 +08:00
|
|
|
use Filament\Tables;
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2022-07-03 14:00:07 +08:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2022-07-02 15:08:23 +08:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
2022-10-06 18:19:39 +08:00
|
|
|
use Illuminate\Support\HtmlString;
|
2022-07-02 15:08:23 +08:00
|
|
|
|
|
|
|
|
class ClaimResource extends Resource
|
|
|
|
|
{
|
|
|
|
|
protected static ?string $model = Claim::class;
|
|
|
|
|
|
2024-12-25 23:09:07 +08:00
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
2022-07-02 15:08:23 +08:00
|
|
|
|
|
|
|
|
protected static ?string $navigationGroup = 'User';
|
|
|
|
|
|
|
|
|
|
protected static ?int $navigationSort = 4;
|
|
|
|
|
|
2024-12-25 23:09:07 +08:00
|
|
|
public static function getNavigationLabel(): string
|
2022-07-02 15:08:23 +08:00
|
|
|
{
|
|
|
|
|
return __('admin.sidebar.claims');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getBreadcrumb(): string
|
|
|
|
|
{
|
|
|
|
|
return self::getNavigationLabel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function form(Form $form): Form
|
|
|
|
|
{
|
|
|
|
|
return $form
|
|
|
|
|
->schema([
|
|
|
|
|
//
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function table(Table $table): Table
|
|
|
|
|
{
|
|
|
|
|
return $table
|
|
|
|
|
->columns([
|
|
|
|
|
Tables\Columns\TextColumn::make('id')->sortable(),
|
2022-08-02 01:58:08 +08:00
|
|
|
Tables\Columns\TextColumn::make('uid')->searchable(),
|
2022-10-06 18:19:39 +08:00
|
|
|
Tables\Columns\TextColumn::make('user.username')
|
|
|
|
|
->label(__('label.user.label'))
|
|
|
|
|
->searchable()
|
2022-10-07 02:51:52 +08:00
|
|
|
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->uid, false, true, true, true)))
|
2022-10-06 18:19:39 +08:00
|
|
|
,
|
2022-07-04 14:41:27 +08:00
|
|
|
Tables\Columns\TextColumn::make('torrent.name')->limit(40)->label(__('label.torrent.label'))->searchable(),
|
2022-07-03 14:00:07 +08:00
|
|
|
Tables\Columns\TextColumn::make('torrent.size')->label(__('label.torrent.size'))->formatStateUsing(fn (Model $record) => mksize($record->torrent->size)),
|
|
|
|
|
Tables\Columns\TextColumn::make('torrent.added')->label(__('label.torrent.ttl'))->formatStateUsing(fn (Model $record) => mkprettytime($record->torrent->added->diffInSeconds())),
|
2022-07-02 15:08:23 +08:00
|
|
|
Tables\Columns\TextColumn::make('created_at')->label(__('label.created_at'))->dateTime(),
|
|
|
|
|
Tables\Columns\TextColumn::make('last_settle_at')->label(__('label.claim.last_settle_at'))->dateTime(),
|
|
|
|
|
Tables\Columns\TextColumn::make('seedTimeThisMonth')->label(__('label.claim.seed_time_this_month')),
|
|
|
|
|
Tables\Columns\TextColumn::make('uploadedThisMonth')->label(__('label.claim.uploaded_this_month')),
|
|
|
|
|
Tables\Columns\BooleanColumn::make('isReachedThisMonth')->label(__('label.claim.is_reached_this_month')),
|
|
|
|
|
])
|
|
|
|
|
->defaultSort('id', 'desc')
|
|
|
|
|
->filters([
|
2022-10-22 01:49:34 +08:00
|
|
|
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));
|
|
|
|
|
})
|
|
|
|
|
,
|
2022-10-22 20:52:08 +08:00
|
|
|
Tables\Filters\Filter::make('torrent_id')
|
|
|
|
|
->form([
|
|
|
|
|
Forms\Components\TextInput::make('torrent_id')
|
|
|
|
|
->label(__('claim.fields.torrent_id'))
|
|
|
|
|
->placeholder(__('claim.fields.torrent_id'))
|
|
|
|
|
,
|
|
|
|
|
])->query(function (Builder $query, array $data) {
|
|
|
|
|
return $query->when($data['torrent_id'], fn (Builder $query, $value) => $query->where("torrent_id", $value));
|
|
|
|
|
})
|
|
|
|
|
,
|
2022-07-02 15:08:23 +08:00
|
|
|
])
|
|
|
|
|
->actions([
|
|
|
|
|
// Tables\Actions\EditAction::make(),
|
|
|
|
|
])
|
|
|
|
|
->bulkActions([
|
|
|
|
|
// Tables\Actions\DeleteBulkAction::make(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-02 16:58:07 +08:00
|
|
|
public static function getEloquentQuery(): Builder
|
|
|
|
|
{
|
|
|
|
|
return parent::getEloquentQuery()->with(['user', 'torrent', 'snatch']);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-02 15:08:23 +08:00
|
|
|
public static function getRelations(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
//
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getPages(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'index' => Pages\ListClaims::route('/'),
|
|
|
|
|
'create' => Pages\CreateClaim::route('/create'),
|
|
|
|
|
'edit' => Pages\EditClaim::route('/{record}/edit'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|