From f68b88f75404441a6673d0312d105ecc4940a365 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Tue, 6 Sep 2022 20:45:29 +0800 Subject: [PATCH] init section --- app/Console/Commands/Test.php | 6 +- .../Resources/System/SectionResource.php | 130 ++++++++++++++++++ .../SectionResource/Pages/CreateSection.php | 27 ++++ .../SectionResource/Pages/EditSection.php | 34 +++++ .../SectionResource/Pages/ListSections.php | 20 +++ app/Models/SearchBox.php | 73 +++++++++- app/Models/Taxonomy.php | 11 ++ app/Models/TorrentCustomField.php | 23 ++++ app/Models/TorrentCustomFieldValue.php | 13 ++ ..._05_230532_add_mode_to_section_related.php | 40 ++++++ ...2_09_05_235445_create_taxonomies_table.php | 38 +++++ ...18_add_section_name_to_searchbox_table.php | 33 +++++ ...4_change_searchbox_field_extra_to_json.php | 32 +++++ nexus/Install/Install.php | 2 +- resources/lang/zh_CN/admin.php | 1 + resources/lang/zh_CN/label.php | 18 +++ 16 files changed, 496 insertions(+), 5 deletions(-) create mode 100644 app/Filament/Resources/System/SectionResource.php create mode 100644 app/Filament/Resources/System/SectionResource/Pages/CreateSection.php create mode 100644 app/Filament/Resources/System/SectionResource/Pages/EditSection.php create mode 100644 app/Filament/Resources/System/SectionResource/Pages/ListSections.php create mode 100644 app/Models/Taxonomy.php create mode 100644 app/Models/TorrentCustomField.php create mode 100644 app/Models/TorrentCustomFieldValue.php create mode 100644 database/migrations/2022_09_05_230532_add_mode_to_section_related.php create mode 100644 database/migrations/2022_09_05_235445_create_taxonomies_table.php create mode 100644 database/migrations/2022_09_06_004318_add_section_name_to_searchbox_table.php create mode 100644 database/migrations/2022_09_06_030324_change_searchbox_field_extra_to_json.php diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 7d629dd5..9ff9217b 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -86,7 +86,11 @@ class Test extends Command */ public function handle() { - + $box = SearchBox::query()->find(6); + $update = [ + 'extra->taxonomy_labels->ss' => '444' + ]; + $box->update($update); } diff --git a/app/Filament/Resources/System/SectionResource.php b/app/Filament/Resources/System/SectionResource.php new file mode 100644 index 00000000..c2038194 --- /dev/null +++ b/app/Filament/Resources/System/SectionResource.php @@ -0,0 +1,130 @@ +schema([ + Forms\Components\TextInput::make('section_name')->label(__('label.search_box.section_name'))->required(), + Forms\Components\TextInput::make('name')->label(__('label.search_box.name'))->rules('alpha_dash')->required(), + Forms\Components\TextInput::make('catsperrow') + ->label(__('label.search_box.catsperrow')) + ->helperText(__('label.search_box.catsperrow_help')) + ->integer() + , + Forms\Components\TextInput::make('catpadding') + ->label(__('label.search_box.catpadding')) + ->helperText(__('label.search_box.catpadding_help')) + ->integer() + , + Forms\Components\CheckboxList::make('custom_fields') + ->options(TorrentCustomField::getCheckboxOptions()) + ->label(__('label.search_box.custom_fields')) + , + Forms\Components\TextInput::make('custom_fields_display_name') + ->label(__('label.search_box.custom_fields_display_name')) + , + Forms\Components\Textarea::make('custom_fields_display') + ->label(__('label.search_box.custom_fields_display')) + ->helperText(__('label.search_box.custom_fields_display_help')) + ->columnSpan(['sm' => 'full']) + , + Forms\Components\Toggle::make('is_default') + ->label(__('label.search_box.is_default')) + ->columnSpan(['sm' => 'full']) + , + 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), + ]), + ])->columns(3); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('id'), + Tables\Columns\TextColumn::make('section_name')->label(__('label.search_box.section_name')), + Tables\Columns\TextColumn::make('name')->label(__('label.search_box.name')), + Tables\Columns\BooleanColumn::make('is_default')->label(__('label.search_box.is_default')), + Tables\Columns\BooleanColumn::make('showsubcat')->label(__('label.search_box.showsubcat')), + Tables\Columns\BooleanColumn::make('showsource'), + Tables\Columns\BooleanColumn::make('showmedium'), + Tables\Columns\BooleanColumn::make('showcodec'), + Tables\Columns\BooleanColumn::make('showstandard'), + Tables\Columns\BooleanColumn::make('showprocessing'), + Tables\Columns\BooleanColumn::make('showteam'), + Tables\Columns\BooleanColumn::make('showaudiocodec'), + ]) + ->filters([ + // + ]) + ->actions([ + Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make(), + ]) + ->bulkActions([ + Tables\Actions\DeleteBulkAction::make(), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListSections::route('/'), + 'create' => Pages\CreateSection::route('/create'), + 'edit' => Pages\EditSection::route('/{record}/edit'), + ]; + } +} diff --git a/app/Filament/Resources/System/SectionResource/Pages/CreateSection.php b/app/Filament/Resources/System/SectionResource/Pages/CreateSection.php new file mode 100644 index 00000000..4c426dd8 --- /dev/null +++ b/app/Filament/Resources/System/SectionResource/Pages/CreateSection.php @@ -0,0 +1,27 @@ +" . SearchBox::EXTRA_TAXONOMY_LABELS][] = $item; + } + } + } + return array_filter($data); + } +} diff --git a/app/Filament/Resources/System/SectionResource/Pages/EditSection.php b/app/Filament/Resources/System/SectionResource/Pages/EditSection.php new file mode 100644 index 00000000..d8b9993e --- /dev/null +++ b/app/Filament/Resources/System/SectionResource/Pages/EditSection.php @@ -0,0 +1,34 @@ +" . SearchBox::EXTRA_TAXONOMY_LABELS][] = $item; + } + } + } + return array_filter($data); + } +} diff --git a/app/Filament/Resources/System/SectionResource/Pages/ListSections.php b/app/Filament/Resources/System/SectionResource/Pages/ListSections.php new file mode 100644 index 00000000..7c563ad4 --- /dev/null +++ b/app/Filament/Resources/System/SectionResource/Pages/ListSections.php @@ -0,0 +1,20 @@ +' . self::EXTRA_TAXONOMY_LABELS, + 'extra->' . self::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST ]; protected $casts = [ - 'extra' => 'object' + 'extra' => 'array', + 'is_default' => 'boolean', + 'showsubcat' => 'boolean', ]; + const EXTRA_TAXONOMY_LABELS = 'taxonomy_labels'; + const EXTRA_DISPLAY_COVER_ON_TORRENT_LIST = 'display_cover_on_torrent_list'; + public static array $subCatFields = [ + 'source', 'medium', 'codec', 'audiocodec', 'team', 'standard', 'processing' + ]; + public static array $extras = [ self::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST => ['text' => 'Display cover on torrent list'], ]; @@ -31,6 +43,19 @@ class SearchBox extends NexusModel return $result; } + protected function customFields(): Attribute + { + return new Attribute( + get: fn ($value) => is_string($value) ? explode(',', $value) : $value, + set: fn ($value) => is_array($value) ? implode(',', $value) : $value, + ); + } + + public static function getSubCatOptions(): array + { + return array_combine(self::$subCatFields, self::$subCatFields); + } + public function categories(): \Illuminate\Database\Eloquent\Relations\HasMany { return $this->hasMany(Category::class, 'mode'); @@ -41,4 +66,46 @@ class SearchBox extends NexusModel return $this->hasMany(SearchBoxField::class, 'searchbox_id'); } + public function taxonomy_sources(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Source::class, 'mode'); + } + + public function taxonomy_media(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Media::class, 'mode'); + } + + public function taxonomy_standards(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Standard::class, 'mode'); + } + + public function taxonomy_codecs(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Codec::class, 'mode'); + } + + public function taxonomy_audio_codecs(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(AudioCodec::class, 'mode'); + } + + public function taxonomy_teams(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Team::class, 'mode'); + } + + public function taxonomy_processing(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Processing::class, 'mode'); + } + + public function taxonomies(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Taxonomy::class, 'mode'); + } + + + } diff --git a/app/Models/Taxonomy.php b/app/Models/Taxonomy.php new file mode 100644 index 00000000..8e895004 --- /dev/null +++ b/app/Models/Taxonomy.php @@ -0,0 +1,11 @@ +get(); + foreach ($records as $value) { + $result[$value->id] = sprintf('%s[%s]', $value->name, $value->label); + } + return $result; + } +} diff --git a/app/Models/TorrentCustomFieldValue.php b/app/Models/TorrentCustomFieldValue.php new file mode 100644 index 00000000..a4f99c4e --- /dev/null +++ b/app/Models/TorrentCustomFieldValue.php @@ -0,0 +1,13 @@ +integer('mode')->default(0); + }); + } + + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + foreach (self::$tables as $table) { + Schema::table($table, function (Blueprint $table) { + $table->dropColumn('mode'); + }); + } + } +}; diff --git a/database/migrations/2022_09_05_235445_create_taxonomies_table.php b/database/migrations/2022_09_05_235445_create_taxonomies_table.php new file mode 100644 index 00000000..f1148928 --- /dev/null +++ b/database/migrations/2022_09_05_235445_create_taxonomies_table.php @@ -0,0 +1,38 @@ +id(); + $table->integer('mode')->default(0); + $table->string('name'); + $table->string('torrent_field'); + $table->string('image')->nullable(true); + $table->string('class_name')->nullable(true); + $table->integer('priority')->default(0); + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('taxonomies'); + } +}; diff --git a/database/migrations/2022_09_06_004318_add_section_name_to_searchbox_table.php b/database/migrations/2022_09_06_004318_add_section_name_to_searchbox_table.php new file mode 100644 index 00000000..ab80ef46 --- /dev/null +++ b/database/migrations/2022_09_06_004318_add_section_name_to_searchbox_table.php @@ -0,0 +1,33 @@ +string('section_name')->after('name')->default(''); + $table->integer('is_default')->after('section_name')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('searchbox', function (Blueprint $table) { + $table->dropColumn('section_name', 'is_default'); + }); + } +}; diff --git a/database/migrations/2022_09_06_030324_change_searchbox_field_extra_to_json.php b/database/migrations/2022_09_06_030324_change_searchbox_field_extra_to_json.php new file mode 100644 index 00000000..b950aa15 --- /dev/null +++ b/database/migrations/2022_09_06_030324_change_searchbox_field_extra_to_json.php @@ -0,0 +1,32 @@ +json('extra')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('json', function (Blueprint $table) { + // + }); + } +}; diff --git a/nexus/Install/Install.php b/nexus/Install/Install.php index a610ad9a..f6222705 100644 --- a/nexus/Install/Install.php +++ b/nexus/Install/Install.php @@ -675,7 +675,7 @@ class Install $sql = 'select version() as v'; $result = NexusDB::select($sql); $version = $result[0]['v']; - $match = version_compare($version, '5.7.7', '>='); + $match = version_compare($version, '5.7.8', '>='); return compact('version', 'match'); } diff --git a/resources/lang/zh_CN/admin.php b/resources/lang/zh_CN/admin.php index 8c3e900f..1afc82db 100644 --- a/resources/lang/zh_CN/admin.php +++ b/resources/lang/zh_CN/admin.php @@ -24,6 +24,7 @@ return [ 'torrent_deny_reason' => '拒绝原因', 'roles' => '角色', 'permissions' => '权限', + 'section' => '分区', ], 'resources' => [ 'agent_allow' => [ diff --git a/resources/lang/zh_CN/label.php b/resources/lang/zh_CN/label.php index f29bad89..2a0fe4d4 100644 --- a/resources/lang/zh_CN/label.php +++ b/resources/lang/zh_CN/label.php @@ -229,4 +229,22 @@ return [ \App\Models\UserMeta::META_KEY_PERSONALIZED_USERNAME => '彩虹 ID', ], ], + 'search_box' => [ + 'label' => '分区', + 'name' => '别名', + 'section_name' => '名称', + 'is_default' => '是否默认', + 'showsubcat' => '次分类', + 'taxonomies' => '分类法', + 'taxonomy_display_text' => '显示文案', + 'torrent_field' => '种子表字段', + 'catsperrow' => '每行项目数', + 'catsperrow_help' => "设置在搜索箱中每行显示的项目数,如'8'。", + 'catpadding' => "项目间距", + 'catpadding_help' => "单位为像素。搜索箱中项目的水平间隔距离,如'3'。", + 'custom_fields' => '启用自字义字段', + 'custom_fields_display_name' => '自定义字段展示名称', + 'custom_fields_display' => '自定义字段展示', + 'custom_fields_display_help' => '使用特殊的标签代表字段的名称和值,如某字段其 Name 为 artist,则它的名称为:<%artist.label%>,它的值为:<%artist.value%>', + ], ];