Apply hasMany for projectRoleTemplateBindings

This commit is contained in:
loganhz 2017-11-27 21:21:22 +08:00
parent 2683d101f2
commit 0fb9802b33
5 changed files with 50 additions and 53 deletions

View File

@ -7,8 +7,6 @@ export default Route.extend({
model: function (params) { model: function (params) {
return hash({ return hash({
project: this.get('authzStore').find('project', params.project_id), project: this.get('authzStore').find('project', params.project_id),
projectRoleTemplateBindings: this.get('authzStore').findAll('projectRoleTemplateBinding', { forceReload: true })
.then(bindings => bindings.filter(b => b.projectId === params.project_id)),
projects: this.get('authzStore').findAll('project'), projects: this.get('authzStore').findAll('project'),
roles: this.get('authzStore').findAll('projectRoleTemplate'), roles: this.get('authzStore').findAll('projectRoleTemplate'),
}); });

View File

@ -8,16 +8,15 @@ export default Route.extend({
const project = this.get('authzStore').createRecord({ const project = this.get('authzStore').createRecord({
type: `project`, type: `project`,
name: '', name: '',
projectRoleTemplateBindings: [{
subjectKind: 'User',
subjectName: '',
projectRoleTemplateId: '',
projectId: '',
}]
}); });
const projectRoleTemplateBindings = [{
subjectKind: 'User',
subjectName: '',
projectRoleTemplateId: '',
projectId: '',
}];
return hash({ return hash({
project, project,
projectRoleTemplateBindings,
projects: this.get('authzStore').findAll('project'), projects: this.get('authzStore').findAll('project'),
roles: this.get('authzStore').findAll('projectRoleTemplate'), roles: this.get('authzStore').findAll('projectRoleTemplate'),
}); });

View File

@ -75,6 +75,7 @@ export default Route.extend(Subscribe, {
this.preload('namespace'), this.preload('namespace'),
this.preload('node'), this.preload('node'),
this.preload('pod'), this.preload('pod'),
this.preload('projectRoleTemplateBinding', 'authzStore'),
]); ]);
}).catch((err) => { }).catch((err) => {
return this.loadingError(err, transition); return this.loadingError(err, transition);

View File

@ -1,6 +1,7 @@
import { notEmpty, equal } from '@ember/object/computed'; import { notEmpty, equal } from '@ember/object/computed';
import { computed } from '@ember/object'; import { computed } from '@ember/object';
import { inject as service } from '@ember/service'; import { inject as service } from '@ember/service';
import { hasMany } from 'ember-api-store/utils/denormalize';
import Resource from 'ember-api-store/models/resource'; import Resource from 'ember-api-store/models/resource';
import PolledResource from 'ui/mixins/cattle-polled-resource'; import PolledResource from 'ui/mixins/cattle-polled-resource';
import Util from 'ui/utils/util'; import Util from 'ui/utils/util';
@ -8,34 +9,35 @@ import C from 'ui/utils/constants';
import { reference } from 'ember-api-store/utils/denormalize'; import { reference } from 'ember-api-store/utils/denormalize';
var Project = Resource.extend(PolledResource, { var Project = Resource.extend(PolledResource, {
access: service(), access: service(),
prefs: service(), prefs: service(),
scope: service(), scope: service(),
settings: service(), settings: service(),
modalService: service('modal'), modalService: service('modal'),
router: service(), router: service(),
cookies: service(), cookies: service(),
clusterStore: service('cluster-store'), clusterStore: service('cluster-store'),
state: 'active', // @TODO-2.0 state: 'active', // @TODO-2.0
type: 'project', type: 'project',
name: null, name: null,
description: null, description: null,
cluster: reference('clusterId', 'cluster', 'clusterStore'), cluster: reference('clusterId', 'cluster', 'clusterStore'),
clusterId: 'mycluster', // @TODO-2.0 clusterId: 'mycluster', // @TODO-2.0
canAddHost: notEmpty('cluster.registrationToken.hostCommand'), canAddHost: notEmpty('cluster.registrationToken.hostCommand'),
canImport: notEmpty('cluster.registrationToken.clusterCommand'), canImport: notEmpty('cluster.registrationToken.clusterCommand'),
isKubernetes: equal('cluster.orchestration','kubernetes'), isKubernetes: equal('cluster.orchestration', 'kubernetes'),
projectRoleTemplateBindings: hasMany('id', 'projectRoleTemplateBinding', 'projectId'),
actions: { actions: {
edit: function() { edit: function () {
this.get('router').transitionTo('authenticated.projects.edit', this.get('id')); this.get('router').transitionTo('authenticated.projects.edit', this.get('id'));
}, },
activate: function() { activate: function () {
return this.doAction('activate').then(() => { return this.doAction('activate').then(() => {
return this.waitForState('active').then(() => { return this.waitForState('active').then(() => {
this.get('scope').refreshAll(); this.get('scope').refreshAll();
@ -43,25 +45,24 @@ var Project = Resource.extend(PolledResource, {
}); });
}, },
deactivate: function() { deactivate: function () {
return this.doAction('deactivate').then(() => { return this.doAction('deactivate').then(() => {
if ( this.get('active') ) if (this.get('active')) {
{
window.location.href = window.location.href; window.location.href = window.location.href;
} }
}); });
}, },
setAsDefault: function() { setAsDefault: function () {
this.get('prefs').set(C.PREFS.PROJECT_DEFAULT, this.get('id')); this.get('prefs').set(C.PREFS.PROJECT_DEFAULT, this.get('id'));
}, },
switchTo: function() { switchTo: function () {
// @TODO bad // @TODO bad
window.lc('authenticated').send('switchProject', this.get('id')); window.lc('authenticated').send('switchProject', this.get('id'));
}, },
promptStop: function() { promptStop: function () {
this.get('modalService').toggleModal('modal-confirm-deactivate', { this.get('modalService').toggleModal('modal-confirm-deactivate', {
originalModel: this, originalModel: this,
action: 'deactivate' action: 'deactivate'
@ -70,16 +71,16 @@ var Project = Resource.extend(PolledResource, {
}, },
availableActions: computed('actionLinks.{activate,deactivate}','links.{update,remove}','state','canSetDefault', function() { availableActions: computed('actionLinks.{activate,deactivate}', 'links.{update,remove}', 'state', 'canSetDefault', function () {
let a = this.get('actionLinks'); let a = this.get('actionLinks');
let l = this.get('links'); let l = this.get('links');
var choices = [ var choices = [
{ label: 'action.edit', icon: 'icon icon-edit', action: 'edit', enabled: true}, { label: 'action.edit', icon: 'icon icon-edit', action: 'edit', enabled: true },
{ divider: true }, { divider: true },
{ label: 'action.remove', icon: 'icon icon-trash', action: 'promptDelete', enabled: true, altAction: 'delete', bulkable: true }, { label: 'action.remove', icon: 'icon icon-trash', action: 'promptDelete', enabled: true, altAction: 'delete', bulkable: true },
{ divider: true }, { divider: true },
{ label: 'action.viewInApi', icon: 'icon icon-external-link',action: 'goToApi', enabled: true }, { label: 'action.viewInApi', icon: 'icon icon-external-link', action: 'goToApi', enabled: true },
]; ];
return choices; return choices;
@ -94,46 +95,44 @@ var Project = Resource.extend(PolledResource, {
}); });
}, },
icon: computed('active', function() { icon: computed('active', function () {
if ( this.get('active') ) if (this.get('active')) {
{
return 'icon icon-folder-open'; return 'icon icon-folder-open';
} }
else else {
{
return 'icon icon-folder text-muted'; return 'icon icon-folder text-muted';
} }
}), }),
isDefault: computed(`prefs.${C.PREFS.PROJECT_DEFAULT}`, 'id', function() { isDefault: computed(`prefs.${C.PREFS.PROJECT_DEFAULT}`, 'id', function () {
return this.get(`prefs.${C.PREFS.PROJECT_DEFAULT}`) === this.get('id'); return this.get(`prefs.${C.PREFS.PROJECT_DEFAULT}`) === this.get('id');
}), }),
active: computed(`cookies.${C.COOKIE.PROJECT}`, 'id', function() { active: computed(`cookies.${C.COOKIE.PROJECT}`, 'id', function () {
return ( this.get('id') === this.get('cookies').get(C.COOKIE.PROJECT)); return (this.get('id') === this.get('cookies').get(C.COOKIE.PROJECT));
}), }),
canSetDefault: computed('state','isDefault', function() { canSetDefault: computed('state', 'isDefault', function () {
return this.get('state') === 'active' && !this.get('isDefault'); return this.get('state') === 'active' && !this.get('isDefault');
}), }),
displayOrchestration: computed('orchestration', function() { displayOrchestration: computed('orchestration', function () {
return Util.ucFirst(this.get('orchestration')); return Util.ucFirst(this.get('orchestration'));
}), }),
isWindows: equal('orchestration','windows'), isWindows: equal('orchestration', 'windows'),
// @TODO real data // @TODO real data
numStacks: computed(function() { numStacks: computed(function () {
return 3+Math.round(Math.random()*3); return 3 + Math.round(Math.random() * 3);
}).volatile(), }).volatile(),
numServices: computed(function() { numServices: computed(function () {
return 10+Math.round(Math.random()*9); return 10 + Math.round(Math.random() * 9);
}).volatile(), }).volatile(),
numContainers: computed(function() { numContainers: computed(function () {
return 50+Math.round(Math.random()*49); return 50 + Math.round(Math.random() * 49);
}).volatile(), }).volatile(),
}); });

View File

@ -13,7 +13,7 @@ export default Component.extend(NewOrEdit, {
model: null, model: null,
primaryResource: alias('model.project'), primaryResource: alias('model.project'),
memberArray: alias('model.projectRoleTemplateBindings'), memberArray: alias('model.project.projectRoleTemplateBindings'),
actions: { actions: {
cancel() { cancel() {
@ -145,4 +145,4 @@ export default Component.extend(NewOrEdit, {
}); });
}); });
}, },
}); });