mirror of https://github.com/rancher/ui.git
commit
f19f9a8fc6
|
|
@ -57,31 +57,6 @@ export default Controller.extend(NewOrEdit, {
|
|||
return false;
|
||||
},
|
||||
|
||||
doSave(opt) {
|
||||
let promises = [];
|
||||
let store = get(this, 'globalStore');
|
||||
|
||||
// TODO 2.0 , principalIds: ['local://']?
|
||||
set(this, 'primaryResource.principalIds', [`local://${get(this, 'primaryResource.userName')}`]);
|
||||
|
||||
get(this, 'roles').forEach((role) => {
|
||||
let promise;
|
||||
if (get(role, 'active')) { // new role for user
|
||||
promise = store.createRecord({
|
||||
type: 'globalRoleBindings',
|
||||
globalRoleId: get(role, 'globalId'),
|
||||
// subjectName: get(this, 'model.account.principalIds.firstObject'), // TODO 2.0
|
||||
subjectName: `local://${get(this, 'primaryResource.userName')}`, // TODO 2.0
|
||||
subjectKind: 'User', // TODO 2.0
|
||||
}).save();
|
||||
promises.push(promise);
|
||||
}
|
||||
});
|
||||
return all(promises.compact()).then(( /* list */ ) => {
|
||||
return this._super(opt);
|
||||
});
|
||||
},
|
||||
|
||||
validate: function () {
|
||||
var errors = [];
|
||||
|
||||
|
|
@ -98,19 +73,35 @@ export default Controller.extend(NewOrEdit, {
|
|||
}
|
||||
|
||||
if (errors.length) {
|
||||
this.set('errors', errors.uniq());
|
||||
set(this, 'errors', errors.uniq());
|
||||
return false;
|
||||
} else {
|
||||
this.set('errors', null);
|
||||
set(this, 'errors', null);
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
didSave() {
|
||||
var account = get(this, 'model.account');
|
||||
didSave(user) {
|
||||
let promises = [];
|
||||
let store = get(this, 'globalStore');
|
||||
|
||||
return account.save();
|
||||
get(this, 'roles').forEach((role) => {
|
||||
let promise;
|
||||
if (get(role, 'active')) { // new role for user
|
||||
promise = store.createRecord({
|
||||
type: 'globalRoleBindings',
|
||||
globalRoleId: get(role, 'globalId'),
|
||||
subjectName: get(user, 'id'),
|
||||
subjectKind: 'User',
|
||||
}).save();
|
||||
promises.push(promise);
|
||||
}
|
||||
});
|
||||
|
||||
return all(promises.compact()).then(( /* list */ ) => {
|
||||
return user;
|
||||
});
|
||||
},
|
||||
|
||||
doneSaving() {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { alias } from '@ember/object/computed';
|
|||
import Mixin from '@ember/object/mixin';
|
||||
import Resource from 'ember-api-store/models/resource';
|
||||
import Errors from 'ui/utils/errors';
|
||||
import { get, set } from '@ember/object';
|
||||
|
||||
export default Mixin.create({
|
||||
originalModel: null,
|
||||
|
|
@ -15,19 +16,19 @@ export default Mixin.create({
|
|||
|
||||
init: function() {
|
||||
this._super();
|
||||
this.set('errors',null);
|
||||
set(this, 'errors',null);
|
||||
},
|
||||
|
||||
validate: function() {
|
||||
var model = this.get('primaryResource');
|
||||
var model = get(this, 'primaryResource');
|
||||
var errors = model.validationErrors();
|
||||
if ( errors.get('length') )
|
||||
{
|
||||
this.set('errors', errors);
|
||||
set(this, 'errors', errors);
|
||||
return false;
|
||||
}
|
||||
|
||||
this.set('errors', null);
|
||||
set(this, 'errors', null);
|
||||
return true;
|
||||
},
|
||||
|
||||
|
|
@ -41,11 +42,11 @@ export default Mixin.create({
|
|||
if (err)
|
||||
{
|
||||
var body = Errors.stringify(err);
|
||||
this.set('errors', [body]);
|
||||
set(this, 'errors', [body]);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.set('errors', null);
|
||||
set(this, 'errors', null);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -84,19 +85,19 @@ export default Mixin.create({
|
|||
|
||||
// willSave happens before save and can stop the save from happening
|
||||
willSave: function() {
|
||||
this.set('errors',null);
|
||||
set(this, 'errors',null);
|
||||
var ok = this.validate();
|
||||
return ok;
|
||||
},
|
||||
|
||||
doSave: function(opt) {
|
||||
return this.get('primaryResource').save(opt).then((newData) => {
|
||||
return get(this, 'primaryResource').save(opt).then((newData) => {
|
||||
return this.mergeResult(newData);
|
||||
});
|
||||
},
|
||||
|
||||
mergeResult: function(newData) {
|
||||
var original = this.get('originalPrimaryResource');
|
||||
var original = get(this, 'originalPrimaryResource');
|
||||
if ( original )
|
||||
{
|
||||
if ( Resource.detectInstance(original) )
|
||||
|
|
@ -116,7 +117,7 @@ export default Mixin.create({
|
|||
|
||||
// doneSaving happens after didSave
|
||||
doneSaving: function(neu) {
|
||||
return neu || this.get('originalPrimaryResource') || this.get('primaryResource');
|
||||
return neu || get(this, 'originalPrimaryResource') || get(this, 'primaryResource');
|
||||
},
|
||||
|
||||
// errorSaving can be used to do additional cleanup of dependent resources on failure
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import {
|
|||
} from 'rsvp';
|
||||
import Service, { inject as service } from '@ember/service';
|
||||
import C from 'shared/utils/constants';
|
||||
import { computed } from '@ember/object';
|
||||
import { alias } from '@ember/object/computed';
|
||||
import { computed, get, set, setProperties } from '@ember/object';
|
||||
|
||||
let ACTIVEISH = ['active','upgrading'];
|
||||
|
||||
|
|
@ -28,16 +28,18 @@ export default Service.extend({
|
|||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
this.set('all', []);
|
||||
this.set('allClusters', []);
|
||||
setProperties(this, {
|
||||
all: [],
|
||||
allCluster: [],
|
||||
})
|
||||
},
|
||||
|
||||
setPageScope: function(scope) {
|
||||
return this.set('currentPageScope', scope);
|
||||
return set(this, 'currentPageScope', scope);
|
||||
},
|
||||
|
||||
active: computed('all.@each.state', function() {
|
||||
return this.get('all').filter((project) => {
|
||||
return get(this, 'all').filter((project) => {
|
||||
return ACTIVEISH.includes(project.get('state'));
|
||||
});
|
||||
}),
|
||||
|
|
@ -48,7 +50,7 @@ export default Service.extend({
|
|||
forceReload: true,
|
||||
};
|
||||
|
||||
if ( !this.get('access.enabled') || moreOpt.all )
|
||||
if ( !get(this, 'access.enabled') || moreOpt.all )
|
||||
{
|
||||
opt.filter = {all: 'true'};
|
||||
delete moreOpt.all;
|
||||
|
|
@ -56,7 +58,7 @@ export default Service.extend({
|
|||
|
||||
Object.assign(opt, moreOpt);
|
||||
|
||||
const store = this.get('globalStore');
|
||||
const store = get(this, 'globalStore');
|
||||
return store.find('project', null, opt).then(() => {
|
||||
return store.all('project');
|
||||
});
|
||||
|
|
@ -68,7 +70,7 @@ export default Service.extend({
|
|||
forceReload: true,
|
||||
};
|
||||
|
||||
if ( !this.get('access.enabled') || moreOpt.all )
|
||||
if ( !get(this, 'access.enabled') || moreOpt.all )
|
||||
{
|
||||
opt.filter = {all: 'true'};
|
||||
delete moreOpt.all;
|
||||
|
|
@ -76,46 +78,46 @@ export default Service.extend({
|
|||
|
||||
Object.assign(opt, moreOpt);
|
||||
|
||||
return this.get('globalStore').find('cluster', null, opt).then(() => {
|
||||
return this.get('globalStore').all('cluster');
|
||||
return get(this, 'globalStore').find('cluster', null, opt).then(() => {
|
||||
return get(this, 'globalStore').all('cluster');
|
||||
});
|
||||
},
|
||||
|
||||
refreshAllClusters: function() {
|
||||
return this.getAllClusters().then((all) => {
|
||||
this.set('allClusters', all);
|
||||
set(this, 'allClusters', all);
|
||||
this.selectDefaultCluster();
|
||||
});
|
||||
},
|
||||
|
||||
refreshAll: function() {
|
||||
this.getAll().then((all) => {
|
||||
this.set('all', all);
|
||||
set(this, 'all', all);
|
||||
this.selectDefaultProject();
|
||||
});
|
||||
},
|
||||
|
||||
selectDefaultCluster: function() {
|
||||
var self = this;
|
||||
var cookies = this.get('cookies');
|
||||
var cookies = get(this, 'cookies');
|
||||
|
||||
return this._activeClusterFromId(cookies.get(C.COOKIE.CLUSTER)).then(selectCluster)
|
||||
.catch(() => {
|
||||
|
||||
return this._activeClusterFromId(this.get('prefs').get(C.PREFS.CLUSTER_DEFAULT)).then(selectCluster)
|
||||
return this._activeClusterFromId(get(this, 'prefs').get(C.PREFS.CLUSTER_DEFAULT)).then(selectCluster)
|
||||
.catch(() => {
|
||||
|
||||
// Then the first active project you're a member of
|
||||
var cluster = this.get('activeCluster.firstObject');
|
||||
var cluster = get(this, 'activeCluster.firstObject');
|
||||
|
||||
if ( cluster )
|
||||
{
|
||||
return selectCluster(cluster, true);
|
||||
}
|
||||
else if ( this.get('access.admin') )
|
||||
else if ( get(this, 'access.admin') )
|
||||
{
|
||||
// Then if you're an admin the first active of any kind
|
||||
var firstActive = this.get('allClusters').find((cluster) => {
|
||||
var firstActive = get(this, 'allClusters').find((cluster) => {
|
||||
return ACTIVEISH.includes(cluster.get('state'));
|
||||
});
|
||||
|
||||
|
|
@ -166,7 +168,7 @@ export default Service.extend({
|
|||
|
||||
selectDefaultProject: function(desired) {
|
||||
var self = this;
|
||||
var cookies = this.get('cookies');
|
||||
var cookies = get(this, 'cookies');
|
||||
|
||||
// The one specifically asked for
|
||||
return this._activeProjectFromId(desired).then(select)
|
||||
|
|
@ -177,21 +179,21 @@ export default Service.extend({
|
|||
.catch(() => {
|
||||
|
||||
// Then the default project ID from the prefs
|
||||
return this._activeProjectFromId(this.get('prefs').get(C.PREFS.PROJECT_DEFAULT)).then(select)
|
||||
return this._activeProjectFromId(get(this, 'prefs').get(C.PREFS.PROJECT_DEFAULT)).then(select)
|
||||
.catch(() => {
|
||||
|
||||
|
||||
// Then the first active project you're a member of
|
||||
var project = this.get('active.firstObject');
|
||||
var project = get(this, 'active.firstObject');
|
||||
|
||||
if ( project )
|
||||
{
|
||||
return select(project, true);
|
||||
}
|
||||
else if ( this.get('access.admin') )
|
||||
else if ( get(this, 'access.admin') )
|
||||
{
|
||||
// Then if you're an admin the first active of any kind
|
||||
var firstActive = this.get('all').find((project) => {
|
||||
var firstActive = get(this, 'all').find((project) => {
|
||||
return ACTIVEISH.includes(project.get('state'));
|
||||
});
|
||||
|
||||
|
|
@ -240,29 +242,29 @@ export default Service.extend({
|
|||
},
|
||||
|
||||
setCurrentCluster: function(cluster) {
|
||||
this.setProperties({
|
||||
setProperties(this, {
|
||||
currentCluster: cluster,
|
||||
currentPageScope: 'cluster'
|
||||
currentPageScope: 'global'
|
||||
});
|
||||
|
||||
if ( cluster ) {
|
||||
this.set('clusterStore.baseUrl', `${this.get('app.apiEndpoint')}/clusters/${cluster.get('id')}`);
|
||||
set(this, 'clusterStore.baseUrl', `${get(this, 'app.apiEndpoint')}/clusters/${cluster.get('id')}`);
|
||||
} else {
|
||||
this.set('clusterStore.baseUrl', this.get('app.apiEndpoint'));
|
||||
set(this, 'clusterStore.baseUrl', get(this, 'app.apiEndpoint'));
|
||||
}
|
||||
|
||||
return resolve(cluster);
|
||||
},
|
||||
|
||||
setCurrent: function(project) {
|
||||
this.setProperties({
|
||||
setProperties(this, {
|
||||
current: project,
|
||||
currentPageScope: 'project'
|
||||
});
|
||||
if ( project ) {
|
||||
this.set('store.baseUrl', `${this.get('app.apiEndpoint')}/projects/${project.get('id')}`);
|
||||
set(this, 'store.baseUrl', `${get(this, 'app.apiEndpoint')}/projects/${project.get('id')}`);
|
||||
} else {
|
||||
this.set('store.baseUrl', this.get('app.apiEndpoint'));
|
||||
set(this, 'store.baseUrl', get(this, 'app.apiEndpoint'));
|
||||
}
|
||||
return resolve(project);
|
||||
},
|
||||
|
|
@ -275,7 +277,7 @@ export default Service.extend({
|
|||
return;
|
||||
}
|
||||
|
||||
this.get('globalStore').find('cluster', clusterId, {url: `clusters/${encodeURIComponent(clusterId)}`}).then((cluster) => {
|
||||
get(this, 'globalStore').find('cluster', clusterId, {url: `clusters/${encodeURIComponent(clusterId)}`}).then((cluster) => {
|
||||
if ( ACTIVEISH.includes(cluster.get('state')) )
|
||||
{
|
||||
resolve(cluster);
|
||||
|
|
@ -298,7 +300,7 @@ export default Service.extend({
|
|||
return;
|
||||
}
|
||||
|
||||
this.get('globalStore').find('project', projectId, {url: 'projects/'+encodeURIComponent(projectId)}).then((project) => {
|
||||
get(this, 'globalStore').find('project', projectId, {url: 'projects/'+encodeURIComponent(projectId)}).then((project) => {
|
||||
if ( ACTIVEISH.includes(project.get('state')) )
|
||||
{
|
||||
resolve(project);
|
||||
|
|
|
|||
Loading…
Reference in New Issue