mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
finish searchbox build + upload/edit form quality render
This commit is contained in:
@@ -87,7 +87,8 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$rep = new SearchBoxRepository();
|
||||
$rep->migrateToModeRelated();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ class SectionResource extends Resource
|
||||
{
|
||||
return $form
|
||||
->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'))
|
||||
@@ -61,6 +60,10 @@ class SectionResource extends Resource
|
||||
->required()
|
||||
->default(3)
|
||||
,
|
||||
Forms\Components\TextInput::make('section_name')
|
||||
->label(__('label.search_box.section_name'))
|
||||
->helperText(__('label.search_box.section_name_help'))
|
||||
,
|
||||
Forms\Components\CheckboxList::make('custom_fields')
|
||||
->options(TorrentCustomField::getCheckboxOptions())
|
||||
->label(__('label.search_box.custom_fields'))
|
||||
@@ -109,8 +112,8 @@ class SectionResource extends Resource
|
||||
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\TextColumn::make('section_name')->label(__('label.search_box.section_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'),
|
||||
|
||||
@@ -23,4 +23,9 @@ class EditSection extends EditRecord
|
||||
return SearchBox::formatTaxonomyExtra($data);
|
||||
}
|
||||
|
||||
protected function afterSave()
|
||||
{
|
||||
clear_search_box_cache($this->record->id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,15 +26,16 @@ class CategoriesRelationManager extends RelationManager
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')->required()->label(__('label.search_box.taxonomy.name')),
|
||||
Forms\Components\TextInput::make('name')->required()->label(__('label.search_box.taxonomy.name'))->required(),
|
||||
Forms\Components\TextInput::make('image')
|
||||
->rule('alpha_dash')
|
||||
->label(__('label.search_box.taxonomy.image'))
|
||||
->helperText(__('label.search_box.taxonomy.image_help'))
|
||||
->required()
|
||||
,
|
||||
Forms\Components\Select::make('icon_id')
|
||||
->options(Icon::query()->pluck('name', 'id')->toArray())
|
||||
->label(__('label.search_box.taxonomy.icon_id'))
|
||||
->required()
|
||||
,
|
||||
Forms\Components\TextInput::make('class_name')
|
||||
->label(__('label.search_box.taxonomy.class_name'))
|
||||
@@ -57,19 +58,27 @@ class CategoriesRelationManager extends RelationManager
|
||||
Tables\Columns\TextColumn::make('icon.name')->label(__('label.search_box.taxonomy.icon_id')),
|
||||
Tables\Columns\TextColumn::make('image')->label(__('label.search_box.taxonomy.image')),
|
||||
Tables\Columns\TextColumn::make('class_name')->label(__('label.search_box.taxonomy.class_name')),
|
||||
Tables\Columns\TextColumn::make('sort_index')->label(__('label.search_box.taxonomy.sort_index'))->sortable(),
|
||||
])
|
||||
->defaultSort('sort_index')
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
Tables\Actions\CreateAction::make()->after(function ($record) {
|
||||
clear_search_box_cache($record->mode);
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
Tables\Actions\EditAction::make()->after(function ($record) {
|
||||
clear_search_box_cache($record->mode);
|
||||
}),
|
||||
Tables\Actions\DeleteAction::make()->after(function ($record) {
|
||||
clear_search_box_cache($record->mode);
|
||||
}),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class TaxonomyAudioCodecsRelationManager extends TaxonomySourcesRelationManager
|
||||
{
|
||||
protected static string $relationship = 'taxonomy_audio_codecs';
|
||||
protected static string $relationship = 'taxonomy_audiocodec';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class TaxonomyCodecsRelationManager extends TaxonomySourcesRelationManager
|
||||
{
|
||||
protected static string $relationship = 'taxonomy_codecs';
|
||||
protected static string $relationship = 'taxonomy_codec';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class TaxonomySourcesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'taxonomy_sources';
|
||||
protected static string $relationship = 'taxonomy_source';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
@@ -94,14 +94,20 @@ class TaxonomySourcesRelationManager extends RelationManager
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
Tables\Actions\CreateAction::make()->after(function ($record) {
|
||||
clear_search_box_cache($record->mode);
|
||||
}),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
Tables\Actions\EditAction::make()->after(function ($record) {
|
||||
clear_search_box_cache($record->mode);
|
||||
}),
|
||||
Tables\Actions\DeleteAction::make()->after(function ($record) {
|
||||
clear_search_box_cache($record->mode);
|
||||
}),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class TaxonomyStandardsRelationManager extends TaxonomySourcesRelationManager
|
||||
{
|
||||
protected static string $relationship = 'taxonomy_standards';
|
||||
protected static string $relationship = 'taxonomy_standard';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class TaxonomyTeamsRelationManager extends TaxonomySourcesRelationManager
|
||||
{
|
||||
protected static string $relationship = 'taxonomy_teams';
|
||||
protected static string $relationship = 'taxonomy_team';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SearchBox extends NexusModel
|
||||
{
|
||||
@@ -27,8 +28,8 @@ 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 $subCategories = [
|
||||
'source' => 'surces',
|
||||
public static array $taxonomies = [
|
||||
'source' => 'sources',
|
||||
'medium' => 'media',
|
||||
'codec' => 'codecs',
|
||||
'audiocodec' => 'audiocodecs',
|
||||
@@ -53,7 +54,7 @@ class SearchBox extends NexusModel
|
||||
|
||||
public static function formatTaxonomyExtra(array $data): array
|
||||
{
|
||||
foreach (self::$subCategories as $field => $table) {
|
||||
foreach (self::$taxonomies as $field => $table) {
|
||||
$data["show{$field}"] = 0;
|
||||
foreach ($data['extra'][self::EXTRA_TAXONOMY_LABELS] ?? [] as $item) {
|
||||
if ($field == $item['torrent_field']) {
|
||||
@@ -65,6 +66,16 @@ class SearchBox extends NexusModel
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getTaxonomyLabel($torrentField)
|
||||
{
|
||||
foreach ($this->extra[self::EXTRA_TAXONOMY_LABELS] ?? [] as $item) {
|
||||
if ($item['torrent_field'] == $torrentField) {
|
||||
return $item['display_text'];
|
||||
}
|
||||
}
|
||||
return nexus_trans('label.torrent.' . $torrentField) ?: ucfirst($torrentField);
|
||||
}
|
||||
|
||||
protected function customFields(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
@@ -75,7 +86,7 @@ class SearchBox extends NexusModel
|
||||
|
||||
public static function getSubCatOptions(): array
|
||||
{
|
||||
return array_combine(array_keys(self::$subCategories), array_keys(self::$subCategories));
|
||||
return array_combine(array_keys(self::$taxonomies), array_keys(self::$taxonomies));
|
||||
}
|
||||
|
||||
public function categories(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
@@ -88,7 +99,7 @@ class SearchBox extends NexusModel
|
||||
return $this->hasMany(SearchBoxField::class, 'searchbox_id');
|
||||
}
|
||||
|
||||
public function taxonomy_sources(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
public function taxonomy_source(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Source::class, 'mode');
|
||||
}
|
||||
@@ -98,22 +109,22 @@ class SearchBox extends NexusModel
|
||||
return $this->hasMany(Media::class, 'mode');
|
||||
}
|
||||
|
||||
public function taxonomy_standards(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
public function taxonomy_standard(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Standard::class, 'mode');
|
||||
}
|
||||
|
||||
public function taxonomy_codecs(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
public function taxonomy_codec(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Codec::class, 'mode');
|
||||
}
|
||||
|
||||
public function taxonomy_audio_codecs(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
public function taxonomy_audiocodec(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(AudioCodec::class, 'mode');
|
||||
}
|
||||
|
||||
public function taxonomy_teams(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
public function taxonomy_team(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Team::class, 'mode');
|
||||
}
|
||||
@@ -129,7 +140,4 @@ class SearchBox extends NexusModel
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Models\NexusModel;
|
||||
use App\Models\SearchBox;
|
||||
use App\Models\SearchBoxField;
|
||||
use App\Models\Setting;
|
||||
use Elasticsearch\Endpoints\Search;
|
||||
use Illuminate\Support\Arr;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
@@ -102,13 +103,14 @@ class SearchBoxRepository extends BaseRepository
|
||||
return Icon::query()->find(array_keys($iconIdArr));
|
||||
}
|
||||
|
||||
public static function migrateToModeRelated()
|
||||
public function migrateToModeRelated()
|
||||
{
|
||||
$secondIconTable = 'secondicons';
|
||||
$normalId = Setting::get('main.browsecat');
|
||||
$specialId = Setting::get('main.specialcat');
|
||||
$searchBoxList = SearchBox::query()->get();
|
||||
$tables = array_values(SearchBox::$subCategories);
|
||||
$tables = array_values(SearchBox::$taxonomies);
|
||||
|
||||
foreach ($searchBoxList as $searchBox) {
|
||||
if ($searchBox->id == $normalId) {
|
||||
//all sub categories add `mode` field
|
||||
@@ -129,17 +131,56 @@ class SearchBoxRepository extends BaseRepository
|
||||
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");
|
||||
// $fields = array_keys(SearchBox::$taxonomies);
|
||||
// $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");
|
||||
}
|
||||
$taxonomies = [];
|
||||
foreach (SearchBox::$taxonomies as $field => $taxonomyTable) {
|
||||
$showField = "show" . $field;
|
||||
if ($searchBox->{$showField}) {
|
||||
$taxonomies[] = [
|
||||
'torrent_field' => $field,
|
||||
'display_text' => $field,
|
||||
];
|
||||
}
|
||||
}
|
||||
$searchBox->update(["extra->" . SearchBox::EXTRA_TAXONOMY_LABELS => $taxonomies]);
|
||||
}
|
||||
}
|
||||
|
||||
public function renderQualitySelect($searchBox, array $torrentInfo = []): string
|
||||
{
|
||||
if (!$searchBox instanceof SearchBox) {
|
||||
$searchBox = SearchBox::query()->findOrFail(intval($searchBox));
|
||||
}
|
||||
$results = [];
|
||||
foreach (SearchBox::$taxonomies as $torrentField => $table) {
|
||||
$searchBoxField = "show" . $torrentField;
|
||||
if ($searchBox->{$searchBoxField}) {
|
||||
$select = sprintf("<b>%s:</b>", $searchBox->getTaxonomyLabel($torrentField));
|
||||
$select .= sprintf('<select name="%s" data-mode="%s">', $torrentField . "_sel", $searchBox->id);
|
||||
$select .= sprintf('<option value="%s">%s</option>', 0, nexus_trans('nexus.select_one_please'));
|
||||
$relation = "taxonomy_$torrentField";
|
||||
$list = $searchBox->{$relation};
|
||||
foreach ($list as $item) {
|
||||
$selected = '';
|
||||
if (isset($torrentInfo[$torrentField]) && $torrentInfo[$torrentField] == $item->id) {
|
||||
$selected = " selected";
|
||||
}
|
||||
$select .= sprintf('<option value="%s"%s>%s</option>', $item->id, $selected, $item->name);
|
||||
}
|
||||
$select .= '</select>';
|
||||
$results[] = $select;
|
||||
}
|
||||
}
|
||||
return implode(' ', $results);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user