From 8dd2880e760d1ce8087f8b49dc8eff0695a322f6 Mon Sep 17 00:00:00 2001 From: xiaomlove Date: Sat, 5 Nov 2022 01:08:04 +0800 Subject: [PATCH] improve searchbox extra --- app/Console/Commands/Test.php | 12 ++++- .../Resources/Section/CategoryResource.php | 2 +- .../Resources/Section/IconResource.php | 1 + .../Resources/Section/SecondIconResource.php | 14 ++--- .../Resources/Section/SectionResource.php | 6 +++ .../SectionResource/Pages/EditSection.php | 11 ++++ .../Torrent/TagResource/Pages/EditTag.php | 1 + app/Http/Controllers/TrackerController.php | 4 ++ app/Http/Kernel.php | 5 +- app/Models/SearchBox.php | 33 ++++++++++-- config/livewire.php | 2 +- config/notifications.php | 51 ------------------- public/catmanage.php | 1 + resources/lang/en/label.php | 10 +++- resources/lang/zh_CN/label.php | 2 + resources/lang/zh_TW/label.php | 12 ++++- 16 files changed, 96 insertions(+), 71 deletions(-) delete mode 100644 config/notifications.php diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 29cab844..1346d9ec 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -33,6 +33,7 @@ use App\Repositories\ToolRepository; use App\Repositories\TorrentRepository; use App\Repositories\UserRepository; use Carbon\Carbon; +use Filament\Notifications\Notification; use GeoIp2\Database\Reader; use Illuminate\Console\Command; use Illuminate\Encryption\Encrypter; @@ -90,8 +91,15 @@ class Test extends Command */ public function handle() { - $columnInfo = NexusDB::getMysqlColumnInfo('searchbox', 'section_name'); - dd($columnInfo); +// Notification::make() +// ->success() +// ->title('Test Test') +// ->send() +// ; + $key = 'sbsb'; + $r = session()->push($key, [1,2,3]); + $r = session()->get($key); + dd($r); } diff --git a/app/Filament/Resources/Section/CategoryResource.php b/app/Filament/Resources/Section/CategoryResource.php index e009421d..0dfaf8c2 100644 --- a/app/Filament/Resources/Section/CategoryResource.php +++ b/app/Filament/Resources/Section/CategoryResource.php @@ -40,7 +40,7 @@ class CategoryResource extends Resource return $form ->schema([ Forms\Components\Select::make('mode') - ->options(SearchBox::query()->pluck('name', 'id')->toArray()) + ->options(SearchBox::listModeOptions()) ->label(__('label.search_box.label')) ->required() , diff --git a/app/Filament/Resources/Section/IconResource.php b/app/Filament/Resources/Section/IconResource.php index e18741ac..3caa067d 100644 --- a/app/Filament/Resources/Section/IconResource.php +++ b/app/Filament/Resources/Section/IconResource.php @@ -84,6 +84,7 @@ class IconResource extends Resource ]) ->actions([ Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make(), ]) ->bulkActions([ Tables\Actions\DeleteBulkAction::make(), diff --git a/app/Filament/Resources/Section/SecondIconResource.php b/app/Filament/Resources/Section/SecondIconResource.php index 8c853c17..1aab9207 100644 --- a/app/Filament/Resources/Section/SecondIconResource.php +++ b/app/Filament/Resources/Section/SecondIconResource.php @@ -44,7 +44,7 @@ class SecondIconResource extends Resource $specialMode = Setting::get('main.specialcat'); $torrentTaxonomySchema = $searchBoxRep->listTaxonomyFormSchema($torrentMode); $specialTaxonomySchema = $searchBoxRep->listTaxonomyFormSchema($specialMode); - $modeOptions = SearchBox::query()->whereIn('id', [$torrentMode, $specialMode])->pluck('name', 'id')->toArray(); + $modeOptions = SearchBox::listModeOptions(); return $form ->schema([ Forms\Components\TextInput::make('name') @@ -52,12 +52,6 @@ class SecondIconResource extends Resource ->required() ->helperText(__('label.second_icon.name_help')) , - Forms\Components\Select::make('mode') - ->label(__('label.search_box.label')) - ->options($modeOptions) - ->required() - ->reactive() - , Forms\Components\TextInput::make('image') ->label(__('label.second_icon.image')) ->required() @@ -79,6 +73,11 @@ class SecondIconResource extends Resource ->columns(4) ->hidden(fn (\Closure $get) => $get('mode') != $specialMode) , + Forms\Components\Select::make('mode') + ->options($modeOptions) + ->label(__('label.search_box.taxonomy.mode')) + ->helperText(__('label.search_box.taxonomy.mode_help')) + , ]); } @@ -109,6 +108,7 @@ class SecondIconResource extends Resource ]) ->actions([ Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make(), ]) ->bulkActions([ Tables\Actions\DeleteBulkAction::make(), diff --git a/app/Filament/Resources/Section/SectionResource.php b/app/Filament/Resources/Section/SectionResource.php index 232cc93f..23d0f46f 100644 --- a/app/Filament/Resources/Section/SectionResource.php +++ b/app/Filament/Resources/Section/SectionResource.php @@ -87,6 +87,12 @@ class SectionResource extends Resource ->label(__('label.search_box.custom_fields_display')) ->helperText(__('label.search_box.custom_fields_display_help')) , + Forms\Components\CheckboxList::make('other') + ->options(SearchBox::listExtraText()) + ->columns(2) + ->label(__('label.search_box.other')) + , + Forms\Components\Section::make(__('label.search_box.section_name')) ->schema($sectionNameLocalSchema) ->columns(count($sectionNameLocalSchema)) diff --git a/app/Filament/Resources/Section/SectionResource/Pages/EditSection.php b/app/Filament/Resources/Section/SectionResource/Pages/EditSection.php index a171b3fd..373ebf3e 100644 --- a/app/Filament/Resources/Section/SectionResource/Pages/EditSection.php +++ b/app/Filament/Resources/Section/SectionResource/Pages/EditSection.php @@ -28,4 +28,15 @@ class EditSection extends EditRecord clear_search_box_cache($this->record->id); } + protected function mutateFormDataBeforeFill(array $data): array + { + foreach (SearchBox::$extras as $field => $text) { + if (!empty($data['extra'][$field])) { + $data['other'][] = $field; + } + unset($data['extra'][$field]); + } + return $data; + } + } diff --git a/app/Filament/Resources/Torrent/TagResource/Pages/EditTag.php b/app/Filament/Resources/Torrent/TagResource/Pages/EditTag.php index d0fe31c3..ea01f313 100644 --- a/app/Filament/Resources/Torrent/TagResource/Pages/EditTag.php +++ b/app/Filament/Resources/Torrent/TagResource/Pages/EditTag.php @@ -21,4 +21,5 @@ class EditTag extends EditRecord { return $this->getResource()::getUrl('index'); } + } diff --git a/app/Http/Controllers/TrackerController.php b/app/Http/Controllers/TrackerController.php index 371e2253..8928baa6 100644 --- a/app/Http/Controllers/TrackerController.php +++ b/app/Http/Controllers/TrackerController.php @@ -15,20 +15,24 @@ class TrackerController extends Controller } /** + * @deprecated * @param Request $request * @return \Illuminate\Http\Response */ public function announce(Request $request): \Illuminate\Http\Response { + throw new \RuntimeException("Deprecated! Reference to: https://nexusphp.org/2022/07/18/tracker-url-recommend-to-use-old-announce-php/"); return $this->repository->announce($request); } /** + * @deprecated * @param Request $request * @return \Illuminate\Http\Response */ public function scrape(Request $request): \Illuminate\Http\Response { + throw new \RuntimeException("Deprecated! Reference to: https://nexusphp.org/2022/07/18/tracker-url-recommend-to-use-old-announce-php/"); return $this->repository->scrape($request); } } diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 478fab94..13fbdfa6 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -45,6 +45,10 @@ class Kernel extends HttpKernel \Illuminate\Routing\Middleware\SubstituteBindings::class, \App\Http\Middleware\Platform::class, ], + 'filament' => [ + \Illuminate\Session\Middleware\StartSession::class, + \Filament\Http\Middleware\Authenticate::class, + ], ]; /** @@ -58,7 +62,6 @@ class Kernel extends HttpKernel 'auth' => \App\Http\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 'auth.nexus' => \App\Http\Middleware\NexusAuth::class, - 'auth.filament' => \Filament\Http\Middleware\Authenticate::class, 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, diff --git a/app/Models/SearchBox.php b/app/Models/SearchBox.php index 01b7c03e..7c6fdc68 100644 --- a/app/Models/SearchBox.php +++ b/app/Models/SearchBox.php @@ -11,6 +11,8 @@ class SearchBox extends NexusModel { private static array $instances = []; + private static array $modeOptions = []; + protected $table = 'searchbox'; protected $fillable = [ @@ -18,7 +20,8 @@ class SearchBox extends NexusModel 'showsource', 'showmedium', 'showcodec', 'showstandard', 'showprocessing', 'showteam', 'showaudiocodec', 'custom_fields', 'custom_fields_display_name', 'custom_fields_display', 'extra->' . self::EXTRA_TAXONOMY_LABELS, - 'extra->' . self::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST + 'extra->' . self::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST, + 'extra->' . self::EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST, ]; protected $casts = [ @@ -55,27 +58,36 @@ class SearchBox extends NexusModel self::EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST => ['text' => 'Display seed box icon on torrent list'], ]; - public static function listExtraText(): array + public static function listExtraText($fullName = false): array { $result = []; - foreach (self::$extras as $extra => $info) { - $result[$extra] = nexus_trans("searchbox.extras.$extra"); + foreach (self::$extras as $field => $info) { + if ($fullName) { + $name = "extra[$field]"; + } else { + $name = $field; + } + $result[$name] = nexus_trans("searchbox.extras.$field"); } return $result; } public static function formatTaxonomyExtra(array $data): array { + do_log("data: " . json_encode($data)); foreach (self::$taxonomies 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; } } } $data["extra->" . self::EXTRA_TAXONOMY_LABELS] = $data['extra'][self::EXTRA_TAXONOMY_LABELS]; + $other = $data['other'] ?? []; + $data["extra->" . self::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST] = in_array(self::EXTRA_DISPLAY_COVER_ON_TORRENT_LIST, $other) ? 1 : 0; + $data["extra->" . self::EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST] = in_array(self::EXTRA_DISPLAY_SEED_BOX_ICON_ON_TORRENT_LIST, $other) ? 1 : 0; + return $data; } @@ -137,6 +149,17 @@ class SearchBox extends NexusModel })->get(); } + public static function listModeOptions(): array + { + if (!empty(self::$modeOptions)) { + return self::$modeOptions; + } + self::$modeOptions = SearchBox::query() + ->pluck('name', 'id') + ->toArray(); + return self::$modeOptions; + } + public function getCustomFieldsAttribute($value): array { if (!is_array($value)) { diff --git a/config/livewire.php b/config/livewire.php index c5bfd70b..d108a622 100644 --- a/config/livewire.php +++ b/config/livewire.php @@ -81,8 +81,8 @@ return [ | */ - 'middleware_group' => 'auth.filament', // 'middleware_group' => 'web', + 'middleware_group' => 'filament', /* |-------------------------------------------------------------------------- diff --git a/config/notifications.php b/config/notifications.php deleted file mode 100644 index b758f889..00000000 --- a/config/notifications.php +++ /dev/null @@ -1,51 +0,0 @@ - false, - - /* - |-------------------------------------------------------------------------- - | Database notifications - |-------------------------------------------------------------------------- - | - | By enabling this feature, your users are able to open a slide-over within - | the app to view their database notifications. - | - */ - - 'database' => [ - 'enabled' => false, - 'trigger' => null, - 'polling_interval' => '30s', - ], - - /* - |-------------------------------------------------------------------------- - | Layout - |-------------------------------------------------------------------------- - | - | This is the configuration for the general layout of notifications. - | - */ - - 'layout' => [ - 'alignment' => [ - 'horizontal' => 'right', - 'vertical' => 'top', - ], - ], - -]; diff --git a/public/catmanage.php b/public/catmanage.php index 9593e9cc..1d343ed3 100644 --- a/public/catmanage.php +++ b/public/catmanage.php @@ -679,6 +679,7 @@ elseif($action == 'add') } elseif($action == 'submit') { + die("This method is deprecated! This method is no longer available in 1.8, it does not save data correctly, please go to the management system!"); $dbtablename=return_category_db_table_name($type); if ($_POST['isedit']){ $id = intval($_POST['id'] ?? 0); diff --git a/resources/lang/en/label.php b/resources/lang/en/label.php index e192bfd4..851405d2 100644 --- a/resources/lang/en/label.php +++ b/resources/lang/en/label.php @@ -150,7 +150,14 @@ return [ 'approval_status' => 'Approval status', 'pos_state' => 'Pos state', 'sp_state' => 'Promotion', - 'visible' => 'Visible', + 'visible' => 'Active', + 'source' => 'Source', + 'codec' => 'Codec', + 'audiocodec' => 'Audio codec', + 'medium' => 'Medium', + 'team' => 'Team', + 'processing' => 'Processing', + 'standard' => 'Standard', 'picktype' => 'Recommend', 'promotion_time_type' => 'Promotion type time', 'hr' => 'H&R', @@ -254,6 +261,7 @@ return [ then it's label:<%artist.label%>,it's value:<%artist.value%>", 'category' => 'Category', 'torrent_field_duplicate' => 'Torrent table field::field cannot be reused!', + 'other' => 'Other', 'taxonomy' => [ 'name' => 'Name', 'sort_index' => 'Sort', diff --git a/resources/lang/zh_CN/label.php b/resources/lang/zh_CN/label.php index 5df353ff..144bc75d 100644 --- a/resources/lang/zh_CN/label.php +++ b/resources/lang/zh_CN/label.php @@ -114,6 +114,7 @@ return [ ], 'exam' => [ 'label' => '考核', + 'is_done' => '是否完成', 'is_discovered' => '自动发现', 'register_time_range' => [ 'begin' => '注册时间开始', @@ -262,6 +263,7 @@ return [ 'custom_fields_display_help' => '使用特殊的标签代表字段的名称和值,如某字段其 Name 为 artist,则它的名称为:<%artist.label%>,它的值为:<%artist.value%>', 'category' => '分类', 'torrent_field_duplicate' => '种子表字段::field 不能重复使用!', + 'other' => '其他', 'taxonomy' => [ 'name' => '名称', 'sort_index' => '排序', diff --git a/resources/lang/zh_TW/label.php b/resources/lang/zh_TW/label.php index 6371cc60..32dd6e84 100644 --- a/resources/lang/zh_TW/label.php +++ b/resources/lang/zh_TW/label.php @@ -143,14 +143,21 @@ return [ 'owner' => '發布者', 'size' => '大小', 'ttl' => '存活時間', - 'seeders' => '做种', - 'leechers' => '下载', + 'seeders' => '做種', + 'leechers' => '下載', 'times_completed' => '完成次數', 'category' => '類型', 'approval_status' => '審核狀態', 'pos_state' => '置頂', 'sp_state' => '優惠', 'visible' => '活種', + 'source' => '來源', + 'codec' => '編碼', + 'audiocodec' => '音頻編碼', + 'medium' => '媒介', + 'team' => '製作組', + 'processing' => '處理', + 'standard' => '分辨率', 'picktype' => '推薦', 'promotion_time_type' => '優惠時間類型', 'hr' => 'H&R', @@ -252,6 +259,7 @@ return [ 'custom_fields_display_help' => '使用特殊的標簽代表字段的名稱和值,如某字段其 Name 為 artist,則它的名稱為:<%artist.label%>,它的值為:<%artist.value%>', 'category' => '分類', 'torrent_field_duplicate' => '種子表字段::field 不能重復使用!', + 'other' => '其他', 'taxonomy' => [ 'name' => '名稱', 'sort_index' => '排序',