2024-04-26 12:59:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\SharedVariables\Environment;
|
|
|
|
|
|
|
|
use App\Models\Application;
|
|
|
|
use App\Models\Project;
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Show extends Component
|
|
|
|
{
|
|
|
|
public Project $project;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-26 12:59:03 +00:00
|
|
|
public Application $application;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-26 12:59:03 +00:00
|
|
|
public $environment;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-26 12:59:03 +00:00
|
|
|
public array $parameters;
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-26 12:59:03 +00:00
|
|
|
protected $listeners = ['refreshEnvs' => '$refresh', 'saveKey' => 'saveKey'];
|
|
|
|
|
|
|
|
public function saveKey($data)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$found = $this->environment->environment_variables()->where('key', $data['key'])->first();
|
|
|
|
if ($found) {
|
|
|
|
throw new \Exception('Variable already exists.');
|
|
|
|
}
|
|
|
|
$this->environment->environment_variables()->create([
|
|
|
|
'key' => $data['key'],
|
|
|
|
'value' => $data['value'],
|
|
|
|
'is_multiline' => $data['is_multiline'],
|
|
|
|
'is_literal' => $data['is_literal'],
|
|
|
|
'type' => 'environment',
|
|
|
|
'team_id' => currentTeam()->id,
|
|
|
|
]);
|
|
|
|
$this->environment->refresh();
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
return handleError($e, $this);
|
|
|
|
}
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-26 12:59:03 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->parameters = get_route_parameters();
|
|
|
|
$this->project = Project::ownedByCurrentTeam()->where('uuid', request()->route('project_uuid'))->first();
|
|
|
|
$this->environment = $this->project->environments()->where('name', request()->route('environment_name'))->first();
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-26 12:59:03 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.shared-variables.environment.show');
|
|
|
|
}
|
|
|
|
}
|