chore: Refactor loadServices2 method and remove unused code
This commit is contained in:
@@ -49,11 +49,8 @@ class Select extends Component
|
||||
|
||||
public ?string $existingPostgresqlUrl = null;
|
||||
|
||||
public ?string $search = null;
|
||||
|
||||
protected $queryString = [
|
||||
'server_id',
|
||||
'search',
|
||||
];
|
||||
|
||||
public function mount()
|
||||
@@ -90,13 +87,13 @@ class Select extends Component
|
||||
// }
|
||||
// }
|
||||
|
||||
public function loadServices2()
|
||||
public function loadServices()
|
||||
{
|
||||
$services = get_service_templates(true);
|
||||
$services = collect($services)->map(function ($service, $key) {
|
||||
return [
|
||||
'name' => str($key)->headline(),
|
||||
'logo' => asset(data_get($service, 'logo', 'svgs/unknown.svg')),
|
||||
'logo' => asset(data_get($service, 'logo', 'svgs/coolify.png')),
|
||||
] + (array) $service;
|
||||
})->all();
|
||||
$gitBasedApplications = [
|
||||
@@ -205,42 +202,6 @@ class Select extends Component
|
||||
];
|
||||
}
|
||||
|
||||
public function updatedSearch()
|
||||
{
|
||||
$this->loadServices();
|
||||
}
|
||||
|
||||
public function loadServices(bool $force = false)
|
||||
{
|
||||
try {
|
||||
$this->loadingServices = true;
|
||||
if (count($this->allServices) > 0 && ! $force) {
|
||||
if (! $this->search) {
|
||||
$this->services = $this->allServices;
|
||||
|
||||
return;
|
||||
}
|
||||
$this->services = $this->allServices->filter(function ($service, $key) {
|
||||
$tags = collect(data_get($service, 'tags', []));
|
||||
|
||||
return str_contains(strtolower($key), strtolower($this->search)) || $tags->contains(function ($tag) {
|
||||
return str_contains(strtolower($tag), strtolower($this->search));
|
||||
});
|
||||
});
|
||||
} else {
|
||||
$this->search = null;
|
||||
$this->allServices = get_service_templates($force);
|
||||
$this->services = $this->allServices->filter(function ($service, $key) {
|
||||
return str_contains(strtolower($key), strtolower($this->search));
|
||||
});
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
} finally {
|
||||
$this->loadingServices = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
{
|
||||
if ($this->includeSwarm) {
|
||||
|
@@ -10,13 +10,14 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="pb-4">Deploy resources, like Applications, Databases, Services...</div>
|
||||
<div class="flex flex-col gap-4 py-4" x-data="searchResources()">
|
||||
<div x-data="searchResources()">
|
||||
@if ($current_step === 'type')
|
||||
<div class="sticky top-0 z-50 py-2">
|
||||
<input autocomplete="off" x-ref="searchInput" class="input w-full" x-model="search"
|
||||
placeholder="Type / to search..." @keydown.window.slash.prevent="$refs.searchInput.focus()">
|
||||
</div>
|
||||
<div x-show="loading">Loading...</div>
|
||||
<div x-show="!loading" class="flex flex-col gap-4 py-4">
|
||||
<h2 x-show="filteredGitBasedApplications.length > 0">Applications</h2>
|
||||
<h4 x-show="filteredGitBasedApplications.length > 0">Git Based</h4>
|
||||
<div x-show="filteredGitBasedApplications.length > 0"
|
||||
@@ -75,11 +76,13 @@
|
||||
<h2>Services</h2>
|
||||
<x-forms.button x-on:click="loadResources">Reload List</x-forms.button>
|
||||
</div>
|
||||
<div class="pb-4 text-xs">Trademarks Policy: The respective trademarks mentioned here are owned by the
|
||||
<div class="pb-4 text-xs">Trademarks Policy: The respective trademarks mentioned here are owned by
|
||||
the
|
||||
respective
|
||||
companies, and use of them does not imply any affiliation or endorsement.<br>Find more services <a
|
||||
class="dark:text-white underline" target="_blank"
|
||||
href="https://coolify.io/docs/services">here</a>.</div>
|
||||
companies, and use of them does not imply any affiliation or endorsement.<br>Find more services
|
||||
<a class="dark:text-white underline" target="_blank"
|
||||
href="https://coolify.io/docs/services">here</a>.
|
||||
</div>
|
||||
|
||||
<div class="grid justify-start grid-cols-1 gap-4 text-left xl:grid-cols-2">
|
||||
<template x-for="service in filteredServices" :key="service.name">
|
||||
@@ -121,6 +124,7 @@
|
||||
x-show="filteredGitBasedApplications.length === 0 && filteredDockerBasedApplications.length === 0 && filteredDatabases.length === 0 && filteredServices.length === 0 && loading === false">
|
||||
<div>No resources found.</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
function sortFn(a, b) {
|
||||
return a.name.localeCompare(b.name)
|
||||
@@ -144,7 +148,7 @@
|
||||
gitBasedApplications,
|
||||
dockerBasedApplications,
|
||||
databases
|
||||
} = await this.$wire.loadServices2();
|
||||
} = await this.$wire.loadServices();
|
||||
this.services = services;
|
||||
this.gitBasedApplications = gitBasedApplications;
|
||||
this.dockerBasedApplications = dockerBasedApplications;
|
||||
|
Reference in New Issue
Block a user