This commit is contained in:
Andras Bacsai
2023-05-15 14:54:03 +02:00
parent c47b0ddcc1
commit bdd4a24567
8 changed files with 38 additions and 37 deletions

View File

@@ -9,7 +9,7 @@ use Livewire\Component;
class Create extends Component class Create extends Component
{ {
public string $name; public string $name;
public string|null $description; public string|null $description = null;
public string $value; public string $value;
public string $currentRoute; public string $currentRoute;
@@ -29,9 +29,6 @@ class Create extends Component
'private_key' => $this->value, 'private_key' => $this->value,
'team_id' => session('currentTeam')->id 'team_id' => session('currentTeam')->id
]); ]);
session('currentTeam')->privateKeys = PrivateKey::where('team_id', session('currentTeam')->id)->get(); redirect()->route('server.new');
if ($this->currentRoute !== 'server/new') {
redirect()->route('private-key.show', $new_private_key->uuid);
}
} }
} }

View File

@@ -29,7 +29,6 @@ class ByIp extends Component
public function mount() public function mount()
{ {
$this->name = generateRandomName(); $this->name = generateRandomName();
$this->private_keys = PrivateKey::where('team_id', session('currentTeam')->id)->get();
} }
public function setPrivateKey(string $private_key_id) public function setPrivateKey(string $private_key_id)
{ {

View File

@@ -33,7 +33,7 @@ if (!function_exists('generalErrorHandler')) {
} }
} catch (\Throwable $error) { } catch (\Throwable $error) {
if ($that) { if ($that) {
$that->emit('error', $error); $that->emit('error', $error->getMessage());
} elseif ($isJson) { } elseif ($isJson) {
return response()->json([ return response()->json([
'code' => $error->getCode(), 'code' => $error->getCode(),

View File

@@ -13,7 +13,9 @@
<template x-for="(item,index) in filteredItems" :key="item.name"> <template x-for="(item,index) in filteredItems" :key="item.name">
<div x-on:click="await set(item.next ?? 'server',item.name)" <div x-on:click="await set(item.next ?? 'server',item.name)"
:class="focusedIndex === index && 'magic-item-focused'" class="magic-item"> :class="focusedIndex === index && 'magic-item-focused'" class="magic-item">
<span class="px-2 mr-1 text-xs text-white bg-green-600 rounded" x-show="item.type === 'Add'" <span class="px-2 mr-1 text-xs text-white bg-green-600 rounded" x-show="item.type === 'App'"
x-text="item.type"></span>
<span class="px-2 mr-1 text-xs text-white bg-indigo-600 rounded" x-show="item.type === 'Add'"
x-text="item.type"></span> x-text="item.type"></span>
<span class="px-2 mr-1 text-xs text-white bg-purple-600 rounded" x-show="item.type === 'Jump'" <span class="px-2 mr-1 text-xs text-white bg-purple-600 rounded" x-show="item.type === 'Jump'"
x-text="item.type"></span> x-text="item.type"></span>
@@ -222,6 +224,21 @@
focusedIndex: "", focusedIndex: "",
items: [{ items: [{
name: 'Public Repository',
type: 'App',
tags: 'application,public,repository,github,gitlab,bitbucket,git',
},
{
name: 'Private Repository (with GitHub App)',
type: 'App',
tags: 'application,private,repository,github,gitlab,bitbucket,git',
},
{
name: 'Private Repository (with Deploy Key)',
type: 'App',
tags: 'application,private,repository,github,gitlab,bitbucket,git',
},
{
name: 'Server', name: 'Server',
type: 'Add', type: 'Add',
tags: 'new,server', tags: 'new,server',
@@ -245,21 +262,7 @@
tags: 'new,source,github,gitlab,bitbucket', tags: 'new,source,github,gitlab,bitbucket',
next: 'newSource' next: 'newSource'
}, },
{
name: 'Public Repository',
type: 'Add',
tags: 'application,public,repository,github,gitlab,bitbucket,git',
},
{
name: 'Private Repository (with GitHub App)',
type: 'Add',
tags: 'application,private,repository,github,gitlab,bitbucket,git',
},
{
name: 'Private Repository (with Deploy Key)',
type: 'Add',
tags: 'application,private,repository,github,gitlab,bitbucket,git',
},
{ {
name: 'Database', name: 'Database',
type: 'Add', type: 'Add',
@@ -491,7 +494,7 @@
return await this.newEnvironment() return await this.newEnvironment()
} }
this.selectedEnvironment = id this.selectedEnvironment = id
console.log(this.selectedAction)
if (this.selectedAction === 0) { if (this.selectedAction === 0) {
window.location = window.location =
`/project/${this.selectedProject}/${this.selectedEnvironment}/new?type=public&destination=${this.selectedDestination}` `/project/${this.selectedProject}/${this.selectedEnvironment}/new?type=public&destination=${this.selectedDestination}`

View File

@@ -38,7 +38,6 @@
<div class="flex gap-2"> <div class="flex gap-2">
<x-inputs.button isBold wire:click.prevent='validateServer'>Validate Server</x-inputs.button> <x-inputs.button isBold wire:click.prevent='validateServer'>Validate Server</x-inputs.button>
<x-inputs.button isBold wire:click.prevent='installDocker'>Install Docker</x-inputs.button> <x-inputs.button isBold wire:click.prevent='installDocker'>Install Docker</x-inputs.button>
</div> </div>
</form> </form>

View File

@@ -13,20 +13,15 @@
<x-inputs.input type="number" id="port" label="Port" /> <x-inputs.input type="number" id="port" label="Port" />
<x-inputs.input id="private_key_id" label="Private Key Id" readonly hidden /> <x-inputs.input id="private_key_id" label="Private Key Id" readonly hidden />
@if ($private_keys->count() > 0) <h1>Select a private key</h1>
<h1>Select a private key</h1> <div class="flex">
@foreach ($private_keys as $key) @foreach ($private_keys as $key)
<div class="box" :class="{ 'bg-coollabs': {{ $private_key_id === $key->id }} }" <div class="w-32 box" :class="{ 'bg-coollabs': {{ $private_key_id == $key->id }} }"
wire:click.defer.prevent="setPrivateKey('{{ $key->id }}')"> wire:click.defer.prevent="setPrivateKey('{{ $key->id }}')">
{{ $key->name }} {{ $key->name }}
</div> </div>
@endforeach @endforeach
@endif </div>
</form> </form>
@if ($private_keys->count() > 0)
<h2>Or add a new private key</h2>
@else
<h2>Create private key</h2>
@endif
<livewire:private-key.create />
</div> </div>

View File

@@ -1,3 +1,9 @@
<x-layout> <x-layout>
<livewire:server.new.by-ip /> @if ($private_keys->count() === 0)
<h2>Create private key</h2>
<div>You need to create a private key before you can create a server.</div>
<livewire:private-key.create />
@else
<livewire:server.new.by-ip :private_keys="$private_keys" />
@endif
</x-layout> </x-layout>

View File

@@ -170,7 +170,9 @@ Route::middleware(['auth'])->group(function () {
})->name('source.github.show'); })->name('source.github.show');
}); });
Route::middleware(['auth'])->group(function () { Route::middleware(['auth'])->group(function () {
Route::get('/server/new', fn () => view('server.new'))->name('server.new'); Route::get('/server/new', fn () => view('server.new', [
'private_keys' => PrivateKey::where('team_id', session('currentTeam')->id)->get(),
]))->name('server.new');
Route::get('/server/{server_uuid}', function () { Route::get('/server/{server_uuid}', function () {
$server = session('currentTeam')->load(['servers'])->servers->firstWhere('uuid', request()->server_uuid); $server = session('currentTeam')->load(['servers'])->servers->firstWhere('uuid', request()->server_uuid);
if (!$server) { if (!$server) {