2022-07-09 18:06:09 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Filament\Resources\System;
|
|
|
|
|
|
2025-09-21 18:07:38 +08:00
|
|
|
use Filament\Schemas\Schema;
|
|
|
|
|
use Filament\Forms\Components\Select;
|
|
|
|
|
use Filament\Forms\Components\DateTimePicker;
|
|
|
|
|
use Filament\Tables\Columns\TextColumn;
|
|
|
|
|
use Filament\Actions\EditAction;
|
|
|
|
|
use App\Filament\Resources\System\TorrentStateResource\Pages\ManageTorrentStates;
|
2022-07-09 18:06:09 +08:00
|
|
|
use App\Filament\Resources\System\TorrentStateResource\Pages;
|
|
|
|
|
use App\Filament\Resources\System\TorrentStateResource\RelationManagers;
|
2022-08-26 17:35:49 +08:00
|
|
|
use App\Models\Setting;
|
2022-07-09 18:06:09 +08:00
|
|
|
use App\Models\Torrent;
|
|
|
|
|
use App\Models\TorrentState;
|
|
|
|
|
use Filament\Forms;
|
|
|
|
|
use Filament\Resources\Resource;
|
2024-12-25 23:09:07 +08:00
|
|
|
use Filament\Tables\Table;
|
2022-07-09 18:06:09 +08:00
|
|
|
use Filament\Tables;
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
|
|
|
use Nexus\Database\NexusDB;
|
|
|
|
|
|
|
|
|
|
class TorrentStateResource extends Resource
|
|
|
|
|
{
|
|
|
|
|
protected static ?string $model = TorrentState::class;
|
|
|
|
|
|
2025-09-21 18:07:38 +08:00
|
|
|
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-megaphone';
|
2022-07-09 18:06:09 +08:00
|
|
|
|
2025-09-21 18:07:38 +08:00
|
|
|
protected static string | \UnitEnum | null $navigationGroup = 'System';
|
2022-07-09 18:06:09 +08:00
|
|
|
|
2025-05-05 18:24:17 +07:00
|
|
|
protected static ?int $navigationSort = 9;
|
2022-07-09 18:06:09 +08:00
|
|
|
|
2024-12-25 23:09:07 +08:00
|
|
|
public static function getNavigationLabel(): string
|
2022-07-09 18:06:09 +08:00
|
|
|
{
|
|
|
|
|
return __('admin.sidebar.torrent_state');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getBreadcrumb(): string
|
|
|
|
|
{
|
|
|
|
|
return self::getNavigationLabel();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-21 18:07:38 +08:00
|
|
|
public static function form(Schema $schema): Schema
|
2022-07-09 18:06:09 +08:00
|
|
|
{
|
2025-09-21 18:07:38 +08:00
|
|
|
return $schema
|
|
|
|
|
->components([
|
|
|
|
|
Select::make('global_sp_state')
|
2022-07-09 18:06:09 +08:00
|
|
|
->options(Torrent::listPromotionTypes(true))
|
|
|
|
|
->label(__('label.torrent_state.global_sp_state'))
|
|
|
|
|
->required(),
|
2025-09-21 18:07:38 +08:00
|
|
|
DateTimePicker::make('begin')
|
2022-08-26 17:35:49 +08:00
|
|
|
->label(__('label.begin')),
|
2025-09-21 18:07:38 +08:00
|
|
|
DateTimePicker::make('deadline')
|
2022-07-09 18:06:09 +08:00
|
|
|
->label(__('label.deadline')),
|
|
|
|
|
])->columns(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function table(Table $table): Table
|
|
|
|
|
{
|
|
|
|
|
return $table
|
|
|
|
|
->columns([
|
2025-09-21 18:07:38 +08:00
|
|
|
TextColumn::make('global_sp_state_text')->label(__('label.torrent_state.global_sp_state')),
|
|
|
|
|
TextColumn::make('begin')->label(__('label.begin')),
|
|
|
|
|
TextColumn::make('deadline')->label(__('label.deadline')),
|
2022-07-09 18:06:09 +08:00
|
|
|
])
|
|
|
|
|
->filters([
|
|
|
|
|
//
|
|
|
|
|
])
|
2025-09-21 18:07:38 +08:00
|
|
|
->recordActions([
|
|
|
|
|
EditAction::make()->after(function () {
|
2022-07-09 18:06:09 +08:00
|
|
|
do_log("cache_del: global_promotion_state");
|
2022-08-26 17:35:49 +08:00
|
|
|
NexusDB::cache_del(Setting::TORRENT_GLOBAL_STATE_CACHE_KEY);
|
2024-11-17 02:44:41 +08:00
|
|
|
do_log("publish_model_event: global_promotion_state_updated");
|
|
|
|
|
publish_model_event("global_promotion_state_updated", 0);
|
2022-07-09 18:06:09 +08:00
|
|
|
}),
|
|
|
|
|
// Tables\Actions\DeleteAction::make(),
|
|
|
|
|
])
|
2025-09-21 18:07:38 +08:00
|
|
|
->toolbarActions([
|
2022-07-09 18:06:09 +08:00
|
|
|
// Tables\Actions\DeleteBulkAction::make(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getPages(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2025-09-21 18:07:38 +08:00
|
|
|
'index' => ManageTorrentStates::route('/'),
|
2022-07-09 18:06:09 +08:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|