fix modal, add env variables, etc
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Application;
|
||||
|
||||
use App\Models\Application;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Livewire\Component;
|
||||
|
||||
class EnvironmentVariable extends Component
|
||||
{
|
||||
public $parameters;
|
||||
public $env;
|
||||
public string|null $keyName = null;
|
||||
public string|null $value = null;
|
||||
public bool $isBuildOnly = false;
|
||||
public bool $isNewEnv = false;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->parameters = Route::current()->parameters();
|
||||
if (data_get($this->env, 'value') !== null) {
|
||||
$this->value = $this->env['value'];
|
||||
$this->isBuildOnly = $this->env['isBuildOnly'];
|
||||
} else {
|
||||
$this->isNewEnv = true;
|
||||
}
|
||||
}
|
||||
public function updateEnv()
|
||||
{
|
||||
$application = Application::where('uuid', $this->parameters['application_uuid'])->first();
|
||||
$application->environment_variables->set("{$this->keyName}.value", $this->value);
|
||||
$application->environment_variables->set("{$this->keyName}.isBuildOnly", $this->isBuildOnly);
|
||||
$application->save();
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
$this->updateEnv();
|
||||
$this->emit('reloadWindow');
|
||||
}
|
||||
public function delete()
|
||||
{
|
||||
$application = Application::where('uuid', $this->parameters['application_uuid'])->first();
|
||||
$application->environment_variables->forget($this->keyName);
|
||||
$application->save();
|
||||
$this->emit('reloadWindow');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Application\EnvironmentVariable;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\EnvironmentVariable;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Livewire\Component;
|
||||
|
||||
class Add extends Component
|
||||
{
|
||||
public $parameters;
|
||||
public string $key;
|
||||
public string $value;
|
||||
public bool $is_build_time = false;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->parameters = Route::current()->parameters();
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
$application_id = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail()->id;
|
||||
EnvironmentVariable::create([
|
||||
'key' => $this->key,
|
||||
'value' => $this->value,
|
||||
'is_build_time' => $this->is_build_time,
|
||||
'application_id' => $application_id,
|
||||
]);
|
||||
$this->emit('reloadWindow');
|
||||
} catch (mixed $e) {
|
||||
dd('asdf');
|
||||
if ($e instanceof QueryException) {
|
||||
dd($e->errorInfo);
|
||||
$this->emit('error', $e->errorInfo[2]);
|
||||
} else {
|
||||
$this->emit('error', $e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Project\Application\EnvironmentVariable;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\EnvironmentVariable as ModelsEnvironmentVariable;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Livewire\Component;
|
||||
|
||||
class Show extends Component
|
||||
{
|
||||
public $parameters;
|
||||
public ModelsEnvironmentVariable $env;
|
||||
|
||||
protected $rules = [
|
||||
'env.key' => 'required|string',
|
||||
'env.value' => 'required|string',
|
||||
'env.is_build_time' => 'required|boolean',
|
||||
];
|
||||
public function mount()
|
||||
{
|
||||
$this->parameters = Route::current()->parameters();
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
$this->validate();
|
||||
$this->env->save();
|
||||
}
|
||||
public function delete()
|
||||
{
|
||||
$this->env->delete();
|
||||
$this->emit('reloadWindow');
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Application extends BaseModel
|
||||
{
|
||||
@@ -38,14 +37,6 @@ class Application extends BaseModel
|
||||
'ports_exposes',
|
||||
'publish_directory',
|
||||
];
|
||||
public $casts = [
|
||||
'environment_variables' => SchemalessAttributes::class,
|
||||
];
|
||||
public function scopeWithEnvironmentVariables(): Builder
|
||||
{
|
||||
return $this->environment_variables->modelScope();
|
||||
}
|
||||
|
||||
public function publishDirectory(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
@@ -83,6 +74,10 @@ class Application extends BaseModel
|
||||
: explode(',', $this->ports_exposes)
|
||||
);
|
||||
}
|
||||
public function environment_variables(): HasMany
|
||||
{
|
||||
return $this->hasMany(EnvironmentVariable::class);
|
||||
}
|
||||
public function environment()
|
||||
{
|
||||
return $this->belongsTo(Environment::class);
|
||||
|
||||
46
app/Models/EnvironmentVariable.php
Normal file
46
app/Models/EnvironmentVariable.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class EnvironmentVariable extends Model
|
||||
{
|
||||
|
||||
protected $fillable = ['key', 'value', 'is_build_time', 'application_id'];
|
||||
protected $casts = [
|
||||
'value' => 'encrypted',
|
||||
'is_build_time' => 'boolean',
|
||||
];
|
||||
private function get_environment_variables(string $environment_variable): string|null
|
||||
{
|
||||
$team_id = session('currentTeam')->id;
|
||||
if (str_contains(trim($environment_variable), '{{') && str_contains(trim($environment_variable), '}}')) {
|
||||
$environment_variable = preg_replace('/\s+/', '', $environment_variable);
|
||||
$environment_variable = str_replace('{{', '', $environment_variable);
|
||||
$environment_variable = str_replace('}}', '', $environment_variable);
|
||||
if (str_starts_with($environment_variable, 'global.')) {
|
||||
$environment_variable = str_replace('global.', '', $environment_variable);
|
||||
// $environment_variable = GlobalEnvironmentVariable::where('name', $environment_variable)->where('team_id', $team_id)->first()?->value;
|
||||
return $environment_variable;
|
||||
}
|
||||
}
|
||||
return decrypt($environment_variable);
|
||||
}
|
||||
private function set_environment_variables(string $environment_variable): string|null
|
||||
{
|
||||
if (!str_contains(trim($environment_variable), '{{') && !str_contains(trim($environment_variable), '}}')) {
|
||||
return encrypt($environment_variable);
|
||||
}
|
||||
return $environment_variable;
|
||||
}
|
||||
protected function value(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn (string $value) => $this->get_environment_variables($value),
|
||||
set: fn (string $value) => $this->set_environment_variables($value),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user