improve searchbox extra

This commit is contained in:
xiaomlove
2022-11-05 01:08:04 +08:00
parent 7b65d84752
commit 8dd2880e76
16 changed files with 96 additions and 71 deletions
+10 -2
View File
@@ -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);
}
@@ -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()
,
@@ -84,6 +84,7 @@ class IconResource extends Resource
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
@@ -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(),
@@ -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))
@@ -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;
}
}
@@ -21,4 +21,5 @@ class EditTag extends EditRecord
{
return $this->getResource()::getUrl('index');
}
}
@@ -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);
}
}
+4 -1
View File
@@ -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,
+28 -5
View File
@@ -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)) {