finish seed box basic

This commit is contained in:
xiaomlove
2022-07-23 15:05:32 +08:00
parent b507c41bf0
commit 42bf8f0467
32 changed files with 644 additions and 249 deletions

View File

@@ -5,6 +5,8 @@ namespace App\Filament\Resources\System;
use App\Filament\Resources\System\SeedBoxRecordResource\Pages;
use App\Filament\Resources\System\SeedBoxRecordResource\RelationManagers;
use App\Models\SeedBoxRecord;
use App\Repositories\SeedBoxRepository;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
@@ -12,6 +14,7 @@ use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use phpDocumentor\Reflection\DocBlock\Tags\See;
class SeedBoxRecordResource extends Resource
{
@@ -25,7 +28,7 @@ class SeedBoxRecordResource extends Resource
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.seedbox_records');
return __('admin.sidebar.seed_box_records');
}
public static function getBreadcrumb(): string
@@ -37,11 +40,11 @@ class SeedBoxRecordResource extends Resource
{
return $form
->schema([
Forms\Components\TextInput::make('operator')->label(__('label.seedbox_record.operator')),
Forms\Components\TextInput::make('bandwidth')->label(__('label.seedbox_record.bandwidth'))->integer(),
Forms\Components\TextInput::make('ip_begin')->label(__('label.seedbox_record.ip_begin')),
Forms\Components\TextInput::make('ip_end')->label(__('label.seedbox_record.ip_end')),
Forms\Components\TextInput::make('ip')->label(__('label.seedbox_record.ip'))->helperText(__('label.seedbox_record.ip_help')),
Forms\Components\TextInput::make('operator')->label(__('label.seed_box_record.operator')),
Forms\Components\TextInput::make('bandwidth')->label(__('label.seed_box_record.bandwidth'))->integer(),
Forms\Components\TextInput::make('ip_begin')->label(__('label.seed_box_record.ip_begin')),
Forms\Components\TextInput::make('ip_end')->label(__('label.seed_box_record.ip_end')),
Forms\Components\TextInput::make('ip')->label(__('label.seed_box_record.ip'))->helperText(__('label.seed_box_record.ip_help')),
Forms\Components\Textarea::make('comment')->label(__('label.comment')),
])->columns(1);
}
@@ -51,18 +54,45 @@ class SeedBoxRecordResource extends Resource
return $table
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\TextColumn::make('typeText')->label(__('label.seedbox_record.type')),
Tables\Columns\TextColumn::make('user.username')->label(__('label.username')),
Tables\Columns\TextColumn::make('operation')->label(__('label.seedbox_record.operator')),
Tables\Columns\TextColumn::make('bandwidth')->label(__('label.seedbox_record.bandwidth')),
Tables\Columns\TextColumn::make('ip')->label(__('label.seedbox_record.ip'))->formatStateUsing(fn ($record) => $record->ip ?: sprintf('%s ~ %s', $record->ip_begin, $record->ip_end)),
Tables\Columns\TextColumn::make('typeText')->label(__('label.seed_box_record.type')),
Tables\Columns\TextColumn::make('user.username')->label(__('label.username'))->searchable(),
Tables\Columns\TextColumn::make('operator')->label(__('label.seed_box_record.operator'))->searchable(),
Tables\Columns\TextColumn::make('bandwidth')->label(__('label.seed_box_record.bandwidth')),
Tables\Columns\TextColumn::make('ip')
->label(__('label.seed_box_record.ip'))
->searchable()
->formatStateUsing(fn ($record) => $record->ip ?: sprintf('%s ~ %s', $record->ip_begin, $record->ip_end)),
Tables\Columns\TextColumn::make('comment')->label(__('label.comment')),
Tables\Columns\BadgeColumn::make('status')
->colors([
'success' => SeedBoxRecord::STATUS_ALLOWED,
'warning' => SeedBoxRecord::STATUS_UNAUDITED,
'danger' => SeedBoxRecord::STATUS_DENIED,
])
->formatStateUsing(fn ($record) => $record->statusText)
->label(__('label.seed_box_record.status')),
])
->filters([
//
Tables\Filters\SelectFilter::make('type')->options(SeedBoxRecord::listTypes('text'))->label(__('label.seed_box_record.type')),
Tables\Filters\SelectFilter::make('status')->options(SeedBoxRecord::listStatus('text'))->label(__('label.seed_box_record.status')),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\Action::make('audit')
->label(__('admin.resources.seed_box_record.toggle_status'))
->form([
Forms\Components\Radio::make('status')->options(SeedBoxRecord::listStatus('text'))
->inline()->label(__('label.seed_box_record.status'))->required()
])
->action(function (SeedBoxRecord $record, array $data) {
$rep = new SeedBoxRepository();
try {
$rep->updateStatus($record, $data['status']);
} catch (\Exception $exception) {
Filament::notify('danger', class_basename($exception));
}
})
,
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),