2024-04-26 12:59:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Livewire\SharedVariables\Project;
|
|
|
|
|
|
|
|
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
|
|
|
protected $listeners = ['refreshEnvs' => '$refresh', 'saveKey' => 'saveKey'];
|
|
|
|
|
|
|
|
public function saveKey($data)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$found = $this->project->environment_variables()->where('key', $data['key'])->first();
|
|
|
|
if ($found) {
|
|
|
|
throw new \Exception('Variable already exists.');
|
|
|
|
}
|
|
|
|
$this->project->environment_variables()->create([
|
|
|
|
'key' => $data['key'],
|
|
|
|
'value' => $data['value'],
|
|
|
|
'is_multiline' => $data['is_multiline'],
|
|
|
|
'is_literal' => $data['is_literal'],
|
|
|
|
'type' => 'project',
|
|
|
|
'team_id' => currentTeam()->id,
|
|
|
|
]);
|
|
|
|
$this->project->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()
|
|
|
|
{
|
|
|
|
$projectUuid = request()->route('project_uuid');
|
|
|
|
$teamId = currentTeam()->id;
|
|
|
|
$project = Project::where('team_id', $teamId)->where('uuid', $projectUuid)->first();
|
2024-06-10 20:43:34 +00:00
|
|
|
if (! $project) {
|
2024-04-26 12:59:03 +00:00
|
|
|
return redirect()->route('dashboard');
|
|
|
|
}
|
|
|
|
$this->project = $project;
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-04-26 12:59:03 +00:00
|
|
|
public function render()
|
|
|
|
{
|
|
|
|
return view('livewire.shared-variables.project.show');
|
|
|
|
}
|
|
|
|
}
|