2023-10-12 07:12:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project\Service;
|
|
|
|
|
|
|
|
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',
|
|
|
|
];
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
$this->emit('refreshStacks');
|
|
|
|
$this->emit('refreshEnvs');
|
|
|
|
$this->emit('success', 'Service saved successfully.');
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.project.service.stack-form');
|
|
|
|
}
|
|
|
|
}
|