mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
finish seed box basic
This commit is contained in:
@@ -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(),
|
||||
|
||||
@@ -13,23 +13,28 @@ class CreateSeedBoxRecord extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SeedBoxRecordResource::class;
|
||||
|
||||
protected function mutateFormDataBeforeCreate(array $data): array
|
||||
public function create(bool $another = false): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$data['uid'] = auth()->id();
|
||||
$data['type'] = SeedBoxRecord::TYPE_ADMIN;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function handleRecordCreation(array $data): Model
|
||||
{
|
||||
$seedBoxRep = new SeedBoxRepository();
|
||||
$data['status'] = SeedBoxRecord::STATUS_ALLOWED;
|
||||
$rep = new SeedBoxRepository();
|
||||
try {
|
||||
return $seedBoxRep->store($data);
|
||||
$this->record = $rep->store($data);
|
||||
$this->notify('success', $this->getCreatedNotificationMessage());
|
||||
if ($another) {
|
||||
// Ensure that the form record is anonymized so that relationships aren't loaded.
|
||||
$this->form->model($this->record::class);
|
||||
$this->record = null;
|
||||
|
||||
$this->fillForm();
|
||||
|
||||
return;
|
||||
}
|
||||
$this->redirect($this->getResource()::getUrl('index'));
|
||||
} catch (\Exception $exception) {
|
||||
//this wont work...
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Resources\System\SeedBoxRecordResource\Pages;
|
||||
|
||||
use App\Filament\Resources\System\SeedBoxRecordResource;
|
||||
use App\Repositories\SeedBoxRepository;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
@@ -16,4 +17,17 @@ class EditSeedBoxRecord extends EditRecord
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function save(bool $shouldRedirect = true): void
|
||||
{
|
||||
$data = $this->form->getState();
|
||||
$rep = new SeedBoxRepository();
|
||||
try {
|
||||
$this->record = $rep->update($data, $this->record->id);
|
||||
$this->notify('success', $this->getSavedNotificationMessage());
|
||||
$this->redirect($this->getResource()::getUrl('index'));
|
||||
} catch (\Exception $exception) {
|
||||
$this->notify('danger', $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
])->columns(2),
|
||||
Forms\Components\Tabs\Tab::make(__('label.setting.backup.tab_header'))
|
||||
->schema([
|
||||
Forms\Components\Radio::make('backup.enabled')->options(self::$yesOrNo)->inline(true)->label(__('label.setting.backup.enabled'))->helperText(__('label.setting.backup.enabled_help')),
|
||||
Forms\Components\Radio::make('backup.enabled')->options(self::$yesOrNo)->inline(true)->label(__('label.enabled'))->helperText(__('label.setting.backup.enabled_help')),
|
||||
Forms\Components\Radio::make('backup.frequency')->options(['daily' => 'daily', 'hourly' => 'hourly'])->inline(true)->label(__('label.setting.backup.frequency'))->helperText(__('label.setting.backup.frequency_help')),
|
||||
Forms\Components\Select::make('backup.hour')->options(range(0, 23))->label(__('label.setting.backup.hour'))->helperText(__('label.setting.backup.hour_help')),
|
||||
Forms\Components\Select::make('backup.minute')->options(range(0, 59))->label(__('label.setting.backup.minute'))->helperText(__('label.setting.backup.minute_help')),
|
||||
@@ -63,6 +63,13 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
Forms\Components\Radio::make('backup.via_ftp')->options(self::$yesOrNo)->inline(true)->label(__('label.setting.backup.via_ftp'))->helperText(__('label.setting.backup.via_ftp_help')),
|
||||
Forms\Components\Radio::make('backup.via_sftp')->options(self::$yesOrNo)->inline(true)->label(__('label.setting.backup.via_sftp'))->helperText(__('label.setting.backup.via_sftp_help')),
|
||||
])->columns(2),
|
||||
Forms\Components\Tabs\Tab::make(__('label.setting.seed_box.tab_header'))
|
||||
->schema([
|
||||
Forms\Components\Radio::make('seed_box.enabled')->options(self::$yesOrNo)->inline(true)->label(__('label.enabled'))->helperText(__('label.setting.seed_box.enabled_help')),
|
||||
Forms\Components\TextInput::make('seed_box.not_seed_box_max_speed')->label(__('label.setting.seed_box.not_seed_box_max_speed'))->helperText(__('label.setting.seed_box.not_seed_box_max_speed_help'))->integer(),
|
||||
Forms\Components\Radio::make('seed_box.no_promotion')->options(self::$yesOrNo)->inline(true)->label(__('label.setting.seed_box.no_promotion'))->helperText(__('label.setting.seed_box.no_promotion_help')),
|
||||
Forms\Components\TextInput::make('seed_box.max_uploaded')->label(__('label.setting.seed_box.max_uploaded'))->helperText(__('label.setting.seed_box.max_uploaded_help'))->integer(),
|
||||
])->columns(2),
|
||||
])
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user