change category form schema

This commit is contained in:
xiaomlove
2025-09-15 13:38:38 +07:00
parent 373b0d4af1
commit 82cccd29c2
8 changed files with 114 additions and 15 deletions
+1 -1
View File
@@ -59,4 +59,4 @@ docker run --name my-nexusphp -e DOMAIN=xxx.com -p 80:80 xiaomlove/nexusphp:late
## More information ## More information
Blog[https://nexusphp.org](https://nexusphp.org/) Blog[https://nexusphp.org](https://nexusphp.org/)
Documentation[https://doc.nexusphp.org](https://doc.nexusphp.org/en/) 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)
+1 -1
View File
@@ -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://nexusphp.org](http://nexusphp.org/)
文档:[https://doc.nexusphp.org](http://doc.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)
@@ -302,7 +302,7 @@ class TorrentResource extends Resource
}) })
->deselectRecordsAfterCompletion(); ->deselectRecordsAfterCompletion();
} }
// $actions[] = self::getBulkActionChangeCategory(); $actions[] = self::getBulkActionChangeCategory();
if (user_can('torrent-delete')) { if (user_can('torrent-delete')) {
$actions[] = Tables\Actions\DeleteBulkAction::make('bulk-delete')->using(function (Collection $records) { $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 private static function getBulkActionChangeCategory(): Tables\Actions\BulkAction
{ {
$searchBoxRep = new SearchBoxRepository();
return Tables\Actions\BulkAction::make('changeCategory') return Tables\Actions\BulkAction::make('changeCategory')
->label(__('admin.resources.torrent.bulk_action_change_category')) ->label(__('admin.resources.torrent.bulk_action_change_category'))
->form([ ->form([
Forms\Components\Select::make('section_id') Forms\Components\Select::make('section_id')
->label(__('searchbox.section')) ->label(__('searchbox.section'))
->helperText(new HtmlString(__('admin.resources.torrent.bulk_action_change_category_section_help')))
->options(function() { ->options(function() {
$rep = new SearchBoxRepository(); $rep = new SearchBoxRepository();
$list = $rep->listSections(false); $list = $rep->listSections(false);
@@ -365,16 +367,15 @@ class TorrentResource extends Resource
->reactive() ->reactive()
->required() ->required()
, ,
Forms\Components\Select::make('category_id') $searchBoxRep->buildSearchBoxFormSchema(SearchBox::getBrowseSearchBox())
->label(__('searchbox.category_label')) ->hidden(function (Forms\Get $get) {
->options(function (callable $get) { return $get('section_id') != SearchBox::getBrowseMode();
$sectionId = $get('section_id'); })
if (!$sectionId) { ,
return []; $searchBoxRep->buildSearchBoxFormSchema(SearchBox::getSpecialSearchBox())
} ->hidden(function (Forms\Get $get) {
return Category::query()->where('mode', $sectionId)->pluck('name', 'id'); return $get('section_id') != SearchBox::getSpecialMode();
}) })
->required()
, ,
]) ])
+10
View File
@@ -225,11 +225,21 @@ class SearchBox extends NexusModel
return Setting::get('main.browsecat'); return Setting::get('main.browsecat');
} }
public static function getBrowseSearchBox()
{
return self::query()->find(self::getBrowseMode());
}
public static function getSpecialMode() public static function getSpecialMode()
{ {
return Setting::get('main.specialcat'); return Setting::get('main.specialcat');
} }
public static function getSpecialSearchBox()
{
return self::query()->find(self::getSpecialMode());
}
public function isSectionBrowse(): bool public function isSectionBrowse(): bool
{ {
return $this->id == self::getBrowseMode(); return $this->id == self::getBrowseMode();
+87 -1
View File
@@ -9,7 +9,6 @@ use App\Models\Category;
use App\Models\Icon; use App\Models\Icon;
use App\Models\NexusModel; use App\Models\NexusModel;
use App\Models\SearchBox; use App\Models\SearchBox;
use App\Models\SearchBoxField;
use App\Models\SecondIcon; use App\Models\SecondIcon;
use App\Models\Setting; use App\Models\Setting;
use App\Models\Torrent; use App\Models\Torrent;
@@ -261,5 +260,92 @@ class SearchBoxRepository extends BaseRepository
return $searchBoxList; 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')
;
}
} }
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.7'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.7');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-09-11'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-09-15');
defined('IN_TRACKER') || define('IN_TRACKER', false); defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
+2 -1
View File
@@ -121,7 +121,8 @@ return [
'bulk_action_recommend' => '推荐', 'bulk_action_recommend' => '推荐',
'bulk_action_sp_state' => '优惠', 'bulk_action_sp_state' => '优惠',
'bulk_action_hr' => 'H&R', 'bulk_action_hr' => 'H&R',
'bulk_action_change_category' => '修改分', 'bulk_action_change_category' => '修改分',
'bulk_action_change_category_section_help' => '注意:选择目标分区后,勾选下面的分类和子分类会将种子对应属性修改为选择的值,勾选标签则会将其附加到种子上。<br/>并且原种子身上不属于新分区的分类、子分类和标签会被移除。',
], ],
'seed_box_record' => [ 'seed_box_record' => [
'toggle_status' => '更改状态', 'toggle_status' => '更改状态',
+1
View File
@@ -3,6 +3,7 @@
return [ return [
'section' => '分区', 'section' => '分区',
'category_label' => '分类', 'category_label' => '分类',
'sub_categories_label' => '子分类',
'sub_category_source_label' => '来源', 'sub_category_source_label' => '来源',
'sub_category_medium_label' => '媒介', 'sub_category_medium_label' => '媒介',
'sub_category_standard_label' => '分辨率', 'sub_category_standard_label' => '分辨率',