mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
Merge branch 'php8' into section
This commit is contained in:
@@ -15,4 +15,12 @@ trait OptionsTrait
|
||||
$disableValue => __('label.disabled'),
|
||||
];
|
||||
}
|
||||
|
||||
private static function getYesNoOptions($yesValue = 1, $noValue = 0): array
|
||||
{
|
||||
return [
|
||||
$yesValue => 'Yes',
|
||||
$noValue => 'No',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament;
|
||||
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Filament\Tables\Filters\Layout;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PageList extends ListRecords
|
||||
@@ -15,4 +16,9 @@ class PageList extends ListRecords
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
protected function getTableFiltersLayout(): ?string
|
||||
{
|
||||
return Layout::AboveContent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament;
|
||||
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
use Filament\Tables\Filters\Layout;
|
||||
|
||||
class PageListSingle extends ManageRecords
|
||||
{
|
||||
protected ?string $maxContentWidth = 'full';
|
||||
|
||||
protected function getTableFiltersLayout(): ?string
|
||||
{
|
||||
return Layout::AboveContent;
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ class ExamResource extends Resource
|
||||
|
||||
Forms\Components\Section::make(__('label.exam.section_time'))->schema([
|
||||
Forms\Components\DateTimePicker::make('begin')->label(__('label.begin')),
|
||||
Forms\Components\DateTimePicker::make('end')->label(__('label.begin')),
|
||||
Forms\Components\DateTimePicker::make('end')->label(__('label.end')),
|
||||
Forms\Components\TextInput::make('duration')
|
||||
->integer()
|
||||
->columnSpan(['sm' => 2])
|
||||
@@ -118,7 +118,7 @@ class ExamResource extends Resource
|
||||
Tables\Columns\TextColumn::make('name')->searchable()->label(__('label.name')),
|
||||
Tables\Columns\TextColumn::make('indexFormatted')->label(__('label.exam.index_formatted'))->html(),
|
||||
Tables\Columns\TextColumn::make('begin')->label(__('label.begin')),
|
||||
Tables\Columns\TextColumn::make('end')->label(__('label.begin')),
|
||||
Tables\Columns\TextColumn::make('end')->label(__('label.end')),
|
||||
Tables\Columns\TextColumn::make('durationText')->label(__('label.duration')),
|
||||
Tables\Columns\TextColumn::make('filterFormatted')->label(__('label.exam.filter_formatted'))->html(),
|
||||
Tables\Columns\BooleanColumn::make('is_discovered')->label(__('label.exam.is_discovered')),
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\System;
|
||||
|
||||
use App\Filament\Resources\System\PluginResource\Pages;
|
||||
use App\Filament\Resources\System\PluginResource\RelationManagers;
|
||||
use App\Models\Plugin;
|
||||
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;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class PluginResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Plugin::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-plus-circle';
|
||||
|
||||
protected static ?string $navigationGroup = 'System';
|
||||
|
||||
protected static ?int $navigationSort = 99;
|
||||
|
||||
protected static bool $shouldRegisterNavigation = false;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.plugin');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('package_name')->label(__('label.plugin.package_name')),
|
||||
Forms\Components\TextInput::make('remote_url')->label(__('label.plugin.remote_url')),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id'),
|
||||
Tables\Columns\TextColumn::make('package_name')->label(__('plugin.labels.package_name')),
|
||||
Tables\Columns\TextColumn::make('remote_url')->label(__('plugin.labels.remote_url')),
|
||||
Tables\Columns\TextColumn::make('installed_version')->label(__('plugin.labels.installed_version')),
|
||||
Tables\Columns\TextColumn::make('statusText')->label(__('label.status')),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions(self::getActions())
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ManagePlugins::route('/'),
|
||||
];
|
||||
}
|
||||
|
||||
private static function getActions()
|
||||
{
|
||||
$actions = [];
|
||||
$actions[] = Tables\Actions\EditAction::make();
|
||||
$actions[] = self::buildInstallAction();
|
||||
$actions[] = self::buildUpdateAction();
|
||||
$actions[] = Tables\Actions\DeleteAction::make('delete')
|
||||
->hidden(fn ($record) => $record->status == Plugin::STATUS_NOT_INSTALLED)
|
||||
->using(function ($record) {
|
||||
$record->update(['status' => Plugin::STATUS_PRE_DELETE]);
|
||||
});
|
||||
return $actions;
|
||||
}
|
||||
|
||||
private static function buildInstallAction()
|
||||
{
|
||||
return Tables\Actions\Action::make('install')
|
||||
->label(__('plugin.actions.install'))
|
||||
->icon('heroicon-o-arrow-down')
|
||||
->requiresConfirmation()
|
||||
->hidden(fn ($record) => $record->status == Plugin::STATUS_NORMAL)
|
||||
->action(function ($record) {
|
||||
$record->update(['status' => Plugin::STATUS_PRE_INSTALL]);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
private static function buildUpdateAction()
|
||||
{
|
||||
return Tables\Actions\Action::make('update')
|
||||
->label(__('plugin.actions.update'))
|
||||
->icon('heroicon-o-arrow-up')
|
||||
->requiresConfirmation()
|
||||
->hidden(fn ($record) => in_array($record->status, [Plugin::STATUS_NOT_INSTALLED, Plugin::STATUS_PRE_UPDATE]))
|
||||
->action(function ($record) {
|
||||
$record->update(['status' => Plugin::STATUS_PRE_UPDATE]);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\System\PluginResource\Pages;
|
||||
|
||||
use App\Filament\Resources\System\PluginResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManagePlugins extends ManageRecords
|
||||
{
|
||||
protected static string $resource = PluginResource::class;
|
||||
|
||||
protected ?string $maxContentWidth = 'full';
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\See;
|
||||
use PhpIP\IP;
|
||||
|
||||
class SeedBoxRecordResource extends Resource
|
||||
{
|
||||
@@ -55,12 +56,23 @@ class SeedBoxRecordResource extends Resource
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id'),
|
||||
Tables\Columns\TextColumn::make('typeText')->label(__('label.seed_box_record.type')),
|
||||
Tables\Columns\TextColumn::make('uid')->searchable(),
|
||||
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()
|
||||
->searchable(true, function (Builder $query, $search) {
|
||||
try {
|
||||
$ip = IP::create($search);
|
||||
$ipNumeric = $ip->numeric();
|
||||
return $query->orWhere(function (Builder $query) use ($ipNumeric) {
|
||||
return $query->where('ip_begin_numeric', '<=', $ipNumeric)->where('ip_end_numeric', '>=', $ipNumeric);
|
||||
});
|
||||
} catch (\Exception $exception) {
|
||||
do_log("Invalid IP: $search, error: " . $exception->getMessage());
|
||||
}
|
||||
})
|
||||
->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')
|
||||
@@ -73,6 +85,16 @@ class SeedBoxRecordResource extends Resource
|
||||
->label(__('label.seed_box_record.status')),
|
||||
])
|
||||
->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('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')),
|
||||
])
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Filament\OptionsTrait;
|
||||
use App\Filament\Resources\System\SettingResource;
|
||||
use App\Models\HitAndRun;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Tag;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\ComponentContainer;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
@@ -58,9 +59,6 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
$data = [];
|
||||
foreach ($formData as $prefix => $parts) {
|
||||
foreach ($parts as $name => $value) {
|
||||
if (is_null($value)) {
|
||||
continue;
|
||||
}
|
||||
if (in_array($name, $notAutoloadNames)) {
|
||||
$autoload = 'no';
|
||||
} else {
|
||||
@@ -78,6 +76,7 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
}
|
||||
}
|
||||
Setting::query()->upsert($data, ['name'], ['value']);
|
||||
do_action("nexus_setting_update");
|
||||
clear_setting_cache();
|
||||
Filament::notify('success', __('filament::resources/pages/edit-record.messages.saved'), true);
|
||||
}
|
||||
@@ -87,13 +86,9 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
$tabs = [];
|
||||
$tabs[] = Forms\Components\Tabs\Tab::make(__('label.setting.hr.tab_header'))
|
||||
->id('hr')
|
||||
->schema([
|
||||
Forms\Components\Radio::make('hr.mode')->options(HitAndRun::listModes(true))->inline(true)->label(__('label.setting.hr.mode')),
|
||||
Forms\Components\TextInput::make('hr.inspect_time')->helperText(__('label.setting.hr.inspect_time_help'))->label(__('label.setting.hr.inspect_time'))->integer(),
|
||||
Forms\Components\TextInput::make('hr.seed_time_minimum')->helperText(__('label.setting.hr.seed_time_minimum_help'))->label(__('label.setting.hr.seed_time_minimum'))->integer(),
|
||||
Forms\Components\TextInput::make('hr.ignore_when_ratio_reach')->helperText(__('label.setting.hr.ignore_when_ratio_reach_help'))->label(__('label.setting.hr.ignore_when_ratio_reach'))->integer(),
|
||||
Forms\Components\TextInput::make('hr.ban_user_when_counts_reach')->helperText(__('label.setting.hr.ban_user_when_counts_reach_help'))->label(__('label.setting.hr.ban_user_when_counts_reach'))->integer(),
|
||||
])->columns(2);
|
||||
->schema($this->getHitAndRunSchema())
|
||||
->columns(2)
|
||||
;
|
||||
|
||||
$tabs[] = Forms\Components\Tabs\Tab::make(__('label.setting.backup.tab_header'))
|
||||
->id('backup')
|
||||
@@ -117,6 +112,7 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
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(),
|
||||
Forms\Components\TextInput::make('seed_box.max_uploaded_duration')->label(__('label.setting.seed_box.max_uploaded_duration'))->helperText(__('label.setting.seed_box.max_uploaded_duration_help'))->integer(),
|
||||
])->columns(2);
|
||||
|
||||
$tabs[] = Forms\Components\Tabs\Tab::make(__('label.setting.system.tab_header'))
|
||||
@@ -137,4 +133,16 @@ class EditSetting extends Page implements Forms\Contracts\HasForms
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
private function getHitAndRunSchema()
|
||||
{
|
||||
$default = [
|
||||
Forms\Components\Radio::make('hr.mode')->options(HitAndRun::listModes(true))->inline(true)->label(__('label.setting.hr.mode')),
|
||||
Forms\Components\TextInput::make('hr.inspect_time')->helperText(__('label.setting.hr.inspect_time_help'))->label(__('label.setting.hr.inspect_time'))->integer(),
|
||||
Forms\Components\TextInput::make('hr.seed_time_minimum')->helperText(__('label.setting.hr.seed_time_minimum_help'))->label(__('label.setting.hr.seed_time_minimum'))->integer(),
|
||||
Forms\Components\TextInput::make('hr.ignore_when_ratio_reach')->helperText(__('label.setting.hr.ignore_when_ratio_reach_help'))->label(__('label.setting.hr.ignore_when_ratio_reach'))->integer(),
|
||||
Forms\Components\TextInput::make('hr.ban_user_when_counts_reach')->helperText(__('label.setting.hr.ban_user_when_counts_reach_help'))->label(__('label.setting.hr.ban_user_when_counts_reach'))->integer(),
|
||||
];
|
||||
return apply_filter("hit_and_run_setting_schema", $default);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class UsernameChangeLogResource extends Resource
|
||||
{
|
||||
@@ -50,13 +51,30 @@ class UsernameChangeLogResource extends Resource
|
||||
Tables\Columns\TextColumn::make('uid')->searchable(),
|
||||
Tables\Columns\TextColumn::make('user.username')->searchable()->label(__('label.username')),
|
||||
Tables\Columns\TextColumn::make('username_old')->searchable()->label(__('username-change-log.labels.username_old')),
|
||||
Tables\Columns\TextColumn::make('username_new')->searchable()->label(__('username-change-log.labels.username_new')),
|
||||
Tables\Columns\TextColumn::make('operator')->searchable()->label(__('label.operator')),
|
||||
Tables\Columns\TextColumn::make('username_new')
|
||||
->searchable()
|
||||
->label(__('username-change-log.labels.username_new'))
|
||||
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->uid, false, true, true, true)))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('operator')
|
||||
->searchable()
|
||||
->label(__('label.operator'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('created_at')->label(__('label.created_at'))->formatStateUsing(fn ($state) => format_datetime($state)),
|
||||
|
||||
])
|
||||
->defaultSort('id', 'desc')
|
||||
->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('change_type')->options(UsernameChangeLog::listChangeType())->label(__('username-change-log.labels.change_type')),
|
||||
])
|
||||
->actions([
|
||||
|
||||
+2
-3
@@ -2,14 +2,13 @@
|
||||
|
||||
namespace App\Filament\Resources\System\UsernameChangeLogResource\Pages;
|
||||
|
||||
use App\Filament\PageListSingle;
|
||||
use App\Filament\Resources\System\UsernameChangeLogResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManageUsernameChangeLogs extends ManageRecords
|
||||
class ManageUsernameChangeLogs extends PageListSingle
|
||||
{
|
||||
protected ?string $maxContentWidth = 'full';
|
||||
|
||||
protected static string $resource = UsernameChangeLogResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
|
||||
@@ -9,6 +9,7 @@ use App\Models\Setting;
|
||||
use App\Models\Tag;
|
||||
use App\Models\Torrent;
|
||||
use App\Models\TorrentTag;
|
||||
use App\Models\User;
|
||||
use App\Repositories\TagRepository;
|
||||
use App\Repositories\TorrentRepository;
|
||||
use Filament\Facades\Filament;
|
||||
@@ -24,6 +25,7 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class TorrentResource extends Resource
|
||||
{
|
||||
@@ -83,10 +85,20 @@ class TorrentResource extends Resource
|
||||
})->label(__('label.name'))->searchable(),
|
||||
Tables\Columns\TextColumn::make('posStateText')->label(__('label.torrent.pos_state')),
|
||||
Tables\Columns\TextColumn::make('spStateText')->label(__('label.torrent.sp_state')),
|
||||
Tables\Columns\TextColumn::make('size')->label(__('label.torrent.size'))->formatStateUsing(fn ($state) => mksize($state)),
|
||||
Tables\Columns\TextColumn::make('seeders')->label(__('label.torrent.seeders')),
|
||||
Tables\Columns\TextColumn::make('leechers')->label(__('label.torrent.leechers')),
|
||||
// Tables\Columns\TextColumn::make('times_completed')->label(__('label.torrent.times_completed')),
|
||||
Tables\Columns\TextColumn::make('pickInfoText')
|
||||
->label(__('label.torrent.picktype'))
|
||||
->formatStateUsing(fn ($record) => $record->pickInfo['text'])
|
||||
,
|
||||
Tables\Columns\BooleanColumn::make('hr')
|
||||
->label(__('label.torrent.hr'))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('size')
|
||||
->label(__('label.torrent.size'))
|
||||
->formatStateUsing(fn ($state) => mksize($state))
|
||||
->sortable()
|
||||
,
|
||||
Tables\Columns\TextColumn::make('seeders')->label(__('label.torrent.seeders'))->sortable(),
|
||||
Tables\Columns\TextColumn::make('leechers')->label(__('label.torrent.leechers'))->sortable(),
|
||||
Tables\Columns\BadgeColumn::make('approval_status')
|
||||
->visible($showApproval)
|
||||
->label(__('label.torrent.approval_status'))
|
||||
@@ -95,12 +107,22 @@ class TorrentResource extends Resource
|
||||
Tables\Columns\TextColumn::make('added')->label(__('label.added'))->dateTime(),
|
||||
Tables\Columns\TextColumn::make('user.username')
|
||||
->label(__('label.torrent.owner'))
|
||||
->url(fn ($record) => sprintf('/userdetails.php?id=%s', $record->owner))
|
||||
->openUrlInNewTab(true)
|
||||
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->owner, false, true, true, true)))
|
||||
,
|
||||
])
|
||||
->defaultSort('id', 'desc')
|
||||
->filters([
|
||||
Tables\Filters\Filter::make('owner')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('owner')
|
||||
->label(__('label.torrent.owner'))
|
||||
->placeholder('UID')
|
||||
,
|
||||
])->query(function (Builder $query, array $data) {
|
||||
return $query->when($data['owner'], fn (Builder $query, $owner) => $query->where("owner", $owner));
|
||||
})
|
||||
,
|
||||
|
||||
Tables\Filters\SelectFilter::make('visible')
|
||||
->options(self::$yesOrNo)
|
||||
->label(__('label.torrent.visible')),
|
||||
@@ -113,10 +135,18 @@ class TorrentResource extends Resource
|
||||
->options(Torrent::listPromotionTypes(true))
|
||||
->label(__('label.torrent.sp_state')),
|
||||
|
||||
Tables\Filters\SelectFilter::make('picktype')
|
||||
->options(Torrent::listPickInfo(true))
|
||||
->label(__('label.torrent.picktype')),
|
||||
|
||||
Tables\Filters\SelectFilter::make('approval_status')
|
||||
->options(Torrent::listApprovalStatus(true))
|
||||
->visible($showApproval)
|
||||
->label(__('label.torrent.approval_status')),
|
||||
|
||||
Tables\Filters\SelectFilter::make('hr')
|
||||
->options(self::getYesNoOptions())
|
||||
->label(__('label.torrent.hr')),
|
||||
])
|
||||
->actions(self::getActions())
|
||||
->bulkActions(self::getBulkActions());
|
||||
@@ -146,6 +176,7 @@ class TorrentResource extends Resource
|
||||
|
||||
private static function getBulkActions(): array
|
||||
{
|
||||
$user = Auth::user();
|
||||
$actions = [];
|
||||
if (user_can('torrentsticky')) {
|
||||
$actions[] = Tables\Actions\BulkAction::make('posState')
|
||||
@@ -155,13 +186,77 @@ class TorrentResource extends Resource
|
||||
->label(__('label.torrent.pos_state'))
|
||||
->options(Torrent::listPosStates(true))
|
||||
->required()
|
||||
,
|
||||
Forms\Components\DateTimePicker::make('pos_state_until')
|
||||
->label(__('label.deadline'))
|
||||
,
|
||||
])
|
||||
->icon('heroicon-o-arrow-circle-up')
|
||||
->action(function (Collection $records, array $data) {
|
||||
$idArr = $records->pluck('id')->toArray();
|
||||
try {
|
||||
$torrentRep = new TorrentRepository();
|
||||
$torrentRep->setPosState($idArr, $data['pos_state']);
|
||||
$torrentRep->setPosState($idArr, $data['pos_state'], $data['pos_state_until']);
|
||||
} catch (\Exception $exception) {
|
||||
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
|
||||
Filament::notify('danger', class_basename($exception));
|
||||
}
|
||||
})
|
||||
->deselectRecordsAfterCompletion();
|
||||
}
|
||||
|
||||
if (user_can('torrentonpromotion')) {
|
||||
$actions[] = Tables\Actions\BulkAction::make('sp_state')
|
||||
->label(__('admin.resources.torrent.bulk_action_sp_state'))
|
||||
->form([
|
||||
Forms\Components\Select::make('sp_state')
|
||||
->label(__('label.torrent.sp_state'))
|
||||
->options(Torrent::listPromotionTypes(true))
|
||||
->required()
|
||||
,
|
||||
Forms\Components\Select::make('promotion_time_type')
|
||||
->label(__('label.torrent.promotion_time_type'))
|
||||
->options(Torrent::listPromotionTimeTypes(true))
|
||||
->required()
|
||||
,
|
||||
Forms\Components\DateTimePicker::make('promotion_until')
|
||||
->label(__('label.deadline'))
|
||||
,
|
||||
])
|
||||
->icon('heroicon-o-speakerphone')
|
||||
->action(function (Collection $records, array $data) {
|
||||
$idArr = $records->pluck('id')->toArray();
|
||||
try {
|
||||
$torrentRep = new TorrentRepository();
|
||||
$torrentRep->setSpState($idArr, $data['sp_state'], $data['promotion_time_type'], $data['promotion_until']);
|
||||
} catch (\Exception $exception) {
|
||||
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
|
||||
Filament::notify('danger', $exception->getMessage());
|
||||
}
|
||||
})
|
||||
->deselectRecordsAfterCompletion();
|
||||
}
|
||||
|
||||
if (user_can('torrentmanage') && ($user->picker == 'yes' || $user->class >= User::CLASS_SYSOP)) {
|
||||
$actions[] = Tables\Actions\BulkAction::make('recommend')
|
||||
->label(__('admin.resources.torrent.bulk_action_recommend'))
|
||||
->form([
|
||||
Forms\Components\Radio::make('picktype')
|
||||
->label(__('admin.resources.torrent.bulk_action_recommend'))
|
||||
->inline()
|
||||
->options(Torrent::listPickInfo(true))
|
||||
->required(),
|
||||
|
||||
])
|
||||
->icon('heroicon-o-fire')
|
||||
->action(function (Collection $records, array $data) {
|
||||
if (empty($data['picktype'])) {
|
||||
return;
|
||||
}
|
||||
$idArr = $records->pluck('id')->toArray();
|
||||
try {
|
||||
$torrentRep = new TorrentRepository();
|
||||
$torrentRep->setPickType($idArr, $data['picktype']);
|
||||
} catch (\Exception $exception) {
|
||||
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
|
||||
Filament::notify('danger', class_basename($exception));
|
||||
@@ -213,6 +308,38 @@ class TorrentResource extends Resource
|
||||
}
|
||||
})
|
||||
->deselectRecordsAfterCompletion();
|
||||
|
||||
$actions[] = Tables\Actions\BulkAction::make('hr')
|
||||
->label(__('admin.resources.torrent.bulk_action_hr'))
|
||||
->form([
|
||||
Forms\Components\Radio::make('hr')
|
||||
->label(__('admin.resources.torrent.bulk_action_hr'))
|
||||
->inline()
|
||||
->options(self::getYesNoOptions())
|
||||
->required(),
|
||||
|
||||
])
|
||||
->icon('heroicon-o-sparkles')
|
||||
->action(function (Collection $records, array $data) {
|
||||
if (empty($data['hr'])) {
|
||||
return;
|
||||
}
|
||||
$idArr = $records->pluck('id')->toArray();
|
||||
try {
|
||||
$torrentRep = new TorrentRepository();
|
||||
$torrentRep->setHr($idArr, $data['hr']);
|
||||
} catch (\Exception $exception) {
|
||||
do_log($exception->getMessage() . $exception->getTraceAsString(), 'error');
|
||||
Filament::notify('danger', class_basename($exception));
|
||||
}
|
||||
})
|
||||
->deselectRecordsAfterCompletion();
|
||||
}
|
||||
|
||||
if (user_can('torrent-delete')) {
|
||||
$actions[] = Tables\Actions\DeleteBulkAction::make('bulk-delete')->using(function (Collection $records) {
|
||||
deletetorrent($records->pluck('id')->toArray());
|
||||
});
|
||||
}
|
||||
|
||||
return $actions;
|
||||
@@ -244,7 +371,7 @@ class TorrentResource extends Resource
|
||||
});
|
||||
|
||||
}
|
||||
if (user_can('torrentmanage')) {
|
||||
if (user_can('torrent-delete')) {
|
||||
$actions[] = Tables\Actions\DeleteAction::make('delete')->using(function ($record) {
|
||||
deletetorrent($record->id);
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Filament\Resources\Torrent\TorrentResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
|
||||
class ListTorrents extends PageList
|
||||
{
|
||||
protected static string $resource = TorrentResource::class;
|
||||
@@ -17,4 +18,6 @@ class ListTorrents extends PageList
|
||||
// Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class ClaimResource extends Resource
|
||||
{
|
||||
@@ -48,7 +49,11 @@ class ClaimResource extends Resource
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->sortable(),
|
||||
Tables\Columns\TextColumn::make('uid')->searchable(),
|
||||
Tables\Columns\TextColumn::make('user.username')->label(__('label.user.label'))->searchable(),
|
||||
Tables\Columns\TextColumn::make('user.username')
|
||||
->label(__('label.user.label'))
|
||||
->searchable()
|
||||
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->uid, false, true, true, true)))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('torrent.name')->limit(40)->label(__('label.torrent.label'))->searchable(),
|
||||
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())),
|
||||
@@ -60,7 +65,26 @@ class ClaimResource extends Resource
|
||||
])
|
||||
->defaultSort('id', 'desc')
|
||||
->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\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));
|
||||
})
|
||||
,
|
||||
])
|
||||
->actions([
|
||||
// Tables\Actions\EditAction::make(),
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Filament\Resources\User;
|
||||
|
||||
use App\Filament\Resources\User\ExamUserResource\Pages;
|
||||
use App\Filament\Resources\User\ExamUserResource\RelationManagers;
|
||||
use App\Models\Exam;
|
||||
use App\Models\ExamUser;
|
||||
use App\Repositories\ExamRepository;
|
||||
use App\Repositories\HitAndRunRepository;
|
||||
@@ -16,6 +17,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class ExamUserResource extends Resource
|
||||
{
|
||||
@@ -51,7 +53,11 @@ class ExamUserResource extends Resource
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->sortable(),
|
||||
Tables\Columns\TextColumn::make('uid')->searchable(),
|
||||
Tables\Columns\TextColumn::make('user.username')->label(__('label.username'))->searchable(),
|
||||
Tables\Columns\TextColumn::make('user.username')
|
||||
->label(__('label.username'))
|
||||
->searchable()
|
||||
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->uid, false, true, true, true)))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('exam.name')->label(__('label.exam.label')),
|
||||
Tables\Columns\TextColumn::make('begin')->label(__('label.begin'))->dateTime(),
|
||||
Tables\Columns\TextColumn::make('end')->label(__('label.end'))->dateTime(),
|
||||
@@ -61,6 +67,20 @@ class ExamUserResource extends Resource
|
||||
])
|
||||
->defaultSort('id', 'desc')
|
||||
->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('exam_id')
|
||||
->options(Exam::query()->pluck('name', 'id')->toArray())
|
||||
->label(__('exam.label'))
|
||||
,
|
||||
Tables\Filters\SelectFilter::make('status')->options(ExamUser::listStatus(true))->label(__("label.status")),
|
||||
Tables\Filters\SelectFilter::make('is_done')->options(['0' => 'No', '1' => 'yes'])->label(__('label.exam_user.is_done')),
|
||||
])
|
||||
|
||||
@@ -15,6 +15,7 @@ use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class HitAndRunResource extends Resource
|
||||
{
|
||||
@@ -42,7 +43,12 @@ class HitAndRunResource extends Resource
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->sortable(),
|
||||
Tables\Columns\TextColumn::make('uid')->searchable(),
|
||||
Tables\Columns\TextColumn::make('user.username')->searchable()->label(__('label.username')),
|
||||
Tables\Columns\TextColumn::make('user.username')
|
||||
->searchable()
|
||||
->label(__('label.username'))
|
||||
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->uid, false, true, true, true)))
|
||||
,
|
||||
|
||||
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')),
|
||||
@@ -53,6 +59,16 @@ class HitAndRunResource extends Resource
|
||||
])
|
||||
->defaultSort('id', 'desc')
|
||||
->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')),
|
||||
])
|
||||
->actions([
|
||||
@@ -72,7 +88,7 @@ class HitAndRunResource extends Resource
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()->with(['user', 'torrent', 'snatch']);
|
||||
return parent::getEloquentQuery()->with(['user', 'torrent', 'snatch', 'torrent.basic_category']);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Filament\Resources\User;
|
||||
|
||||
use App\Filament\Resources\User\UserMedalResource\Pages;
|
||||
use App\Filament\Resources\User\UserMedalResource\RelationManagers;
|
||||
use App\Models\Medal;
|
||||
use App\Models\UserMedal;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
@@ -12,6 +13,7 @@ use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class UserMedalResource extends Resource
|
||||
{
|
||||
@@ -47,14 +49,31 @@ class UserMedalResource extends Resource
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->sortable(),
|
||||
Tables\Columns\TextColumn::make('uid')->searchable(),
|
||||
Tables\Columns\TextColumn::make('user.username')->label(__('label.username'))->searchable(),
|
||||
Tables\Columns\TextColumn::make('user.username')
|
||||
->label(__('label.username'))
|
||||
->searchable()
|
||||
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->uid, false, true, true, true)))
|
||||
,
|
||||
Tables\Columns\TextColumn::make('medal.name')->label(__('label.medal.label'))->searchable(),
|
||||
Tables\Columns\ImageColumn::make('medal.image_large')->label(__('label.image')),
|
||||
Tables\Columns\TextColumn::make('expire_at')->label(__('label.expire_at'))->dateTime(),
|
||||
])
|
||||
->defaultSort('id', 'desc')
|
||||
->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('medal_id')
|
||||
->options(Medal::query()->pluck('name', 'id')->toArray())
|
||||
->label(__('medal.label'))
|
||||
,
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
|
||||
@@ -61,7 +61,7 @@ class UserResource extends Resource
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')->sortable()->searchable(),
|
||||
Tables\Columns\TextColumn::make('username')->searchable()->label(__("label.user.username"))
|
||||
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->id, false, true, false, true))),
|
||||
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->id, false, true, true, true))),
|
||||
Tables\Columns\TextColumn::make('email')->searchable()->label(__("label.email")),
|
||||
Tables\Columns\TextColumn::make('class')->label('Class')
|
||||
->formatStateUsing(fn(Tables\Columns\Column $column) => $column->getRecord()->classText)
|
||||
@@ -80,6 +80,15 @@ class UserResource extends Resource
|
||||
])
|
||||
->defaultSort('added', 'desc')
|
||||
->filters([
|
||||
Tables\Filters\Filter::make('id')
|
||||
->form([
|
||||
Forms\Components\TextInput::make('id')
|
||||
->placeholder('UID')
|
||||
,
|
||||
])->query(function (Builder $query, array $data) {
|
||||
return $query->when($data['id'], fn (Builder $query, $id) => $query->where("id", $id));
|
||||
})
|
||||
,
|
||||
Tables\Filters\SelectFilter::make('class')->options(array_column(User::$classes, 'text'))->label(__('label.user.class')),
|
||||
Tables\Filters\SelectFilter::make('status')->options(['confirmed' => 'confirmed', 'pending' => 'pending'])->label(__('label.user.status')),
|
||||
Tables\Filters\SelectFilter::make('enabled')->options(self::$yesOrNo)->label(__('label.user.enabled')),
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Filament\Resources\User\UserResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Filament\Tables\Filters\Layout;
|
||||
|
||||
class ListUsers extends PageList
|
||||
{
|
||||
@@ -25,6 +26,9 @@ class ListUsers extends PageList
|
||||
// }
|
||||
|
||||
|
||||
|
||||
protected function getTableFiltersLayout(): ?string
|
||||
{
|
||||
return Layout::AboveContent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -278,11 +278,6 @@ class UserProfile extends ViewRecord
|
||||
->action(function ($data) {
|
||||
$rep = $this->getRep();
|
||||
try {
|
||||
if (!empty($data['duration'])) {
|
||||
$data['deadline'] = now()->addDays($data['duration']);
|
||||
} else {
|
||||
$data['deadline'] = null;
|
||||
}
|
||||
$rep->addMeta($this->record, $data, $data);
|
||||
$this->notify('success', 'Success!');
|
||||
$this->emitSelf(self::EVENT_RECORD_UPDATED, $this->record->id);
|
||||
|
||||
Reference in New Issue
Block a user