change category basic

This commit is contained in:
xiaomlove
2025-09-11 20:08:43 +07:00
parent 58075c37a5
commit 4c46f376ba
5 changed files with 58 additions and 15 deletions

View File

@@ -12,6 +12,7 @@ use App\Models\Tag;
use App\Models\Torrent;
use App\Models\TorrentTag;
use App\Models\User;
use App\Repositories\SearchBoxRepository;
use App\Repositories\TagRepository;
use App\Repositories\TorrentRepository;
use Filament\Facades\Filament;
@@ -301,13 +302,13 @@ class TorrentResource extends Resource
})
->deselectRecordsAfterCompletion();
}
// $actions[] = self::getBulkActionChangeCategory();
if (user_can('torrent-delete')) {
$actions[] = Tables\Actions\DeleteBulkAction::make('bulk-delete')->using(function (Collection $records) {
deletetorrent($records->pluck('id')->toArray());
});
}
return $actions;
}
@@ -341,17 +342,55 @@ class TorrentResource extends Resource
$actions[] = Tables\Actions\DeleteAction::make('delete')->using(function ($record) {
deletetorrent($record->id);
});
// $actions[] = Tables\Actions\Action::make('view')
// ->action(function (Torrent $record) {
// return [
// 'modelContent' => new HtmlString("ssss")
// ];
// })
// ;
}
return $actions;
}
private static function getBulkActionChangeCategory(): Tables\Actions\BulkAction
{
return Tables\Actions\BulkAction::make('changeCategory')
->label(__('admin.resources.torrent.bulk_action_change_category'))
->form([
Forms\Components\Select::make('section_id')
->label(__('searchbox.section'))
->options(function() {
$rep = new SearchBoxRepository();
$list = $rep->listSections(false);
$result = [];
foreach ($list as $section) {
$result[$section->id] = $section->displaySectionName;
}
return $result;
})
->reactive()
->afterStateUpdated(fn (callable $set) => $set('section_id', null))
->required()
,
Forms\Components\Select::make('category')
->label(__('searchbox.category_label'))
->options(function (callable $get) {
$sectionId = $get('section_id');
if (!$sectionId) {
return [];
}
return Category::query()->where('mode', $sectionId)->pluck('name', 'id');
})
->reactive()
->required()
,
])
->action(function (Collection $records, array $data) {
// $torrentRep = new TorrentRepository();
// try {
// $data['torrent_id'] = $record->id;
// $torrentRep->approval(Auth::user(), $data);
// } catch (\Exception $exception) {
// do_log($exception->getMessage(), 'error');
// }
});
}
private static function shouldShowApproval(): bool
{
return false;

View File

@@ -243,18 +243,20 @@ class SearchBoxRepository extends BaseRepository
return Category::query()->whereIn('id', $idArr)->delete();
}
public function listSections()
public function listSections($withCategoryAndTags = true)
{
$modeIds = [SearchBox::getBrowseMode()];
if (SearchBox::isSpecialEnabled() && Permission::canUploadToSpecialSection()) {
$modeIds[] = SearchBox::getSpecialMode();
}
$searchBoxList = SearchBox::query()->with("categories")->find($modeIds);
foreach ($searchBoxList as $searchBox) {
if ($searchBox->showsubcat) {
$searchBox->loadSubCategories();
$searchBoxList = SearchBox::query()->with($withCategoryAndTags ? ['categories'] : [])->find($modeIds);
if ($withCategoryAndTags) {
foreach ($searchBoxList as $searchBox) {
if ($searchBox->showsubcat) {
$searchBox->loadSubCategories();
}
$searchBox->loadTags();
}
$searchBox->loadTags();
}
return $searchBoxList;
}

View File

@@ -37,7 +37,7 @@ class class_cache_redis {
if (!empty($config['port'])) {
$params[] = $config['port'];
}
if (!empty($config['timeout'])) {
if (isset($config['timeout']) && is_numeric($config['timeout'])) {
$params[] = $config['timeout'];
}
$connectResult = $redis->connect(...$params);

View File

@@ -121,6 +121,7 @@ return [
'bulk_action_recommend' => '推荐',
'bulk_action_sp_state' => '优惠',
'bulk_action_hr' => 'H&R',
'bulk_action_change_category' => '修改分类',
],
'seed_box_record' => [
'toggle_status' => '更改状态',

View File

@@ -1,6 +1,7 @@
<?php
return [
'section' => '分区',
'category_label' => '分类',
'sub_category_source_label' => '来源',
'sub_category_medium_label' => '媒介',