mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
change category form schema
This commit is contained in:
@@ -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()
|
||||
,
|
||||
|
||||
])
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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')
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user