migrate searchbox to mode related

This commit is contained in:
xiaomlove
2022-09-13 19:21:05 +08:00
parent cee206df4c
commit f2c4a7d30f
12 changed files with 168 additions and 30 deletions

View File

@@ -10,6 +10,8 @@ class CreateCategoryIcon extends CreateRecord
{
protected static string $resource = CategoryIconResource::class;
protected static string $view = 'filament.resources.system.category-icon-resource.pages.create-record';
protected function mutateFormDataBeforeCreate(array $data): array
{
return array_filter($data);
@@ -19,4 +21,11 @@ class CreateCategoryIcon extends CreateRecord
{
return static::$resource::getUrl('index');
}
protected function getViewData(): array
{
return [
'desc' => nexus_trans('label.icon.desc')
];
}
}

View File

@@ -10,6 +10,8 @@ class EditCategoryIcon extends EditRecord
{
protected static string $resource = CategoryIconResource::class;
protected static string $view = 'filament.resources.system.category-icon-resource.pages.edit-record';
protected function getActions(): array
{
return [
@@ -26,4 +28,11 @@ class EditCategoryIcon extends EditRecord
{
return static::$resource::getUrl('index');
}
protected function getViewData(): array
{
return [
'desc' => nexus_trans('label.icon.desc')
];
}
}

View File

@@ -17,4 +17,11 @@ class ListCategoryIcons extends PageList
Actions\CreateAction::make(),
];
}
protected function getViewData(): array
{
return [
'desc' => nexus_trans('label.icon.desc')
];
}
}

View File

@@ -79,10 +79,27 @@ class SectionResource extends Resource
,
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),
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);
}

View File

@@ -13,16 +13,7 @@ class CreateSection extends CreateRecord
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 $data;
return SearchBox::formatTaxonomyExtra($data);
}
}

View File

@@ -20,16 +20,7 @@ class EditSection extends EditRecord
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 $data;
return SearchBox::formatTaxonomyExtra($data);
}
}