From 2e73f82db24a7e48e319ec2d5992beb26e34d1c9 Mon Sep 17 00:00:00 2001 From: Gianni Carafa Date: Thu, 19 Dec 2024 23:52:46 +0100 Subject: [PATCH] add search and category select fields --- client/src/components/templates/index.vue | 80 ++++++++++++++++++++--- 1 file changed, 70 insertions(+), 10 deletions(-) diff --git a/client/src/components/templates/index.vue b/client/src/components/templates/index.vue index 5856e23c..60d5e623 100644 --- a/client/src/components/templates/index.vue +++ b/client/src/components/templates/index.vue @@ -2,9 +2,28 @@ - +

Templates

+ + + + + +
@@ -19,7 +38,7 @@ + v-for="template in showedTemplates.services" :key="template.name"> import axios from "axios"; +import { forEach } from "lodash"; import { defineComponent } from 'vue' type Pipeline = { @@ -139,10 +159,6 @@ type Pipeline = { }[] } -type PipelineList = { - items: Pipeline[] -} - type Template = { name: string, description: string, @@ -154,6 +170,13 @@ type Template = { screenshots: string[], dirname: string, template: string, + addons: string[], + language: string, + categories: string[], + created_at: string, + last_updated: string, + last_pushed: string, + status: string, } type Templates = { @@ -173,8 +196,13 @@ type Catalog = { } } -type Services = { +type TemplatesList = { services: Template[], + categories: Object, + // categories: { + // title: string, + // count: number, + // }[] } export default defineComponent({ @@ -189,7 +217,8 @@ export default defineComponent({ phase: '', pipelines: [] as string[], phases: {} as { [key: string]: string[] }, - services: {} as Services, + templatesList: {} as TemplatesList, + showedTemplates: {} as TemplatesList, dialog: false, clickedTemplate: {} as Template, catalogId: 0, @@ -198,6 +227,14 @@ export default defineComponent({ catalogs: [] as Catalog[], }, catalogTabs: [] as string[], + categories: [ + { title: 'All', value: 'All' }, + ], + search: '', + selectedCategory: { + title: 'All', + value: 'All', + }, }), components: { }, @@ -224,7 +261,7 @@ export default defineComponent({ const self = this; axios.get(`/api/config/catalogs`) .then(response => { - self.templates = response.data; + self.templates = response.data as Templates; if (self.templates.catalogs.length > 0 && self.templates.enabled == true) { self.loadTemplates(self.templates.catalogs[catalogId].index.url) } @@ -234,11 +271,34 @@ export default defineComponent({ console.log(error); }); }, + filterByCategory(selectedCategory: string) { + console.log(selectedCategory); + if (selectedCategory === 'All') { + this.showedTemplates.services = this.templatesList.services; + } else { + this.showedTemplates.services = this.templatesList.services.filter((template) => { + return template.categories.includes(selectedCategory); + }); + } + }, + searchTemplates() { + if (this.search !== '') { + this.showedTemplates.services = this.templatesList.services.filter((template) => { + return template.name.toLowerCase().includes(this.search.toLowerCase()); + }); + } else { + this.showedTemplates.services = this.templatesList.services; + } + }, async loadTemplates(indexUrl: string) { const self = this; axios.get(indexUrl) .then(response => { - self.services = response.data; + self.templatesList = response.data; + forEach(self.templatesList.categories, (value, key) => { + self.categories.push({ title: key + ' (' + value + ')', value: key }); + }); + self.searchTemplates(); }) .catch(error => { console.log(error);