storages
This commit is contained in:
		@@ -28,7 +28,6 @@ class Add extends Component
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->validate();
 | 
					        $this->validate();
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 | 
					 | 
				
			||||||
            $application_id = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail()->id;
 | 
					            $application_id = Application::where('uuid', $this->parameters['application_uuid'])->firstOrFail()->id;
 | 
				
			||||||
            EnvironmentVariable::create([
 | 
					            EnvironmentVariable::create([
 | 
				
			||||||
                'key' => $this->key,
 | 
					                'key' => $this->key,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ use Livewire\Component;
 | 
				
			|||||||
class All extends Component
 | 
					class All extends Component
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public Application $application;
 | 
					    public Application $application;
 | 
				
			||||||
    protected $listeners = ['refreshEnvs' => 'refreshEnvs'];
 | 
					    protected $listeners = ['refreshEnvs'];
 | 
				
			||||||
    public function refreshEnvs()
 | 
					    public function refreshEnvs()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->application->refresh();
 | 
					        $this->application->refresh();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,11 +0,0 @@
 | 
				
			|||||||
<?php
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
namespace App\Http\Livewire\Project\Application;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
use Illuminate\Database\Eloquent\Collection;
 | 
					 | 
				
			||||||
use Livewire\Component;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Storages extends Component
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    public Collection $storages;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
							
								
								
									
										52
									
								
								app/Http/Livewire/Project/Application/Storages/Add.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								app/Http/Livewire/Project/Application/Storages/Add.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace App\Http\Livewire\Project\Application\Storages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App\Models\Application;
 | 
				
			||||||
 | 
					use App\Models\LocalPersistentVolume;
 | 
				
			||||||
 | 
					use Illuminate\Database\QueryException;
 | 
				
			||||||
 | 
					use Illuminate\Support\Facades\Route;
 | 
				
			||||||
 | 
					use Livewire\Component;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Add extends Component
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public $parameters;
 | 
				
			||||||
 | 
					    public string $name;
 | 
				
			||||||
 | 
					    public string $mount_path;
 | 
				
			||||||
 | 
					    public string|null $host_path = null;
 | 
				
			||||||
 | 
					    protected $rules = [
 | 
				
			||||||
 | 
					        'name' => '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);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										16
									
								
								app/Http/Livewire/Project/Application/Storages/All.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								app/Http/Livewire/Project/Application/Storages/All.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace App\Http\Livewire\Project\Application\Storages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App\Models\Application;
 | 
				
			||||||
 | 
					use Livewire\Component;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class All extends Component
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public Application $application;
 | 
				
			||||||
 | 
					    protected $listeners = ['refreshStorages'];
 | 
				
			||||||
 | 
					    public function refreshStorages()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->application->refresh();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										25
									
								
								app/Http/Livewire/Project/Application/Storages/Show.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								app/Http/Livewire/Project/Application/Storages/Show.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace App\Http\Livewire\Project\Application\Storages;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Livewire\Component;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Show extends Component
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public $storage;
 | 
				
			||||||
 | 
					    protected $rules = [
 | 
				
			||||||
 | 
					        'storage.name' => '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');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -2,10 +2,45 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\Models;
 | 
					namespace App\Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Illuminate\Database\Eloquent\Casts\Attribute;
 | 
				
			||||||
 | 
					use Illuminate\Support\Str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class LocalPersistentVolume extends BaseModel
 | 
					class LocalPersistentVolume extends BaseModel
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    protected $fillable = [
 | 
				
			||||||
 | 
					        'name',
 | 
				
			||||||
 | 
					        'mount_path',
 | 
				
			||||||
 | 
					        'host_path',
 | 
				
			||||||
 | 
					        'container_id',
 | 
				
			||||||
 | 
					        'resource_id',
 | 
				
			||||||
 | 
					        'resource_type',
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
    public function application()
 | 
					    public function application()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->morphTo();
 | 
					        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;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,12 +14,14 @@ return new class extends Migration
 | 
				
			|||||||
        Schema::create('local_persistent_volumes', function (Blueprint $table) {
 | 
					        Schema::create('local_persistent_volumes', function (Blueprint $table) {
 | 
				
			||||||
            $table->id();
 | 
					            $table->id();
 | 
				
			||||||
            $table->string('uuid')->unique();
 | 
					            $table->string('uuid')->unique();
 | 
				
			||||||
            $table->string('name');
 | 
					            $table->string('name')->unique();
 | 
				
			||||||
            $table->string('mount_path');
 | 
					            $table->string('mount_path');
 | 
				
			||||||
            $table->string('host_path')->nullable();
 | 
					            $table->string('host_path')->nullable();
 | 
				
			||||||
            $table->string('container_id')->nullable();
 | 
					            $table->string('container_id')->nullable();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $table->nullableMorphs('resource');
 | 
					            $table->nullableMorphs('resource');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $table->unique(['name', 'resource_id', 'resource_type']);
 | 
				
			||||||
            $table->timestamps();
 | 
					            $table->timestamps();
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
@props([
 | 
					@props([
 | 
				
			||||||
    'isWarning' => null,
 | 
					    'isWarning' => null,
 | 
				
			||||||
    'defaultClass' => 'text-white bg-neutral-800 hover:bg-violet-600 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',
 | 
					    'defaultWarningClass' => 'text-white bg-red-500 hover:bg-red-600 w-28 h-6',
 | 
				
			||||||
    'loadingClass' => 'text-black bg-green-500 w-28',
 | 
					    'loadingClass' => 'text-black bg-green-500 w-28 h-6',
 | 
				
			||||||
    'confirm' => null,
 | 
					    'confirm' => null,
 | 
				
			||||||
    'confirmAction' => null,
 | 
					    'confirmAction' => null,
 | 
				
			||||||
])
 | 
					])
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,6 @@
 | 
				
			|||||||
<form wire:submit.prevent='submit' class="flex gap-2 px-2">
 | 
					<form wire:submit.prevent='submit' class="flex items-end gap-2 px-2">
 | 
				
			||||||
    <x-inputs.input noLabel noDirty id="key" required />
 | 
					    <x-inputs.input noDirty id="key" label="Name" required />
 | 
				
			||||||
    <x-inputs.input noLabel noDirty id="value" required />
 | 
					    <x-inputs.input noDirty id="value" label="Value" required />
 | 
				
			||||||
    <div class="flex flex-col">
 | 
					    <div class="flex flex-col">
 | 
				
			||||||
        <div class="flex items-center gap-2">
 | 
					        <div class="flex items-center gap-2">
 | 
				
			||||||
            <input type="checkbox" wire:model.defer="is_build_time" />
 | 
					            <input type="checkbox" wire:model.defer="is_build_time" />
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,8 @@
 | 
				
			|||||||
<div class="flex flex-col gap-2">
 | 
					<div class="flex flex-col gap-2">
 | 
				
			||||||
    <h3>Environment Variables</h3>
 | 
					    <h3>Environment Variables</h3>
 | 
				
			||||||
    @forelse ($application->environment_variables as $env)
 | 
					    @forelse ($application->environment_variables as $env)
 | 
				
			||||||
        <livewire:project.application.environment-variable.show wire:key="item-{{ $env->id }}" :env="$env" />
 | 
					        <livewire:project.application.environment-variable.show wire:key="environment-{{ $env->id }}"
 | 
				
			||||||
 | 
					            :env="$env" />
 | 
				
			||||||
    @empty
 | 
					    @empty
 | 
				
			||||||
        <p>There are no environment variables for this application.</p>
 | 
					        <p>There are no environment variables for this application.</p>
 | 
				
			||||||
    @endforelse
 | 
					    @endforelse
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,10 +0,0 @@
 | 
				
			|||||||
<div>
 | 
					 | 
				
			||||||
    @forelse ($storages as $storage)
 | 
					 | 
				
			||||||
        <p>Name:{{ data_get($storage, 'name') }}</p>
 | 
					 | 
				
			||||||
        <p>MountPath:{{ data_get($storage, 'mount_path') }}</p>
 | 
					 | 
				
			||||||
        <p>HostPath:{{ data_get($storage, 'host_path') }}</p>
 | 
					 | 
				
			||||||
        <p>ContainerId:{{ data_get($storage, 'container_id') }}</p>
 | 
					 | 
				
			||||||
    @empty
 | 
					 | 
				
			||||||
        <p>There are no storages added for this application.</p>
 | 
					 | 
				
			||||||
    @endforelse
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
@@ -0,0 +1,9 @@
 | 
				
			|||||||
 | 
					<form wire:submit.prevent='submit' class="flex items-end gap-2 px-2">
 | 
				
			||||||
 | 
					    <x-inputs.input noDirty id="name" label="Name" required />
 | 
				
			||||||
 | 
					    <x-inputs.input noDirty id="mount_path" label="Mount Path (in your app)" required />
 | 
				
			||||||
 | 
					    <x-inputs.input noDirty id="host_path" label="Mount Path (host)" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <x-inputs.button type="submit">
 | 
				
			||||||
 | 
					        Add
 | 
				
			||||||
 | 
					    </x-inputs.button>
 | 
				
			||||||
 | 
					</form>
 | 
				
			||||||
@@ -0,0 +1,10 @@
 | 
				
			|||||||
 | 
					<div class="flex flex-col gap-2">
 | 
				
			||||||
 | 
					    <h3>Persistent Storages</h3>
 | 
				
			||||||
 | 
					    @forelse ($application->persistentStorages as $storage)
 | 
				
			||||||
 | 
					        <livewire:project.application.storages.show :storage="$storage" />
 | 
				
			||||||
 | 
					    @empty
 | 
				
			||||||
 | 
					        <p>There are no persistent storage attached for this application.</p>
 | 
				
			||||||
 | 
					    @endforelse
 | 
				
			||||||
 | 
					    <h4>Add new environment variable</h4>
 | 
				
			||||||
 | 
					    <livewire:project.application.storages.add />
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					<div x-data="{ deleteStorage: false }">
 | 
				
			||||||
 | 
					    <form wire:submit.prevent='submit' class="flex items-end gap-2 px-2">
 | 
				
			||||||
 | 
					        <x-inputs.input id="storage.name" label="Name" required />
 | 
				
			||||||
 | 
					        <x-inputs.input id="storage.mount_path" label="Mount Path (in your app)" required />
 | 
				
			||||||
 | 
					        <x-inputs.input id="storage.host_path" label="Mount Path (host)" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <x-inputs.button type="submit">
 | 
				
			||||||
 | 
					            Update
 | 
				
			||||||
 | 
					        </x-inputs.button>
 | 
				
			||||||
 | 
					        <x-inputs.button x-on:click="deleteStorage = true" isWarning>
 | 
				
			||||||
 | 
					            Delete
 | 
				
			||||||
 | 
					        </x-inputs.button>
 | 
				
			||||||
 | 
					    </form>
 | 
				
			||||||
 | 
					    <x-naked-modal show="deleteStorage" message="Are you sure you want to delete {{ $storage->name }}?" />
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
@@ -35,8 +35,7 @@
 | 
				
			|||||||
            <livewire:project.application.destination :destination="$application->destination" />
 | 
					            <livewire:project.application.destination :destination="$application->destination" />
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div x-cloak x-show="activeTab === 'storages'">
 | 
					        <div x-cloak x-show="activeTab === 'storages'">
 | 
				
			||||||
            <h3>Persistent Storages</h3>
 | 
					            <livewire:project.application.storages.all :application="$application" />
 | 
				
			||||||
            <livewire:project.application.storages :storages="$application->persistentStorages" />
 | 
					 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</x-layout>
 | 
					</x-layout>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user