2023-10-12 07:12:46 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project\Service;
|
2023-10-12 07:12:46 +00:00
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class StackForm extends Component
|
|
|
|
{
|
2023-10-17 08:17:03 +00:00
|
|
|
public $service;
|
2023-11-13 10:09:21 +00:00
|
|
|
public $fields = [];
|
2023-10-12 07:12:46 +00:00
|
|
|
protected $listeners = ["saveCompose"];
|
2023-11-13 10:09:21 +00:00
|
|
|
public $rules = [
|
2023-10-12 07:12:46 +00:00
|
|
|
'service.docker_compose_raw' => 'required',
|
|
|
|
'service.docker_compose' => 'required',
|
|
|
|
'service.name' => 'required',
|
|
|
|
'service.description' => 'nullable',
|
2024-01-21 13:30:03 +00:00
|
|
|
'service.connect_to_docker_network' => 'nullable',
|
2023-10-12 07:12:46 +00:00
|
|
|
];
|
2023-11-13 10:09:21 +00:00
|
|
|
public $validationAttributes = [];
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$extraFields = $this->service->extraFields();
|
|
|
|
foreach ($extraFields as $serviceName => $fields) {
|
|
|
|
foreach ($fields as $fieldKey => $field) {
|
|
|
|
$key = data_get($field, 'key');
|
|
|
|
$value = data_get($field, 'value');
|
2023-11-24 20:38:39 +00:00
|
|
|
$rules = data_get($field, 'rules', 'nullable');
|
2023-11-13 10:09:21 +00:00
|
|
|
$isPassword = data_get($field, 'isPassword');
|
|
|
|
$this->fields[$key] = [
|
|
|
|
"serviceName" => $serviceName,
|
|
|
|
"key" => $key,
|
|
|
|
"name" => $fieldKey,
|
|
|
|
"value" => $value,
|
|
|
|
"isPassword" => $isPassword,
|
2023-11-24 20:04:15 +00:00
|
|
|
"rules" => $rules
|
2023-11-13 10:09:21 +00:00
|
|
|
];
|
|
|
|
$this->rules["fields.$key.value"] = $rules;
|
|
|
|
$this->validationAttributes["fields.$key.value"] = $fieldKey;
|
|
|
|
}
|
2023-11-11 20:32:41 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-12 07:12:46 +00:00
|
|
|
public function saveCompose($raw)
|
|
|
|
{
|
2023-11-11 20:32:41 +00:00
|
|
|
|
2023-10-12 07:12:46 +00:00
|
|
|
$this->service->docker_compose_raw = $raw;
|
|
|
|
$this->submit();
|
|
|
|
}
|
2024-02-15 19:44:01 +00:00
|
|
|
public function instantSave()
|
|
|
|
{
|
2024-01-21 13:30:03 +00:00
|
|
|
$this->service->save();
|
2024-02-15 19:44:01 +00:00
|
|
|
$this->dispatch('success', 'Service settings saved successfully.');
|
2024-01-21 13:30:03 +00:00
|
|
|
}
|
2023-10-12 07:12:46 +00:00
|
|
|
|
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->validate();
|
|
|
|
$this->service->save();
|
2023-11-13 10:09:21 +00:00
|
|
|
$this->service->saveExtraFields($this->fields);
|
2023-10-12 07:12:46 +00:00
|
|
|
$this->service->parse();
|
|
|
|
$this->service->refresh();
|
|
|
|
$this->service->saveComposeConfigs();
|
2023-12-07 18:06:32 +00:00
|
|
|
$this->dispatch('refreshStacks');
|
|
|
|
$this->dispatch('refreshEnvs');
|
|
|
|
$this->dispatch('success', 'Service saved successfully.');
|
2023-10-12 07:12:46 +00:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.project.service.stack-form');
|
|
|
|
}
|
|
|
|
}
|