torrent global state add begin

This commit is contained in:
xiaomlove
2022-08-26 17:35:49 +08:00
parent cedd9ec437
commit e6888c043c
12 changed files with 94 additions and 29 deletions
@@ -4,6 +4,7 @@ namespace App\Filament\Resources\System;
use App\Filament\Resources\System\TorrentStateResource\Pages;
use App\Filament\Resources\System\TorrentStateResource\RelationManagers;
use App\Models\Setting;
use App\Models\Torrent;
use App\Models\TorrentState;
use Filament\Forms;
@@ -43,8 +44,9 @@ class TorrentStateResource extends Resource
->options(Torrent::listPromotionTypes(true))
->label(__('label.torrent_state.global_sp_state'))
->required(),
Forms\Components\DateTimePicker::make('begin')
->label(__('label.begin')),
Forms\Components\DateTimePicker::make('deadline')
->required()
->label(__('label.deadline')),
])->columns(1);
}
@@ -54,6 +56,7 @@ class TorrentStateResource extends Resource
return $table
->columns([
Tables\Columns\TextColumn::make('global_sp_state_text')->label(__('label.torrent_state.global_sp_state')),
Tables\Columns\TextColumn::make('begin')->label(__('label.begin')),
Tables\Columns\TextColumn::make('deadline')->label(__('label.deadline')),
])
->filters([
@@ -62,8 +65,7 @@ class TorrentStateResource extends Resource
->actions([
Tables\Actions\EditAction::make()->after(function () {
do_log("cache_del: global_promotion_state");
NexusDB::cache_del('global_promotion_state');
NexusDB::cache_del('global_promotion_state_deadline');
NexusDB::cache_del(Setting::TORRENT_GLOBAL_STATE_CACHE_KEY);
}),
// Tables\Actions\DeleteAction::make(),
])
@@ -37,6 +37,8 @@ class TorrentResource extends Resource
protected static ?int $navigationSort = 1;
private static ?TorrentRepository $rep;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.torrent_list');
@@ -55,6 +57,14 @@ class TorrentResource extends Resource
]);
}
public static function getRep(): ?TorrentRepository
{
if (self::$rep === null) {
self::$rep = new TorrentRepository();
}
return self::$rep;
}
public static function table(Table $table): Table
{
$showApproval = self::shouldShowApproval();
@@ -64,8 +74,8 @@ class TorrentResource extends Resource
Tables\Columns\TextColumn::make('basic_category.name')->label(__('label.torrent.category')),
Tables\Columns\TextColumn::make('name')->formatStateUsing(function (Torrent $record) {
$name = sprintf(
'<div class="text-primary-600 transition hover:underline hover:text-primary-500 focus:underline focus:text-primary-500"><a href="/details.php?id=%s" target="_blank">%s</a></div>',
$record->id, Str::limit($record->name, 40)
'<div class="text-primary-600 transition hover:underline hover:text-primary-500 focus:underline focus:text-primary-500"><a href="/details.php?id=%s" target="_blank" title="%s">%s</a></div>',
$record->id, $record->name, Str::limit($record->name, 40)
);
$tags = sprintf('&nbsp;<div>%s</div>', $record->tagsFormatted);
@@ -206,8 +216,7 @@ class TorrentResource extends Resource
private static function getActions(): array
{
$actions = [];
$userClass = Auth::user()->class;
if (self::shouldShowApproval() && $userClass >= Setting::get('authority.torrentmanage')) {
if (self::shouldShowApproval() && user_can('torrent-approval')) {
$actions[] = Tables\Actions\Action::make('approval')
->label(__('admin.resources.torrent.action_approval'))
->form([
@@ -228,6 +237,12 @@ class TorrentResource extends Resource
do_log($exception->getMessage(), 'error');
}
});
}
if (user_can('torrentmanage')) {
$actions[] = Tables\Actions\DeleteAction::make('delete')->using(function ($record) {
deletetorrent($record->id);
});
}
return $actions;
}
+2
View File
@@ -18,6 +18,8 @@ class Setting extends NexusModel
const DIRECT_PERMISSION_CACHE_KEY_PREFIX = 'nexus_direct_permissions_';
const ROLE_PERMISSION_CACHE_KEY_PREFIX = 'nexus_role_permissions_';
const TORRENT_GLOBAL_STATE_CACHE_KEY = 'global_promotion_state';
/**
* get setting autoload = yes with cache
*
+1 -1
View File
@@ -5,7 +5,7 @@ namespace App\Models;
class TorrentState extends NexusModel
{
protected $fillable = ['global_sp_state', 'deadline'];
protected $fillable = ['global_sp_state', 'deadline', 'begin'];
protected $table = 'torrents_state';
-1
View File
@@ -605,5 +605,4 @@ class TorrentRepository extends BaseRepository
return Torrent::query()->whereIn('id', $idArr)->update(['pos_state' => $posState]);
}
}