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