2023-05-04 20:29:14 +00:00
|
|
|
<?php
|
|
|
|
|
2023-08-07 20:14:21 +00:00
|
|
|
namespace App\Http\Livewire\Project\Shared\EnvironmentVariable;
|
2023-05-04 20:29:14 +00:00
|
|
|
|
|
|
|
use App\Models\EnvironmentVariable as ModelsEnvironmentVariable;
|
|
|
|
use Livewire\Component;
|
2023-07-13 11:16:24 +00:00
|
|
|
use Visus\Cuid2\Cuid2;
|
2023-05-04 20:29:14 +00:00
|
|
|
|
|
|
|
class Show extends Component
|
|
|
|
{
|
|
|
|
public $parameters;
|
|
|
|
public ModelsEnvironmentVariable $env;
|
2023-09-22 09:23:49 +00:00
|
|
|
public ?string $modalId = null;
|
2023-09-27 13:48:19 +00:00
|
|
|
public bool $isDisabled = false;
|
2023-10-24 13:41:21 +00:00
|
|
|
public bool $isLocked = false;
|
2023-09-22 09:23:49 +00:00
|
|
|
public string $type;
|
|
|
|
|
2023-05-04 20:29:14 +00:00
|
|
|
protected $rules = [
|
|
|
|
'env.key' => 'required|string',
|
2023-09-26 12:45:52 +00:00
|
|
|
'env.value' => 'nullable',
|
2023-05-04 20:29:14 +00:00
|
|
|
'env.is_build_time' => 'required|boolean',
|
2023-10-24 13:41:21 +00:00
|
|
|
'env.is_shown_once' => 'required|boolean',
|
2023-05-04 20:29:14 +00:00
|
|
|
];
|
2023-06-16 10:35:40 +00:00
|
|
|
protected $validationAttributes = [
|
2023-10-24 13:41:21 +00:00
|
|
|
'key' => 'Key',
|
|
|
|
'value' => 'Value',
|
|
|
|
'is_build_time' => 'Build Time',
|
|
|
|
'is_shown_once' => 'Shown Once',
|
2023-06-16 10:35:40 +00:00
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-04 20:29:14 +00:00
|
|
|
public function mount()
|
2023-10-24 13:41:21 +00:00
|
|
|
{
|
|
|
|
$this->modalId = new Cuid2(7);
|
|
|
|
$this->parameters = get_route_parameters();
|
|
|
|
$this->checkEnvs();
|
|
|
|
}
|
|
|
|
public function checkEnvs()
|
2023-05-04 20:29:14 +00:00
|
|
|
{
|
2023-09-27 13:48:19 +00:00
|
|
|
$this->isDisabled = false;
|
2023-10-24 13:41:21 +00:00
|
|
|
if (str($this->env->key)->startsWith('SERVICE_FQDN') || str($this->env->key)->startsWith('SERVICE_URL')) {
|
2023-09-27 13:48:19 +00:00
|
|
|
$this->isDisabled = true;
|
|
|
|
}
|
2023-10-24 13:41:21 +00:00
|
|
|
if ($this->env->is_shown_once) {
|
|
|
|
$this->isLocked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public function lock()
|
|
|
|
{
|
|
|
|
$this->env->is_shown_once = true;
|
|
|
|
$this->env->save();
|
|
|
|
$this->checkEnvs();
|
|
|
|
$this->emit('refreshEnvs');
|
2023-05-04 20:29:14 +00:00
|
|
|
}
|
2023-08-11 20:41:47 +00:00
|
|
|
public function instantSave()
|
|
|
|
{
|
|
|
|
$this->submit();
|
|
|
|
}
|
2023-05-04 20:29:14 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
$this->env->save();
|
2023-06-22 08:04:39 +00:00
|
|
|
$this->emit('success', 'Environment variable updated successfully.');
|
2023-09-22 09:23:49 +00:00
|
|
|
$this->emit('refreshEnvs');
|
2023-05-04 20:29:14 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-04 20:29:14 +00:00
|
|
|
public function delete()
|
|
|
|
{
|
|
|
|
$this->env->delete();
|
2023-05-05 07:28:00 +00:00
|
|
|
$this->emit('refreshEnvs');
|
2023-05-04 20:29:14 +00:00
|
|
|
}
|
|
|
|
}
|