mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 05:56:16 +00:00
- 2.x - scripts
This commit is contained in:
86
app/Web/Pages/Scripts/Executions.php
Normal file
86
app/Web/Pages/Scripts/Executions.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Pages\Scripts;
|
||||
|
||||
use App\Actions\Script\ExecuteScript;
|
||||
use App\Models\Script;
|
||||
use App\Models\Server;
|
||||
use App\Web\Components\Page;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Support\Enums\MaxWidth;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class Executions extends Page
|
||||
{
|
||||
protected static bool $shouldRegisterNavigation = false;
|
||||
|
||||
protected static ?string $slug = 'scripts/{script}/executions';
|
||||
|
||||
public Script $script;
|
||||
|
||||
public function getTitle(): string|Htmlable
|
||||
{
|
||||
return $this->script->name.' - Executions';
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return auth()->user()?->can('view', get_from_route(Script::class, 'script')) ?? false;
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
[Widgets\ScriptExecutionsList::class, ['script' => $this->script]],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
$form = [
|
||||
Select::make('server')
|
||||
->options(function () {
|
||||
return 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 = [
|
||||
'root' => 'root',
|
||||
];
|
||||
|
||||
$server = Server::query()->find($get('server'));
|
||||
if ($server) {
|
||||
$options[$server->ssh_user] = $server->ssh_user;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}),
|
||||
];
|
||||
|
||||
foreach ($this->script->getVariables() as $variable) {
|
||||
$form[] = TextInput::make($variable)
|
||||
->label($variable)
|
||||
->rules(fn (Get $get) => ExecuteScript::rules($get())['variables.*']);
|
||||
}
|
||||
|
||||
return [
|
||||
Action::make('execute')
|
||||
->icon('heroicon-o-bolt')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->form($form)
|
||||
->action(function (array $data) {
|
||||
app(ExecuteScript::class)->execute($this->script, $data);
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user