diff --git a/app/Http/Livewire/PrivateKey/Change.php b/app/Http/Livewire/PrivateKey/Change.php index a070e600b..def6b40da 100644 --- a/app/Http/Livewire/PrivateKey/Change.php +++ b/app/Http/Livewire/PrivateKey/Change.php @@ -19,9 +19,9 @@ class Change extends Component { $this->private_key = PrivateKey::where('uuid', $this->private_key_uuid)->first(); } - public function delete($private_key_uuid) + public function delete() { - PrivateKey::where('uuid', $private_key_uuid)->delete(); + PrivateKey::where('uuid', $this->private_key_uuid)->delete(); session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get(); redirect()->route('dashboard'); } diff --git a/app/Http/Livewire/Project/Application/EnvironmentVariable.php b/app/Http/Livewire/Project/Application/EnvironmentVariable.php new file mode 100644 index 000000000..aeb15c878 --- /dev/null +++ b/app/Http/Livewire/Project/Application/EnvironmentVariable.php @@ -0,0 +1,48 @@ +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'); + } +} diff --git a/app/Http/Livewire/Project/Application/EnvironmentVariables.php b/app/Http/Livewire/Project/Application/EnvironmentVariables.php deleted file mode 100644 index dc05c61c7..000000000 --- a/app/Http/Livewire/Project/Application/EnvironmentVariables.php +++ /dev/null @@ -1,10 +0,0 @@ - SchemalessAttributes::class, + ]; + public function scopeWithEnvironmentVariables(): Builder + { + return $this->environment_variables->modelScope(); + } public function publishDirectory(): Attribute { diff --git a/app/Models/Server.php b/app/Models/Server.php index 96253d290..fe1929007 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -23,21 +23,26 @@ class Server extends BaseModel 'team_id', 'private_key_id', ]; + + public $casts = [ + 'extra_attributes' => SchemalessAttributes::class, + ]; + public function standaloneDockers() { return $this->hasMany(StandaloneDocker::class); } + public function swarmDockers() { return $this->hasMany(SwarmDocker::class); } - public $casts = [ - 'extra_attributes' => SchemalessAttributes::class, - ]; + public function scopeWithExtraAttributes(): Builder { return $this->extra_attributes->modelScope(); } + public function privateKey() { return $this->belongsTo(PrivateKey::class); diff --git a/database/migrations/2023_03_27_081716_create_applications_table.php b/database/migrations/2023_03_27_081716_create_applications_table.php index b408589d2..462b58e6f 100644 --- a/database/migrations/2023_03_27_081716_create_applications_table.php +++ b/database/migrations/2023_03_27_081716_create_applications_table.php @@ -39,6 +39,8 @@ return new class extends Migration $table->string('base_directory')->default('/'); $table->string('publish_directory')->nullable(); + $table->schemalessAttributes('environment_variables'); + $table->string('health_check_path')->default('/'); $table->string('health_check_port')->nullable(); $table->string('health_check_host')->default('localhost'); diff --git a/database/seeders/ApplicationSeeder.php b/database/seeders/ApplicationSeeder.php index 2a03a7911..3f17d6ee6 100644 --- a/database/seeders/ApplicationSeeder.php +++ b/database/seeders/ApplicationSeeder.php @@ -35,6 +35,16 @@ class ApplicationSeeder extends Seeder 'destination_type' => StandaloneDocker::class, 'source_id' => $github_public_source->id, 'source_type' => GithubApp::class, + 'environment_variables' => [ + 'NODE_ENV' => [ + 'value' => 'production', + 'isBuildOnly' => true, + ], + 'PORT' => [ + 'value' => 3000, + 'isBuildOnly' => false, + ] + ] ]); } } diff --git a/resources/views/components/confirm-modal.blade.php b/resources/views/components/confirm-modal.blade.php index ab707519f..033800ab6 100644 --- a/resources/views/components/confirm-modal.blade.php +++ b/resources/views/components/confirm-modal.blade.php @@ -2,11 +2,17 @@ document.addEventListener('alpine:init', () => { Alpine.data('confirmModal', () => ({ open: false, + confirmAction: null, message: 'Are you sure?', - toggleConfirmModal(customMessage) { + toggleConfirmModal(customMessage, confirmAction) { + this.confirmAction = confirmAction this.message = customMessage this.open = !this.open }, + confirmed() { + this.open = false + this.$dispatch(this.confirmAction) + } })) }) @@ -16,7 +22,7 @@