mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-03 06:56:15 +00:00
Add phpstan level 7(#544)
This commit is contained in:
@ -42,18 +42,17 @@ protected function getHeaderActions(): array
|
||||
{
|
||||
$form = [
|
||||
Select::make('server')
|
||||
->options(function () {
|
||||
return auth()->user()?->currentProject?->servers?->pluck('name', 'id') ?? [];
|
||||
})
|
||||
->options(fn () => auth()->user()?->currentProject?->servers?->pluck('name', 'id') ?? [])
|
||||
->rules(fn (Get $get) => ExecuteScript::rules($get())['server'])
|
||||
->searchable()
|
||||
->reactive(),
|
||||
Select::make('user')
|
||||
->rules(fn (Get $get) => ExecuteScript::rules($get())['user'])
|
||||
->native(false)
|
||||
->options(function (Get $get) {
|
||||
->options(function (Get $get): array {
|
||||
$users = ['root'];
|
||||
|
||||
/** @var ?Server $server */
|
||||
$server = Server::query()->find($get('server'));
|
||||
if ($server) {
|
||||
$users = $server->getSshUsers();
|
||||
@ -74,7 +73,7 @@ protected function getHeaderActions(): array
|
||||
->icon('heroicon-o-bolt')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->form($form)
|
||||
->action(function (array $data) {
|
||||
->action(function (array $data): void {
|
||||
app(ExecuteScript::class)->execute($this->script, $data);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
|
@ -40,6 +40,9 @@ public function getWidgets(): array
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
/** @var \App\Models\User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return [
|
||||
Action::make('read-the-docs')
|
||||
->label('Read the Docs')
|
||||
@ -62,9 +65,9 @@ protected function getHeaderActions(): array
|
||||
->label('Is Global (Accessible in all projects)'),
|
||||
])
|
||||
->modalSubmitActionLabel('Create')
|
||||
->action(function (array $data) {
|
||||
run_action($this, function () use ($data) {
|
||||
app(CreateScript::class)->create(auth()->user(), $data);
|
||||
->action(function (array $data) use ($user): void {
|
||||
run_action($this, function () use ($data, $user): void {
|
||||
app(CreateScript::class)->create($user, $data);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
});
|
||||
|
@ -14,15 +14,25 @@
|
||||
|
||||
class ScriptExecutionsList extends Widget
|
||||
{
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
public Script $script;
|
||||
|
||||
/**
|
||||
* @return Builder<ScriptExecution>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return ScriptExecution::query()->where('script_id', $this->script->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<ScriptExecution> $query
|
||||
* @return Builder<ScriptExecution>
|
||||
*/
|
||||
protected function applyDefaultSortingToTableQuery(Builder $query): Builder
|
||||
{
|
||||
return $query->latest('created_at');
|
||||
@ -32,13 +42,11 @@ protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('server')
|
||||
->formatStateUsing(function (ScriptExecution $record) {
|
||||
return $record->getServer()?->name ?? 'Unknown';
|
||||
})
|
||||
->url(function (ScriptExecution $record) {
|
||||
->formatStateUsing(fn (ScriptExecution $record) => $record->getServer()->name ?? 'Unknown')
|
||||
->url(function (ScriptExecution $record): ?string {
|
||||
$server = $record->getServer();
|
||||
|
||||
return $server ? View::getUrl(['server' => $server]) : null;
|
||||
return $server instanceof \App\Models\Server ? View::getUrl(['server' => $server]) : null;
|
||||
})
|
||||
->searchable()
|
||||
->sortable(),
|
||||
@ -66,14 +74,12 @@ public function table(Table $table): Table
|
||||
->hiddenLabel()
|
||||
->tooltip('Logs')
|
||||
->icon('heroicon-o-eye')
|
||||
->authorize(fn (ScriptExecution $record) => auth()->user()->can('view', $record->serverLog))
|
||||
->authorize(fn (ScriptExecution $record) => auth()->user()?->can('view', $record->serverLog))
|
||||
->modalHeading('View Log')
|
||||
->modalContent(function (ScriptExecution $record) {
|
||||
return view('components.console-view', [
|
||||
'slot' => $record->serverLog?->getContent(),
|
||||
'attributes' => new ComponentAttributeBag,
|
||||
]);
|
||||
})
|
||||
->modalContent(fn (ScriptExecution $record) => view('components.console-view', [
|
||||
'slot' => $record->serverLog?->getContent(),
|
||||
'attributes' => new ComponentAttributeBag,
|
||||
]))
|
||||
->modalSubmitAction(false)
|
||||
->modalCancelActionLabel('Close'),
|
||||
]);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
use App\Actions\Script\EditScript;
|
||||
use App\Models\Script;
|
||||
use App\Models\User;
|
||||
use App\Web\Fields\CodeEditorField;
|
||||
use App\Web\Pages\Scripts\Executions;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
@ -18,11 +19,20 @@
|
||||
|
||||
class ScriptsList extends Widget
|
||||
{
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $listeners = ['$refresh'];
|
||||
|
||||
/**
|
||||
* @return Builder<Script>
|
||||
*/
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Script::getByProjectId(auth()->user()->current_project_id, auth()->user()->id);
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return Script::getByProjectId($user->current_project_id, $user->id);
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
@ -34,10 +44,8 @@ protected function getTableColumns(): array
|
||||
TextColumn::make('id')
|
||||
->label('Global')
|
||||
->badge()
|
||||
->color(fn ($record) => $record->project_id ? 'gray' : 'success')
|
||||
->formatStateUsing(function (Script $record) {
|
||||
return $record->project_id ? 'No' : 'Yes';
|
||||
}),
|
||||
->color(fn ($record): string => $record->project_id ? 'gray' : 'success')
|
||||
->formatStateUsing(fn (Script $record): string => $record->project_id ? 'No' : 'Yes'),
|
||||
TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->formatStateUsing(fn (Script $record) => $record->created_at_by_timezone)
|
||||
@ -48,22 +56,23 @@ protected function getTableColumns(): array
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
|
||||
return $table
|
||||
->heading(null)
|
||||
->query($this->getTableQuery())
|
||||
->columns($this->getTableColumns())
|
||||
->recordUrl(fn (Script $record) => Executions::getUrl(['script' => $record]))
|
||||
->recordUrl(fn (Script $record): string => Executions::getUrl(['script' => $record]))
|
||||
->actions([
|
||||
EditAction::make('edit')
|
||||
->label('Edit')
|
||||
->modalHeading('Edit Script')
|
||||
->mutateRecordDataUsing(function (array $data, Script $record) {
|
||||
return [
|
||||
'name' => $record->name,
|
||||
'content' => $record->content,
|
||||
'global' => $record->project_id === null,
|
||||
];
|
||||
})
|
||||
->mutateRecordDataUsing(fn (array $data, Script $record): array => [
|
||||
'name' => $record->name,
|
||||
'content' => $record->content,
|
||||
'global' => $record->project_id === null,
|
||||
])
|
||||
->form([
|
||||
TextInput::make('name')
|
||||
->rules(EditScript::rules()['name']),
|
||||
@ -73,17 +82,17 @@ public function table(Table $table): Table
|
||||
Checkbox::make('global')
|
||||
->label('Is Global (Accessible in all projects)'),
|
||||
])
|
||||
->authorize(fn (Script $record) => auth()->user()->can('update', $record))
|
||||
->using(function (array $data, Script $record) {
|
||||
app(EditScript::class)->edit($record, auth()->user(), $data);
|
||||
->authorize(fn (Script $record) => $user->can('update', $record))
|
||||
->using(function (array $data, Script $record) use ($user): void {
|
||||
app(EditScript::class)->edit($record, $user, $data);
|
||||
$this->dispatch('$refresh');
|
||||
})
|
||||
->modalWidth(MaxWidth::ThreeExtraLarge),
|
||||
DeleteAction::make('delete')
|
||||
->label('Delete')
|
||||
->modalHeading('Delete Script')
|
||||
->authorize(fn (Script $record) => auth()->user()->can('delete', $record))
|
||||
->using(function (array $data, Script $record) {
|
||||
->authorize(fn (Script $record) => $user->can('delete', $record))
|
||||
->using(function (array $data, Script $record): void {
|
||||
$record->delete();
|
||||
}),
|
||||
]);
|
||||
|
Reference in New Issue
Block a user