diff --git a/app/catalog-tab/route.js b/app/catalog-tab/route.js index 940f84898..f8497b9ed 100644 --- a/app/catalog-tab/route.js +++ b/app/catalog-tab/route.js @@ -1,6 +1,6 @@ import { inject as service } from '@ember/service'; import Route from '@ember/routing/route'; -import { get } from '@ember/object'; +import { get, set } from '@ember/object'; export default Route.extend({ access: service(), @@ -18,6 +18,8 @@ export default Route.extend({ model(params) { const project = this.modelFor('authenticated.project').get('project'); + set(params, 'project', project); + return get(this, 'catalog').fetchTemplates(params) .then((res) => { res.catalog.forEach((tpl) => { diff --git a/lib/shared/addon/catalog/service.js b/lib/shared/addon/catalog/service.js index 5aef5c570..98dcbe8bf 100644 --- a/lib/shared/addon/catalog/service.js +++ b/lib/shared/addon/catalog/service.js @@ -69,7 +69,7 @@ export default Service.extend({ const store = get(this, 'globalStore'); return this.fetchUnScopedCatalogs().then(() => { - this.set('templateCache', null); + set(this, 'templateCache', null); return hash({ projectCatalogs: store.request({ @@ -148,6 +148,9 @@ export default Service.extend({ let cache = get(this, 'templateCache'); let catalogId = null; let qp = { 'category_ne': 'system', }; + let project = params.project ? params.project : null; + let currentProjectId = project ? project.id.split(':')[1] : null; + let currentClusterId = project ? project.clusterId : null; if (params.catalogId) { catalogId = params.catalogId; @@ -186,7 +189,25 @@ export default Service.extend({ return get(this, 'globalStore').request({ url, }).then((res) => { res.catalogId = catalogId; - this.set('templateCache', res); + + if (catalogId === 'all' || !catalogId) { + set(this, 'templateCache', res.filter((t) => { + this; + if (t.clusterId && currentClusterId) { + if (t.clusterId === currentClusterId) { + return t; + } + } else if (t.projectId && currentProjectId) { + if (t.projectId === currentProjectId) { + return t; + } + } else { + return t; + } + })); + } else { + set(this, 'templateCache', res); + } return this.filter(res, params.category); }).catch((err) => {