diff --git a/app/Http/Livewire/Project/Application/EnvironmentVariable/Add.php b/app/Http/Livewire/Project/Application/EnvironmentVariable/Add.php index 3e1635a65..b182652d7 100644 --- a/app/Http/Livewire/Project/Application/EnvironmentVariable/Add.php +++ b/app/Http/Livewire/Project/Application/EnvironmentVariable/Add.php @@ -28,7 +28,6 @@ class Add extends Component { $this->validate(); try { - $application_id = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail()->id; EnvironmentVariable::create([ 'key' => $this->key, diff --git a/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php b/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php index 37c2bd7ec..05085b433 100644 --- a/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php +++ b/app/Http/Livewire/Project/Application/EnvironmentVariable/All.php @@ -8,7 +8,7 @@ use Livewire\Component; class All extends Component { public Application $application; - protected $listeners = ['refreshEnvs' => 'refreshEnvs']; + protected $listeners = ['refreshEnvs']; public function refreshEnvs() { $this->application->refresh(); diff --git a/app/Http/Livewire/Project/Application/Storages.php b/app/Http/Livewire/Project/Application/Storages.php deleted file mode 100644 index 38d5b4595..000000000 --- a/app/Http/Livewire/Project/Application/Storages.php +++ /dev/null @@ -1,11 +0,0 @@ - 'required|string', + 'mount_path' => 'required|string', + 'host_path' => 'string|nullable', + ]; + public function mount() + { + $this->parameters = Route::current()->parameters(); + } + public function submit() + { + $this->validate(); + try { + $application_id = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail()->id; + LocalPersistentVolume::create([ + 'name' => $this->name, + 'mount_path' => $this->mount_path, + 'host_path' => $this->host_path, + 'resource_id' => $application_id, + 'resource_type' => Application::class, + ]); + $this->emit('refreshStorages'); + $this->name = ''; + $this->mount_path = ''; + $this->host_path = ''; + } catch (mixed $e) { + dd('asdf'); + if ($e instanceof QueryException) { + dd($e->errorInfo); + $this->emit('error', $e->errorInfo[2]); + } else { + $this->emit('error', $e); + } + } + } +} diff --git a/app/Http/Livewire/Project/Application/Storages/All.php b/app/Http/Livewire/Project/Application/Storages/All.php new file mode 100644 index 000000000..590350bdb --- /dev/null +++ b/app/Http/Livewire/Project/Application/Storages/All.php @@ -0,0 +1,16 @@ +application->refresh(); + } +} diff --git a/app/Http/Livewire/Project/Application/Storages/Show.php b/app/Http/Livewire/Project/Application/Storages/Show.php new file mode 100644 index 000000000..d9255f284 --- /dev/null +++ b/app/Http/Livewire/Project/Application/Storages/Show.php @@ -0,0 +1,25 @@ + 'required|string', + 'storage.mount_path' => 'required|string', + 'storage.host_path' => 'string|nullable', + ]; + public function submit() + { + $this->validate(); + $this->storage->save(); + } + public function delete() + { + $this->storage->delete(); + $this->emit('refreshStorages'); + } +} diff --git a/app/Models/LocalPersistentVolume.php b/app/Models/LocalPersistentVolume.php index e0cdfcc60..a8bb991f1 100644 --- a/app/Models/LocalPersistentVolume.php +++ b/app/Models/LocalPersistentVolume.php @@ -2,10 +2,45 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; +use Illuminate\Support\Str; + class LocalPersistentVolume extends BaseModel { + protected $fillable = [ + 'name', + 'mount_path', + 'host_path', + 'container_id', + 'resource_id', + 'resource_type', + ]; public function application() { return $this->morphTo(); } + protected function name(): Attribute + { + return Attribute::make( + set: fn (string $value) => Str::of($value)->trim()->value, + ); + } + protected function mountPath(): Attribute + { + return Attribute::make( + set: fn (string $value) => Str::of($value)->trim()->start('/')->value + ); + } + protected function hostPath(): Attribute + { + return Attribute::make( + set: function (string|null $value) { + if ($value) { + return Str::of($value)->trim()->start('/')->value; + } else { + return $value; + } + } + ); + } } diff --git a/database/migrations/2023_04_03_111012_create_local_persistent_volumes_table.php b/database/migrations/2023_04_03_111012_create_local_persistent_volumes_table.php index d86178ec4..3f6d7aa8b 100644 --- a/database/migrations/2023_04_03_111012_create_local_persistent_volumes_table.php +++ b/database/migrations/2023_04_03_111012_create_local_persistent_volumes_table.php @@ -14,12 +14,14 @@ return new class extends Migration Schema::create('local_persistent_volumes', function (Blueprint $table) { $table->id(); $table->string('uuid')->unique(); - $table->string('name'); + $table->string('name')->unique(); $table->string('mount_path'); $table->string('host_path')->nullable(); $table->string('container_id')->nullable(); $table->nullableMorphs('resource'); + + $table->unique(['name', 'resource_id', 'resource_type']); $table->timestamps(); }); } diff --git a/resources/views/components/inputs/button.blade.php b/resources/views/components/inputs/button.blade.php index 08f9f9d3e..d74b19978 100644 --- a/resources/views/components/inputs/button.blade.php +++ b/resources/views/components/inputs/button.blade.php @@ -1,8 +1,8 @@ @props([ 'isWarning' => null, - 'defaultClass' => 'text-white bg-neutral-800 hover:bg-violet-600 w-28', - 'defaultWarningClass' => 'text-white bg-red-500 hover:bg-red-600 w-28', - 'loadingClass' => 'text-black bg-green-500 w-28', + 'defaultClass' => 'text-white bg-neutral-800 hover:bg-violet-600 w-28 h-6', + 'defaultWarningClass' => 'text-white bg-red-500 hover:bg-red-600 w-28 h-6', + 'loadingClass' => 'text-black bg-green-500 w-28 h-6', 'confirm' => null, 'confirmAction' => null, ]) diff --git a/resources/views/livewire/project/application/environment-variable/add.blade.php b/resources/views/livewire/project/application/environment-variable/add.blade.php index 4ad26a2f0..03ba88a77 100644 --- a/resources/views/livewire/project/application/environment-variable/add.blade.php +++ b/resources/views/livewire/project/application/environment-variable/add.blade.php @@ -1,6 +1,6 @@ -
- - + + +
diff --git a/resources/views/livewire/project/application/environment-variable/all.blade.php b/resources/views/livewire/project/application/environment-variable/all.blade.php index b68741be8..270efa283 100644 --- a/resources/views/livewire/project/application/environment-variable/all.blade.php +++ b/resources/views/livewire/project/application/environment-variable/all.blade.php @@ -1,7 +1,8 @@

Environment Variables

@forelse ($application->environment_variables as $env) - + @empty

There are no environment variables for this application.

@endforelse diff --git a/resources/views/livewire/project/application/storages.blade.php b/resources/views/livewire/project/application/storages.blade.php deleted file mode 100644 index 75d49bc78..000000000 --- a/resources/views/livewire/project/application/storages.blade.php +++ /dev/null @@ -1,10 +0,0 @@ -
- @forelse ($storages as $storage) -

Name:{{ data_get($storage, 'name') }}

-

MountPath:{{ data_get($storage, 'mount_path') }}

-

HostPath:{{ data_get($storage, 'host_path') }}

-

ContainerId:{{ data_get($storage, 'container_id') }}

- @empty -

There are no storages added for this application.

- @endforelse -
diff --git a/resources/views/livewire/project/application/storages/add.blade.php b/resources/views/livewire/project/application/storages/add.blade.php new file mode 100644 index 000000000..e8cee8afd --- /dev/null +++ b/resources/views/livewire/project/application/storages/add.blade.php @@ -0,0 +1,9 @@ + + + + + + + Add + + diff --git a/resources/views/livewire/project/application/storages/all.blade.php b/resources/views/livewire/project/application/storages/all.blade.php new file mode 100644 index 000000000..31ec29bca --- /dev/null +++ b/resources/views/livewire/project/application/storages/all.blade.php @@ -0,0 +1,10 @@ +
+

Persistent Storages

+ @forelse ($application->persistentStorages as $storage) + + @empty +

There are no persistent storage attached for this application.

+ @endforelse +

Add new environment variable

+ +
diff --git a/resources/views/livewire/project/application/storages/show.blade.php b/resources/views/livewire/project/application/storages/show.blade.php new file mode 100644 index 000000000..1f234e330 --- /dev/null +++ b/resources/views/livewire/project/application/storages/show.blade.php @@ -0,0 +1,15 @@ +
+
+ + + + + + Update + + + Delete + + + +
diff --git a/resources/views/project/application/configuration.blade.php b/resources/views/project/application/configuration.blade.php index 795268f1c..c75e37f39 100644 --- a/resources/views/project/application/configuration.blade.php +++ b/resources/views/project/application/configuration.blade.php @@ -35,8 +35,7 @@
-

Persistent Storages

- +