Fix initial answers not loading for helm charts without questions

This commit is contained in:
Westly Wright 2019-02-05 16:32:41 -07:00
parent 0b176aa116
commit 281df1ea1b
No known key found for this signature in database
GPG Key ID: 4FAB3D8673DC54A3
5 changed files with 90 additions and 22 deletions

View File

@ -584,8 +584,10 @@ export default Component.extend(NewOrEdit, CatalogApp, {
return false;
}
if ( get(this, 'actuallySave') && get(this, 'selectedTemplateModel.questions')) {
if ( get(this, 'actuallySave') ) {
if ( get(this, 'selectedTemplateModel.questions') ) {
primaryResource.set('answers', this.buildAnswerMap())
}
return true;
} else {

View File

@ -245,7 +245,10 @@
showHeader=false
}}
{{else}}
{{input-custom-answers app=primaryResource}}
{{input-custom-answers
app=multiClusterApp
isMultiClusterApp=true
}}
{{/if}}
</div>
{{/if}}

View File

@ -66,9 +66,16 @@ export default Route.extend({
neuApp = results.app;
}
} else {
let defaultAnswwer = store.createRecord({
clusterId: null,
projectId: null,
type: 'answer',
values: []
});
neuApp = store.createRecord({
type: 'multiclusterapp',
answers: [],
answers: [defaultAnswwer],
catalogId: results.tpl.catalogId,
targets: [],
members: [],

View File

@ -33,16 +33,14 @@ export default Component.extend({
showInput: true,
accept: '.yml, .yaml',
app: null,
isMultiClusterApp: false,
intialAnswerMap: null,
init() {
this._super(...arguments);
if (!dotObject) {
import('dot-object').then( (module) => {
dotObject = module.default;
});
}
this.initLazyModules();
this.initInitialAnswerMap();
},
actions: {
@ -56,8 +54,18 @@ export default Component.extend({
cancel() {
set(this, 'pasteOrUpload', false);
},
updateAnswers(answers) {
const { isMultiClusterApp } = this;
if (isMultiClusterApp) {
set(this, 'app.answers.firstObject.values', answers);
} else {
set(this, 'app.answers', answers);
}
},
},
actualAccept: computed('accept', function() {
if ( isSafari ) {
@ -156,4 +164,33 @@ export default Component.extend({
reader.readAsText(file);
}
},
initInitialAnswerMap() {
const { isMultiClusterApp } = this;
let answers;
if (isMultiClusterApp) {
answers = this.getInitialMultiClusterAnswerMap();
} else {
answers = this.getInitialMap();
}
set(this, 'intialAnswerMap', answers);
},
getInitialMultiClusterAnswerMap() {
return get(this, 'app.answers.firstObject.values');
},
getInitialMap() {
return get(this, 'app.answers');
},
initLazyModules() {
if (!dotObject) {
import('dot-object').then( (module) => {
dotObject = module.default;
});
}
},
});

View File

@ -1,15 +1,34 @@
<div class="btn-group pull-right">
{{#if pasteOrUpload}}
<button class="btn btn-sm" {{action 'cancel'}}>{{t 'inputAnswers.editAsForm'}}</button>
<button
class="btn btn-sm"
{{action "cancel"}}
>
{{t "inputAnswers.editAsForm"}}
</button>
{{else}}
<button class="btn btn-sm bg-primary" {{action 'showPaste'}}>{{t 'inputAnswers.yaml'}} <span class="icon icon-copy"></span></button>
<button
class="btn btn-sm bg-primary"
{{action "showPaste"}}
>
{{t "inputAnswers.yaml"}}
<i class="icon icon-copy"></i>
</button>
{{/if}}
<button class="btn btn-sm bg-primary" {{action 'upload'}}>{{t 'uploadFile.label'}} <span class="icon icon-upload"></span></button>
<button
class="btn btn-sm bg-primary"
{{action "upload"}}
>
{{t "uploadFile.label"}}
<i class="icon icon-upload"></i>
</button>
</div>
<div class="mt-25">
{{#if pasteOrUpload}}
<div class="clearfix">
<label class="acc-label">{{t 'inputAnswers.yamlConfig'}}</label>
<label class="acc-label">
{{t "inputAnswers.yamlConfig"}}
</label>
</div>
<div class="p-20">
{{input-yaml
@ -24,12 +43,12 @@
{{top-errors errors=yamlErrors}}
{{else if showInput}}
{{form-key-value
initialMap=app.answers
changed=(action (mut app.answers))
initialMap=intialAnswerMap
changed="updateAnswers"
allowEmptyValue=true
addInitialEmptyRow=true
editing=true
header=(t 'newCatalog.answers.label')
header=(t "newCatalog.answers.label")
addActionLabel="newCatalog.answers.addAction"
keyLabel="newContainer.environment.keyLabel"
keyPlaceholder="newContainer.environment.keyPlaceholder"