section basic

This commit is contained in:
xiaomlove
2022-10-27 20:21:54 +08:00
parent 0053d14183
commit ce5d99c16a
92 changed files with 3188 additions and 1367 deletions
@@ -24,8 +24,6 @@ class PluginResource extends Resource
protected static ?int $navigationSort = 99;
protected static bool $shouldRegisterNavigation = false;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.plugin');
@@ -1,161 +0,0 @@
<?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('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()
->required()
->default(8)
,
Forms\Components\TextInput::make('catpadding')
->label(__('label.search_box.catpadding'))
->helperText(__('label.search_box.catpadding_help'))
->integer()
->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'))
,
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)
->rules([
function () {
return function (string $attribute, $value, \Closure $fail) {
$fields = [];
foreach ($value as $item) {
if (!in_array($item['torrent_field'], $fields)) {
$fields[] = $item['torrent_field'];
} else {
$fail(__('label.search_box.torrent_field_duplicate', ['field' => $item['torrent_field']]));
}
}
};
}
])
,
]),
])->columns(3);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id'),
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'),
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 [
RelationManagers\CategoriesRelationManager::class,
RelationManagers\TaxonomySourcesRelationManager::class,
RelationManagers\TaxonomyMediumRelationManager::class,
RelationManagers\TaxonomyCodecsRelationManager::class,
RelationManagers\TaxonomyAudioCodecsRelationManager::class,
RelationManagers\TaxonomyTeamsRelationManager::class,
RelationManagers\TaxonomyStandardsRelationManager::class,
RelationManagers\TaxonomyProcessingRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListSections::route('/'),
'create' => Pages\CreateSection::route('/create'),
'edit' => Pages\EditSection::route('/{record}/edit'),
];
}
}
@@ -1,19 +0,0 @@
<?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
{
return SearchBox::formatTaxonomyExtra($data);
}
}
@@ -1,31 +0,0 @@
<?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
{
return SearchBox::formatTaxonomyExtra($data);
}
protected function afterSave()
{
clear_search_box_cache($this->record->id);
}
}
@@ -1,22 +0,0 @@
<?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(),
];
}
}
@@ -1,84 +0,0 @@
<?php
namespace App\Filament\Resources\System\SectionResource\RelationManagers;
use App\Models\Icon;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class CategoriesRelationManager extends RelationManager
{
protected static string $relationship = 'categories';
protected static ?string $recordTitleAttribute = 'name';
protected static function getModelLabel(): string
{
return __('label.search_box.category');
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')->required()->label(__('label.search_box.taxonomy.name'))->required(),
Forms\Components\TextInput::make('image')
->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'))
->helperText(__('label.search_box.taxonomy.class_name_help'))
,
Forms\Components\TextInput::make('sort_index')
->default(0)
->label(__('label.search_box.taxonomy.sort_index'))
->helperText(__('label.search_box.taxonomy.sort_index_help'))
,
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\TextColumn::make('name')->label(__('label.search_box.taxonomy.name')),
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()->after(function ($record) {
clear_search_box_cache($record->mode);
}),
])
->actions([
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([
]);
}
}
@@ -1,22 +0,0 @@
<?php
namespace App\Filament\Resources\System\SectionResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class TaxonomyAudioCodecsRelationManager extends TaxonomySourcesRelationManager
{
protected static string $relationship = 'taxonomy_audiocodec';
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $torrentField = 'audiocodec';
}
@@ -1,22 +0,0 @@
<?php
namespace App\Filament\Resources\System\SectionResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class TaxonomyCodecsRelationManager extends TaxonomySourcesRelationManager
{
protected static string $relationship = 'taxonomy_codec';
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $torrentField = 'codec';
}
@@ -1,22 +0,0 @@
<?php
namespace App\Filament\Resources\System\SectionResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class TaxonomyMediumRelationManager extends TaxonomySourcesRelationManager
{
protected static string $relationship = 'taxonomy_medium';
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $torrentField = 'medium';
}
@@ -1,22 +0,0 @@
<?php
namespace App\Filament\Resources\System\SectionResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class TaxonomyProcessingRelationManager extends TaxonomySourcesRelationManager
{
protected static string $relationship = 'taxonomy_processing';
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $torrentField = 'processing';
}
@@ -1,114 +0,0 @@
<?php
namespace App\Filament\Resources\System\SectionResource\RelationManagers;
use App\Filament\Resources\System\SectionResource\TaxonomyTrait;
use App\Models\SearchBox;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class TaxonomySourcesRelationManager extends RelationManager
{
protected static string $relationship = 'taxonomy_source';
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $torrentField = 'source';
protected static function getModelLabel(): string
{
static $taxonomies;
if (!$taxonomies) {
$params = request()->all();
$taxonomies = $params['serverMemo']['data']['data']['extra'][SearchBox::EXTRA_TAXONOMY_LABELS] ?? [];
if (empty($taxonomies)) {
$id = request()->route()->parameter('record');
if (!$id) {
$id = $params['serverMemo']['dataMeta']['models']['ownerRecord']['id'] ?? null;
}
do_log("searchBox ID: $id");
$searchBox = SearchBox::query()->find($id);
if ($searchBox) {
$taxonomies = $searchBox->extra[SearchBox::EXTRA_TAXONOMY_LABELS] ?? [];
} else {
$taxonomies = [];
}
}
}
foreach ($taxonomies as $taxonomy) {
if ($taxonomy['torrent_field'] == static::$torrentField) {
return $taxonomy['display_text'];
}
}
$field = static::$torrentField;
return __("label.search_box.$field") ?? $field;
}
public static function shouldShowTaxonomy(SearchBox $searchBox): bool
{
$taxonomies = $searchBox->extra[SearchBox::EXTRA_TAXONOMY_LABELS] ?? [];
foreach ($taxonomies as $taxonomy) {
if ($taxonomy['torrent_field'] == static::$torrentField) {
do_log("torrent_field: " . static::$torrentField . " should show");
return true;
}
}
do_log("torrent_field: " . static::$torrentField . " don't show");
return false;
}
public static function canViewForRecord(Model $ownerRecord): bool
{
return self::shouldShowTaxonomy($ownerRecord);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')->required(),
Forms\Components\TextInput::make('sort_index')
->default(0)
->label(__('label.search_box.taxonomy.sort_index'))
->helperText(__('label.search_box.taxonomy.sort_index_help'))
,
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id'),
Tables\Columns\TextColumn::make('name')->label(__('label.search_box.taxonomy.name')),
Tables\Columns\TextColumn::make('sort_index')->label(__('label.search_box.taxonomy.sort_index'))->sortable(),
])
->defaultSort('sort_index')
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make()->after(function ($record) {
clear_search_box_cache($record->mode);
}),
])
->actions([
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([
]);
}
}
@@ -1,21 +0,0 @@
<?php
namespace App\Filament\Resources\System\SectionResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class TaxonomyStandardsRelationManager extends TaxonomySourcesRelationManager
{
protected static string $relationship = 'taxonomy_standard';
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $torrentField = 'standard';
}
@@ -1,21 +0,0 @@
<?php
namespace App\Filament\Resources\System\SectionResource\RelationManagers;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class TaxonomyTeamsRelationManager extends TaxonomySourcesRelationManager
{
protected static string $relationship = 'taxonomy_team';
protected static ?string $recordTitleAttribute = 'name';
protected static ?string $torrentField = 'team';
}