diff --git a/app/Filament/Resources/System/CategoryIconResource/Pages/CreateCategoryIcon.php b/app/Filament/Resources/System/CategoryIconResource/Pages/CreateCategoryIcon.php
index 85e78604..bc5e5098 100644
--- a/app/Filament/Resources/System/CategoryIconResource/Pages/CreateCategoryIcon.php
+++ b/app/Filament/Resources/System/CategoryIconResource/Pages/CreateCategoryIcon.php
@@ -10,6 +10,8 @@ class CreateCategoryIcon extends CreateRecord
{
protected static string $resource = CategoryIconResource::class;
+ protected static string $view = 'filament.resources.system.category-icon-resource.pages.create-record';
+
protected function mutateFormDataBeforeCreate(array $data): array
{
return array_filter($data);
@@ -19,4 +21,11 @@ class CreateCategoryIcon extends CreateRecord
{
return static::$resource::getUrl('index');
}
+
+ protected function getViewData(): array
+ {
+ return [
+ 'desc' => nexus_trans('label.icon.desc')
+ ];
+ }
}
diff --git a/app/Filament/Resources/System/CategoryIconResource/Pages/EditCategoryIcon.php b/app/Filament/Resources/System/CategoryIconResource/Pages/EditCategoryIcon.php
index 0feb47a9..bcace12a 100644
--- a/app/Filament/Resources/System/CategoryIconResource/Pages/EditCategoryIcon.php
+++ b/app/Filament/Resources/System/CategoryIconResource/Pages/EditCategoryIcon.php
@@ -10,6 +10,8 @@ class EditCategoryIcon extends EditRecord
{
protected static string $resource = CategoryIconResource::class;
+ protected static string $view = 'filament.resources.system.category-icon-resource.pages.edit-record';
+
protected function getActions(): array
{
return [
@@ -26,4 +28,11 @@ class EditCategoryIcon extends EditRecord
{
return static::$resource::getUrl('index');
}
+
+ protected function getViewData(): array
+ {
+ return [
+ 'desc' => nexus_trans('label.icon.desc')
+ ];
+ }
}
diff --git a/app/Filament/Resources/System/CategoryIconResource/Pages/ListCategoryIcons.php b/app/Filament/Resources/System/CategoryIconResource/Pages/ListCategoryIcons.php
index dab912e4..c834ef39 100644
--- a/app/Filament/Resources/System/CategoryIconResource/Pages/ListCategoryIcons.php
+++ b/app/Filament/Resources/System/CategoryIconResource/Pages/ListCategoryIcons.php
@@ -17,4 +17,11 @@ class ListCategoryIcons extends PageList
Actions\CreateAction::make(),
];
}
+
+ protected function getViewData(): array
+ {
+ return [
+ 'desc' => nexus_trans('label.icon.desc')
+ ];
+ }
}
diff --git a/app/Filament/Resources/System/SectionResource.php b/app/Filament/Resources/System/SectionResource.php
index f2cdfdd4..62a2c1a1 100644
--- a/app/Filament/Resources/System/SectionResource.php
+++ b/app/Filament/Resources/System/SectionResource.php
@@ -79,10 +79,27 @@ class SectionResource extends Resource
,
Forms\Components\Toggle::make('showsubcat')->label(__('label.search_box.showsubcat')),
Forms\Components\Section::make(__('label.search_box.showsubcat'))->schema([
- Forms\Components\Repeater::make('extra.' . SearchBox::EXTRA_TAXONOMY_LABELS)->schema([
- Forms\Components\Select::make('torrent_field')->options(SearchBox::getSubCatOptions())->label(__('label.search_box.torrent_field')),
- Forms\Components\TextInput::make('display_text')->label(__('label.search_box.taxonomy_display_text')),
- ])->label(__('label.search_box.taxonomies'))->columns(2),
+ Forms\Components\Repeater::make('extra.' . SearchBox::EXTRA_TAXONOMY_LABELS)
+ ->schema([
+ Forms\Components\Select::make('torrent_field')->options(SearchBox::getSubCatOptions())->label(__('label.search_box.torrent_field')),
+ Forms\Components\TextInput::make('display_text')->label(__('label.search_box.taxonomy_display_text')),
+ ])
+ ->label(__('label.search_box.taxonomies'))->columns(2)
+ ->rules([
+ function () {
+ return function (string $attribute, $value, \Closure $fail) {
+ $fields = [];
+ foreach ($value as $item) {
+ if (!in_array($item['torrent_field'], $fields)) {
+ $fields[] = $item['torrent_field'];
+ } else {
+ $fail(__('label.search_box.torrent_field_duplicate', ['field' => $item['torrent_field']]));
+ }
+ }
+ };
+ }
+ ])
+ ,
]),
])->columns(3);
}
diff --git a/app/Filament/Resources/System/SectionResource/Pages/CreateSection.php b/app/Filament/Resources/System/SectionResource/Pages/CreateSection.php
index 4baf29a0..12b2035b 100644
--- a/app/Filament/Resources/System/SectionResource/Pages/CreateSection.php
+++ b/app/Filament/Resources/System/SectionResource/Pages/CreateSection.php
@@ -13,16 +13,7 @@ class CreateSection extends CreateRecord
protected function mutateFormDataBeforeCreate(array $data): array
{
- foreach (SearchBox::$subCatFields as $field) {
- $data["show{$field}"] = 0;
- foreach ($data['extra'][SearchBox::EXTRA_TAXONOMY_LABELS] ?? [] as $item) {
- if ($field == $item['torrent_field']) {
- $data["show{$field}"] = 1;
- $data["extra->" . SearchBox::EXTRA_TAXONOMY_LABELS][] = $item;
- }
- }
- }
- return $data;
+ return SearchBox::formatTaxonomyExtra($data);
}
}
diff --git a/app/Filament/Resources/System/SectionResource/Pages/EditSection.php b/app/Filament/Resources/System/SectionResource/Pages/EditSection.php
index 6cc3f2c0..6f586813 100644
--- a/app/Filament/Resources/System/SectionResource/Pages/EditSection.php
+++ b/app/Filament/Resources/System/SectionResource/Pages/EditSection.php
@@ -20,16 +20,7 @@ class EditSection extends EditRecord
protected function mutateFormDataBeforeSave(array $data): array
{
- foreach (SearchBox::$subCatFields as $field) {
- $data["show{$field}"] = 0;
- foreach ($data['extra'][SearchBox::EXTRA_TAXONOMY_LABELS] ?? [] as $item) {
- if ($field == $item['torrent_field']) {
- $data["show{$field}"] = 1;
- $data["extra->" . SearchBox::EXTRA_TAXONOMY_LABELS][] = $item;
- }
- }
- }
- return $data;
+ return SearchBox::formatTaxonomyExtra($data);
}
}
diff --git a/app/Models/SearchBox.php b/app/Models/SearchBox.php
index 9dcd45e8..40cd1746 100644
--- a/app/Models/SearchBox.php
+++ b/app/Models/SearchBox.php
@@ -27,8 +27,14 @@ class SearchBox extends NexusModel
const EXTRA_DISPLAY_COVER_ON_TORRENT_LIST = 'display_cover_on_torrent_list';
const EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST = 'display_seed_box_icon_on_torrent_list';
- public static array $subCatFields = [
- 'source', 'medium', 'codec', 'audiocodec', 'team', 'standard', 'processing'
+ public static array $subCategories = [
+ 'source' => 'surces',
+ 'medium' => 'media',
+ 'codec' => 'codecs',
+ 'audiocodec' => 'audiocodecs',
+ 'team' => 'teams',
+ 'standard' => 'standards',
+ 'processing' => 'processings'
];
public static array $extras = [
@@ -45,9 +51,18 @@ class SearchBox extends NexusModel
return $result;
}
- public static function getTaxonomyDisplayText($field)
+ public static function formatTaxonomyExtra(array $data): array
{
-
+ foreach (self::$subCategories as $field => $table) {
+ $data["show{$field}"] = 0;
+ foreach ($data['extra'][self::EXTRA_TAXONOMY_LABELS] ?? [] as $item) {
+ if ($field == $item['torrent_field']) {
+ $data["show{$field}"] = 1;
+ $data["extra->" . self::EXTRA_TAXONOMY_LABELS][] = $item;
+ }
+ }
+ }
+ return $data;
}
protected function customFields(): Attribute
@@ -60,7 +75,7 @@ class SearchBox extends NexusModel
public static function getSubCatOptions(): array
{
- return array_combine(self::$subCatFields, self::$subCatFields);
+ return array_combine(array_keys(self::$subCategories), array_keys(self::$subCategories));
}
public function categories(): \Illuminate\Database\Eloquent\Relations\HasMany
@@ -115,4 +130,6 @@ class SearchBox extends NexusModel
+
+
}
diff --git a/app/Repositories/SearchBoxRepository.php b/app/Repositories/SearchBoxRepository.php
index 6dd91280..b265e2cf 100644
--- a/app/Repositories/SearchBoxRepository.php
+++ b/app/Repositories/SearchBoxRepository.php
@@ -6,7 +6,9 @@ use App\Models\Icon;
use App\Models\NexusModel;
use App\Models\SearchBox;
use App\Models\SearchBoxField;
+use App\Models\Setting;
use Illuminate\Support\Arr;
+use Nexus\Database\NexusDB;
class SearchBoxRepository extends BaseRepository
{
@@ -100,5 +102,44 @@ class SearchBoxRepository extends BaseRepository
return Icon::query()->find(array_keys($iconIdArr));
}
+ public static function migrateToModeRelated()
+ {
+ $secondIconTable = 'secondicons';
+ $normalId = Setting::get('main.browsecat');
+ $specialId = Setting::get('main.specialcat');
+ $searchBoxList = SearchBox::query()->get();
+ $tables = array_values(SearchBox::$subCategories);
+ foreach ($searchBoxList as $searchBox) {
+ if ($searchBox->id == $normalId) {
+ //all sub categories add `mode` field
+ foreach ($tables as $table) {
+ NexusDB::table($table)->update(['mode' => $normalId]);
+ do_log("update table $table mode = $normalId");
+ }
+ //also second icons
+ NexusDB::table($secondIconTable)->update(['mode' => $normalId]);
+ do_log("update table $secondIconTable mode = $normalId");
+ } elseif ($searchBox->id == $specialId && $specialId != $normalId) {
+ //copy from normal section
+ foreach ($tables as $table) {
+ $sql = sprintf(
+ "insert into `%s` (name, sort_index, mode) select name, sort_index, '%s' from `%s`",
+ $table, $specialId, $table
+ );
+ NexusDB::statement($sql);
+ do_log("copy table $table, $sql");
+ }
+ $fields = array_keys(SearchBox::$subCategories);
+ $fields = array_merge($fields, ['name', 'class_name', 'image']);
+ $fieldStr = implode(', ', $fields);
+ $sql = sprintf(
+ "insert into `%s` (%s, mode) select %s, '%s' from `%s`",
+ $secondIconTable, $fieldStr, $fieldStr, $specialId, $secondIconTable
+ );
+ NexusDB::statement($sql);
+ do_log("copy table $secondIconTable, $sql");
+ }
+ }
+ }
}
diff --git a/database/migrations/2022_09_05_230532_add_mode_to_section_related.php b/database/migrations/2022_09_05_230532_add_mode_to_section_related.php
index a756af50..3a414d88 100644
--- a/database/migrations/2022_09_05_230532_add_mode_to_section_related.php
+++ b/database/migrations/2022_09_05_230532_add_mode_to_section_related.php
@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
private static array $tables = [
- 'sources', 'media', 'standards', 'codecs', 'audiocodecs', 'teams', 'processings'
+ 'sources', 'media', 'standards', 'codecs', 'audiocodecs', 'teams', 'processings', 'secondicons'
];
/**
* Run the migrations.
diff --git a/resources/lang/zh_CN/label.php b/resources/lang/zh_CN/label.php
index e244b276..08b0a17c 100644
--- a/resources/lang/zh_CN/label.php
+++ b/resources/lang/zh_CN/label.php
@@ -247,6 +247,7 @@ return [
'custom_fields_display' => '自定义字段展示',
'custom_fields_display_help' => '使用特殊的标签代表字段的名称和值,如某字段其 Name 为 artist,则它的名称为:<%artist.label%>,它的值为:<%artist.value%>',
'category' => '主分类',
+ 'torrent_field_duplicate' => '种子表字段::field 不能重复使用!',
'taxonomy' => [
'name' => '名称',
'sort_index' => '排序',
@@ -272,5 +273,18 @@ return [
'designer_help' => '此图标集的设计者。',
'comment' => '说明',
'comment_help' => '此图标集的说明。',
+ 'desc' => "你必须将图标文件放入服务器正确的目录才能使得以下设定起作用。将普通的分类图标放入'pic/category/分类模式名字/图标文件夹[语言缩写/]',将第二图标放入'pic/category/分类模式名字/图标文件夹[语言缩写/]additional/'.不明白?参考下面的例子:
+当
+ 分类模式名字='nhd'
+ 图标文件夹='scenetorrents/'
+ 多语言='是'
+ 第二图标='否'
+你应该将一个英语的电影类型的图标(如'movies.png')文件放入'pic/category/nhd/scenetorrents/en/'。
+当
+ 分类模式名字='chd'
+ 图标文件夹='nanosofts/'
+ 多语言='否'
+ 第二图标='是'
+你应该将一个电影类型的图标(如'movies.png')文件放入'pic/category/chd/nanosofts/',将一个第二图标(如'bdh264.png')放入'pic/category/chd/nanosofts/additional/'。",
],
];
diff --git a/resources/views/filament/resources/system/category-icon-resource/pages/create-record.blade.php b/resources/views/filament/resources/system/category-icon-resource/pages/create-record.blade.php
new file mode 100644
index 00000000..9d625d86
--- /dev/null
+++ b/resources/views/filament/resources/system/category-icon-resource/pages/create-record.blade.php
@@ -0,0 +1,17 @@
+
+
+ {!! $desc !!}
+
+ {{ $this->form }}
+
+
+
+
diff --git a/resources/views/filament/resources/system/category-icon-resource/pages/edit-record.blade.php b/resources/views/filament/resources/system/category-icon-resource/pages/edit-record.blade.php
new file mode 100644
index 00000000..e8f49b73
--- /dev/null
+++ b/resources/views/filament/resources/system/category-icon-resource/pages/edit-record.blade.php
@@ -0,0 +1,25 @@
+
+
+ {!! $desc !!}
+
+ {{ $this->form }}
+
+
+
+
+ @if (count($relationManagers = $this->getRelationManagers()))
+
+
+
+ @endif
+