From 96a1146db63bccaf0f2d0bfc7090c2afecb16c2f Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Mon, 14 Nov 2022 19:02:42 +0800 Subject: [PATCH] add searchbox select unselect --- .../Resources/Section/IconResource.php | 1 + .../Section/IconResource/Pages/EditIcon.php | 3 + .../Resources/Section/SecondIconResource.php | 6 +- .../Pages/EditSecondIcon.php | 5 +- app/Models/SearchBox.php | 16 ++-- app/Models/SecondIcon.php | 2 +- app/Repositories/SearchBoxRepository.php | 10 +-- include/constants.php | 2 +- include/functions.php | 80 ++++++++++++++----- public/torrents.php | 2 +- resources/lang/en/label.php | 5 +- resources/lang/zh_CN/label.php | 5 +- resources/lang/zh_CN/nexus.php | 2 + resources/lang/zh_TW/label.php | 5 +- 14 files changed, 100 insertions(+), 44 deletions(-) diff --git a/app/Filament/Resources/Section/IconResource.php b/app/Filament/Resources/Section/IconResource.php index a904274c..6a35506f 100644 --- a/app/Filament/Resources/Section/IconResource.php +++ b/app/Filament/Resources/Section/IconResource.php @@ -3,6 +3,7 @@ namespace App\Filament\Resources\Section; use App\Filament\OptionsTrait; +use App\Filament\RedirectIndexTrait; use App\Filament\Resources\Section\IconResource\Pages; use App\Filament\Resources\Section\IconResource\RelationManagers; use App\Models\Icon; diff --git a/app/Filament/Resources/Section/IconResource/Pages/EditIcon.php b/app/Filament/Resources/Section/IconResource/Pages/EditIcon.php index 2e591e6b..3f7a2b20 100644 --- a/app/Filament/Resources/Section/IconResource/Pages/EditIcon.php +++ b/app/Filament/Resources/Section/IconResource/Pages/EditIcon.php @@ -2,12 +2,15 @@ namespace App\Filament\Resources\Section\IconResource\Pages; +use App\Filament\RedirectIndexTrait; use App\Filament\Resources\Section\IconResource; use Filament\Pages\Actions; use Filament\Resources\Pages\EditRecord; class EditIcon extends EditRecord { + use RedirectIndexTrait; + protected static string $resource = IconResource::class; protected static string $view = 'filament.resources.system.category-icon-resource.pages.edit-record'; diff --git a/app/Filament/Resources/Section/SecondIconResource.php b/app/Filament/Resources/Section/SecondIconResource.php index 330b08cb..72aed771 100644 --- a/app/Filament/Resources/Section/SecondIconResource.php +++ b/app/Filament/Resources/Section/SecondIconResource.php @@ -98,7 +98,7 @@ class SecondIconResource extends Resource Tables\Columns\TextColumn::make('class_name')->label(__('label.second_icon.class_name')), ]; $taxonomyList = self::listTaxonomy(); - foreach (SearchBox::$taxonomies as $torrentField => $tableName) { + foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) { $columns[] = Tables\Columns\TextColumn::make($torrentField)->formatStateUsing(function ($state) use ($taxonomyList, $torrentField) { return $taxonomyList[$torrentField]->get($state); }); @@ -121,8 +121,8 @@ class SecondIconResource extends Resource { static $taxonomyList = []; if (empty($taxonomyList)) { - foreach (SearchBox::$taxonomies as $torrentField => $tableName) { - $taxonomyList[$torrentField] = NexusDB::table($tableName)->pluck('name', 'id'); + foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) { + $taxonomyList[$torrentField] = NexusDB::table($taxonomyTableModel['table'])->pluck('name', 'id'); } } return $taxonomyList; diff --git a/app/Filament/Resources/Section/SecondIconResource/Pages/EditSecondIcon.php b/app/Filament/Resources/Section/SecondIconResource/Pages/EditSecondIcon.php index d203b001..59fe2eef 100644 --- a/app/Filament/Resources/Section/SecondIconResource/Pages/EditSecondIcon.php +++ b/app/Filament/Resources/Section/SecondIconResource/Pages/EditSecondIcon.php @@ -2,6 +2,7 @@ namespace App\Filament\Resources\Section\SecondIconResource\Pages; +use App\Filament\RedirectIndexTrait; use App\Filament\Resources\Section\SecondIconResource; use App\Models\SearchBox; use App\Models\SecondIcon; @@ -10,6 +11,8 @@ use Filament\Resources\Pages\EditRecord; class EditSecondIcon extends EditRecord { + use RedirectIndexTrait; + protected static string $resource = SecondIconResource::class; protected function getActions(): array @@ -27,7 +30,7 @@ class EditSecondIcon extends EditRecord protected function mutateFormDataBeforeFill(array $data): array { $mode = $data['mode']; - foreach (SearchBox::$taxonomies as $torrentField => $table) { + foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) { $taxonomyValue = $data[$torrentField] ?? null; unset($data[$torrentField]); $data[$torrentField][$mode] = $taxonomyValue; diff --git a/app/Models/SearchBox.php b/app/Models/SearchBox.php index 7c6fdc68..06950b86 100644 --- a/app/Models/SearchBox.php +++ b/app/Models/SearchBox.php @@ -44,13 +44,13 @@ class SearchBox extends NexusModel const EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST = 'display_seed_box_icon_on_torrent_list'; public static array $taxonomies = [ - 'source' => 'sources', - 'medium' => 'media', - 'codec' => 'codecs', - 'audiocodec' => 'audiocodecs', - 'standard' => 'standards', - 'processing' => 'processings', - 'team' => 'teams', + 'source' => ['table' => 'sources', 'model' => Source::class], + 'medium' => ['table' => 'media', 'model' => Media::class], + 'codec' => ['table' => 'codecs', 'model' => Codec::class], + 'audiocodec' => ['table' => 'audiocodecs', 'model' => AudioCodec::class], + 'standard' => ['table' => 'standards', 'model' => Standard::class], + 'processing' => ['table' => 'processings', 'model' => Processing::class], + 'team' => ['table' => 'teams', 'model' => Team::class] ]; public static array $extras = [ @@ -143,7 +143,7 @@ class SearchBox extends NexusModel if (!$searchBox instanceof self) { $searchBox = self::get(intval($searchBox)); } - $table = self::$taxonomies[$torrentField]; + $table = self::$taxonomies[$torrentField]['table']; return NexusDB::table($table)->where(function (Builder $query) use ($searchBox) { return $query->where('mode', $searchBox->id)->orWhere('mode', 0); })->get(); diff --git a/app/Models/SecondIcon.php b/app/Models/SecondIcon.php index 32b174ac..2e3e0140 100644 --- a/app/Models/SecondIcon.php +++ b/app/Models/SecondIcon.php @@ -14,7 +14,7 @@ class SecondIcon extends NexusModel public static function formatFormData(array $data): array { - foreach (SearchBox::$taxonomies as $torrentField => $table) { + foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) { $mode = $data['mode']; if ($mode === null || empty($data[$torrentField][$mode])) { unset($data[$torrentField]); diff --git a/app/Repositories/SearchBoxRepository.php b/app/Repositories/SearchBoxRepository.php index 27b7d10d..fdf6972e 100644 --- a/app/Repositories/SearchBoxRepository.php +++ b/app/Repositories/SearchBoxRepository.php @@ -119,7 +119,7 @@ class SearchBoxRepository extends BaseRepository $searchBoxList = SearchBox::query()->get(); foreach ($searchBoxList as $searchBox) { $taxonomies = []; - foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTable) { + foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) { $searchBoxField = "show" . $torrentField; if ($searchBox->showsubcat && $searchBox->{$searchBoxField}) { $taxonomies[] = [ @@ -154,7 +154,7 @@ class SearchBoxRepository extends BaseRepository } } } else { - foreach (SearchBox::$taxonomies as $torrentField => $table) { + foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) { $select = $this->buildTaxonomySelect($searchBox, $torrentField, $torrentInfo); if ($select) { $results[] = $select; @@ -180,7 +180,7 @@ class SearchBoxRepository extends BaseRepository } } } else { - foreach (SearchBox::$taxonomies as $torrentField => $table) { + foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) { $taxonomy = $this->getTaxonomyInfo($searchBox, $torrentWithTaxonomy, $torrentField); if ($taxonomy) { $results[] = $taxonomy; @@ -208,7 +208,7 @@ class SearchBoxRepository extends BaseRepository $searchBoxId = $searchBox->id; $searchBoxField = "show" . $torrentField; if ($searchBox->showsubcat && $searchBox->{$searchBoxField}) { - $table = SearchBox::$taxonomies[$torrentField]; + $table = SearchBox::$taxonomies[$torrentField]['table']; $select = sprintf("%s: ", $searchBox->getTaxonomyLabel($torrentField)); $select .= sprintf('", + $checkPrefix, nexus_trans('nexus.select_all'), $checkPrefix, $checkPrefix, nexus_trans('nexus.select_all'), nexus_trans('nexus.unselect_all') + ); } - $icon = $item->icon; - $backgroundImagePath = sprintf('pic/category/%s/%s/%s%s', $searchBox->name, trim($icon->folder, '/'), $icon->multilang == 'yes' ? "$lang/" : "", $item->image); $td = << - - {$item->name} + $tdContent TD; $html .= $td; @@ -6067,29 +6088,46 @@ TD; $namePrefix = $torrentField; } $html .= sprintf('%s', $searchBox->getTaxonomyLabel($torrentField)); - $taxonomyChunks = \Nexus\Database\NexusDB::table($tableName) + /** @var \Illuminate\DataBase\Eloquent\Collection $taxonomyCollection */ + $taxonomyCollection = \Nexus\Database\NexusDB::table($tableName) ->where(function (\Illuminate\Database\Query\Builder $query) use ($mode) { return $query->where('mode', $mode)->orWhere('mode', 0); }) ->orderBy('sort_index', 'asc') ->orderBy('id', 'asc') ->get() - ->chunk($searchBox->catsperrow); + ; + $modelName = \App\Models\SearchBox::$taxonomies[$torrentField]['model']; + $checkPrefix = $torrentField; + if (!empty($options['select_unselect'])) { + $taxonomyCollection->push(new $modelName(['mode' => -1])); + } + $taxonomyChunks = $taxonomyCollection->chunk($searchBox->catsperrow); foreach ($taxonomyChunks as $chunk) { $html .= ''; foreach ($chunk as $item) { - if ($taxonomyHrefPrefix) { - $afterInput = sprintf('%s', $taxonomyHrefPrefix, $namePrefix, $item->id, $item->name); + if ($item->mode != -1) { + if ($taxonomyHrefPrefix) { + $afterInput = sprintf('%s', $taxonomyHrefPrefix, $namePrefix, $item->id, $item->name); + } else { + $afterInput = $item->name; + } + $checked = ''; + if (str_contains($checkedValues, "[{$namePrefix}{$item->id}]") || str_contains($checkedValues, "{$namePrefix}{$item->id}=1")) { + $checked = ' checked'; + } + $tdContent = <<$afterInput +TDCONTENT; } else { - $afterInput = $item->name; - } - $checked = ''; - if (str_contains($checkedValues, "[{$namePrefix}{$item->id}]") || str_contains($checkedValues, "{$namePrefix}{$item->id}=1")) { - $checked = ' checked'; + $tdContent = sprintf( + "", + $checkPrefix, nexus_trans('nexus.select_all'), $checkPrefix, $checkPrefix, nexus_trans('nexus.select_all'), nexus_trans('nexus.unselect_all') + ); } $td = << - + $tdContent TD; $html .= $td; diff --git a/public/torrents.php b/public/torrents.php index 6bc9b2ff..e48040b6 100644 --- a/public/torrents.php +++ b/public/torrents.php @@ -983,7 +983,7 @@ if ($allsec != 1 || $enablespecial != 'yes'){ //do not print searchbox if showin // } // ?> - + true])?> diff --git a/resources/lang/en/label.php b/resources/lang/en/label.php index 851405d2..2fc1adef 100644 --- a/resources/lang/en/label.php +++ b/resources/lang/en/label.php @@ -303,7 +303,10 @@ When icon_pack_folder='nanosofts/' multi-lang='no' second_icon='yes' -you should put a normal icon file for movies (e.g. movies.png) in 'pic/category/chd/nanosofts/' and an additional icon file (e.g. 'bdh264.png') in 'pic/category/chd/nanosofts/additional/'.", +you should put a normal icon file for movies (e.g. movies.png) in 'pic/category/chd/nanosofts/' and an additional icon file (e.g. 'bdh264.png') in 'pic/category/chd/nanosofts/additional/'. + +Note: In 1.8, the 'searchbox_name' part can be omitted, i.e. the rule is 'pic/category/icon_pack_folder[language_short_name/].' +", ], 'second_icon' => [ 'label' => 'Second icon', diff --git a/resources/lang/zh_CN/label.php b/resources/lang/zh_CN/label.php index 144bc75d..956e893c 100644 --- a/resources/lang/zh_CN/label.php +++ b/resources/lang/zh_CN/label.php @@ -303,7 +303,10 @@ return [ 图标文件夹='nanosofts/' 多语言='否' 第二图标='是' -你应该将一个电影类型的图标(如'movies.png')文件放入'pic/category/chd/nanosofts/',将一个第二图标(如'bdh264.png')放入'pic/category/chd/nanosofts/additional/'。", +你应该将一个电影类型的图标(如'movies.png')文件放入'pic/category/chd/nanosofts/',将一个第二图标(如'bdh264.png')放入'pic/category/chd/nanosofts/additional/'。 + +注意:在 1.8 中,可以省略'分类模式名字'这一部分,即规则是'pic/category/图标文件夹[语言缩写/]'。 +", ], 'second_icon' => [ 'label' => '第二图标', diff --git a/resources/lang/zh_CN/nexus.php b/resources/lang/zh_CN/nexus.php index a885fc86..345c5645 100644 --- a/resources/lang/zh_CN/nexus.php +++ b/resources/lang/zh_CN/nexus.php @@ -8,4 +8,6 @@ return [ 'time_units' => [ 'week' => '周', ], + 'select_all' => '全选', + 'unselect_all' => '全不选', ]; diff --git a/resources/lang/zh_TW/label.php b/resources/lang/zh_TW/label.php index 32dd6e84..1d9cc33d 100644 --- a/resources/lang/zh_TW/label.php +++ b/resources/lang/zh_TW/label.php @@ -299,7 +299,10 @@ return [ 圖標文件夾='nanosofts/' 多語言='否' 第二圖標='是' -你應該將一個電影類型的圖標(如'movies.png')文件放入'pic/category/chd/nanosofts/',將一個第二圖標(如'bdh264.png')放入'pic/category/chd/nanosofts/additional/'。", +你應該將一個電影類型的圖標(如'movies.png')文件放入'pic/category/chd/nanosofts/',將一個第二圖標(如'bdh264.png')放入'pic/category/chd/nanosofts/additional/'。 + +註意:在 1.8 中,可以省略'分類模式名字'這一部分,即規則是'pic/category/圖標文件夾[語言縮寫/]'。 +", ], 'second_icon' => [ 'label' => '第二圖標',