fix: services view

This commit is contained in:
Andras Bacsai 2023-09-27 21:14:13 +02:00
parent 398f122593
commit fe8a7fc54f
6 changed files with 38 additions and 49 deletions

View File

@ -73,7 +73,6 @@ class ProjectController extends Controller
if ($oneClickDotEnvs) { if ($oneClickDotEnvs) {
$oneClickDotEnvs = Str::of(base64_decode($oneClickDotEnvs))->split('/\r\n|\r|\n/'); $oneClickDotEnvs = Str::of(base64_decode($oneClickDotEnvs))->split('/\r\n|\r|\n/');
} }
ray($oneClickDotEnvs);
if ($oneClickService) { if ($oneClickService) {
$service = Service::create([ $service = Service::create([
'name' => "$oneClickServiceName-" . Str::random(10), 'name' => "$oneClickServiceName-" . Str::random(10),
@ -83,7 +82,7 @@ class ProjectController extends Controller
]); ]);
$service->name = "$oneClickServiceName-" . $service->uuid; $service->name = "$oneClickServiceName-" . $service->uuid;
$service->save(); $service->save();
if ($oneClickDotEnvs->count() > 0) { if ($oneClickDotEnvs?->count() > 0) {
$oneClickDotEnvs->each(function ($value) use ($service) { $oneClickDotEnvs->each(function ($value) use ($service) {
$key = Str::before($value, '='); $key = Str::before($value, '=');
$value = Str::of(Str::after($value, '=')); $value = Str::of(Str::after($value, '='));

View File

@ -9,7 +9,6 @@ use Livewire\Component;
class Index extends Component class Index extends Component
{ {
use WithRateLimiting;
public Service $service; public Service $service;
public $applications; public $applications;
public $databases; public $databases;
@ -21,26 +20,22 @@ class Index extends Component
'service.name' => 'required', 'service.name' => 'required',
'service.description' => 'nullable', 'service.description' => 'nullable',
]; ];
public function manualRefreshStack() { public function checkStatus() {
try { dispatch_sync(new ContainerStatusJob($this->service->server));
$this->rateLimit(5); $this->refreshStack();
dispatch_sync(new ContainerStatusJob($this->service->server));
$this->refreshStack();
} catch(\Throwable $e) {
return handleError($e, $this);
}
} }
public function refreshStack() public function refreshStack()
{ {
$this->applications = $this->service->applications->sort(); $this->applications = $this->service->applications->sort();
$this->applications->each(function ($application) { $this->applications->each(function ($application) {
$application->refresh();
$application->configuration_required = $application->configurationRequired(); $application->configuration_required = $application->configurationRequired();
}); });
$this->databases = $this->service->databases->sort(); $this->databases = $this->service->databases->sort();
$this->databases->each(function ($database) { $this->databases->each(function ($database) {
$database->refresh();
$database->configuration_required = $database->configurationRequired(); $database->configuration_required = $database->configurationRequired();
}); });
$this->emit('success', 'Stack refreshed successfully.');
} }
public function mount() public function mount()
{ {

View File

@ -115,30 +115,30 @@ class Service extends BaseModel
} }
return "{$server->ip}.sslip.io"; return "{$server->ip}.sslip.io";
} }
private function generateFqdn($serviceVariables, $serviceName, Collection $configuration) // private function generateFqdn($serviceVariables, $serviceName, Collection $configuration)
{ // {
// Add sslip.io to the service // // Add sslip.io to the service
$defaultUsableFqdn = null; // $defaultUsableFqdn = null;
$sslip = $this->sslip($this->server); // $sslip = $this->sslip($this->server);
if (Str::of($serviceVariables)->contains('SERVICE_FQDN') || Str::of($serviceVariables)->contains('SERVICE_URL')) { // if (Str::of($serviceVariables)->contains('SERVICE_FQDN') || Str::of($serviceVariables)->contains('SERVICE_URL')) {
$defaultUsableFqdn = "http://$serviceName-{$this->uuid}.{$sslip}"; // $defaultUsableFqdn = "http://$serviceName-{$this->uuid}.{$sslip}";
} // }
if ($configuration->count() > 0) { // if ($configuration->count() > 0) {
foreach ($configuration as $requiredFqdn) { // foreach ($configuration as $requiredFqdn) {
$requiredFqdn = (array)$requiredFqdn; // $requiredFqdn = (array)$requiredFqdn;
$name = data_get($requiredFqdn, 'name'); // $name = data_get($requiredFqdn, 'name');
$path = data_get($requiredFqdn, 'path'); // $path = data_get($requiredFqdn, 'path');
$customFqdn = data_get($requiredFqdn, 'customFqdn'); // $customFqdn = data_get($requiredFqdn, 'customFqdn');
if ($serviceName === $name) { // if ($serviceName === $name) {
$defaultUsableFqdn = "http://$serviceName-{$this->uuid}.{$sslip}{$path}"; // $defaultUsableFqdn = "http://$serviceName-{$this->uuid}.{$sslip}{$path}";
if ($customFqdn) { // if ($customFqdn) {
$defaultUsableFqdn = "http://$customFqdn-{$this->uuid}.{$sslip}{$path}"; // $defaultUsableFqdn = "http://$customFqdn-{$this->uuid}.{$sslip}{$path}";
} // }
} // }
} // }
} // }
return $defaultUsableFqdn ?? null; // return $defaultUsableFqdn ?? null;
} // }
public function parse(bool $isNew = false): Collection public function parse(bool $isNew = false): Collection
{ {
// ray()->clearAll(); // ray()->clearAll();
@ -376,14 +376,10 @@ class Service extends BaseModel
$generatedServiceFQDNS->put($key->value(), $fqdn); $generatedServiceFQDNS->put($key->value(), $fqdn);
} }
} else { } else {
ray($key, $fqdn);
$generatedServiceFQDNS->put($key->value(), $fqdn); $generatedServiceFQDNS->put($key->value(), $fqdn);
} }
$fqdn = "http://$containerName.$sslip$path"; $fqdn = "http://$containerName.$sslip$path";
ray($fqdn);
} }
if (!$isDatabase) { if (!$isDatabase) {
$savedService->fqdn = $fqdn; $savedService->fqdn = $fqdn;
$savedService->save(); $savedService->save();

View File

@ -11,9 +11,9 @@
</svg> </svg>
</a> </a>
</li> </li>
<li title="Send feedback or get help" class="fixed top-0 right-0 p-2 px-4 pt-4 mt-auto"> <li title="Send us feedback or get help!" class="fixed top-0 right-0 p-2 px-4 pt-4 mt-auto text-xs">
<div class="justify-center" wire:click="help" onclick="help.showModal()"> <div class="justify-center" wire:click="help" onclick="help.showModal()">
<svg class="icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> <svg class="w-5 h-5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path fill="currentColor" <path fill="currentColor"
d="M22 5.5H9c-1.1 0-2 .9-2 2v9a2 2 0 0 0 2 2h13c1.11 0 2-.89 2-2v-9a2 2 0 0 0-2-2m0 11H9V9.17l6.5 3.33L22 9.17v7.33m-6.5-5.69L9 7.5h13l-6.5 3.31M5 16.5c0 .17.03.33.05.5H1c-.552 0-1-.45-1-1s.448-1 1-1h4v1.5M3 7h2.05c-.02.17-.05.33-.05.5V9H3c-.55 0-1-.45-1-1s.45-1 1-1m-2 5c0-.55.45-1 1-1h3v2H2c-.55 0-1-.45-1-1Z" /> d="M22 5.5H9c-1.1 0-2 .9-2 2v9a2 2 0 0 0 2 2h13c1.11 0 2-.89 2-2v-9a2 2 0 0 0-2-2m0 11H9V9.17l6.5 3.33L22 9.17v7.33m-6.5-5.69L9 7.5h13l-6.5 3.31M5 16.5c0 .17.03.33.05.5H1c-.552 0-1-.45-1-1s.448-1 1-1h4v1.5M3 7h2.05c-.02.17-.05.33-.05.5V9H3c-.55 0-1-.45-1-1s.45-1 1-1m-2 5c0-.55.45-1 1-1h3v2H2c-.55 0-1-.45-1-1Z" />
</svg> </svg>

View File

@ -115,9 +115,9 @@
</li> </li>
@endif @endif
@if (isSubscriptionActive() || isDev()) @if (isSubscriptionActive() || isDev())
<li title="Send feedback or get help" class="fixed top-0 right-0 p-2 px-4 pt-4 mt-auto"> <li title="Send us feedback or get help!" class="fixed top-0 right-0 p-2 px-4 pt-4 mt-auto text-xs">
<div class="justify-center" wire:click="help" onclick="help.showModal()"> <div class="justify-center" wire:click="help" onclick="help.showModal()">
<svg class="icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> <svg class="w-5 h-5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path fill="currentColor" <path fill="currentColor"
d="M22 5.5H9c-1.1 0-2 .9-2 2v9a2 2 0 0 0 2 2h13c1.11 0 2-.89 2-2v-9a2 2 0 0 0-2-2m0 11H9V9.17l6.5 3.33L22 9.17v7.33m-6.5-5.69L9 7.5h13l-6.5 3.31M5 16.5c0 .17.03.33.05.5H1c-.552 0-1-.45-1-1s.448-1 1-1h4v1.5M3 7h2.05c-.02.17-.05.33-.05.5V9H3c-.55 0-1-.45-1-1s.45-1 1-1m-2 5c0-.55.45-1 1-1h3v2H2c-.55 0-1-.45-1-1Z" /> d="M22 5.5H9c-1.1 0-2 .9-2 2v9a2 2 0 0 0 2 2h13c1.11 0 2-.89 2-2v-9a2 2 0 0 0-2-2m0 11H9V9.17l6.5 3.33L22 9.17v7.33m-6.5-5.69L9 7.5h13l-6.5 3.31M5 16.5c0 .17.03.33.05.5H1c-.552 0-1-.45-1-1s.448-1 1-1h4v1.5M3 7h2.05c-.02.17-.05.33-.05.5V9H3c-.55 0-1-.45-1-1s.45-1 1-1m-2 5c0-.55.45-1 1-1h3v2H2c-.55 0-1-.45-1-1Z" />
</svg> </svg>

View File

@ -1,7 +1,7 @@
<div x-data="{ raw: true, activeTab: window.location.hash ? window.location.hash.substring(1) : 'service-stack' }"> <div x-data="{ raw: true, activeTab: window.location.hash ? window.location.hash.substring(1) : 'service-stack' }" wire:poll.10000ms="checkStatus">
<livewire:project.service.navbar :service="$service" :parameters="$parameters" :query="$query" /> <livewire:project.service.navbar :service="$service" :parameters="$parameters" :query="$query" />
<div class="flex h-full pt-6"> <div class="flex h-full pt-6">
<div class="flex flex-col gap-4 min-w-fit"> <div class="flex flex-col items-start gap-4 min-w-fit">
<a target="_blank" href="{{ $service->documentation() }}">Documentation <x-external-link /></a> <a target="_blank" href="{{ $service->documentation() }}">Documentation <x-external-link /></a>
<a :class="activeTab === 'service-stack' && 'text-white'" <a :class="activeTab === 'service-stack' && 'text-white'"
@click.prevent="activeTab = 'service-stack'; window.location.hash = 'service-stack'" @click.prevent="activeTab = 'service-stack'; window.location.hash = 'service-stack'"
@ -23,7 +23,6 @@
<div>Configuration</div> <div>Configuration</div>
</div> </div>
<x-forms.button type="submit">Save</x-forms.button> <x-forms.button type="submit">Save</x-forms.button>
<x-forms.button wire:click='manualRefreshStack'>Refresh Status</x-forms.button>
<div x-cloak x-show="raw"> <div x-cloak x-show="raw">
<x-forms.button class="w-64" @click.prevent="raw = !raw">Show Deployable <x-forms.button class="w-64" @click.prevent="raw = !raw">Show Deployable
Compose</x-forms.button> Compose</x-forms.button>
@ -59,7 +58,7 @@
</div> </div>
</form> </form>
<div class="grid grid-cols-1 gap-2 pt-4 xl:grid-cols-3"> <div class="grid grid-cols-1 gap-2 pt-4 xl:grid-cols-3">
@foreach ($applications as $application) @foreach ($service->applications as $application)
<a @class([ <a @class([
'border-l border-dashed border-red-500' => Str::of( 'border-l border-dashed border-red-500' => Str::of(
$application->status)->contains(['exited']), $application->status)->contains(['exited']),
@ -107,7 +106,7 @@
<span class="text-xs text-error">(configuration required)</span> <span class="text-xs text-error">(configuration required)</span>
@endif @endif
@if ($database->description) @if ($database->description)
<span class="text-xs">{{ Str::limit($database->description, 60) }}</span> <span class="text-xs">{{ Str::limit($database->description, 60) }}</span>
@endif @endif
<div class="text-xs">{{ $database->status }}</div> <div class="text-xs">{{ $database->status }}</div>
</a> </a>