mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-04 23:42:34 +00:00
Feature/nodejs (#397)
* Add node support using nvm * Add icon * Rename to NodeJS * Rename to NodeJS * update php and node logo * only services which have units can be started,restarted,stopped,disabled and enabled * add tests --------- Co-authored-by: Saeed Vaziry <mr.saeedvaziry@gmail.com> Co-authored-by: Saeed Vaziry <61919774+saeedvaziry@users.noreply.github.com>
This commit is contained in:
66
app/Web/Pages/Servers/NodeJS/Index.php
Normal file
66
app/Web/Pages/Servers/NodeJS/Index.php
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Web\Pages\Servers\NodeJS;
|
||||
|
||||
use App\Actions\NodeJS\InstallNewNodeJsVersion;
|
||||
use App\Enums\NodeJS;
|
||||
use App\Models\Service;
|
||||
use App\Web\Pages\Servers\NodeJS\Widgets\NodeJSList;
|
||||
use App\Web\Pages\Servers\Page;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Support\Enums\MaxWidth;
|
||||
|
||||
class Index extends Page
|
||||
{
|
||||
protected static ?string $slug = 'servers/{server}/nodejs';
|
||||
|
||||
protected static ?string $title = 'NodeJS';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->authorize('viewAny', [Service::class, $this->server]);
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
[NodeJSList::class, ['server' => $this->server]],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
$installedNodeVersions = $this->server->installedNodejsVersions();
|
||||
|
||||
return [
|
||||
Action::make('install')
|
||||
->authorize(fn () => auth()->user()?->can('create', [Service::class, $this->server]))
|
||||
->label('Install Node')
|
||||
->icon('heroicon-o-archive-box-arrow-down')
|
||||
->modalWidth(MaxWidth::Large)
|
||||
->form([
|
||||
Select::make('version')
|
||||
->options(
|
||||
collect(config('core.nodejs_versions'))
|
||||
->filter(fn ($version) => ! in_array($version, array_merge($installedNodeVersions, [NodeJS::NONE])))
|
||||
->mapWithKeys(fn ($version) => [$version => $version])
|
||||
->toArray()
|
||||
)
|
||||
->rules(InstallNewNodeJsVersion::rules($this->server)['version']),
|
||||
])
|
||||
->modalSubmitActionLabel('Install')
|
||||
->action(function (array $data) {
|
||||
app(InstallNewNodeJsVersion::class)->install($this->server, $data);
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title('Installing Node...')
|
||||
->send();
|
||||
|
||||
$this->dispatch('$refresh');
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user