This commit is contained in:
Andras Bacsai 2023-05-05 12:08:38 +02:00
parent dcc1c72882
commit 96b9f8213c
16 changed files with 175 additions and 33 deletions

View File

@ -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,

View File

@ -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();

View File

@ -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;
}

View 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);
}
}
}
}

View 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();
}
}

View 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');
}
}

View File

@ -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;
}
}
);
}
}

View File

@ -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();
});
}

View File

@ -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,
])

View File

@ -1,6 +1,6 @@
<form wire:submit.prevent='submit' class="flex gap-2 px-2">
<x-inputs.input noLabel noDirty id="key" required />
<x-inputs.input noLabel noDirty id="value" required />
<form wire:submit.prevent='submit' class="flex items-end gap-2 px-2">
<x-inputs.input noDirty id="key" label="Name" required />
<x-inputs.input noDirty id="value" label="Value" required />
<div class="flex flex-col">
<div class="flex items-center gap-2">
<input type="checkbox" wire:model.defer="is_build_time" />

View File

@ -1,7 +1,8 @@
<div class="flex flex-col gap-2">
<h3>Environment Variables</h3>
@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
<p>There are no environment variables for this application.</p>
@endforelse

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -35,8 +35,7 @@
<livewire:project.application.destination :destination="$application->destination" />
</div>
<div x-cloak x-show="activeTab === 'storages'">
<h3>Persistent Storages</h3>
<livewire:project.application.storages :storages="$application->persistentStorages" />
<livewire:project.application.storages.all :application="$application" />
</div>
</div>
</x-layout>