mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-20 06:23:23 +00:00
Extract a shared forms collapsible for advanced SSH/build settings across boarding, server creation, and application general. Support larger modals with header actions, close the compose editor after save via compose-save-finished, and cover the layout in tests.
107 lines
3.0 KiB
PHP
107 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Project\Service;
|
|
|
|
use App\Models\Service;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Livewire\Component;
|
|
|
|
class EditCompose extends Component
|
|
{
|
|
use AuthorizesRequests;
|
|
|
|
public Service $service;
|
|
|
|
public $serviceId;
|
|
|
|
public ?string $dockerComposeRaw = null;
|
|
|
|
public ?string $dockerCompose = null;
|
|
|
|
public bool $isContainerLabelEscapeEnabled = false;
|
|
|
|
protected $listeners = [
|
|
'refreshEnvs',
|
|
'envsUpdated',
|
|
'refresh' => 'envsUpdated',
|
|
];
|
|
|
|
protected $rules = [
|
|
'dockerComposeRaw' => 'required',
|
|
'dockerCompose' => 'required',
|
|
'isContainerLabelEscapeEnabled' => 'required',
|
|
];
|
|
|
|
public function envsUpdated()
|
|
{
|
|
$this->dispatch('saveCompose', $this->dockerComposeRaw);
|
|
$this->refreshEnvs();
|
|
}
|
|
|
|
public function refreshEnvs()
|
|
{
|
|
$this->service = Service::ownedByCurrentTeam()->find($this->serviceId);
|
|
$this->syncData(false);
|
|
}
|
|
|
|
public function mount()
|
|
{
|
|
$this->service = Service::ownedByCurrentTeam()->find($this->serviceId);
|
|
$this->syncData(false);
|
|
}
|
|
|
|
private function syncData(bool $toModel = false): void
|
|
{
|
|
if ($toModel) {
|
|
$this->service->docker_compose_raw = $this->dockerComposeRaw;
|
|
$this->service->docker_compose = $this->dockerCompose;
|
|
$this->service->is_container_label_escape_enabled = $this->isContainerLabelEscapeEnabled;
|
|
} else {
|
|
$this->dockerComposeRaw = $this->service->docker_compose_raw;
|
|
$this->dockerCompose = $this->service->docker_compose;
|
|
$this->isContainerLabelEscapeEnabled = $this->service->is_container_label_escape_enabled ?? false;
|
|
}
|
|
}
|
|
|
|
public function validateCompose()
|
|
{
|
|
$isValid = validateComposeFile($this->dockerComposeRaw, $this->service->server_id);
|
|
if ($isValid !== 'OK') {
|
|
$this->dispatch('error', "Invalid docker-compose file.\n$isValid");
|
|
} else {
|
|
$this->dispatch('success', 'Docker compose is valid.');
|
|
}
|
|
}
|
|
|
|
public function saveEditedCompose()
|
|
{
|
|
try {
|
|
$this->authorize('update', $this->service);
|
|
$this->dispatch('saveCompose', $this->dockerComposeRaw);
|
|
$this->dispatch('refreshStorages');
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
public function instantSave()
|
|
{
|
|
try {
|
|
$this->authorize('update', $this->service);
|
|
$this->validate([
|
|
'isContainerLabelEscapeEnabled' => 'required',
|
|
]);
|
|
$this->syncData(true);
|
|
$this->service->save(['is_container_label_escape_enabled' => $this->isContainerLabelEscapeEnabled]);
|
|
$this->dispatch('success', 'Service updated successfully');
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.project.service.edit-compose');
|
|
}
|
|
}
|