mirror of https://github.com/rancher/ui.git
Apply hasMany for projectRoleTemplateBindings
This commit is contained in:
parent
2683d101f2
commit
0fb9802b33
|
|
@ -7,8 +7,6 @@ export default Route.extend({
|
|||
model: function (params) {
|
||||
return hash({
|
||||
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'),
|
||||
roles: this.get('authzStore').findAll('projectRoleTemplate'),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -8,16 +8,15 @@ export default Route.extend({
|
|||
const project = this.get('authzStore').createRecord({
|
||||
type: `project`,
|
||||
name: '',
|
||||
projectRoleTemplateBindings: [{
|
||||
subjectKind: 'User',
|
||||
subjectName: '',
|
||||
projectRoleTemplateId: '',
|
||||
projectId: '',
|
||||
}]
|
||||
});
|
||||
const projectRoleTemplateBindings = [{
|
||||
subjectKind: 'User',
|
||||
subjectName: '',
|
||||
projectRoleTemplateId: '',
|
||||
projectId: '',
|
||||
}];
|
||||
return hash({
|
||||
project,
|
||||
projectRoleTemplateBindings,
|
||||
projects: this.get('authzStore').findAll('project'),
|
||||
roles: this.get('authzStore').findAll('projectRoleTemplate'),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ export default Route.extend(Subscribe, {
|
|||
this.preload('namespace'),
|
||||
this.preload('node'),
|
||||
this.preload('pod'),
|
||||
this.preload('projectRoleTemplateBinding', 'authzStore'),
|
||||
]);
|
||||
}).catch((err) => {
|
||||
return this.loadingError(err, transition);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { notEmpty, equal } from '@ember/object/computed';
|
||||
import { computed } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { hasMany } from 'ember-api-store/utils/denormalize';
|
||||
import Resource from 'ember-api-store/models/resource';
|
||||
import PolledResource from 'ui/mixins/cattle-polled-resource';
|
||||
import Util from 'ui/utils/util';
|
||||
|
|
@ -8,34 +9,35 @@ import C from 'ui/utils/constants';
|
|||
import { reference } from 'ember-api-store/utils/denormalize';
|
||||
|
||||
var Project = Resource.extend(PolledResource, {
|
||||
access: service(),
|
||||
prefs: service(),
|
||||
scope: service(),
|
||||
settings: service(),
|
||||
access: service(),
|
||||
prefs: service(),
|
||||
scope: service(),
|
||||
settings: service(),
|
||||
modalService: service('modal'),
|
||||
router: service(),
|
||||
cookies: service(),
|
||||
router: service(),
|
||||
cookies: service(),
|
||||
clusterStore: service('cluster-store'),
|
||||
|
||||
state: 'active', // @TODO-2.0
|
||||
|
||||
type: 'project',
|
||||
name: null,
|
||||
description: null,
|
||||
type: 'project',
|
||||
name: null,
|
||||
description: null,
|
||||
|
||||
cluster: reference('clusterId', 'cluster', 'clusterStore'),
|
||||
cluster: reference('clusterId', 'cluster', 'clusterStore'),
|
||||
clusterId: 'mycluster', // @TODO-2.0
|
||||
|
||||
canAddHost: notEmpty('cluster.registrationToken.hostCommand'),
|
||||
canImport: notEmpty('cluster.registrationToken.clusterCommand'),
|
||||
isKubernetes: equal('cluster.orchestration','kubernetes'),
|
||||
canAddHost: notEmpty('cluster.registrationToken.hostCommand'),
|
||||
canImport: notEmpty('cluster.registrationToken.clusterCommand'),
|
||||
isKubernetes: equal('cluster.orchestration', 'kubernetes'),
|
||||
projectRoleTemplateBindings: hasMany('id', 'projectRoleTemplateBinding', 'projectId'),
|
||||
|
||||
actions: {
|
||||
edit: function() {
|
||||
edit: function () {
|
||||
this.get('router').transitionTo('authenticated.projects.edit', this.get('id'));
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
activate: function () {
|
||||
return this.doAction('activate').then(() => {
|
||||
return this.waitForState('active').then(() => {
|
||||
this.get('scope').refreshAll();
|
||||
|
|
@ -43,25 +45,24 @@ var Project = Resource.extend(PolledResource, {
|
|||
});
|
||||
},
|
||||
|
||||
deactivate: function() {
|
||||
deactivate: function () {
|
||||
return this.doAction('deactivate').then(() => {
|
||||
if ( this.get('active') )
|
||||
{
|
||||
if (this.get('active')) {
|
||||
window.location.href = window.location.href;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setAsDefault: function() {
|
||||
setAsDefault: function () {
|
||||
this.get('prefs').set(C.PREFS.PROJECT_DEFAULT, this.get('id'));
|
||||
},
|
||||
|
||||
switchTo: function() {
|
||||
switchTo: function () {
|
||||
// @TODO bad
|
||||
window.lc('authenticated').send('switchProject', this.get('id'));
|
||||
},
|
||||
|
||||
promptStop: function() {
|
||||
promptStop: function () {
|
||||
this.get('modalService').toggleModal('modal-confirm-deactivate', {
|
||||
originalModel: this,
|
||||
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 l = this.get('links');
|
||||
|
||||
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 },
|
||||
{ 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 },
|
||||
{ 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;
|
||||
|
|
@ -94,46 +95,44 @@ var Project = Resource.extend(PolledResource, {
|
|||
});
|
||||
},
|
||||
|
||||
icon: computed('active', function() {
|
||||
if ( this.get('active') )
|
||||
{
|
||||
icon: computed('active', function () {
|
||||
if (this.get('active')) {
|
||||
return 'icon icon-folder-open';
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
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');
|
||||
}),
|
||||
|
||||
active: computed(`cookies.${C.COOKIE.PROJECT}`, 'id', function() {
|
||||
return ( this.get('id') === this.get('cookies').get(C.COOKIE.PROJECT));
|
||||
active: computed(`cookies.${C.COOKIE.PROJECT}`, 'id', function () {
|
||||
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');
|
||||
}),
|
||||
|
||||
displayOrchestration: computed('orchestration', function() {
|
||||
displayOrchestration: computed('orchestration', function () {
|
||||
return Util.ucFirst(this.get('orchestration'));
|
||||
}),
|
||||
|
||||
isWindows: equal('orchestration','windows'),
|
||||
isWindows: equal('orchestration', 'windows'),
|
||||
|
||||
// @TODO real data
|
||||
numStacks: computed(function() {
|
||||
return 3+Math.round(Math.random()*3);
|
||||
numStacks: computed(function () {
|
||||
return 3 + Math.round(Math.random() * 3);
|
||||
}).volatile(),
|
||||
|
||||
numServices: computed(function() {
|
||||
return 10+Math.round(Math.random()*9);
|
||||
numServices: computed(function () {
|
||||
return 10 + Math.round(Math.random() * 9);
|
||||
}).volatile(),
|
||||
|
||||
numContainers: computed(function() {
|
||||
return 50+Math.round(Math.random()*49);
|
||||
numContainers: computed(function () {
|
||||
return 50 + Math.round(Math.random() * 49);
|
||||
}).volatile(),
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export default Component.extend(NewOrEdit, {
|
|||
model: null,
|
||||
|
||||
primaryResource: alias('model.project'),
|
||||
memberArray: alias('model.projectRoleTemplateBindings'),
|
||||
memberArray: alias('model.project.projectRoleTemplateBindings'),
|
||||
|
||||
actions: {
|
||||
cancel() {
|
||||
|
|
@ -145,4 +145,4 @@ export default Component.extend(NewOrEdit, {
|
|||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue