admin add claim

This commit is contained in:
xiaomlove
2022-07-02 15:08:23 +08:00
parent 579351c0eb
commit 5191a1ba9a
48 changed files with 992 additions and 293 deletions
@@ -0,0 +1,86 @@
<?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;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class ClaimResource extends Resource
{
protected static ?string $model = Claim::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationGroup = 'User';
protected static ?int $navigationSort = 4;
protected static function getNavigationLabel(): string
{
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(),
Tables\Columns\TextColumn::make('user.username')->label(__('label.user.label'))->searchable(),
Tables\Columns\TextColumn::make('torrent.name')->limit(50)->label(__('label.torrent.label'))->searchable(),
Tables\Columns\TextColumn::make('torrent.size')->label(__('label.torrent.size'))->formatStateUsing(fn ($record) => mksize($record->size)),
Tables\Columns\TextColumn::make('torrent.added')->label(__('label.torrent.ttl'))->formatStateUsing(fn ($record) => mkprettytime($record->added)),
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([
//
])
->actions([
// Tables\Actions\EditAction::make(),
])
->bulkActions([
// Tables\Actions\DeleteBulkAction::make(),
]);
}
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'),
];
}
}
@@ -0,0 +1,12 @@
<?php
namespace App\Filament\Resources\User\ClaimResource\Pages;
use App\Filament\Resources\User\ClaimResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateClaim extends CreateRecord
{
protected static string $resource = ClaimResource::class;
}
@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\User\ClaimResource\Pages;
use App\Filament\Resources\User\ClaimResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;
class EditClaim extends EditRecord
{
protected static string $resource = ClaimResource::class;
protected function getActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Filament\Resources\User\ClaimResource\Pages;
use App\Filament\PageList;
use App\Filament\Resources\User\ClaimResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;
class ListClaims extends PageList
{
protected static string $resource = ClaimResource::class;
protected function getActions(): array
{
return [
// Actions\CreateAction::make(),
];
}
}
@@ -25,6 +25,8 @@ class ExamUserResource extends Resource
protected static ?string $navigationGroup = 'User';
protected static ?int $navigationSort = 2;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.exam_users');
@@ -61,7 +63,7 @@ class ExamUserResource extends Resource
Tables\Filters\SelectFilter::make('is_done')->options(['0' => 'No', '1' => 'yes'])->label(__('label.exam.is_done')),
])
->actions([
// Tables\Actions\ViewAction::make(),
Tables\Actions\ViewAction::make(),
])
->prependBulkActions([
Tables\Actions\BulkAction::make('Avoid')->action(function (Collection $records) {
@@ -86,8 +88,9 @@ class ExamUserResource extends Resource
{
return [
'index' => Pages\ListExamUsers::route('/'),
'create' => Pages\CreateExamUser::route('/create'),
'edit' => Pages\EditExamUser::route('/{record}/edit'),
// 'create' => Pages\CreateExamUser::route('/create'),
// 'edit' => Pages\EditExamUser::route('/{record}/edit'),
'view' => Pages\ViewExamUser::route('/{record}'),
];
}
}
@@ -0,0 +1,93 @@
<?php
namespace App\Filament\Resources\User\ExamUserResource\Pages;
use App\Filament\Resources\User\ExamUserResource;
use App\Repositories\ExamRepository;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ViewRecord;
use Filament\Tables\Table;
class ViewExamUser extends ViewRecord
{
protected static string $resource = ExamUserResource::class;
protected static string $view = 'filament.resources.user.exam-user-resource.pages.detail';
private function getDetailCardData(): array
{
// dd($this->record->progressFormatted);
$data = [];
$record = $this->record;
$data[] = [
'label' => 'ID',
'value' => $record->id,
];
$data[] = [
'label' => __('label.status'),
'value' => $record->statusText,
];
$data[] = [
'label' => __('label.username'),
'value' => $record->user->username,
];
$data[] = [
'label' => __('label.exam.label'),
'value' => $record->exam->name,
];
$data[] = [
'label' => __('label.begin'),
'value' => $record->begin,
];
$data[] = [
'label' => __('label.end'),
'value' => $record->end,
];
$data[] = [
'label' => __('label.exam_user.is_done'),
'value' => $record->isDoneText,
];
$data[] = [
'label' => __('label.created_at'),
'value' => $record->created_at,
];
$data[] = [
'label' => __('label.updated_at'),
'value' => $record->updated_at,
];
return $data;
}
protected function getViewData(): array
{
return [
'cardData' => $this->getDetailCardData(),
];
}
protected function getActions(): array
{
return [
Actions\Action::make('Avoid')
->requiresConfirmation()
->action(function () {
$examRep = new ExamRepository();
try {
$examRep->avoidExamUser($this->record->id);
$this->notify('success', 'Success !');
$this->record = $this->resolveRecord($this->record->id);
} catch (\Exception $exception) {
$this->notify('danger', $exception->getMessage());
}
})
->label(__('admin.resources.exam_user.action_avoid')),
Actions\DeleteAction::make(),
];
}
private function getProgress()
{
}
}
@@ -24,6 +24,8 @@ class HitAndRunResource extends Resource
protected static ?string $navigationGroup = 'User';
protected static ?int $navigationSort = 3;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.hit_and_runs');
@@ -34,18 +36,18 @@ class HitAndRunResource extends Resource
return self::getNavigationLabel();
}
public static function form(Form $form): Form
{
return $form
->schema(Forms\Components\Card::make()->schema([
// Forms\Components\Select::make('user')->relationship('user', 'username')->required(),
// Forms\Components\Select::make('torrent_id')->relationship('torrent', 'name')->required(),
Forms\Components\Radio::make('status')->options(HitAndRun::listStatus(true))->inline()->required(),
// Forms\Components\Select::make('snatch_id')->relationship('snatch', 'uploaded'),
Forms\Components\Textarea::make('comment'),
Forms\Components\DateTimePicker::make('created_at')->displayFormat('Y-m-d H:i:s'),
]));
}
// public static function form(Form $form): Form
// {
// return $form
// ->schema(Forms\Components\Card::make()->schema([
//// Forms\Components\Select::make('user')->relationship('user', 'username')->required(),
//// Forms\Components\Select::make('torrent_id')->relationship('torrent', 'name')->required(),
// Forms\Components\Radio::make('status')->options(HitAndRun::listStatus(true))->inline()->required(),
//// Forms\Components\Select::make('snatch_id')->relationship('snatch', 'uploaded'),
// Forms\Components\Textarea::make('comment'),
// Forms\Components\DateTimePicker::make('created_at')->displayFormat('Y-m-d H:i:s'),
// ]));
// }
public static function table(Table $table): Table
{
@@ -74,6 +76,8 @@ class HitAndRunResource extends Resource
$rep->bulkPardon(['id' => $idArr], Auth::user());
})
->deselectRecordsAfterCompletion()
->label(__('admin.resources.hit_and_run.bulk_action_pardon'))
->icon('heroicon-o-x')
]);
}
@@ -4,22 +4,98 @@ namespace App\Filament\Resources\User\HitAndRunResource\Pages;
use App\Filament\Resources\User\HitAndRunResource;
use App\Models\HitAndRun;
use App\Repositories\HitAndRunRepository;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ViewRecord;
use Filament\Forms;
use Illuminate\Support\Facades\Auth;
class ViewHitAndRun extends ViewRecord
{
protected static string $resource = HitAndRunResource::class;
protected function getFormSchema(): array
protected static string $view = 'filament.detail-card';
private function getDetailCardData(): array
{
$data = [];
$record = $this->record;
$data[] = [
'label' => 'ID',
'value' => $record->id,
];
$data[] = [
'label' => __('label.status'),
'value' => $record->statusText,
];
$data[] = [
'label' => __('label.username'),
'value' => $record->user->username,
];
$data[] = [
'label' => __('label.torrent.label'),
'value' => $record->torrent->name,
];
$data[] = [
'label' => __('label.uploaded'),
'value' => $record->snatch->uploadedText,
];
$data[] = [
'label' => __('label.downloaded'),
'value' => $record->snatch->downloadedText,
];
$data[] = [
'label' => __('label.ratio'),
'value' => $record->snatch->shareRatio,
];
$data[] = [
'label' => __('label.seed_time_required'),
'value' => $record->seedTimeRequired,
];
$data[] = [
'label' => __('label.inspect_time_left'),
'value' => $record->inspectTimeLeft,
];
$data[] = [
'label' => __('label.comment'),
'value' => nl2br($record->comment),
];
$data[] = [
'label' => __('label.created_at'),
'value' => $record->created_at,
];
$data[] = [
'label' => __('label.updated_at'),
'value' => $record->updated_at,
];
return $data;
}
protected function getViewData(): array
{
return [
Forms\Components\TextInput::make('id'),
Forms\Components\TextInput::make('uid'),
Forms\Components\Radio::make('status')->options(HitAndRun::listStatus(true))->inline(),
Forms\Components\Textarea::make('comment'),
Forms\Components\DateTimePicker::make('created_at'),
'cardData' => $this->getDetailCardData(),
];
}
protected function getActions(): array
{
return [
Actions\Action::make('Pardon')
->requiresConfirmation()
->action(function () {
$hitAndRunRep = new HitAndRunRepository();
try {
$hitAndRunRep->pardon($this->record->id, Auth::user());
$this->notify('success', 'Success !');
$this->record = $this->resolveRecord($this->record->id);
} catch (\Exception $exception) {
$this->notify('danger', $exception->getMessage());
}
})
->label(__('admin.resources.hit_and_run.action_pardon')),
Actions\DeleteAction::make(),
];
}
@@ -21,9 +21,11 @@ class UserMedalResource extends Resource
protected static ?string $navigationGroup = 'User';
protected static ?int $navigationSort = 5;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.users_medal');
return __('admin.sidebar.users_medals');
}
public static function getBreadcrumb(): string
@@ -26,6 +26,8 @@ class UserResource extends Resource
protected static ?string $navigationGroup = 'User';
protected static ?int $navigationSort = 1;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.users_list');