Merge pull request #2547 from westlywright/catalog-fixes

filter catalog categories by cluster and project
This commit is contained in:
Westly Wright 2019-01-04 10:37:53 -07:00 committed by GitHub
commit 1ad58aaeac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -1,6 +1,6 @@
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import Route from '@ember/routing/route'; import Route from '@ember/routing/route';
import { get } from '@ember/object'; import { get, set } from '@ember/object';
export default Route.extend({ export default Route.extend({
access: service(), access: service(),
@ -18,6 +18,8 @@ export default Route.extend({
model(params) { model(params) {
const project = this.modelFor('authenticated.project').get('project'); const project = this.modelFor('authenticated.project').get('project');
set(params, 'project', project);
return get(this, 'catalog').fetchTemplates(params) return get(this, 'catalog').fetchTemplates(params)
.then((res) => { .then((res) => {
res.catalog.forEach((tpl) => { res.catalog.forEach((tpl) => {

View File

@ -69,7 +69,7 @@ export default Service.extend({
const store = get(this, 'globalStore'); const store = get(this, 'globalStore');
return this.fetchUnScopedCatalogs().then(() => { return this.fetchUnScopedCatalogs().then(() => {
this.set('templateCache', null); set(this, 'templateCache', null);
return hash({ return hash({
projectCatalogs: store.request({ projectCatalogs: store.request({
@ -148,6 +148,9 @@ export default Service.extend({
let cache = get(this, 'templateCache'); let cache = get(this, 'templateCache');
let catalogId = null; let catalogId = null;
let qp = { 'category_ne': 'system', }; 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) { if (params.catalogId) {
catalogId = params.catalogId; catalogId = params.catalogId;
@ -186,7 +189,25 @@ export default Service.extend({
return get(this, 'globalStore').request({ url, }).then((res) => { return get(this, 'globalStore').request({ url, }).then((res) => {
res.catalogId = catalogId; 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); return this.filter(res, params.category);
}).catch((err) => { }).catch((err) => {