From 82cccd29c29cbb21b8c18c80b2aa051d4c973f2e Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 15 Sep 2025 13:38:38 +0700 Subject: [PATCH] change category form schema --- README-EN.md | 2 +- README.md | 2 +- .../Resources/Torrent/TorrentResource.php | 21 ++--- app/Models/SearchBox.php | 10 +++ app/Repositories/SearchBoxRepository.php | 88 ++++++++++++++++++- include/constants.php | 2 +- resources/lang/zh_CN/admin.php | 3 +- resources/lang/zh_CN/searchbox.php | 1 + 8 files changed, 114 insertions(+), 15 deletions(-) diff --git a/README-EN.md b/README-EN.md index 601a6c9f..e9a38687 100644 --- a/README-EN.md +++ b/README-EN.md @@ -59,4 +59,4 @@ docker run --name my-nexusphp -e DOMAIN=xxx.com -p 80:80 xiaomlove/nexusphp:late ## More information Blog:[https://nexusphp.org](https://nexusphp.org/) Documentation:[https://doc.nexusphp.org](https://doc.nexusphp.org/en/) -Telegram: [https://t.me/nexusphp](https://t.me/nexusphp) +Telegram: [https://t.me/nexusphp_dev](https://t.me/nexusphp_dev) diff --git a/README.md b/README.md index c43bbc47..61a5211c 100644 --- a/README.md +++ b/README.md @@ -64,4 +64,4 @@ docker run --name my-nexusphp -e DOMAIN=xxx.com -p 80:80 xiaomlove/nexusphp:late ## 更多信息 博客:[https://nexusphp.org](http://nexusphp.org/) 文档:[https://doc.nexusphp.org](http://doc.nexusphp.org/) -Telegram: [https://t.me/nexusphp](https://t.me/nexusphp) +Telegram: [https://t.me/nexusphp_dev](https://t.me/nexusphp_dev) diff --git a/app/Filament/Resources/Torrent/TorrentResource.php b/app/Filament/Resources/Torrent/TorrentResource.php index fa4142ea..3dd187c8 100644 --- a/app/Filament/Resources/Torrent/TorrentResource.php +++ b/app/Filament/Resources/Torrent/TorrentResource.php @@ -302,7 +302,7 @@ class TorrentResource extends Resource }) ->deselectRecordsAfterCompletion(); } -// $actions[] = self::getBulkActionChangeCategory(); + $actions[] = self::getBulkActionChangeCategory(); if (user_can('torrent-delete')) { $actions[] = Tables\Actions\DeleteBulkAction::make('bulk-delete')->using(function (Collection $records) { @@ -348,11 +348,13 @@ class TorrentResource extends Resource private static function getBulkActionChangeCategory(): Tables\Actions\BulkAction { + $searchBoxRep = new SearchBoxRepository(); return Tables\Actions\BulkAction::make('changeCategory') ->label(__('admin.resources.torrent.bulk_action_change_category')) ->form([ Forms\Components\Select::make('section_id') ->label(__('searchbox.section')) + ->helperText(new HtmlString(__('admin.resources.torrent.bulk_action_change_category_section_help'))) ->options(function() { $rep = new SearchBoxRepository(); $list = $rep->listSections(false); @@ -365,16 +367,15 @@ class TorrentResource extends Resource ->reactive() ->required() , - Forms\Components\Select::make('category_id') - ->label(__('searchbox.category_label')) - ->options(function (callable $get) { - $sectionId = $get('section_id'); - if (!$sectionId) { - return []; - } - return Category::query()->where('mode', $sectionId)->pluck('name', 'id'); + $searchBoxRep->buildSearchBoxFormSchema(SearchBox::getBrowseSearchBox()) + ->hidden(function (Forms\Get $get) { + return $get('section_id') != SearchBox::getBrowseMode(); + }) + , + $searchBoxRep->buildSearchBoxFormSchema(SearchBox::getSpecialSearchBox()) + ->hidden(function (Forms\Get $get) { + return $get('section_id') != SearchBox::getSpecialMode(); }) - ->required() , ]) diff --git a/app/Models/SearchBox.php b/app/Models/SearchBox.php index a60bce17..3cd5af17 100644 --- a/app/Models/SearchBox.php +++ b/app/Models/SearchBox.php @@ -225,11 +225,21 @@ class SearchBox extends NexusModel return Setting::get('main.browsecat'); } + public static function getBrowseSearchBox() + { + return self::query()->find(self::getBrowseMode()); + } + public static function getSpecialMode() { return Setting::get('main.specialcat'); } + public static function getSpecialSearchBox() + { + return self::query()->find(self::getSpecialMode()); + } + public function isSectionBrowse(): bool { return $this->id == self::getBrowseMode(); diff --git a/app/Repositories/SearchBoxRepository.php b/app/Repositories/SearchBoxRepository.php index 83b698ac..91602cd3 100644 --- a/app/Repositories/SearchBoxRepository.php +++ b/app/Repositories/SearchBoxRepository.php @@ -9,7 +9,6 @@ use App\Models\Category; use App\Models\Icon; use App\Models\NexusModel; use App\Models\SearchBox; -use App\Models\SearchBoxField; use App\Models\SecondIcon; use App\Models\Setting; use App\Models\Torrent; @@ -261,5 +260,92 @@ class SearchBoxRepository extends BaseRepository return $searchBoxList; } + public function buildSearchBoxFormSchema(SearchBox $searchBox, string $namePrefix = ""): Forms\Components\Section + { + $lang = get_langfolder_cookie(); + $heading = $searchBox->section_name[$lang] ?? nexus_trans('searchbox.sections.browse'); + return Forms\Components\Section::make($heading) + ->schema($this->buildCategoryTaxonomyTagSchema($searchBox, false, $namePrefix)); + } + + public function buildCategoryTaxonomyTagSchema(SearchBox $searchBox, bool $multiple, string $namePrefix): array + { + $schema = []; + $mode = $searchBox->id; + $namePrefix .= ".section.$mode"; + if ($multiple) { + $schema[] = Forms\Components\CheckboxList::make("$namePrefix.category") + ->options($searchBox->categories()->orderBy('sort_index', 'desc')->orderBy('id')->pluck('name', 'id')) + ->label(nexus_trans('label.search_box.category')) + ->columns(6); + } else { + $schema[] = Forms\Components\Radio::make("$namePrefix.category") + ->options($searchBox->categories()->orderBy('sort_index', 'desc')->orderBy('id')->pluck('name', 'id')) + ->label(nexus_trans('label.search_box.category')) + ->columns(6); + } + + $fieldset = Forms\Components\Fieldset::make(nexus_trans('searchbox.sub_categories_label')); + $fieldsetSchema = []; + //Keep the order + if (!empty($searchBox->extra[SearchBox::EXTRA_TAXONOMY_LABELS])) { + foreach ($searchBox->extra[SearchBox::EXTRA_TAXONOMY_LABELS] as $taxonomy) { + $torrentField = $taxonomy['torrent_field']; + $showField = "show" . $torrentField; + if ($searchBox->showsubcat && $searchBox->{$showField}) { + if ($multiple) { + $fieldsetSchema[] = Forms\Components\CheckboxList::make("$namePrefix.$torrentField") + ->options($this->listTaxonomies($torrentField, $mode)) + ->label($searchBox->getTaxonomyLabel($torrentField)) + ->columns(6) + ; + } else { + $fieldsetSchema[] = Forms\Components\Radio::make("$namePrefix.$torrentField") + ->options($this->listTaxonomies($torrentField, $mode)) + ->label($searchBox->getTaxonomyLabel($torrentField)) + ->columns(6) + ; + } + } + } + } else { + foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) { + $showField = "show" . $torrentField; + if ($searchBox->showsubcat && $searchBox->{$showField}) { + $fieldsetSchema[] = Forms\Components\CheckboxList::make("$namePrefix.$torrentField") + ->options($this->listTaxonomies($torrentField, $mode)) + ->label($searchBox->getTaxonomyLabel($torrentField)) + ->columns(6) + ; + } + } + } + $fieldset->schema($fieldsetSchema)->columns(1); + $schema[] = $fieldset; + + $tagRep = new TagRepository(); + $tags = $tagRep->listAll($searchBox->id); + $schema[] = Forms\Components\CheckboxList::make("$namePrefix.tag") + ->options($tags->pluck('name', 'id')) + ->label(nexus_trans('label.tag.label')) + ->columns(6) + ; + + return $schema; + } + + private function listTaxonomies($torrentField, $mode) + { + $tableName = SearchBox::$taxonomies[$torrentField]['table']; + return NexusDB::table($tableName) + ->where(function (\Illuminate\Database\Query\Builder $query) use ($mode) { + return $query->where('mode', $mode)->orWhere('mode', 0); + }) + ->orderBy('sort_index', 'desc') + ->orderBy('id', 'desc') + ->pluck('name', 'id') + ; + } + } diff --git a/include/constants.php b/include/constants.php index bb102bcb..36bc6c0b 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ '推荐', 'bulk_action_sp_state' => '优惠', 'bulk_action_hr' => 'H&R', - 'bulk_action_change_category' => '修改分类', + 'bulk_action_change_category' => '修改分区', + 'bulk_action_change_category_section_help' => '注意:选择目标分区后,勾选下面的分类和子分类会将种子对应属性修改为选择的值,勾选标签则会将其附加到种子上。
并且原种子身上不属于新分区的分类、子分类和标签会被移除。', ], 'seed_box_record' => [ 'toggle_status' => '更改状态', diff --git a/resources/lang/zh_CN/searchbox.php b/resources/lang/zh_CN/searchbox.php index 586e52b7..0f6c0f19 100644 --- a/resources/lang/zh_CN/searchbox.php +++ b/resources/lang/zh_CN/searchbox.php @@ -3,6 +3,7 @@ return [ 'section' => '分区', 'category_label' => '分类', + 'sub_categories_label' => '子分类', 'sub_category_source_label' => '来源', 'sub_category_medium_label' => '媒介', 'sub_category_standard_label' => '分辨率',