diff --git a/app/Filament/Resources/Torrent/TorrentResource.php b/app/Filament/Resources/Torrent/TorrentResource.php index 13ab02fb..d5370996 100644 --- a/app/Filament/Resources/Torrent/TorrentResource.php +++ b/app/Filament/Resources/Torrent/TorrentResource.php @@ -12,6 +12,7 @@ use App\Models\Tag; use App\Models\Torrent; use App\Models\TorrentTag; use App\Models\User; +use App\Repositories\SearchBoxRepository; use App\Repositories\TagRepository; use App\Repositories\TorrentRepository; use Filament\Facades\Filament; @@ -301,13 +302,13 @@ class TorrentResource extends Resource }) ->deselectRecordsAfterCompletion(); } +// $actions[] = self::getBulkActionChangeCategory(); if (user_can('torrent-delete')) { $actions[] = Tables\Actions\DeleteBulkAction::make('bulk-delete')->using(function (Collection $records) { deletetorrent($records->pluck('id')->toArray()); }); } - return $actions; } @@ -341,17 +342,55 @@ class TorrentResource extends Resource $actions[] = Tables\Actions\DeleteAction::make('delete')->using(function ($record) { deletetorrent($record->id); }); -// $actions[] = Tables\Actions\Action::make('view') -// ->action(function (Torrent $record) { -// return [ -// 'modelContent' => new HtmlString("ssss") -// ]; -// }) -// ; } return $actions; } + private static function getBulkActionChangeCategory(): Tables\Actions\BulkAction + { + return Tables\Actions\BulkAction::make('changeCategory') + ->label(__('admin.resources.torrent.bulk_action_change_category')) + ->form([ + Forms\Components\Select::make('section_id') + ->label(__('searchbox.section')) + ->options(function() { + $rep = new SearchBoxRepository(); + $list = $rep->listSections(false); + $result = []; + foreach ($list as $section) { + $result[$section->id] = $section->displaySectionName; + } + return $result; + }) + ->reactive() + ->afterStateUpdated(fn (callable $set) => $set('section_id', null)) + ->required() + , + Forms\Components\Select::make('category') + ->label(__('searchbox.category_label')) + ->options(function (callable $get) { + $sectionId = $get('section_id'); + if (!$sectionId) { + return []; + } + return Category::query()->where('mode', $sectionId)->pluck('name', 'id'); + }) + ->reactive() + ->required() + , + + ]) + ->action(function (Collection $records, array $data) { +// $torrentRep = new TorrentRepository(); +// try { +// $data['torrent_id'] = $record->id; +// $torrentRep->approval(Auth::user(), $data); +// } catch (\Exception $exception) { +// do_log($exception->getMessage(), 'error'); +// } + }); + } + private static function shouldShowApproval(): bool { return false; diff --git a/app/Repositories/SearchBoxRepository.php b/app/Repositories/SearchBoxRepository.php index 83b8bc2b..83b698ac 100644 --- a/app/Repositories/SearchBoxRepository.php +++ b/app/Repositories/SearchBoxRepository.php @@ -243,18 +243,20 @@ class SearchBoxRepository extends BaseRepository return Category::query()->whereIn('id', $idArr)->delete(); } - public function listSections() + public function listSections($withCategoryAndTags = true) { $modeIds = [SearchBox::getBrowseMode()]; if (SearchBox::isSpecialEnabled() && Permission::canUploadToSpecialSection()) { $modeIds[] = SearchBox::getSpecialMode(); } - $searchBoxList = SearchBox::query()->with("categories")->find($modeIds); - foreach ($searchBoxList as $searchBox) { - if ($searchBox->showsubcat) { - $searchBox->loadSubCategories(); + $searchBoxList = SearchBox::query()->with($withCategoryAndTags ? ['categories'] : [])->find($modeIds); + if ($withCategoryAndTags) { + foreach ($searchBoxList as $searchBox) { + if ($searchBox->showsubcat) { + $searchBox->loadSubCategories(); + } + $searchBox->loadTags(); } - $searchBox->loadTags(); } return $searchBoxList; } diff --git a/classes/class_cache_redis.php b/classes/class_cache_redis.php index 9fb037cc..bd8d580b 100644 --- a/classes/class_cache_redis.php +++ b/classes/class_cache_redis.php @@ -37,7 +37,7 @@ class class_cache_redis { if (!empty($config['port'])) { $params[] = $config['port']; } - if (!empty($config['timeout'])) { + if (isset($config['timeout']) && is_numeric($config['timeout'])) { $params[] = $config['timeout']; } $connectResult = $redis->connect(...$params); diff --git a/resources/lang/zh_CN/admin.php b/resources/lang/zh_CN/admin.php index ba845a8e..70a1f5e5 100644 --- a/resources/lang/zh_CN/admin.php +++ b/resources/lang/zh_CN/admin.php @@ -121,6 +121,7 @@ return [ 'bulk_action_recommend' => '推荐', 'bulk_action_sp_state' => '优惠', 'bulk_action_hr' => 'H&R', + 'bulk_action_change_category' => '修改分类', ], 'seed_box_record' => [ 'toggle_status' => '更改状态', diff --git a/resources/lang/zh_CN/searchbox.php b/resources/lang/zh_CN/searchbox.php index 5f543412..586e52b7 100644 --- a/resources/lang/zh_CN/searchbox.php +++ b/resources/lang/zh_CN/searchbox.php @@ -1,6 +1,7 @@ '分区', 'category_label' => '分类', 'sub_category_source_label' => '来源', 'sub_category_medium_label' => '媒介',