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

102 lines
2.9 KiB
PHP
Raw Normal View History

2024-01-07 16:23:41 +01:00
<?php
namespace App\Livewire\Project\Service;
use App\Models\Service;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
2024-01-07 16:23:41 +01:00
use Livewire\Component;
class Configuration extends Component
{
use AuthorizesRequests;
2024-12-17 11:13:13 +01:00
public $currentRoute;
public $project;
public $environment;
2024-01-31 13:46:40 +01:00
public ?Service $service = null;
2024-06-10 20:43:34 +00:00
2024-01-07 16:23:41 +01:00
public $applications;
2024-06-10 20:43:34 +00:00
2024-01-07 16:23:41 +01:00
public $databases;
2024-06-10 20:43:34 +00:00
2024-01-07 16:23:41 +01:00
public array $query;
2024-06-10 20:43:34 +00:00
2024-12-17 11:13:13 +01:00
public array $parameters;
protected $listeners = [
'refreshServices' => 'refreshServices',
'refresh' => 'refreshServices',
];
2024-06-10 20:43:34 +00:00
2024-01-07 16:23:41 +01:00
public function render()
{
return view('livewire.project.service.configuration');
}
2024-06-10 20:43:34 +00:00
2024-01-07 16:23:41 +01:00
public function mount()
{
try {
$this->parameters = get_route_parameters();
$this->currentRoute = request()->route()->getName();
$this->query = request()->query();
$project = currentTeam()
->projects()
2026-04-23 14:53:31 +05:30
->select('id', 'uuid', 'name', 'team_id')
->where('uuid', request()->route('project_uuid'))
->firstOrFail();
$environment = $project->environments()
->select('id', 'uuid', 'name', 'project_id')
->where('uuid', request()->route('environment_uuid'))
->firstOrFail();
$this->service = $environment->services()->whereUuid(request()->route('service_uuid'))->firstOrFail();
$this->authorize('view', $this->service);
$this->project = $project;
$this->environment = $environment;
$this->applications = $this->service->applications->sort();
$this->databases = $this->service->databases->sort();
} catch (\Throwable $e) {
return handleError($e, $this);
}
2024-01-07 16:23:41 +01:00
}
2024-06-10 20:43:34 +00:00
public function refreshServices()
{
$this->service->refresh();
$this->applications = $this->service->applications->sort();
$this->databases = $this->service->databases->sort();
}
2024-03-25 11:33:38 +01:00
public function restartApplication($id)
{
try {
$this->authorize('update', $this->service);
2024-03-25 11:33:38 +01:00
$application = $this->service->applications->find($id);
if ($application) {
$application->restart();
2024-09-03 16:59:51 +02:00
$this->dispatch('success', 'Service application restarted successfully.');
2024-03-25 11:33:38 +01:00
}
2025-01-07 15:31:43 +01:00
} catch (\Exception $e) {
2024-03-25 11:33:38 +01:00
return handleError($e, $this);
}
}
2024-06-10 20:43:34 +00:00
2024-03-25 11:33:38 +01:00
public function restartDatabase($id)
{
try {
$this->authorize('update', $this->service);
2024-03-25 11:33:38 +01:00
$database = $this->service->databases->find($id);
if ($database) {
$database->restart();
2024-09-03 16:59:51 +02:00
$this->dispatch('success', 'Service database restarted successfully.');
2024-03-25 11:33:38 +01:00
}
2025-01-07 15:31:43 +01:00
} catch (\Exception $e) {
2024-03-25 11:33:38 +01:00
return handleError($e, $this);
}
}
2024-01-07 16:23:41 +01:00
}