2024-02-16 20:56:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\Server;
|
|
|
|
|
|
|
|
use App\Models\Server;
|
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
2024-02-16 22:09:35 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2024-02-16 20:56:38 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Resources extends Component
|
|
|
|
{
|
|
|
|
use AuthorizesRequests;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-16 20:56:38 +00:00
|
|
|
public ?Server $server = null;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-16 20:56:38 +00:00
|
|
|
public $parameters = [];
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-03-01 18:13:22 +00:00
|
|
|
public Collection $unmanagedContainers;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-16 21:15:18 +00:00
|
|
|
public function getListeners()
|
|
|
|
{
|
|
|
|
$teamId = auth()->user()->currentTeam()->id;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-16 21:15:18 +00:00
|
|
|
return [
|
|
|
|
"echo-private:team.{$teamId},ApplicationStatusChanged" => 'refreshStatus',
|
|
|
|
];
|
|
|
|
}
|
2024-02-16 20:56:38 +00:00
|
|
|
|
2024-06-10 20:43:34 +00:00
|
|
|
public function startUnmanaged($id)
|
|
|
|
{
|
2024-02-16 22:09:35 +00:00
|
|
|
$this->server->startUnmanaged($id);
|
|
|
|
$this->dispatch('success', 'Container started.');
|
|
|
|
$this->loadUnmanagedContainers();
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
|
|
|
public function restartUnmanaged($id)
|
|
|
|
{
|
2024-02-16 22:09:35 +00:00
|
|
|
$this->server->restartUnmanaged($id);
|
|
|
|
$this->dispatch('success', 'Container restarted.');
|
|
|
|
$this->loadUnmanagedContainers();
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
|
|
|
public function stopUnmanaged($id)
|
|
|
|
{
|
2024-02-16 22:09:35 +00:00
|
|
|
$this->server->stopUnmanaged($id);
|
|
|
|
$this->dispatch('success', 'Container stopped.');
|
|
|
|
$this->loadUnmanagedContainers();
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
|
|
|
public function refreshStatus()
|
|
|
|
{
|
2024-02-16 21:15:18 +00:00
|
|
|
$this->server->refresh();
|
2024-02-16 22:09:35 +00:00
|
|
|
$this->loadUnmanagedContainers();
|
2024-02-16 21:15:18 +00:00
|
|
|
$this->dispatch('success', 'Resource statuses refreshed.');
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
|
|
|
public function loadUnmanagedContainers()
|
|
|
|
{
|
2024-04-02 13:01:50 +00:00
|
|
|
try {
|
|
|
|
$this->unmanagedContainers = $this->server->loadUnmanagedContainers();
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
2024-02-16 22:09:35 +00:00
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2024-02-16 22:09:35 +00:00
|
|
|
$this->unmanagedContainers = collect();
|
2024-02-16 20:56:38 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
|
|
|
try {
|
|
|
|
$this->server = Server::ownedByCurrentTeam()->whereUuid(request()->server_uuid)->first();
|
|
|
|
if (is_null($this->server)) {
|
|
|
|
return redirect()->route('server.index');
|
|
|
|
}
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-02-16 20:56:38 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.server.resources');
|
|
|
|
}
|
|
|
|
}
|