Skip to content

Commit c2d6ea8

Browse files
authored
Merge pull request #559 from kubero-dev/feature/improve-template-view
add search and category select fields
2 parents 6cc8eba + 2e73f82 commit c2d6ea8

File tree

1 file changed

+70
-10
lines changed

1 file changed

+70
-10
lines changed

client/src/components/templates/index.vue

Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,28 @@
22
<v-container>
33

44
<v-row class="justify-space-between">
5-
<v-col cols="6" sm="6" md="6" lg="6" xl="6">
5+
<v-col cols="6" sm="12" md="12" lg="6" xl="6">
66
<h1>Templates</h1>
77
</v-col>
8+
<v-col cols="3" sm="6" md="3">
9+
<v-text-field
10+
label="Search"
11+
v-model="search"
12+
color="secondary"
13+
@input="searchTemplates"
14+
density="comfortable"
15+
></v-text-field>
16+
</v-col>
17+
<v-col cols="3" sm="6" md="3">
18+
<v-select
19+
:items="categories"
20+
color="secondary"
21+
density="comfortable"
22+
@update:modelValue="filterByCategory"
23+
label="Category"
24+
:v-model="selectedCategory"
25+
></v-select>
26+
</v-col>
827
</v-row>
928
<v-row>
1029
<v-tabs v-if="templates.catalogs.length > 1">
@@ -19,7 +38,7 @@
1938
</v-row>
2039
<v-row>
2140
<v-col cols="12" sm="12" md="3"
22-
v-for="template in services.services" :key="template.name">
41+
v-for="template in showedTemplates.services" :key="template.name">
2342
<v-card
2443
style="padding-bottom: 40px;"
2544
height="320px"
@@ -123,6 +142,7 @@
123142

124143
<script lang="ts">
125144
import axios from "axios";
145+
import { forEach } from "lodash";
126146
import { defineComponent } from 'vue'
127147
128148
type Pipeline = {
@@ -139,10 +159,6 @@ type Pipeline = {
139159
}[]
140160
}
141161
142-
type PipelineList = {
143-
items: Pipeline[]
144-
}
145-
146162
type Template = {
147163
name: string,
148164
description: string,
@@ -154,6 +170,13 @@ type Template = {
154170
screenshots: string[],
155171
dirname: string,
156172
template: string,
173+
addons: string[],
174+
language: string,
175+
categories: string[],
176+
created_at: string,
177+
last_updated: string,
178+
last_pushed: string,
179+
status: string,
157180
}
158181
159182
type Templates = {
@@ -173,8 +196,13 @@ type Catalog = {
173196
}
174197
}
175198
176-
type Services = {
199+
type TemplatesList = {
177200
services: Template[],
201+
categories: Object,
202+
// categories: {
203+
// title: string,
204+
// count: number,
205+
// }[]
178206
}
179207
180208
export default defineComponent({
@@ -189,7 +217,8 @@ export default defineComponent({
189217
phase: '',
190218
pipelines: [] as string[],
191219
phases: {} as { [key: string]: string[] },
192-
services: {} as Services,
220+
templatesList: {} as TemplatesList,
221+
showedTemplates: {} as TemplatesList,
193222
dialog: false,
194223
clickedTemplate: {} as Template,
195224
catalogId: 0,
@@ -198,6 +227,14 @@ export default defineComponent({
198227
catalogs: [] as Catalog[],
199228
},
200229
catalogTabs: [] as string[],
230+
categories: [
231+
{ title: 'All', value: 'All' },
232+
],
233+
search: '',
234+
selectedCategory: {
235+
title: 'All',
236+
value: 'All',
237+
},
201238
}),
202239
components: {
203240
},
@@ -224,7 +261,7 @@ export default defineComponent({
224261
const self = this;
225262
axios.get(`/api/config/catalogs`)
226263
.then(response => {
227-
self.templates = response.data;
264+
self.templates = response.data as Templates;
228265
if (self.templates.catalogs.length > 0 && self.templates.enabled == true) {
229266
self.loadTemplates(self.templates.catalogs[catalogId].index.url)
230267
}
@@ -234,11 +271,34 @@ export default defineComponent({
234271
console.log(error);
235272
});
236273
},
274+
filterByCategory(selectedCategory: string) {
275+
console.log(selectedCategory);
276+
if (selectedCategory === 'All') {
277+
this.showedTemplates.services = this.templatesList.services;
278+
} else {
279+
this.showedTemplates.services = this.templatesList.services.filter((template) => {
280+
return template.categories.includes(selectedCategory);
281+
});
282+
}
283+
},
284+
searchTemplates() {
285+
if (this.search !== '') {
286+
this.showedTemplates.services = this.templatesList.services.filter((template) => {
287+
return template.name.toLowerCase().includes(this.search.toLowerCase());
288+
});
289+
} else {
290+
this.showedTemplates.services = this.templatesList.services;
291+
}
292+
},
237293
async loadTemplates(indexUrl: string) {
238294
const self = this;
239295
axios.get(indexUrl)
240296
.then(response => {
241-
self.services = response.data;
297+
self.templatesList = response.data;
298+
forEach(self.templatesList.categories, (value, key) => {
299+
self.categories.push({ title: key + ' (' + value + ')', value: key });
300+
});
301+
self.searchTemplates();
242302
})
243303
.catch(error => {
244304
console.log(error);

0 commit comments

Comments
 (0)