mirror of https://github.com/rancher/ui.git
fix bug in launching host templates
This commit is contained in:
parent
9d30f56a8e
commit
5cb408da65
|
|
@ -9,7 +9,7 @@ import Util from 'ui/utils/util';
|
|||
import NewOrEdit from 'shared/mixins/new-or-edit';
|
||||
import ManageLabels from 'shared/mixins/manage-labels';
|
||||
import { addAction } from 'ui/utils/add-view-action';
|
||||
import { get } from '@ember/object';
|
||||
import { get, set, setProperties } from '@ember/object';
|
||||
|
||||
export default Mixin.create(NewOrEdit, ManageLabels, {
|
||||
intl: service(),
|
||||
|
|
@ -47,7 +47,7 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
|
|||
},
|
||||
|
||||
passConfigBack(cb) {
|
||||
this.sendAction('completed', this.get('model'));
|
||||
this.sendAction('completed', get(this, 'model'));
|
||||
cb(true);
|
||||
},
|
||||
|
||||
|
|
@ -57,20 +57,24 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
|
|||
out[row.key] = row.value;
|
||||
});
|
||||
|
||||
this.set('labelResource.labels', out);
|
||||
set(this, 'labelResource.labels', out);
|
||||
}
|
||||
},
|
||||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
|
||||
this.set('error', null);
|
||||
this.set('editing', false);
|
||||
setProperties(this, {
|
||||
error: null,
|
||||
editing: false
|
||||
});
|
||||
|
||||
if (this.get('clonedModel')) {
|
||||
this.set('model', this.get('clonedModel'));
|
||||
this.set('prefix', '');
|
||||
} else if (typeof this.get('bootstrap') === 'function') {
|
||||
if (get(this, 'clonedModel')) {
|
||||
setProperties(this, {
|
||||
model: get(this, 'clonedModel'),
|
||||
prefix: '',
|
||||
});
|
||||
} else if (typeof get(this, 'bootstrap') === 'function') {
|
||||
this.bootstrap();
|
||||
}
|
||||
|
||||
|
|
@ -78,12 +82,12 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
|
|||
let locationA = ['region'];
|
||||
let locationB = ['zone','availabilityZone','location','datacenter'];
|
||||
let size = ['instanceType','offering','flavor','size'];
|
||||
this.set('displayLocation', computed(
|
||||
set(this, 'displayLocation', computed(
|
||||
this.driver+'.{'+locationA.join(',')+'}',
|
||||
this.driver+'.{'+locationB.join(',')+'}',
|
||||
function() {
|
||||
let out = '';
|
||||
let config = this.get(this.get('driver'));
|
||||
let config = get(this, get(this, 'driver'));
|
||||
for ( let i = 0 ; i < locationA.length ; i++ ) {
|
||||
let key = locationA[i];
|
||||
let val = get(config, key);
|
||||
|
|
@ -105,8 +109,8 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
|
|||
return out;
|
||||
}));
|
||||
|
||||
this.set('displaySize', computed(this.driver+'.{'+size.join(',')+'}', function() {
|
||||
let config = this.get(this.get('driver'));
|
||||
set(this, 'displaySize', computed(this.driver+'.{'+size.join(',')+'}', function() {
|
||||
let config = get(this, get(this, 'driver'));
|
||||
for ( let i = 0 ; i < size.length ; i++ ) {
|
||||
let key = size[i];
|
||||
let val = get(config, key);
|
||||
|
|
@ -120,7 +124,7 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
|
|||
},
|
||||
|
||||
driverSaveAction: computed('inModal', function() {
|
||||
if (this.get('inModal')) {
|
||||
if (get(this, 'inModal')) {
|
||||
return 'passConfigBack';
|
||||
} else {
|
||||
return 'save';
|
||||
|
|
@ -128,8 +132,8 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
|
|||
}),
|
||||
|
||||
nameParts: function() {
|
||||
let input = this.get('prefix')||'';
|
||||
let count = this.get('count');
|
||||
let input = get(this, 'prefix')||'';
|
||||
let count = get(this, 'count');
|
||||
let match = input.match(/^(.*?)([0-9]+)$/);
|
||||
|
||||
if ( count <= 1 )
|
||||
|
|
@ -166,7 +170,7 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
|
|||
}.property('prefix','count'),
|
||||
|
||||
nameCountLabel: function() {
|
||||
let parts = this.get('nameParts');
|
||||
let parts = get(this, 'nameParts');
|
||||
if ( typeof parts.name !== 'undefined' || !parts.prefix )
|
||||
{
|
||||
// qty=1 or no input yet, nothing to see here...
|
||||
|
|
@ -175,16 +179,16 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
|
|||
|
||||
let first = parts.prefix + Util.strPad(parts.start, parts.minLength, '0');
|
||||
let last = parts.prefix + Util.strPad(parts.end, parts.minLength, '0');
|
||||
return this.get('intl').tHtml('driver.multiHostNames',{first: first, last: last});
|
||||
return get(this, 'intl').tHtml('driver.multiHostNames',{first: first, last: last});
|
||||
}.property('nameParts','intl.locale'),
|
||||
|
||||
nameDidChange: function() {
|
||||
this.set('primaryResource.name', this.get('prefix'));
|
||||
set(this, 'primaryResource.name', get(this, 'prefix'));
|
||||
}.observes('prefix'),
|
||||
|
||||
defaultDescription: function() {
|
||||
let loc = this.get('displayLocation');
|
||||
let size = this.get('displaySize');
|
||||
let loc = get(this, 'displayLocation');
|
||||
let size = get(this, 'displaySize');
|
||||
if ( loc && size ) {
|
||||
return loc + ' / ' + size;
|
||||
} else {
|
||||
|
|
@ -193,14 +197,12 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
|
|||
}.property('displayLocation','displaySize'),
|
||||
|
||||
willSave() {
|
||||
this.set('primaryResource.clusterId', this.get('cluster.id'));
|
||||
set(this, 'primaryResource.clusterId', get(this, 'cluster.id'));
|
||||
|
||||
if ( this.get('primaryResource.type').toLowerCase() === 'machinetemplate') {
|
||||
if ( !this.get('primaryResource.description') ) {
|
||||
this.set('primaryResource.description', this.get('defaultDescription'));
|
||||
if ( get(this, 'primaryResource.type').toLowerCase() === 'machinetemplate') {
|
||||
if ( !get(this, 'primaryResource.description') ) {
|
||||
set(this, 'primaryResource.description', get(this, 'defaultDescription'));
|
||||
}
|
||||
} else {
|
||||
this.set('multiTemplate', this.get('primaryResource').clone());
|
||||
}
|
||||
|
||||
return this._super();
|
||||
|
|
@ -209,35 +211,39 @@ export default Mixin.create(NewOrEdit, ManageLabels, {
|
|||
validate() {
|
||||
let errors = [];
|
||||
|
||||
if ( !this.get('nameParts.prefix') && !this.get('nameParts.name') ) {
|
||||
if ( !get(this, 'nameParts.prefix') && !get(this, 'nameParts.name') ) {
|
||||
errors.push('Name is required');
|
||||
}
|
||||
|
||||
this.set('errors', errors);
|
||||
set(this, 'errors', errors);
|
||||
return errors.length === 0;
|
||||
},
|
||||
|
||||
doSave() {
|
||||
if ( this.get('primaryResource.type').toLowerCase() === 'machinetemplate' ) {
|
||||
if ( get(this, 'primaryResource.type').toLowerCase() === 'machinetemplate' ) {
|
||||
return this._super(...arguments);
|
||||
} else {
|
||||
return resolve(this.get('primaryResource'));
|
||||
return resolve(get(this, 'primaryResource'));
|
||||
}
|
||||
},
|
||||
|
||||
didSave() {
|
||||
let count = this.get('count');
|
||||
let parts = this.get('nameParts');
|
||||
let delay = this.get('createDelayMs');
|
||||
let count = get(this, 'count');
|
||||
let parts = get(this, 'nameParts');
|
||||
let delay = get(this, 'createDelayMs');
|
||||
let tpl;
|
||||
|
||||
if ( this.get('primaryResource.type').toLowerCase() === 'machinetemplate') {
|
||||
tpl = this.get('globalStore').createRecord({
|
||||
if ( get(this, 'primaryResource.type').toLowerCase() === 'machinetemplate') {
|
||||
tpl = get(this, 'globalStore').createRecord({
|
||||
type: 'machine',
|
||||
driver: this.get('model.driver'),
|
||||
machineTemplateId: this.get('model.id'),
|
||||
clusterId: this.get('cluster.id'),
|
||||
driver: get(this, 'model.driver'),
|
||||
machineTemplateId: get(this, 'model.id'),
|
||||
clusterId: get(this, 'cluster.id'),
|
||||
});
|
||||
|
||||
} else {
|
||||
// The model was the first one, add subsequent numbers
|
||||
tpl = get(this, 'primaryResource').clone();
|
||||
}
|
||||
|
||||
return addHosts();
|
||||
|
|
|
|||
Loading…
Reference in New Issue