This commit is contained in:
Andras Bacsai 2023-05-05 09:28:00 +02:00
parent 23f58b8c13
commit 539f82eb08
9 changed files with 66 additions and 34 deletions

View File

@ -15,13 +15,20 @@ class Add extends Component
public string $value;
public bool $is_build_time = false;
protected $rules = [
'key' => 'required|string',
'value' => 'required|string',
'is_build_time' => 'required|boolean',
];
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;
EnvironmentVariable::create([
'key' => $this->key,
@ -29,7 +36,9 @@ public function submit()
'is_build_time' => $this->is_build_time,
'application_id' => $application_id,
]);
$this->emit('reloadWindow');
$this->emit('refreshEnvs');
$this->key = '';
$this->value = '';
} catch (mixed $e) {
dd('asdf');
if ($e instanceof QueryException) {

View File

@ -0,0 +1,16 @@
<?php
namespace App\Http\Livewire\Project\Application\EnvironmentVariable;
use App\Models\Application;
use Livewire\Component;
class All extends Component
{
public Application $application;
protected $listeners = ['refreshEnvs' => 'refreshEnvs'];
public function refreshEnvs()
{
$this->application->refresh();
}
}

View File

@ -30,6 +30,6 @@ public function submit()
public function delete()
{
$this->env->delete();
$this->emit('reloadWindow');
$this->emit('refreshEnvs');
}
}

View File

@ -45,7 +45,7 @@ class General extends Component
];
public function instantSave()
{
// @TODO: find another way
// @TODO: find another way - if possible
$this->application->settings->is_static = $this->is_static;
$this->application->settings->is_git_submodules_allowed = $this->is_git_submodules_allowed;
$this->application->settings->is_git_lfs_allowed = $this->is_git_lfs_allowed;

View File

@ -1,36 +1,40 @@
@props([
'id' => null,
'type' => 'text',
'required' => false,
'required' => $attributes->has('required'),
'label' => null,
'instantSave' => false,
'disabled' => false,
'hidden' => false,
'noLabel' => false,
'noDirty' => false,
])
<span @class([
'flex justify-end' => $type === 'checkbox',
'flex flex-col' => $type !== 'checkbox',
])>
<label for={{ $id }}>
@if ($label)
{{ $label }}
@else
{{ $id }}
@endif
@if ($required)
*
@endif
</label>
@if (!$noLabel)
<label for={{ $id }}>
@if ($label)
{{ $label }}
@else
{{ $id }}
@endif
@if ($required)
*
@endif
</label>
@endif
@if ($type === 'textarea')
<textarea {{ $attributes }} type={{ $type }} id={{ $id }} wire:model.defer={{ $id }}></textarea>
<textarea @if (!$noDirty) wire:dirty.class="text-black bg-amber-300" @endif {{ $attributes }}
required={{ $required }} type={{ $type }} id={{ $id }} wire:model.defer={{ $id }}></textarea>
@else
<input wire:dirty.class="text-black bg-amber-300" {{ $attributes }} type={{ $type }}
id={{ $id }}
<input {{ $attributes }} required={{ $required }}
@if (!$noDirty) wire:dirty.class="text-black bg-amber-300" @endif
type={{ $type }} id={{ $id }}
@if ($instantSave) wire:click='instantSave' wire:model.defer={{ $id }} @else wire:model.defer={{ $value ?? $id }} @endif />
@endif
@error($id)
<div class="text-red-500">{{ $message }}</div>
@enderror

View File

@ -1,10 +1,10 @@
<form wire:submit.prevent='submit' class="flex gap-2 p-4">
<input type="text" wire:model.defer="key" wire:dirty.class="text-black bg-amber-300" />
<input type="text" wire:model.defer="value" wire:dirty.class="text-black bg-amber-300" />
<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 />
<div class="flex flex-col">
<div class="flex items-center gap-2">
<input type="checkbox" wire:model.defer="is_build_time" />
<label>Used during build?</label>
<label>Build Variable?</label>
</div>
</div>
<x-inputs.button type="submit">

View File

@ -0,0 +1,10 @@
<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" />
@empty
<p>There are no environment variables for this application.</p>
@endforelse
<h4>Add new environment variable</h4>
<livewire:project.application.environment-variable.add />
</div>

View File

@ -1,11 +1,11 @@
<div x-data="{ deleteEnvironment: false }">
<form wire:submit.prevent='submit' class="flex gap-2 p-4">
<form wire:submit.prevent='submit' class="flex gap-2 px-2">
<input type="text" wire:model.defer="env.key" wire:dirty.class="text-black bg-amber-300" />
<input type="text" wire:model.defer="env.value" wire:dirty.class="text-black bg-amber-300" />
<div class="flex flex-col">
<div class="flex items-center gap-2">
<input type="checkbox" wire:model.defer="env.is_build_time" />
<label>Used during build?</label>
<label wire:dirty.class="text-amber-300" wire:target="env.is_build_time">Build Variable?</label>
</div>
</div>
<x-inputs.button type="submit">

View File

@ -23,15 +23,8 @@
<h3>General Configurations</h3>
<livewire:project.application.general :applicationId="$application->id" />
</div>
<div x-cloak x-show="activeTab === 'environment-variables'" class="flex flex-col gap-2">
<h3>Environment Variables</h3>
@forelse ($application->environment_variables as $env)
<livewire:project.application.environment-variable.show :env="$env" />
@empty
<p>There are no environment variables for this application.</p>
@endforelse
<h4>Add new environment variable</h4>
<livewire:project.application.environment-variable.add />
<div x-cloak x-show="activeTab === 'environment-variables'">
<livewire:project.application.environment-variable.all :application="$application" />
</div>
<div x-cloak x-show="activeTab === 'source'">
<h3>Source</h3>