torrent operation log type add edit&delete

This commit is contained in:
xiaomlove
2022-12-08 03:48:20 +08:00
parent 6c58a38166
commit 7386806bd6
22 changed files with 386 additions and 71 deletions
+1 -1
View File
@@ -95,7 +95,7 @@ class Test extends Command
public function handle()
{
$rep = new WorkRepository();
$rep->settleRole(5);
$rep->settleRole(4);
}
@@ -0,0 +1,110 @@
<?php
namespace App\Filament\Resources\Torrent;
use App\Filament\Resources\Torrent\TorrentOperationLogResource\Pages;
use App\Filament\Resources\Torrent\TorrentOperationLogResource\RelationManagers;
use App\Models\Torrent;
use App\Models\TorrentOperationLog;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class TorrentOperationLogResource extends Resource
{
protected static ?string $model = TorrentOperationLog::class;
protected static ?string $navigationIcon = 'heroicon-o-collection';
protected static ?string $navigationGroup = 'Torrent';
protected static ?int $navigationSort = 4;
protected static function getNavigationLabel(): string
{
return __('admin.sidebar.torrent_operation_log');
}
public static function getBreadcrumb(): string
{
return self::getNavigationLabel();
}
public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')->sortable(),
Tables\Columns\TextColumn::make('user.username')
->formatStateUsing(fn ($record) => username_for_admin($record->uid))
->label(__('label.user.label'))
,
Tables\Columns\TextColumn::make('torrent.name')
->formatStateUsing(fn ($record) => torrent_name_for_admin($record->torrent))
->label(__('label.torrent.label'))
,
Tables\Columns\TextColumn::make('action_type_text')
->label(__('torrent-operation-log.fields.action_type'))
,
Tables\Columns\TextColumn::make('comment')
->label(__('label.comment'))
,
Tables\Columns\TextColumn::make('created_at')
->formatStateUsing(fn ($state) => format_datetime($state))
->label(__('label.created_at'))
,
])
->filters([
Tables\Filters\Filter::make('uid')
->form([
Forms\Components\TextInput::make('uid')
->placeholder('UID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['uid'], fn (Builder $query, $value) => $query->where("uid", $value));
})
,
Tables\Filters\Filter::make('torrent_id')
->form([
Forms\Components\TextInput::make('torrent_id')
->placeholder('Torrent ID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['torrent_id'], fn (Builder $query, $value) => $query->where("torrent_id", $value));
})
,
Tables\Filters\SelectFilter::make('action_type')
->options(TorrentOperationLog::listStaticProps(TorrentOperationLog::$actionTypes, 'torrent.operation_log.%s.type_text', true))
->label(__('torrent-operation-log.fields.action_type'))
->multiple()
,
])
->actions([
// Tables\Actions\EditAction::make(),
// Tables\Actions\DeleteAction::make(),
])
->bulkActions([
// Tables\Actions\DeleteBulkAction::make(),
]);
}
public static function getPages(): array
{
return [
'index' => Pages\ManageTorrentOperationLogs::route('/'),
];
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Filament\Resources\Torrent\TorrentOperationLogResource\Pages;
use App\Filament\PageListSingle;
use App\Filament\Resources\Torrent\TorrentOperationLogResource;
use App\Models\TorrentOperationLog;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ManageRecords;
use Illuminate\Database\Eloquent\Builder;
class ManageTorrentOperationLogs extends PageListSingle
{
protected static string $resource = TorrentOperationLogResource::class;
protected function getActions(): array
{
return [
// Actions\CreateAction::make(),
];
}
protected function getTableQuery(): Builder
{
return TorrentOperationLog::query()->with(['torrent', 'user']);
}
}
@@ -6,6 +6,7 @@ use App\Filament\OptionsTrait;
use App\Filament\Resources\Torrent\TorrentResource\Pages;
use App\Filament\Resources\Torrent\TorrentResource\RelationManagers;
use App\Models\Category;
use App\Models\SearchBox;
use App\Models\Setting;
use App\Models\Tag;
use App\Models\Torrent;
@@ -27,6 +28,7 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Nexus\Database\NexusDB;
class TorrentResource extends Resource
{
@@ -75,23 +77,18 @@ class TorrentResource extends Resource
->columns([
Tables\Columns\TextColumn::make('id')->sortable(),
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" title="%s">%s</a></div>',
$record->id, $record->name, Str::limit($record->name, 40)
);
$tags = sprintf('&nbsp;<div>%s</div>', $record->tagsFormatted);
return new HtmlString('<div class="flex">' . $name . $tags . '</div>');
})->label(__('label.name'))->searchable(),
Tables\Columns\TextColumn::make('name')->formatStateUsing(fn ($record) => torrent_name_for_admin($record, true))
->label(__('label.name'))
->searchable(),
Tables\Columns\TextColumn::make('posStateText')->label(__('label.torrent.pos_state')),
Tables\Columns\TextColumn::make('spStateText')->label(__('label.torrent.sp_state')),
Tables\Columns\TextColumn::make('pickInfoText')
->label(__('label.torrent.picktype'))
->formatStateUsing(fn ($record) => $record->pickInfo['text'])
,
Tables\Columns\BooleanColumn::make('hr')
Tables\Columns\IconColumn::make('hr')
->label(__('label.torrent.hr'))
->boolean()
,
Tables\Columns\TextColumn::make('size')
->label(__('label.torrent.size'))
@@ -108,55 +105,11 @@ class TorrentResource extends Resource
Tables\Columns\TextColumn::make('added')->label(__('label.added'))->dateTime(),
Tables\Columns\TextColumn::make('user.username')
->label(__('label.torrent.owner'))
->formatStateUsing(fn ($record) => new HtmlString(get_username($record->owner, false, true, true, true)))
->formatStateUsing(fn ($record) => username_for_admin($record->owner))
,
])
->defaultSort('id', 'desc')
->filters([
Tables\Filters\Filter::make('owner')
->form([
Forms\Components\TextInput::make('owner')
->label(__('label.torrent.owner'))
->placeholder('UID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['owner'], fn (Builder $query, $owner) => $query->where("owner", $owner));
})
,
Tables\Filters\SelectFilter::make('category')
->options(Category::query()->pluck('name', 'id')->toArray())
->label(__('label.torrent.category')),
Tables\Filters\SelectFilter::make('visible')
->options(self::$yesOrNo)
->label(__('label.torrent.visible')),
Tables\Filters\SelectFilter::make('pos_state')
->options(Torrent::listPosStates(true))
->label(__('label.torrent.pos_state')),
Tables\Filters\SelectFilter::make('sp_state')
->options(Torrent::listPromotionTypes(true))
->label(__('label.torrent.sp_state')),
Tables\Filters\SelectFilter::make('picktype')
->options(Torrent::listPickInfo(true))
->label(__('label.torrent.picktype')),
Tables\Filters\SelectFilter::make('approval_status')
->options(Torrent::listApprovalStatus(true))
->visible($showApproval)
->label(__('label.torrent.approval_status')),
Tables\Filters\SelectFilter::make('hr')
->options(self::getYesNoOptions())
->label(__('label.torrent.hr')),
Tables\Filters\SelectFilter::make('tags')
->relationship('tags', 'name')
->label(__('label.tag.label'))
,
])
->filters(self::getFilters())
->actions(self::getActions())
->bulkActions(self::getBulkActions());
@@ -394,4 +347,117 @@ class TorrentResource extends Resource
// return Setting::get('torrent.approval_status_none_visible') == 'no' || Setting::get('torrent.approval_status_icon_enabled') == 'yes';
}
private static function getFilters()
{
$filters = [
Tables\Filters\Filter::make('owner')
->form([
Forms\Components\TextInput::make('owner')
->label(__('label.torrent.owner'))
->placeholder('UID')
,
])->query(function (Builder $query, array $data) {
return $query->when($data['owner'], fn (Builder $query, $owner) => $query->where("owner", $owner));
})
,
Tables\Filters\SelectFilter::make('visible')
->options(self::$yesOrNo)
->label(__('label.torrent.visible'))
,
Tables\Filters\SelectFilter::make('hr')
->options(self::getYesNoOptions())
->label(__('label.torrent.hr'))
,
Tables\Filters\SelectFilter::make('pos_state')
->options(Torrent::listPosStates(true))
->label(__('label.torrent.pos_state'))
->multiple()
,
Tables\Filters\SelectFilter::make('sp_state')
->options(Torrent::listPromotionTypes(true))
->label(__('label.torrent.sp_state'))
->multiple()
,
Tables\Filters\SelectFilter::make('picktype')
->options(Torrent::listPickInfo(true))
->label(__('label.torrent.picktype'))
->multiple()
,
Tables\Filters\SelectFilter::make('approval_status')
->options(Torrent::listApprovalStatus(true))
->label(__('label.torrent.approval_status'))
->multiple()
,
Tables\Filters\SelectFilter::make('tags')
->relationship('tags', 'name')
->label(__('label.tag.label'))
->multiple()
,
Tables\Filters\SelectFilter::make('category')
->options(Category::query()->pluck('name', 'id')->toArray())
->label(__('label.torrent.category'))
->multiple()
,
];
foreach (SearchBox::$taxonomies as $torrentField => $tableModel) {
$filters[] = Tables\Filters\SelectFilter::make($torrentField)
->options(NexusDB::table($tableModel['table'])->orderBy('sort_index')->orderBy('id')->pluck('name', 'id'))
->multiple()
;
}
$filters[] = Tables\Filters\Filter::make('added_begin')
->form([
Forms\Components\DatePicker::make('added_begin')
->maxDate(now())
->label(__('label.torrent.added_begin'))
,
])->query(function (Builder $query, array $data) {
return $query->when($data['added_begin'], fn (Builder $query, $value) => $query->where("added", '>=', $value));
})
;
$filters[] = Tables\Filters\Filter::make('added_end')
->form([
Forms\Components\DatePicker::make('added_end')
->maxDate(now())
->label(__('label.torrent.added_end'))
,
])->query(function (Builder $query, array $data) {
return $query->when($data['added_end'], fn (Builder $query, $value) => $query->where("added", '<=', $value));
})
;
$filters[] = Tables\Filters\Filter::make('size_begin')
->form([
Forms\Components\TextInput::make('size_begin')
->numeric()
->placeholder('GB')
->label(__('label.torrent.size_begin'))
,
])->query(function (Builder $query, array $data) {
return $query->when($data['size_begin'], fn (Builder $query, $value) => $query->where("size", '>=', $value * 1024 * 1024 * 1024));
})
;
$filters[] = Tables\Filters\Filter::make('size_end')
->form([
Forms\Components\TextInput::make('size_end')
->numeric()
->placeholder('GB')
->label(__('label.torrent.size_end'))
,
])->query(function (Builder $query, array $data) {
return $query->when($data['size_end'], fn (Builder $query, $value) => $query->where("size", '<=', $value * 1024 * 1024 * 1024));
})
;
return $filters;
}
}
+6 -1
View File
@@ -56,7 +56,12 @@ class NexusModel extends Model
$result = $dataSource;
$keyValue = [];
foreach ($result as $key => &$info) {
$text = $textTransPrefix ? nexus_trans("$textTransPrefix.$key") : $info['text'];
if (str_contains($textTransPrefix, '%s')) {
$transKey = sprintf($textTransPrefix, $key);
} else {
$transKey = "$textTransPrefix.$key";
}
$text = $textTransPrefix ? nexus_trans($transKey) : $info['text'];
$info['text'] = $text;
$keyValue[$key] = $info[$valueField];
}
+4
View File
@@ -15,11 +15,15 @@ class TorrentOperationLog extends NexusModel
const ACTION_TYPE_APPROVAL_NONE = 'approval_none';
const ACTION_TYPE_APPROVAL_ALLOW = 'approval_allow';
const ACTION_TYPE_APPROVAL_DENY = 'approval_deny';
const ACTION_TYPE_EDIT = 'edit';
const ACTION_TYPE_DELETE = 'delete';
public static array $actionTypes = [
self::ACTION_TYPE_APPROVAL_NONE => ['text' => 'Approval none'],
self::ACTION_TYPE_APPROVAL_ALLOW => ['text' => 'Approval allow'],
self::ACTION_TYPE_APPROVAL_DENY => ['text' => 'Approval deny'],
self::ACTION_TYPE_EDIT => ['text' => 'Edit'],
self::ACTION_TYPE_DELETE => ['text' => 'Delete'],
];
public function getActionTypeTextAttribute()
+2 -2
View File
@@ -154,7 +154,7 @@ class ClaimRepository extends BaseRepository
public function settleUser($uid, $force = false, $test = false): bool
{
$user = User::query()->with('language')->findOrFail($uid);
$list = Claim::query()->where('uid', $uid)->with(['snatch'])->get();
$list = Claim::query()->where('uid', $uid)->with(['snatch', 'torrent' => fn ($query) => $query->select(Torrent::$commentFields)])->get();
$now = Carbon::now();
$startOfThisMonth = $now->clone()->startOfMonth();
$seedTimeRequiredHours = Claim::getConfigStandardSeedTimeHours();
@@ -210,7 +210,7 @@ class ClaimRepository extends BaseRepository
"reachedTorrentIdArr: %s, unReachedIdArr: %s, bonusResult: %s, seedTimeHours: %s",
json_encode($reachedTorrentIdArr), json_encode($unReachedIdArr), json_encode($bonusResult), $seedTimeHoursAvg
), 'alert');
$bonusFinal = $bonusResult['seed_bonus'] * $seedTimeHoursAvg * $bonusMultiplier;
$bonusFinal = $bonusResult['seed_points'] * $seedTimeHoursAvg * $bonusMultiplier;
do_log("bonus final: $bonusFinal", 'alert');
$totalDeduct = $bonusDeduct * count($unReachedIdArr);