lots of UI fixes

This commit is contained in:
Andras Bacsai
2023-07-14 13:38:24 +02:00
parent 2f613aed26
commit 8b128c1bbe
17 changed files with 188 additions and 145 deletions

View File

@@ -8,7 +8,7 @@ use App\Models\Server;
use Spatie\Activitylog\Models\Activity;
use Illuminate\Support\Str;
class InstallProxy
class StartProxy
{
public function __invoke(Server $server): Activity
{

View File

@@ -13,7 +13,7 @@ class MagicController extends Controller
public function servers()
{
return response()->json([
'servers' => Server::validated()->get()
'servers' => Server::isUsable()->get()
]);
}
public function destinations()

View File

@@ -27,14 +27,16 @@ class Proxy extends Component
}
public function switchProxy()
{
$this->server->proxy->type = null;
$this->server->proxy = null;
$this->server->save();
$this->emit('proxyStatusUpdated');
}
public function setProxy(string $proxy_type)
{
$this->server->proxy->type = $proxy_type;
$this->server->proxy->status = 'exited';
$this->server->save();
$this->emit('proxyStatusUpdated');
}
public function stopProxy()
{

View File

@@ -2,7 +2,7 @@
namespace App\Http\Livewire\Server\Proxy;
use App\Actions\Proxy\InstallProxy;
use App\Actions\Proxy\StartProxy;
use App\Models\Server;
use Livewire\Component;
use Str;
@@ -24,7 +24,7 @@ class Deploy extends Component
) {
$this->saveConfiguration($this->server);
}
$activity = resolve(InstallProxy::class)($this->server);
$activity = resolve(StartProxy::class)($this->server);
$this->emit('newMonitorActivity', $activity->id);
}
public function stop()

View File

@@ -2,8 +2,7 @@
namespace App\Http\Livewire\Settings;
use App\Actions\Proxy\InstallProxy;
use App\Jobs\ProxyCheckJob;
use App\Jobs\ProxyStartJob;
use App\Models\InstanceSettings as ModelsInstanceSettings;
use App\Models\Server;
use Livewire\Component;
@@ -108,7 +107,7 @@ class Configuration extends Component
];
}
$this->save_configuration_to_disk($traefik_dynamic_conf, $file);
dispatch(new ProxyCheckJob($this->server));
dispatch(new ProxyStartJob($this->server));
}
}
private function save_configuration_to_disk(array $traefik_dynamic_conf, string $file)

View File

@@ -117,7 +117,7 @@ class ApplicationDeploymentJob implements ShouldQueue
} else {
$this->deploy();
}
if ($this->application->fqdn) dispatch(new ProxyCheckJob($this->server));
if ($this->application->fqdn) dispatch(new ProxyStartJob($this->server));
$this->next(ApplicationDeploymentStatus::FINISHED->value);
} catch (\Exception $e) {
ray($e);

View File

@@ -2,7 +2,7 @@
namespace App\Jobs;
use App\Actions\Proxy\InstallProxy;
use App\Actions\Proxy\StartProxy;
use App\Enums\ProxyTypes;
use App\Models\Server;
use Illuminate\Bus\Queueable;
@@ -15,30 +15,20 @@ class ProxyCheckJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(protected Server|null $server = null)
public function __construct()
{
}
public function handle()
{
try {
$container_name = 'coolify-proxy';
if ($this->server) {
ray('Checking proxy for server: ' . $this->server->name);
$status = get_container_status(server: $this->server, container_id: $container_name);
if ($status === 'running') {
return;
}
resolve(InstallProxy::class)($this->server);
} else {
$servers = Server::whereRelation('settings', 'is_usable', true)->get();
$servers = Server::isUsable()->whereNotNull('proxy')->get();
foreach ($servers as $server) {
$status = get_container_status(server: $server, container_id: $container_name);
if ($status === 'running') {
continue;
}
resolve(InstallProxy::class)($server);
}
resolve(StartProxy::class)($server);
}
} catch (\Throwable $th) {
ray($th->getMessage());

35
app/Jobs/ProxyStartJob.php Executable file
View File

@@ -0,0 +1,35 @@
<?php
namespace App\Jobs;
use App\Actions\Proxy\StartProxy;
use App\Models\Server;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class ProxyStartJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(protected Server $server)
{
}
public function handle()
{
try {
$container_name = 'coolify-proxy';
ray('Starting proxy for server: ' . $this->server->name);
$status = get_container_status(server: $this->server, container_id: $container_name);
if ($status === 'running') {
return;
}
resolve(StartProxy::class)($this->server);
} catch (\Throwable $th) {
ray($th->getMessage());
//throw $th;
}
}
}

View File

@@ -94,10 +94,14 @@ class Server extends BaseModel
return Server::whereTeamId(session('currentTeam')->id)->with('settings')->select($selectArray->all())->orderBy('name');
}
static public function validated()
static public function isReachable()
{
return Server::ownedByCurrentTeam()->whereRelation('settings', 'is_reachable', true);
}
static public function isUsable()
{
return Server::ownedByCurrentTeam()->whereRelation('settings', 'is_reachable', true)->whereRelation('settings', 'is_usable', true);
}
static public function destinationsByServer(string $server_id)
{

View File

@@ -2,7 +2,6 @@
namespace Database\Seeders;
use App\Actions\Proxy\InstallProxy;
use App\Data\ServerMetadata;
use App\Enums\ProxyStatus;
use App\Enums\ProxyTypes;

View File

@@ -16,11 +16,13 @@ class ServerSettingSeeder extends Seeder
$server_2 = Server::find(0)->load(['settings']);
$server_2->settings->wildcard_domain = 'http://127.0.0.1.sslip.io';
$server_2->settings->is_build_server = true;
$server_2->settings->is_usable = true;
$server_2->settings->is_reachable = true;
$server_2->settings->save();
$server_3 = Server::find(1)->load(['settings']);
$server_3->settings->is_part_of_swarm = false;
$server_2->settings->is_usable = false;
$server_3->settings->is_reachable = false;
$server_3->settings->save();
}

View File

@@ -26,11 +26,9 @@
]) }}">
<button>Destinations</button>
</a>
@if ($server->settings->is_reachable)
@if (request()->routeIs('server.proxy'))
<div class="flex-1"></div>
<livewire:server.proxy.deploy :server="$server" />
@endif
@endif
</nav>
</div>

View File

@@ -1,4 +1,5 @@
<div>
@if ($server->settings->is_usable)
<div class="flex items-end gap-2">
<h2>Destinations</h2>
<a href="{{ route('destination.new', ['server_id' => $server->id]) }}">
@@ -29,4 +30,7 @@
</a>
@endforeach
</div>
@else
<div>Server is not validated. Validate first.</div>
@endif
</div>

View File

@@ -1,7 +1,7 @@
<div x-data="{ stopProxy: false }">
<x-naked-modal show="stopProxy" action="stopProxy" title="Stop Proxy"
message='This proxy will be stopped. It is not reversible. <br>All resources will be unavailable. <br>Please think again.' />
@if ($server->settings->is_reachable)
@if ($server->settings->is_usable)
@if ($server->proxy->type)
<div x-init="$wire.checkProxySettingsInSync">
@if ($selectedProxy->value === 'TRAEFIK_V2')
@@ -12,9 +12,7 @@
@if ($server->proxy->status === 'exited')
<x-forms.button wire:click.prevent="switchProxy">Switch Proxy</x-forms.button>
@endif
@if ($server->settings->is_reachable)
<livewire:server.proxy.status :server="$server" />
@endif
</div>
<div class="pt-3 pb-4 ">Traefik v2</div>
@@ -66,6 +64,6 @@
</div>
@endif
@else
<div class="">Server is not validated. Validate first.</div>
<div>Server is not validated. Validate first.</div>
@endif
</div>

View File

@@ -1,5 +1,6 @@
<div>
@if ($server->proxy->status === 'running')
@if (data_get($server, 'proxy.type'))
@if (data_get($server, 'proxy.status') === 'running')
<div class="flex gap-4">
<div class="group">
<label tabindex="0" class="flex items-center gap-2 cursor-pointer hover:text-white"> Links
@@ -66,11 +67,13 @@
</div>
@else
<button wire:click='deploy' class="flex items-center gap-2 cursor-pointer hover:text-white">
<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-warning" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-warning" viewBox="0 0 24 24"
stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"
stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path d="M7 4v16l13 -8z" />
</svg>Start Proxy
</button>
@endif
@endif
</div>

View File

@@ -11,13 +11,22 @@
<div class="flex flex-col mx-6">
<div class=" group-hover:text-white">
{{ $server->name }}
@if (!$server->settings->is_reachable)
<span class="text-xs text-error">not validated yet</span>
@endif
</div>
<div class="text-xs group-hover:text-white"
href="{{ route('server.show', ['server_uuid' => data_get($server, 'uuid')]) }}">
{{ $server->description }}</div>
<div class="flex gap-1 text-xs text-error">
@if (!$server->settings->is_reachable)
<span>Not reachable</span>
@endif
@if (!$server->settings->is_reachable && !$server->settings->is_usable)
&
@endif
@if (!$server->settings->is_usable)
<span>Not usable by Coolify</span>
@endif
</div>
</div>
<div class="flex-1"></div>
</div>

View File

@@ -93,7 +93,7 @@ Route::middleware(['auth'])->group(function () {
Route::get('/team/new', fn () => view('team.create'))->name('team.create');
Route::get('/team/notifications', fn () => view('team.notifications'))->name('team.notifications');
Route::get('/team/members', [Controller::class, 'members'])->name('team.members');
Route::get('/command-center', fn () => view('command-center', ['servers' => Server::validated()->get()]))->name('command-center');
Route::get('/command-center', fn () => view('command-center', ['servers' => Server::isReachable()->get()]))->name('command-center');
Route::get('/invitations/{uuid}', [Controller::class, 'acceptInvitation'])->name('team.invitation.accept');
Route::get('/invitations/{uuid}/revoke', [Controller::class, 'revokeInvitation'])->name('team.invitation.revoke');
});
@@ -156,7 +156,7 @@ Route::middleware(['auth'])->group(function () {
]);
})->name('destination.all');
Route::get('/destination/new', function () {
$servers = Server::validated()->get();
$servers = Server::isUsable()->get();
$pre_selected_server_uuid = data_get(request()->query(), 'server');
if ($pre_selected_server_uuid) {
$server = $servers->firstWhere('uuid', $pre_selected_server_uuid);