Skip to content

Commit a1124a8

Browse files
committed
feat: project search on frontend
1 parent 9448d0f commit a1124a8

File tree

4 files changed

+60
-30
lines changed

4 files changed

+60
-30
lines changed

app/Models/Project.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class Project extends BaseModel
2424
{
2525
protected $guarded = [];
2626

27+
protected $appends = ['default_environment'];
28+
2729
public static function ownedByCurrentTeam()
2830
{
2931
return Project::whereTeamId(currentTeam()->id)->orderBy('name');
@@ -131,7 +133,7 @@ public function databases()
131133
return $this->postgresqls()->get()->merge($this->redis()->get())->merge($this->mongodbs()->get())->merge($this->mysqls()->get())->merge($this->mariadbs()->get())->merge($this->keydbs()->get())->merge($this->dragonflies()->get())->merge($this->clickhouses()->get());
132134
}
133135

134-
public function default_environment()
136+
public function getDefaultEnvironmentAttribute()
135137
{
136138
$default = $this->environments()->where('name', 'production')->first();
137139
if ($default) {

resources/views/livewire/dashboard.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<div class="grid grid-cols-1 gap-2 xl:grid-cols-2">
2424
@foreach ($projects as $project)
2525
<div class="gap-2 border border-transparent cursor-pointer box group"
26-
onclick="gotoProject('{{ $project->uuid }}','{{ $project->default_environment() }}')">
26+
onclick="gotoProject('{{ $project->uuid }}','{{ $project->default_environment }}')">
2727
<div class="flex flex-1 mx-6">
2828
<div class="flex flex-col justify-center flex-1">
2929
<div class="box-title">{{ $project->name }}</div>
@@ -33,7 +33,7 @@
3333
</div>
3434
<div class="flex items-center justify-center gap-2 text-xs font-bold">
3535
<a class="hover:underline"
36-
href="{{ route('project.resource.create', ['project_uuid' => $project->uuid, 'environment_name' => data_get($project, 'default_environment()', 'production')]) }}">
36+
href="{{ route('project.resource.create', ['project_uuid' => $project->uuid, 'environment_name' => data_get($project, 'default_environment', 'production')]) }}">
3737
<span class="p-2 font-bold">+ Add Resource</span>
3838
</a>
3939
<a class="hover:underline"
@@ -122,7 +122,7 @@
122122
@if (count($deployments_per_server) > 0)
123123
<x-loading />
124124
@endif
125-
<x-modal-confirmation
125+
<x-modal-confirmation
126126
title="Confirm Cleanup Queues?"
127127
buttonTitle="Cleanup Queues"
128128
isErrorButton

resources/views/livewire/project/index.blade.php

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,59 @@
99
</x-modal-input>
1010
</div>
1111
<div class="subtitle">All your projects are here.</div>
12-
<div class="grid gap-2 lg:grid-cols-2">
13-
@forelse ($projects as $project)
14-
<div class="box group" onclick="gotoProject('{{ $project->uuid }}', '{{ $project->default_environment() }}')">
15-
<div class="flex flex-col justify-center flex-1 mx-6">
16-
<div class="box-title">{{ $project->name }}</div>
17-
<div class="box-description ">
18-
{{ $project->description }}</div>
19-
</div>
20-
<div class="flex items-center justify-center gap-2 pt-4 pb-2 mr-4 text-xs lg:py-0 lg:justify-normal">
21-
<a class="mx-4 font-bold hover:underline"
22-
href="{{ route('project.edit', ['project_uuid' => data_get($project, 'uuid')]) }}">
23-
Settings
24-
</a>
12+
<div x-data="searchComponent()">
13+
<x-forms.input placeholder="Search for name, description..." x-model="search" id="null" />
14+
<div class="grid grid-cols-2 gap-4 pt-4">
15+
<template x-if="allFilteredItems.length === 0">
16+
<div>No project found with the search term "<span x-text="search"></span>".</div>
17+
</template>
18+
19+
<template x-for="item in allFilteredItems" :key="item.uuid">
20+
<div class="box group" @click="gotoProject(item)">
21+
<div class="flex flex-col justify-center flex-1 mx-6">
22+
<div class="box-title" x-text="item.name"></div>
23+
<div class="box-description ">
24+
<div x-text="item.description"></div>
25+
</div>
26+
</div>
2527
</div>
26-
</div>
27-
@empty
28-
<div>
29-
<div>No project found.</div>
30-
</div>
31-
@endforelse
28+
</template>
29+
</div>
3230
</div>
3331

3432
<script>
35-
function gotoProject(uuid, environment) {
36-
if (environment) {
37-
window.location.href = '/project/' + uuid + '/' + environment;
38-
} else {
39-
window.location.href = '/project/' + uuid;
33+
function sortFn(a, b) {
34+
return a.name.localeCompare(b.name)
35+
}
36+
37+
function searchComponent() {
38+
return {
39+
search: '',
40+
projects: @js($projects),
41+
filterAndSort(items) {
42+
if (this.search === '') {
43+
return Object.values(items).sort(sortFn);
44+
}
45+
const searchLower = this.search.toLowerCase();
46+
return Object.values(items).filter(item => {
47+
return (item.name?.toLowerCase().includes(searchLower) ||
48+
item.description?.toLowerCase().includes(searchLower))
49+
}).sort(sortFn);
50+
},
51+
get allFilteredItems() {
52+
return [
53+
this.projects,
54+
].flatMap((items) => this.filterAndSort(items));
55+
}
56+
}
57+
}
58+
59+
function gotoProject(item) {
60+
if (item.default_environment) {
61+
window.location.href = '/project/' + item.uuid + '/' + item.default_environment;
62+
} else {
63+
window.location.href = '/project/' + item.uuid;
64+
}
4065
}
41-
}
42-
</script>
66+
</script>
4367
</div>

resources/views/livewire/project/resource/index.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class="items-center justify-center box">+ Add New Resource</a>
5050
<div x-data="searchComponent()">
5151
<x-forms.input placeholder="Search for name, fqdn..." x-model="search" id="null" />
5252
<div class="grid grid-cols-1 gap-4 pt-4 lg:grid-cols-2 xl:grid-cols-3">
53+
<template x-if="allFilteredItems.length === 0">
54+
<div>No resource found with the search term "<span x-text="search"></span>".</div>
55+
</template>
56+
5357
<template x-for="item in allFilteredItems" :key="item.uuid">
5458
<span>
5559
<a class="h-24 box group" :href="item.hrefLink">

0 commit comments

Comments
 (0)