lasthourcloud/app/Livewire/Project/Service/ServiceApplicationView.php

69 lines
2.2 KiB
PHP
Raw Normal View History

2023-09-22 09:23:49 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Project\Service;
2023-09-22 09:23:49 +00:00
use App\Models\ServiceApplication;
use Livewire\Component;
class ServiceApplicationView extends Component
2023-09-22 09:23:49 +00:00
{
public ServiceApplication $application;
2023-09-25 13:48:43 +00:00
public $parameters;
2023-09-22 09:23:49 +00:00
protected $rules = [
'application.human_name' => 'nullable',
'application.description' => 'nullable',
2023-09-22 09:23:49 +00:00
'application.fqdn' => 'nullable',
2023-09-26 12:45:52 +00:00
'application.image' => 'required',
'application.exclude_from_status' => 'required|boolean',
'application.required_fqdn' => 'required|boolean',
'application.is_log_drain_enabled' => 'nullable|boolean',
'application.is_gzip_enabled' => 'nullable|boolean',
2023-09-22 09:23:49 +00:00
];
public function render()
{
return view('livewire.project.service.service-application-view');
2023-09-22 09:23:49 +00:00
}
2023-09-26 12:45:52 +00:00
public function instantSave()
{
2023-09-25 13:48:43 +00:00
$this->submit();
}
public function instantSaveAdvanced()
{
if (!$this->application->service->destination->server->isLogDrainEnabled()) {
$this->application->is_log_drain_enabled = false;
2023-12-07 18:06:32 +00:00
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return;
}
$this->application->save();
2023-12-07 18:06:32 +00:00
$this->dispatch('success', 'You need to restart the service for the changes to take effect.');
}
2023-09-25 13:48:43 +00:00
public function delete()
{
try {
$this->application->delete();
2023-12-07 18:06:32 +00:00
$this->dispatch('success', 'Application deleted successfully.');
2023-12-27 15:45:01 +00:00
return redirect()->route('project.service.configuration', $this->parameters);
2023-09-25 13:48:43 +00:00
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function mount()
{
2023-09-25 13:48:43 +00:00
$this->parameters = get_route_parameters();
}
2023-09-22 09:23:49 +00:00
public function submit()
{
try {
2024-01-30 08:22:34 +00:00
check_fqdn_usage($this->application);
2023-09-22 09:23:49 +00:00
$this->validate();
$this->application->save();
2023-09-27 10:45:53 +00:00
updateCompose($this->application);
2023-12-07 18:06:32 +00:00
$this->dispatch('success', 'Application saved successfully.');
2023-09-22 09:23:49 +00:00
} catch (\Throwable $e) {
2023-09-27 10:45:53 +00:00
return handleError($e, $this);
2023-09-22 09:23:49 +00:00
} finally {
2023-12-07 18:06:32 +00:00
$this->dispatch('generateDockerCompose');
2023-09-22 09:23:49 +00:00
}
}
}