init section

This commit is contained in:
xiaomlove
2022-09-06 20:45:29 +08:00
parent fb329f72cc
commit f68b88f754
16 changed files with 496 additions and 5 deletions
+5 -1
View File
@@ -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);
}
@@ -0,0 +1,130 @@
<?php
namespace App\Filament\Resources\System;
use App\Filament\Resources\System\SectionResource\Pages;
use App\Filament\Resources\System\SectionResource\RelationManagers;
use App\Models\Forum;
use App\Models\SearchBox;
use App\Models\TorrentCustomField;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class SectionResource extends Resource
{
protected static ?string $model = SearchBox::class;
protected static ?string $slug = 'sections';
protected static ?string $pluralModelLabel = 'Section';
protected static ?string $label = 'Section';
protected static ?string $navigationIcon = 'heroicon-o-view-boards';
protected static ?string $navigationGroup = 'System';
protected static ?int $navigationSort = 2;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.section');
}
public static function getBreadcrumb(): string
{
return self::getNavigationLabel();
}
public static function form(Form $form): Form
{
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'))
->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'),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Filament\Resources\System\SectionResource\Pages;
use App\Filament\Resources\System\SectionResource;
use App\Models\SearchBox;
use Filament\Pages\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateSection extends CreateRecord
{
protected static string $resource = SectionResource::class;
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 array_filter($data);
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Filament\Resources\System\SectionResource\Pages;
use App\Filament\Resources\System\SectionResource;
use App\Models\SearchBox;
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;
class EditSection extends EditRecord
{
protected static string $resource = SectionResource::class;
protected function getActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
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 array_filter($data);
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Filament\Resources\System\SectionResource\Pages;
use App\Filament\PageList;
use App\Filament\Resources\System\SectionResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;
class ListSections extends PageList
{
protected static string $resource = SectionResource::class;
protected function getActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
+70 -3
View File
@@ -2,22 +2,34 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
class SearchBox extends NexusModel
{
protected $table = 'searchbox';
protected $fillable = [
'name', 'catsperrow', 'catpadding', 'showsubcat',
'name', 'catsperrow', 'catpadding', 'showsubcat', 'section_name', 'is_default',
'showsource', 'showmedium', 'showcodec', 'showstandard', 'showprocessing', 'showteam', 'showaudiocodec',
'custom_fields', 'custom_fields_display_name', 'custom_fields_display', 'extra'
'custom_fields', 'custom_fields_display_name', 'custom_fields_display',
'extra->' . 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');
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
namespace App\Models;
class Taxonomy extends NexusModel
{
protected $fillable = [
'mode', 'name', 'torrent_field', 'image', 'class_name', 'priority',
];
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace App\Models;
class TorrentCustomField extends NexusModel
{
protected $table = 'torrents_custom_fields';
protected $fillable = [
'name', 'label', 'type', 'required', 'is_single_row', 'options', 'help'
];
public static function getCheckboxOptions(): array
{
$result = [];
$records = self::query()->get();
foreach ($records as $value) {
$result[$value->id] = sprintf('%s[%s]', $value->name, $value->label);
}
return $result;
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Models;
class TorrentCustomFieldValue extends NexusModel
{
protected $table = 'torrents_custom_field_values';
protected $fillable = [
'torrent_id', 'custom_field_id', 'custom_field_value',
];
}
@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
private static array $tables = [
'sources', 'media', 'standards', 'codecs', 'audiocodecs', 'teams', 'processings'
];
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
foreach (self::$tables as $table) {
Schema::table($table, function (Blueprint $table) {
$table->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');
});
}
}
};
@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('taxonomies', function (Blueprint $table) {
$table->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');
}
};
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('searchbox', function (Blueprint $table) {
$table->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');
});
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('searchbox', function (Blueprint $table) {
$table->json('extra')->nullable()->change();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('json', function (Blueprint $table) {
//
});
}
};
+1 -1
View File
@@ -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');
}
+1
View File
@@ -24,6 +24,7 @@ return [
'torrent_deny_reason' => '拒绝原因',
'roles' => '角色',
'permissions' => '权限',
'section' => '分区',
],
'resources' => [
'agent_allow' => [
+18
View File
@@ -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%>',
],
];