Add Docker container management methods and update Livewire component

This commit is contained in:
Andras Bacsai
2024-02-16 23:09:35 +01:00
parent f8c86769a7
commit 7d6bd10cca
3 changed files with 181 additions and 47 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Livewire\Server;
use App\Models\Server;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Collection;
use Livewire\Component;
class Resources extends Component
@@ -11,6 +12,7 @@ class Resources extends Component
use AuthorizesRequests;
public ?Server $server = null;
public $parameters = [];
public Collection $unmanagedContainers;
public function getListeners()
{
$teamId = auth()->user()->currentTeam()->id;
@@ -19,11 +21,31 @@ class Resources extends Component
];
}
public function startUnmanaged($id) {
$this->server->startUnmanaged($id);
$this->dispatch('success', 'Container started.');
$this->loadUnmanagedContainers();
}
public function restartUnmanaged($id) {
$this->server->restartUnmanaged($id);
$this->dispatch('success', 'Container restarted.');
$this->loadUnmanagedContainers();
}
public function stopUnmanaged($id) {
$this->server->stopUnmanaged($id);
$this->dispatch('success', 'Container stopped.');
$this->loadUnmanagedContainers();
}
public function refreshStatus() {
$this->server->refresh();
$this->loadUnmanagedContainers();
$this->dispatch('success', 'Resource statuses refreshed.');
}
public function loadUnmanagedContainers() {
$this->unmanagedContainers = $this->server->loadUnmanagedContainers();
}
public function mount() {
$this->unmanagedContainers = collect();
$this->parameters = get_route_parameters();
try {
$this->server = Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->first();
@@ -33,6 +55,7 @@ class Resources extends Component
} catch (\Throwable $e) {
return handleError($e, $this);
}
$this->loadUnmanagedContainers();
}
public function render()
{