coolify/app/Livewire/Project/Service/Configuration.php

86 lines
2.2 KiB
PHP
Raw Normal View History

2024-01-07 16:23:41 +01:00
<?php
namespace App\Livewire\Project\Service;
2024-05-07 15:41:50 +02:00
use App\Actions\Docker\GetContainersStatus;
2024-01-07 16:23:41 +01:00
use App\Models\Service;
use Livewire\Component;
class Configuration extends Component
{
2024-01-31 13:46:40 +01:00
public ?Service $service = null;
2024-06-10 22:43:34 +02:00
2024-01-07 16:23:41 +01:00
public $applications;
2024-06-10 22:43:34 +02:00
2024-01-07 16:23:41 +01:00
public $databases;
2024-06-10 22:43:34 +02:00
2024-01-07 16:23:41 +01:00
public array $parameters;
2024-06-10 22:43:34 +02:00
2024-01-07 16:23:41 +01:00
public array $query;
2024-06-10 22:43:34 +02:00
2024-01-07 16:23:41 +01:00
public function getListeners()
{
$userId = auth()->user()->id;
2024-06-10 22:43:34 +02:00
2024-01-07 16:23:41 +01:00
return [
2024-03-01 10:36:32 +01:00
"echo-private:user.{$userId},ServiceStatusChanged" => 'check_status',
2024-06-10 22:43:34 +02:00
'check_status',
'refresh' => '$refresh',
2024-01-07 16:23:41 +01:00
];
}
2024-06-10 22:43:34 +02:00
2024-01-07 16:23:41 +01:00
public function render()
{
return view('livewire.project.service.configuration');
}
2024-06-10 22:43:34 +02:00
2024-01-07 16:23:41 +01:00
public function mount()
{
$this->parameters = get_route_parameters();
$this->query = request()->query();
$this->service = Service::whereUuid($this->parameters['service_uuid'])->first();
2024-06-10 22:43:34 +02:00
if (! $this->service) {
return redirect()->route('dashboard');
}
2024-01-07 16:23:41 +01:00
$this->applications = $this->service->applications->sort();
$this->databases = $this->service->databases->sort();
}
2024-06-10 22:43:34 +02:00
2024-03-25 11:33:38 +01:00
public function restartApplication($id)
{
try {
$application = $this->service->applications->find($id);
if ($application) {
$application->restart();
$this->dispatch('success', 'Application restarted successfully.');
}
} catch (\Exception $e) {
return handleError($e, $this);
}
}
2024-06-10 22:43:34 +02:00
2024-03-25 11:33:38 +01:00
public function restartDatabase($id)
{
try {
$database = $this->service->databases->find($id);
if ($database) {
$database->restart();
$this->dispatch('success', 'Database restarted successfully.');
}
} catch (\Exception $e) {
return handleError($e, $this);
}
}
2024-06-10 22:43:34 +02:00
2024-03-01 10:36:32 +01:00
public function check_status()
2024-01-07 16:23:41 +01:00
{
2024-03-14 09:21:48 +01:00
try {
2024-05-07 15:41:50 +02:00
GetContainersStatus::run($this->service->server);
// dispatch_sync(new ContainerStatusJob($this->service->server));
2024-03-14 09:21:48 +01:00
$this->dispatch('refresh')->self();
} catch (\Exception $e) {
return handleError($e, $this);
}
2024-01-07 16:23:41 +01:00
}
}