2023-05-05 10:08:38 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Project\Shared\Storages;
|
2023-05-05 10:08:38 +00:00
|
|
|
|
2023-12-18 13:01:25 +00:00
|
|
|
use App\Models\Application;
|
2023-05-05 10:08:38 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Add extends Component
|
|
|
|
{
|
2023-10-02 07:08:41 +00:00
|
|
|
public $uuid;
|
2023-05-05 10:08:38 +00:00
|
|
|
public $parameters;
|
2023-12-18 13:01:25 +00:00
|
|
|
public $isSwarm = false;
|
2023-05-05 10:08:38 +00:00
|
|
|
public string $name;
|
|
|
|
public string $mount_path;
|
2023-12-18 13:01:25 +00:00
|
|
|
public ?string $host_path = null;
|
2023-05-05 12:20:10 +00:00
|
|
|
|
2023-12-18 13:01:25 +00:00
|
|
|
public $rules = [
|
2023-05-05 10:08:38 +00:00
|
|
|
'name' => 'required|string',
|
|
|
|
'mount_path' => 'required|string',
|
|
|
|
'host_path' => 'string|nullable',
|
|
|
|
];
|
2023-12-18 13:01:25 +00:00
|
|
|
|
|
|
|
protected $listeners = ['clearAddStorage' => 'clear'];
|
|
|
|
|
2023-06-16 10:35:40 +00:00
|
|
|
protected $validationAttributes = [
|
|
|
|
'name' => 'name',
|
|
|
|
'mount_path' => 'mount',
|
|
|
|
'host_path' => 'host',
|
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-05 10:08:38 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
2023-08-09 13:57:53 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
2023-12-20 15:19:48 +00:00
|
|
|
if (data_get($this->parameters, 'application_uuid')) {
|
|
|
|
$applicationUuid = $this->parameters['application_uuid'];
|
|
|
|
$application = Application::where('uuid', $applicationUuid)->first();
|
|
|
|
if (!$application) {
|
|
|
|
abort(404);
|
|
|
|
}
|
|
|
|
if ($application->destination->server->isSwarm()) {
|
|
|
|
$this->isSwarm = true;
|
|
|
|
$this->rules['host_path'] = 'required|string';
|
|
|
|
}
|
2023-12-18 13:01:25 +00:00
|
|
|
}
|
2023-05-05 10:08:38 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-05 10:08:38 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
2023-12-18 13:01:25 +00:00
|
|
|
try {
|
|
|
|
$this->validate($this->rules);
|
|
|
|
$name = $this->uuid . '-' . $this->name;
|
|
|
|
$this->dispatch('addNewVolume', [
|
|
|
|
'name' => $name,
|
|
|
|
'mount_path' => $this->mount_path,
|
|
|
|
'host_path' => $this->host_path,
|
|
|
|
]);
|
|
|
|
$this->dispatch('closeStorageModal');
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
2023-05-05 12:20:10 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-05 12:20:10 +00:00
|
|
|
public function clear()
|
|
|
|
{
|
|
|
|
$this->name = '';
|
|
|
|
$this->mount_path = '';
|
|
|
|
$this->host_path = null;
|
2023-05-05 10:08:38 +00:00
|
|
|
}
|
|
|
|
}
|