destinations

This commit is contained in:
Andras Bacsai 2023-05-04 10:45:09 +02:00
parent b8b0d2243f
commit 32b7a1ffcd
15 changed files with 115 additions and 44 deletions

View File

@ -0,0 +1,39 @@
<?php
namespace App\Http\Livewire\Destination;
use App\Models\StandaloneDocker;
use App\Models\SwarmDocker;
use Livewire\Component;
class Form extends Component
{
public $destination_uuid;
public $destination;
protected $rules = [
'destination.name' => 'required',
'destination.network' => 'required',
'destination.server.ip' => 'required',
];
public function mount()
{
$standalone = StandaloneDocker::where('uuid', $this->destination_uuid)->first();
$swarm = SwarmDocker::where('uuid', $this->destination_uuid)->first();
if (!$standalone && !$swarm) {
abort(404);
}
$this->destination = $standalone ? $standalone->load(['server']) : $swarm->load(['server']);
}
public function submit()
{
$this->validate();
$this->destination->save();
}
public function delete()
{
instantRemoteProcess(['docker network rm -f ' . $this->destination->network], $this->destination->server);
$this->destination->delete();
return redirect()->route('dashboard');
}
}

View File

@ -5,6 +5,7 @@
use App\Models\Server;
use App\Models\StandaloneDocker as ModelsStandaloneDocker;
use Livewire\Component;
use Visus\Cuid2\Cuid2;
class StandaloneDocker extends Component
{
@ -12,7 +13,7 @@ class StandaloneDocker extends Component
public string $network;
public $servers;
public int|null $server_id = null;
public int $server_id;
protected $rules = [
'name' => 'required|string',
@ -21,13 +22,11 @@ class StandaloneDocker extends Component
];
public function mount()
{
$this->name = generateRandomName();
$this->servers = Server::where('team_id', session('currentTeam')->id)->get();
$this->network = new Cuid2(7);
$this->name = generateRandomName();
}
public function setServerId($server_id)
{
$this->server_id = $server_id;
}
public function submit()
{
$this->validate();

View File

@ -8,9 +8,13 @@ body {
a, a:visited {
@apply text-neutral-300 hover:text-purple-500;
}
input, select, textarea {
@apply border-none p-2 bg-neutral-800 text-white disabled:text-neutral-600;
input, textarea {
@apply border-none p-2 bg-neutral-800 text-white disabled:text-neutral-600 read-only:text-neutral-600 read-only:select-none
}
select {
@apply border-none p-2 bg-neutral-800 text-white disabled:text-neutral-600 read-only:select-none
}
button {
@apply border-none px-2 p-1 cursor-pointer;
}

View File

@ -1,7 +1,7 @@
@props([
'isWarning' => null,
'defaultClass' => 'text-white bg-neutral-800 hover:bg-violet-600',
'defaultWarningClass' => 'text-white bg-red-500 hover:bg-red-600',
'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',
'confirm' => null,
'confirmAction' => null,

View File

@ -2,7 +2,6 @@
'id' => null,
'type' => 'text',
'required' => false,
'readonly' => false,
'label' => null,
'instantSave' => false,
'disabled' => false,

View File

@ -0,0 +1,25 @@
@props([
'id' => null,
'label' => null,
'required' => false,
])
<span @class(['flex flex-col'])>
<label for={{ $id }}>
@if ($label)
{{ $label }}
@else
{{ $id }}
@endif
@if ($required)
*
@endif
</label>
<select {{ $attributes }} wire:model.defer={{ $id }}>
{{ $slot }}
</select>
@error($id)
<div class="text-red-500">{{ $message }}</div>
@enderror
</span>

View File

@ -1,11 +1,4 @@
<x-layout>
<h1>Destination</h1>
<p>Name: {{ data_get($destination, 'name') }}</p>
<p>Server:{{ data_get($destination, 'server.ip') }}:{{ data_get($destination, 'server.port') }} </p>
@if ($destination->getMorphClass() === 'App\Models\StandaloneDocker')
<p>Network: {{ data_get($destination, 'network') }}</p>
@endif
@if ($destination->getMorphClass() === 'App\Models\SwarmDocker')
<p>Uuid: {{ data_get($destination, 'uuid') }}</p>
@endif
<livewire:destination.form :destination_uuid="$destination_uuid" />
</x-layout>

View File

@ -1,5 +1,6 @@
<div>
<x-inputs.button wire:click='checkUpdate' type="submit">Check for updates</x-inputs.button>
<x-inputs.button class="w-32 text-white bg-neutral-800 hover:bg-violet-600" wire:click='checkUpdate' type="submit">
Check for updates</x-inputs.button>
@if ($updateAvailable)
Update available
@endif

View File

@ -0,0 +1,18 @@
<div>
<form class="flex flex-col gap-4" wire:submit.prevent='submit'>
<x-inputs.input id="destination.name" label="Name" />
<x-inputs.input id="destination.server.ip" label="Server IP" readonly />
@if ($destination->getMorphClass() === 'App\Models\StandaloneDocker')
<x-inputs.input id="destination.network" label="Docker Network" readonly />
@endif
<div>
<x-inputs.button>
Submit
</x-inputs.button>
<x-inputs.button confirm='Are you sure you would like to delete this private key?'
confirmAction="delete('{{ $destination->id }}')">
Delete
</x-inputs.button>
</div>
</form>
</div>

View File

@ -1,21 +1,14 @@
<div>
<form class="flex flex-col" wire:submit.prevent='submit'>
<form class="flex items-end gap-4" wire:submit.prevent='submit'>
<x-inputs.input id="name" label="Name" required />
<x-inputs.input id="network" label="Network" required />
<x-inputs.input id="server_id" label="Server ID" required />
@foreach ($servers as $key)
@if ($server_id == $key->id)
<x-inputs.button class="bg-green-500" wire:click.prevent="setServerId('{{ $key->id }}')">
{{ $key->name }}
</x-inputs.button>
@else
<x-inputs.button wire:click.prevent="setServerId('{{ $key->id }}')">{{ $key->name }}
</x-inputs.button>
@endif
@endforeach
<x-inputs.button class="mt-4" type="submit">
<x-inputs.select id="server_id" label="Select a server" required>
@foreach ($servers as $server)
<option value="{{ $server->id }}">{{ $server->name }}</option>
@endforeach
</x-inputs.select>
<x-inputs.button type="submit">
Submit
</x-inputs.button>
</form>
</div>

View File

@ -1,5 +1,7 @@
<div>
<p>IP: {{ $destination->server->ip }}</p>
<p>Description: {{ $destination->server->description }}</p>
<p>Server Name: {{ data_get($destination, 'server.name') }}</p>
@if (data_get($destination, 'server.description'))
<p>Description: {{ data_get($destination, 'server.description') }}</p>
@endif
<p>Docker Network: {{ $destination->network }}</p>
</div>

View File

@ -15,18 +15,16 @@
@endif
</div>
<div class="flex flex-col w-96">
<x-inputs.input id="application.base_directory" label="Base Directory" />
@if ($application->settings->is_static)
<x-inputs.input id="application.publish_directory" label="Publish Directory" required />
@else
<x-inputs.input id="application.publish_directory" label="Publish Directory" />
@endif
</div>
<div class="flex flex-col w-96">
@if ($application->settings->is_static)
<x-inputs.input id="application.ports_exposes" label="Ports Exposes" disabled />
<x-inputs.input id="application.ports_exposes" label="Ports Exposes" readonly />
@else
<x-inputs.input id="application.ports_exposes" label="Ports Exposes" required />
@endif
@ -34,7 +32,7 @@
<x-inputs.input id="application.ports_mappings" label="Ports Mappings" />
</div>
</div>
<x-inputs.button class="flex mx-auto mt-4" type="submit">
<x-inputs.button class="mx-auto mt-4 text-white bg-neutral-800 hover:bg-violet-600" type="submit">
Submit
</x-inputs.button>
</form>

View File

@ -5,6 +5,6 @@
<p>HostPath:{{ data_get($storage, 'host_path') }}</p>
<p>ContainerId:{{ data_get($storage, 'container_id') }}</p>
@empty
<p>No storage found.</p>
<p>There are no storages added for this application.</p>
@endforelse
</div>

View File

@ -61,7 +61,7 @@
@if ($is_static)
<x-inputs.input id="publish_directory" label="Publish Directory" />
@else
<x-inputs.input type="number" id="port" label="Port" :disabled="$is_static" />
<x-inputs.input type="number" id="port" label="Port" :readonly="$is_static" />
@endif
<x-inputs.button type="submit">
Submit

View File

@ -93,7 +93,7 @@
Route::middleware(['auth'])->group(function () {
Route::get('/destination/new', function () {
$query_params = request()->query();
$server_id = null;
$server_id = 1;
if (isset($query_params['server_id'])) {
$server_id = $query_params['server_id'];
}
@ -109,7 +109,7 @@
}
$destination = $standalone_dockers ? $standalone_dockers : $swarm_dockers;
return view('destination.show', [
'destination' => $destination,
'destination_uuid' => $destination->uuid,
]);
})->name('destination.show');
});