mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 15:32:35 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -25,14 +25,20 @@ class LogsList extends Widget
|
||||
|
||||
public bool $remote = false;
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<ServerLog>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return ServerLog::query()
|
||||
->where('server_id', $this->server->id)
|
||||
->where(function (Builder $query) {
|
||||
if ($this->site) {
|
||||
->where(function (Builder $query): void {
|
||||
if ($this->site instanceof \App\Models\Site) {
|
||||
$query->where('site_id', $this->site->id);
|
||||
}
|
||||
})
|
||||
@ -53,6 +59,10 @@ protected function getTableColumns(): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<ServerLog> $query
|
||||
* @return Builder<ServerLog>
|
||||
*/
|
||||
protected function applyDefaultSortingToTableQuery(Builder $query): Builder
|
||||
{
|
||||
return $query->latest('created_at');
|
||||
@ -63,6 +73,9 @@ protected function applyDefaultSortingToTableQuery(Builder $query): Builder
|
||||
*/
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->heading(null)
|
||||
->query($this->getTableQuery())
|
||||
@ -73,31 +86,27 @@ public function table(Table $table): Table
|
||||
DatePicker::make('created_from'),
|
||||
DatePicker::make('created_until'),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query
|
||||
->when(
|
||||
$data['created_from'],
|
||||
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date),
|
||||
)
|
||||
->when(
|
||||
$data['created_until'],
|
||||
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
|
||||
);
|
||||
}),
|
||||
->query(fn (Builder $query, array $data): Builder => $query
|
||||
->when(
|
||||
$data['created_from'],
|
||||
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date),
|
||||
)
|
||||
->when(
|
||||
$data['created_until'],
|
||||
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
|
||||
)),
|
||||
])
|
||||
->actions([
|
||||
Action::make('view')
|
||||
->hiddenLabel()
|
||||
->tooltip('View')
|
||||
->icon('heroicon-o-eye')
|
||||
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
||||
->authorize(fn ($record) => $user->can('view', $record))
|
||||
->modalHeading('View Log')
|
||||
->modalContent(function (ServerLog $record) {
|
||||
return view('components.console-view', [
|
||||
'slot' => $record->getContent(),
|
||||
'attributes' => new ComponentAttributeBag,
|
||||
]);
|
||||
})
|
||||
->modalContent(fn (ServerLog $record) => view('components.console-view', [
|
||||
'slot' => $record->getContent(),
|
||||
'attributes' => new ComponentAttributeBag,
|
||||
]))
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Close'),
|
||||
Action::make('download')
|
||||
@ -105,19 +114,19 @@ public function table(Table $table): Table
|
||||
->tooltip('Download')
|
||||
->color('gray')
|
||||
->icon('heroicon-o-archive-box-arrow-down')
|
||||
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
||||
->action(fn (ServerLog $record) => $record->download()),
|
||||
->authorize(fn ($record) => $user->can('view', $record))
|
||||
->action(fn (ServerLog $record): \Symfony\Component\HttpFoundation\StreamedResponse => $record->download()),
|
||||
DeleteAction::make()
|
||||
->hiddenLabel()
|
||||
->tooltip('Delete')
|
||||
->icon('heroicon-o-trash')
|
||||
->color('danger')
|
||||
->authorize(fn ($record) => auth()->user()->can('delete', $record)),
|
||||
->authorize(fn ($record) => $user->can('delete', $record)),
|
||||
])
|
||||
->bulkActions([
|
||||
DeleteBulkAction::make()
|
||||
->requiresConfirmation()
|
||||
->authorize(auth()->user()->can('deleteMany', [ServerLog::class, $this->server])),
|
||||
->authorize($user->can('deleteMany', [ServerLog::class, $this->server])),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user