add searchbox select unselect

This commit is contained in:
xiaomlove
2022-11-14 19:02:42 +08:00
parent 81c3b4fa24
commit 96a1146db6
14 changed files with 100 additions and 44 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Filament\Resources\Section; namespace App\Filament\Resources\Section;
use App\Filament\OptionsTrait; use App\Filament\OptionsTrait;
use App\Filament\RedirectIndexTrait;
use App\Filament\Resources\Section\IconResource\Pages; use App\Filament\Resources\Section\IconResource\Pages;
use App\Filament\Resources\Section\IconResource\RelationManagers; use App\Filament\Resources\Section\IconResource\RelationManagers;
use App\Models\Icon; use App\Models\Icon;

View File

@@ -2,12 +2,15 @@
namespace App\Filament\Resources\Section\IconResource\Pages; namespace App\Filament\Resources\Section\IconResource\Pages;
use App\Filament\RedirectIndexTrait;
use App\Filament\Resources\Section\IconResource; use App\Filament\Resources\Section\IconResource;
use Filament\Pages\Actions; use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord; use Filament\Resources\Pages\EditRecord;
class EditIcon extends EditRecord class EditIcon extends EditRecord
{ {
use RedirectIndexTrait;
protected static string $resource = IconResource::class; protected static string $resource = IconResource::class;
protected static string $view = 'filament.resources.system.category-icon-resource.pages.edit-record'; protected static string $view = 'filament.resources.system.category-icon-resource.pages.edit-record';

View File

@@ -98,7 +98,7 @@ class SecondIconResource extends Resource
Tables\Columns\TextColumn::make('class_name')->label(__('label.second_icon.class_name')), Tables\Columns\TextColumn::make('class_name')->label(__('label.second_icon.class_name')),
]; ];
$taxonomyList = self::listTaxonomy(); $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) { $columns[] = Tables\Columns\TextColumn::make($torrentField)->formatStateUsing(function ($state) use ($taxonomyList, $torrentField) {
return $taxonomyList[$torrentField]->get($state); return $taxonomyList[$torrentField]->get($state);
}); });
@@ -121,8 +121,8 @@ class SecondIconResource extends Resource
{ {
static $taxonomyList = []; static $taxonomyList = [];
if (empty($taxonomyList)) { if (empty($taxonomyList)) {
foreach (SearchBox::$taxonomies as $torrentField => $tableName) { foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) {
$taxonomyList[$torrentField] = NexusDB::table($tableName)->pluck('name', 'id'); $taxonomyList[$torrentField] = NexusDB::table($taxonomyTableModel['table'])->pluck('name', 'id');
} }
} }
return $taxonomyList; return $taxonomyList;

View File

@@ -2,6 +2,7 @@
namespace App\Filament\Resources\Section\SecondIconResource\Pages; namespace App\Filament\Resources\Section\SecondIconResource\Pages;
use App\Filament\RedirectIndexTrait;
use App\Filament\Resources\Section\SecondIconResource; use App\Filament\Resources\Section\SecondIconResource;
use App\Models\SearchBox; use App\Models\SearchBox;
use App\Models\SecondIcon; use App\Models\SecondIcon;
@@ -10,6 +11,8 @@ use Filament\Resources\Pages\EditRecord;
class EditSecondIcon extends EditRecord class EditSecondIcon extends EditRecord
{ {
use RedirectIndexTrait;
protected static string $resource = SecondIconResource::class; protected static string $resource = SecondIconResource::class;
protected function getActions(): array protected function getActions(): array
@@ -27,7 +30,7 @@ class EditSecondIcon extends EditRecord
protected function mutateFormDataBeforeFill(array $data): array protected function mutateFormDataBeforeFill(array $data): array
{ {
$mode = $data['mode']; $mode = $data['mode'];
foreach (SearchBox::$taxonomies as $torrentField => $table) { foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) {
$taxonomyValue = $data[$torrentField] ?? null; $taxonomyValue = $data[$torrentField] ?? null;
unset($data[$torrentField]); unset($data[$torrentField]);
$data[$torrentField][$mode] = $taxonomyValue; $data[$torrentField][$mode] = $taxonomyValue;

View File

@@ -44,13 +44,13 @@ class SearchBox extends NexusModel
const EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST = 'display_seed_box_icon_on_torrent_list'; const EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST = 'display_seed_box_icon_on_torrent_list';
public static array $taxonomies = [ public static array $taxonomies = [
'source' => 'sources', 'source' => ['table' => 'sources', 'model' => Source::class],
'medium' => 'media', 'medium' => ['table' => 'media', 'model' => Media::class],
'codec' => 'codecs', 'codec' => ['table' => 'codecs', 'model' => Codec::class],
'audiocodec' => 'audiocodecs', 'audiocodec' => ['table' => 'audiocodecs', 'model' => AudioCodec::class],
'standard' => 'standards', 'standard' => ['table' => 'standards', 'model' => Standard::class],
'processing' => 'processings', 'processing' => ['table' => 'processings', 'model' => Processing::class],
'team' => 'teams', 'team' => ['table' => 'teams', 'model' => Team::class]
]; ];
public static array $extras = [ public static array $extras = [
@@ -143,7 +143,7 @@ class SearchBox extends NexusModel
if (!$searchBox instanceof self) { if (!$searchBox instanceof self) {
$searchBox = self::get(intval($searchBox)); $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 NexusDB::table($table)->where(function (Builder $query) use ($searchBox) {
return $query->where('mode', $searchBox->id)->orWhere('mode', 0); return $query->where('mode', $searchBox->id)->orWhere('mode', 0);
})->get(); })->get();

View File

@@ -14,7 +14,7 @@ class SecondIcon extends NexusModel
public static function formatFormData(array $data): array public static function formatFormData(array $data): array
{ {
foreach (SearchBox::$taxonomies as $torrentField => $table) { foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) {
$mode = $data['mode']; $mode = $data['mode'];
if ($mode === null || empty($data[$torrentField][$mode])) { if ($mode === null || empty($data[$torrentField][$mode])) {
unset($data[$torrentField]); unset($data[$torrentField]);

View File

@@ -119,7 +119,7 @@ class SearchBoxRepository extends BaseRepository
$searchBoxList = SearchBox::query()->get(); $searchBoxList = SearchBox::query()->get();
foreach ($searchBoxList as $searchBox) { foreach ($searchBoxList as $searchBox) {
$taxonomies = []; $taxonomies = [];
foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTable) { foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) {
$searchBoxField = "show" . $torrentField; $searchBoxField = "show" . $torrentField;
if ($searchBox->showsubcat && $searchBox->{$searchBoxField}) { if ($searchBox->showsubcat && $searchBox->{$searchBoxField}) {
$taxonomies[] = [ $taxonomies[] = [
@@ -154,7 +154,7 @@ class SearchBoxRepository extends BaseRepository
} }
} }
} else { } else {
foreach (SearchBox::$taxonomies as $torrentField => $table) { foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) {
$select = $this->buildTaxonomySelect($searchBox, $torrentField, $torrentInfo); $select = $this->buildTaxonomySelect($searchBox, $torrentField, $torrentInfo);
if ($select) { if ($select) {
$results[] = $select; $results[] = $select;
@@ -180,7 +180,7 @@ class SearchBoxRepository extends BaseRepository
} }
} }
} else { } else {
foreach (SearchBox::$taxonomies as $torrentField => $table) { foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) {
$taxonomy = $this->getTaxonomyInfo($searchBox, $torrentWithTaxonomy, $torrentField); $taxonomy = $this->getTaxonomyInfo($searchBox, $torrentWithTaxonomy, $torrentField);
if ($taxonomy) { if ($taxonomy) {
$results[] = $taxonomy; $results[] = $taxonomy;
@@ -208,7 +208,7 @@ class SearchBoxRepository extends BaseRepository
$searchBoxId = $searchBox->id; $searchBoxId = $searchBox->id;
$searchBoxField = "show" . $torrentField; $searchBoxField = "show" . $torrentField;
if ($searchBox->showsubcat && $searchBox->{$searchBoxField}) { if ($searchBox->showsubcat && $searchBox->{$searchBoxField}) {
$table = SearchBox::$taxonomies[$torrentField]; $table = SearchBox::$taxonomies[$torrentField]['table'];
$select = sprintf("<b>%s: </b>", $searchBox->getTaxonomyLabel($torrentField)); $select = sprintf("<b>%s: </b>", $searchBox->getTaxonomyLabel($torrentField));
$select .= sprintf('<select name="%s_sel[%s]" data-mode="%s_%s">',$torrentField, $searchBoxId, $torrentField, $searchBoxId); $select .= sprintf('<select name="%s_sel[%s]" data-mode="%s_%s">',$torrentField, $searchBoxId, $torrentField, $searchBoxId);
$select .= sprintf('<option value="%s">%s</option>', 0, nexus_trans('nexus.select_one_please')); $select .= sprintf('<option value="%s">%s</option>', 0, nexus_trans('nexus.select_one_please'));
@@ -242,7 +242,7 @@ class SearchBoxRepository extends BaseRepository
} }
} }
} else { } else {
foreach (SearchBox::$taxonomies as $torrentField => $table) { foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) {
$select = $this->buildTaxonomyFormSchema($searchBox, $torrentField); $select = $this->buildTaxonomyFormSchema($searchBox, $torrentField);
if ($select) { if ($select) {
$results[] = $select; $results[] = $select;

View File

@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.0');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-11-08'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2022-11-14');
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");

View File

@@ -6021,14 +6021,14 @@ function build_search_box_category_table($mode, $checkboxValue, $categoryHrefPre
$torrentField = $taxonomyLabelInfo["torrent_field"]; $torrentField = $taxonomyLabelInfo["torrent_field"];
$showField = "show" . $torrentField; $showField = "show" . $torrentField;
if ($searchBox->{$showField}) { if ($searchBox->{$showField}) {
$withTaxonomies[$torrentField] = \App\Models\SearchBox::$taxonomies[$torrentField]; $withTaxonomies[$torrentField] = \App\Models\SearchBox::$taxonomies[$torrentField]['table'];
} }
} }
} else { } else {
foreach (\App\Models\SearchBox::$taxonomies as $torrentField => $taxonomyTable) { foreach (\App\Models\SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) {
$showField = "show" . $torrentField; $showField = "show" . $torrentField;
if ($searchBox->{$showField}) { if ($searchBox->{$showField}) {
$withTaxonomies[$torrentField] = $taxonomyTable; $withTaxonomies[$torrentField] = $taxonomyTableModel['table'];
} }
} }
} }
@@ -6039,20 +6039,41 @@ function build_search_box_category_table($mode, $checkboxValue, $categoryHrefPre
} }
//Category //Category
$html .= sprintf('<tr><td class="embedded" align="left">%s</td></tr>', nexus_trans('label.search_box.category')); $html .= sprintf('<tr><td class="embedded" align="left">%s</td></tr>', nexus_trans('label.search_box.category'));
$categoryChunks = $searchBox->categories->chunk($searchBox->catsperrow); /** @var \Illuminate\DataBase\Eloquent\Collection $categoryCollection */
$categoryCollection = $searchBox->categories;
if (!empty($options['select_unselect'])) {
$categoryCollection->push(new \App\Models\Category(['mode' => -1]));
}
$categoryChunks = $categoryCollection->chunk($searchBox->catsperrow);
$checkPrefix = 'cat';
foreach ($categoryChunks as $chunk) { foreach ($categoryChunks as $chunk) {
$html .= '<tr>'; $html .= '<tr>';
foreach ($chunk as $item) { foreach ($chunk as $item) {
$checked = ''; if ($item->mode != -1) {
if (str_contains($checkedValues, "[cat{$item->id}]") || str_contains($checkedValues, "cat{$item->id}=1")) { $checked = '';
$checked = " checked"; if (str_contains($checkedValues, "[cat{$item->id}]") || str_contains($checkedValues, "cat{$item->id}=1")) {
$checked = " checked";
}
$icon = $item->icon;
$iconFolder = trim($icon->folder, '/');
if (is_dir(getFullDirectory("pic/category/$iconFolder"))) {
$backgroundImagePath = sprintf('pic/category/%s/%s%s', $iconFolder, $icon->multilang == 'yes' ? "$lang/" : "", $item->image);
} else {
$backgroundImagePath = sprintf('pic/category/%s/%s/%s%s', $searchBox->name, $iconFolder, $icon->multilang == 'yes' ? "$lang/" : "", $item->image);
}
$tdContent = <<<TDCONTENT
<input type="checkbox" id="cat{$item->id}" name="cat{$item->id}" value="{$checkboxValue}"{$checked} />
<a href="{$categoryHrefPrefix}cat={$item->id}"><img src="pic/cattrans.gif" class="{$item->class_name}" alt="{$item->name}" title="{$item->name}" style="background-image: url({$backgroundImagePath})" /></a>
TDCONTENT;
} else {
$tdContent = sprintf(
"<input name=\"%s_check\" value=\"%s\" class=\"btn medium\" type=\"button\" onclick=\"javascript:SetChecked('%s','%s_check','%s','%s',-1,10)\">",
$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 = <<<TD $td = <<<TD
<td align="left" class="bottom" style="padding-bottom: 4px;padding-left: {$searchBox->catpadding}px"> <td align="left" class="bottom" style="padding-bottom: 4px;padding-left: {$searchBox->catpadding}px">
<input type="checkbox" id="cat{$item->id}" name="cat{$item->id}" value="{$checkboxValue}"{$checked} /> $tdContent
<a href="{$categoryHrefPrefix}cat={$item->id}"><img src="pic/cattrans.gif" class="{$item->class_name}" alt="{$item->name}" title="{$item->name}" style="background-image: url({$backgroundImagePath})" /></a>
</td> </td>
TD; TD;
$html .= $td; $html .= $td;
@@ -6067,29 +6088,46 @@ TD;
$namePrefix = $torrentField; $namePrefix = $torrentField;
} }
$html .= sprintf('<tr><td class="embedded" align="left">%s</td></tr>', $searchBox->getTaxonomyLabel($torrentField)); $html .= sprintf('<tr><td class="embedded" align="left">%s</td></tr>', $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) { ->where(function (\Illuminate\Database\Query\Builder $query) use ($mode) {
return $query->where('mode', $mode)->orWhere('mode', 0); return $query->where('mode', $mode)->orWhere('mode', 0);
}) })
->orderBy('sort_index', 'asc') ->orderBy('sort_index', 'asc')
->orderBy('id', 'asc') ->orderBy('id', 'asc')
->get() ->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) { foreach ($taxonomyChunks as $chunk) {
$html .= '<tr>'; $html .= '<tr>';
foreach ($chunk as $item) { foreach ($chunk as $item) {
if ($taxonomyHrefPrefix) { if ($item->mode != -1) {
$afterInput = sprintf('<a href="%s%s=%s">%s</a>', $taxonomyHrefPrefix, $namePrefix, $item->id, $item->name); if ($taxonomyHrefPrefix) {
$afterInput = sprintf('<a href="%s%s=%s">%s</a>', $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 = <<<TDCONTENT
<label><input type="checkbox" id="{$namePrefix}{$item->id}" name="{$namePrefix}{$item->id}" value="{$checkboxValue}"{$checked} />$afterInput</label>
TDCONTENT;
} else { } else {
$afterInput = $item->name; $tdContent = sprintf(
} "<input name=\"%s_check\" value=\"%s\" class=\"btn medium\" type=\"button\" onclick=\"javascript:SetChecked('%s','%s_check','%s','%s',-1,10)\">",
$checked = ''; $checkPrefix, nexus_trans('nexus.select_all'), $checkPrefix, $checkPrefix, nexus_trans('nexus.select_all'), nexus_trans('nexus.unselect_all')
if (str_contains($checkedValues, "[{$namePrefix}{$item->id}]") || str_contains($checkedValues, "{$namePrefix}{$item->id}=1")) { );
$checked = ' checked';
} }
$td = <<<TD $td = <<<TD
<td align="left" class="bottom" style="padding-bottom: 4px;padding-left: {$searchBox->catpadding}px"> <td align="left" class="bottom" style="padding-bottom: 4px;padding-left: {$searchBox->catpadding}px">
<label><input type="checkbox" id="{$namePrefix}{$item->id}" name="{$namePrefix}{$item->id}" value="{$checkboxValue}"{$checked} />$afterInput</label> $tdContent
</td> </td>
TD; TD;
$html .= $td; $html .= $td;

View File

@@ -983,7 +983,7 @@ if ($allsec != 1 || $enablespecial != 'yes'){ //do not print searchbox if showin
// } // }
// ?> // ?>
<!-- </table>--> <!-- </table>-->
<?php echo build_search_box_category_table($sectiontype, '1', '?', '?', 0, $_SERVER['QUERY_STRING'])?> <?php echo build_search_box_category_table($sectiontype, '1', '?', '?', 0, $_SERVER['QUERY_STRING'], ['select_unselect' => true])?>
</td> </td>
<td class="rowfollow" valign="middle"> <td class="rowfollow" valign="middle">

View File

@@ -303,7 +303,10 @@ When
icon_pack_folder='nanosofts/' icon_pack_folder='nanosofts/'
multi-lang='no' multi-lang='no'
second_icon='yes' 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' => [ 'second_icon' => [
'label' => 'Second icon', 'label' => 'Second icon',

View File

@@ -303,7 +303,10 @@ return [
图标文件夹='nanosofts/' 图标文件夹='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' => [ 'second_icon' => [
'label' => '第二图标', 'label' => '第二图标',

View File

@@ -8,4 +8,6 @@ return [
'time_units' => [ 'time_units' => [
'week' => '周', 'week' => '周',
], ],
'select_all' => '全选',
'unselect_all' => '全不选',
]; ];

View File

@@ -299,7 +299,10 @@ return [
圖標文件夾='nanosofts/' 圖標文件夾='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' => [ 'second_icon' => [
'label' => '第二圖標', 'label' => '第二圖標',