|
9 | 9 | </x-modal-input>
|
10 | 10 | </div>
|
11 | 11 | <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> |
25 | 27 | </div>
|
26 |
| - </div> |
27 |
| - @empty |
28 |
| - <div> |
29 |
| - <div>No project found.</div> |
30 |
| - </div> |
31 |
| - @endforelse |
| 28 | + </template> |
| 29 | + </div> |
32 | 30 | </div>
|
33 | 31 |
|
34 | 32 | <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 | + } |
40 | 65 | }
|
41 |
| - } |
42 |
| -</script> |
| 66 | + </script> |
43 | 67 | </div>
|
0 commit comments