mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
add searchbox select unselect
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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]);
|
||||
|
||||
@@ -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("<b>%s: </b>", $searchBox->getTaxonomyLabel($torrentField));
|
||||
$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'));
|
||||
@@ -242,7 +242,7 @@ class SearchBoxRepository extends BaseRepository
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach (SearchBox::$taxonomies as $torrentField => $table) {
|
||||
foreach (SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) {
|
||||
$select = $this->buildTaxonomyFormSchema($searchBox, $torrentField);
|
||||
if ($select) {
|
||||
$results[] = $select;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
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('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||
|
||||
@@ -6021,14 +6021,14 @@ function build_search_box_category_table($mode, $checkboxValue, $categoryHrefPre
|
||||
$torrentField = $taxonomyLabelInfo["torrent_field"];
|
||||
$showField = "show" . $torrentField;
|
||||
if ($searchBox->{$showField}) {
|
||||
$withTaxonomies[$torrentField] = \App\Models\SearchBox::$taxonomies[$torrentField];
|
||||
$withTaxonomies[$torrentField] = \App\Models\SearchBox::$taxonomies[$torrentField]['table'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach (\App\Models\SearchBox::$taxonomies as $torrentField => $taxonomyTable) {
|
||||
foreach (\App\Models\SearchBox::$taxonomies as $torrentField => $taxonomyTableModel) {
|
||||
$showField = "show" . $torrentField;
|
||||
if ($searchBox->{$showField}) {
|
||||
$withTaxonomies[$torrentField] = $taxonomyTable;
|
||||
$withTaxonomies[$torrentField] = $taxonomyTableModel['table'];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6039,20 +6039,41 @@ function build_search_box_category_table($mode, $checkboxValue, $categoryHrefPre
|
||||
}
|
||||
//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) {
|
||||
$html .= '<tr>';
|
||||
foreach ($chunk as $item) {
|
||||
$checked = '';
|
||||
if (str_contains($checkedValues, "[cat{$item->id}]") || str_contains($checkedValues, "cat{$item->id}=1")) {
|
||||
$checked = " checked";
|
||||
if ($item->mode != -1) {
|
||||
$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 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} />
|
||||
<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
|
||||
</td>
|
||||
TD;
|
||||
$html .= $td;
|
||||
@@ -6067,29 +6088,46 @@ TD;
|
||||
$namePrefix = $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) {
|
||||
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 .= '<tr>';
|
||||
foreach ($chunk as $item) {
|
||||
if ($taxonomyHrefPrefix) {
|
||||
$afterInput = sprintf('<a href="%s%s=%s">%s</a>', $taxonomyHrefPrefix, $namePrefix, $item->id, $item->name);
|
||||
if ($item->mode != -1) {
|
||||
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 {
|
||||
$afterInput = $item->name;
|
||||
}
|
||||
$checked = '';
|
||||
if (str_contains($checkedValues, "[{$namePrefix}{$item->id}]") || str_contains($checkedValues, "{$namePrefix}{$item->id}=1")) {
|
||||
$checked = ' checked';
|
||||
$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')
|
||||
);
|
||||
}
|
||||
$td = <<<TD
|
||||
<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;
|
||||
$html .= $td;
|
||||
|
||||
@@ -983,7 +983,7 @@ if ($allsec != 1 || $enablespecial != 'yes'){ //do not print searchbox if showin
|
||||
// }
|
||||
// ?>
|
||||
<!-- </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 class="rowfollow" valign="middle">
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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' => '第二图标',
|
||||
|
||||
@@ -8,4 +8,6 @@ return [
|
||||
'time_units' => [
|
||||
'week' => '周',
|
||||
],
|
||||
'select_all' => '全选',
|
||||
'unselect_all' => '全不选',
|
||||
];
|
||||
|
||||
@@ -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' => '第二圖標',
|
||||
|
||||
Reference in New Issue
Block a user