mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-22 02:47:27 +08:00
finish section edit
This commit is contained in:
+49
@@ -2,6 +2,8 @@
|
||||
|
||||
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;
|
||||
@@ -17,9 +19,53 @@ class TaxonomySourcesRelationManager extends RelationManager
|
||||
|
||||
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
|
||||
@@ -41,7 +87,9 @@ class TaxonomySourcesRelationManager extends RelationManager
|
||||
->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([
|
||||
//
|
||||
])
|
||||
@@ -56,4 +104,5 @@ class TaxonomySourcesRelationManager extends RelationManager
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user