From f7a2dd14e33636d5ad70d991d05347ce845415cf Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 1 Feb 2022 22:35:00 -0500 Subject: [PATCH] chore: Integrate compositetypes into route --- addons/api/addon/models/host-catalog.js | 2 +- .../form/host-catalog/aws/index.hbs | 74 +++++++++++------- .../form/host-catalog/azure/index.hbs | 75 ++++++++++++------- .../components/form/host-catalog/index.hbs | 58 ++++++++------ .../app/components/form/host-catalog/index.js | 44 +++++------ .../form/host-catalog/static/index.hbs | 72 ++++++++++-------- .../scopes/scope/host-catalogs/new.js | 16 ---- .../routes/scopes/scope/host-catalogs/new.js | 18 ++--- .../scopes/scope/host-catalogs/new.hbs | 2 +- 9 files changed, 205 insertions(+), 156 deletions(-) diff --git a/addons/api/addon/models/host-catalog.js b/addons/api/addon/models/host-catalog.js index ec34b50e3..08e1a7d82 100644 --- a/addons/api/addon/models/host-catalog.js +++ b/addons/api/addon/models/host-catalog.js @@ -26,7 +26,7 @@ export default class HostCatalogModel extends GeneratedHostCatalogModel { * @type {boolean} */ get isUnknown() { - return this.isPlugin && !types.includes(this.plugin.name); + return this.isPlugin && !types.includes(this.plugin?.name); } /** diff --git a/ui/admin/app/components/form/host-catalog/aws/index.hbs b/ui/admin/app/components/form/host-catalog/aws/index.hbs index 208468752..ca157a9f0 100644 --- a/ui/admin/app/components/form/host-catalog/aws/index.hbs +++ b/ui/admin/app/components/form/host-catalog/aws/index.hbs @@ -2,6 +2,8 @@ @onSubmit={{@submit}} @cancel={{@cancel}} @disabled={{@model.isSaving}} + @error={{@model.errors.base}} + @showEditToggle={{if @model.isNew false true}} as |form| > {{/if}} - - <:title>{{t 'form.type.label'}} - <:body> - - - - - - + + {{#if @model.isNew}} + + <:title>{{t 'form.type.label'}} + <:body> + + + + + + - {{#if @showDynamicPlugins}} <:title>{{t 'resources.host-catalog.form.provider-details'}} <:body> @@ -92,13 +95,32 @@ + {{else}} + + <:title>{{t 'resources.host-catalog.form.provider-details'}} + <:body> + + + + + {{/if}} diff --git a/ui/admin/app/components/form/host-catalog/azure/index.hbs b/ui/admin/app/components/form/host-catalog/azure/index.hbs index 208468752..80b9f9275 100644 --- a/ui/admin/app/components/form/host-catalog/azure/index.hbs +++ b/ui/admin/app/components/form/host-catalog/azure/index.hbs @@ -2,6 +2,9 @@ @onSubmit={{@submit}} @cancel={{@cancel}} @disabled={{@model.isSaving}} + @disabled={{@model.isSaving}} + @error={{@model.errors.base}} + @showEditToggle={{if @model.isNew false true}} as |form| > {{/if}} - - <:title>{{t 'form.type.label'}} - <:body> - - - - - - + + {{#if @model.isNew}} + + <:title>{{t 'form.type.label'}} + <:body> + + + + + + - {{#if @showDynamicPlugins}} <:title>{{t 'resources.host-catalog.form.provider-details'}} <:body> @@ -92,13 +96,32 @@ + {{else}} + + <:title>{{t 'resources.host-catalog.form.provider-details'}} + <:body> + + + + + {{/if}} diff --git a/ui/admin/app/components/form/host-catalog/index.hbs b/ui/admin/app/components/form/host-catalog/index.hbs index d41b3749b..39a9d270c 100644 --- a/ui/admin/app/components/form/host-catalog/index.hbs +++ b/ui/admin/app/components/form/host-catalog/index.hbs @@ -1,24 +1,38 @@ -{{#if @model.isNew}} -
{{@model.type}} {{@model.compositeType}}
- {{#if @model.isStatic}} - {{component - (concat 'form/host-catalog/' @model.compositeType) - model=@model - submit=@submit - cancel=@cancel - toggleType=this.toggleType - showDynamicPlugins=this.showDynamicPlugins - }} - {{/if}} +{{component + (concat 'form/host-catalog/' @model.compositeType) + model=@model + submit=@submit + cancel=@cancel + changeType=@changeType + }} - {{#if this.showDynamicPlugins}} - {{component - (concat 'form/host-catalog/' @model.compositeType) - model=@model - submit=@submit - cancel=@cancel - toggleType=this.toggleType - showDynamicPlugins=this.showDynamicPlugins - }} +{{!-- {{#if @model.isStatic}} + {{component + (concat 'form/host-catalog/' @model.type) + model=@model + submit=@submit + cancel=@cancel + form=form + toggleType=this.toggleType + showDynamicPlugins=this.showDynamicPlugins + }} +{{else if @model.isPlugin}} + Model is plugin + {{#if @model.isAWS}} + Model is Aws + {{else if @model.isAzure}} + Model is Azure {{/if}} -{{/if}} \ No newline at end of file +{{/if}} --}} + +{{!-- {{#if @model.type}} + {{component + (concat 'form/auth-method/' @model.type) + model=@model + submit=@submit + cancel=@cancel + removeItemByIndex=@removeItemByIndex + addStringItem=@addStringItem + addAccountClaimMapItem=@addAccountClaimMapItem + }} +{{/if}} --}} \ No newline at end of file diff --git a/ui/admin/app/components/form/host-catalog/index.js b/ui/admin/app/components/form/host-catalog/index.js index ed49133db..f6ac0ba23 100644 --- a/ui/admin/app/components/form/host-catalog/index.js +++ b/ui/admin/app/components/form/host-catalog/index.js @@ -3,27 +3,27 @@ import { action } from '@ember/object'; import { tracked } from '@glimmer/tracking'; export default class FormHostCatalogIndexComponent extends Component { - // =properties - /** - /** - */ - @tracked showDynamicPlugins = false; - // =actions + // // =properties + // /** + // /** + // */ + // @tracked showDynamicPlugins = false; + // // =actions - @action - toggleType(type) { - this.renderDynamicPlugins(type); - } - //show dynamic type radio cards -> aws and azure if the type is dynamic - //call route action to update the query and rerender the model if static is selected - renderDynamicPlugins(type) { - if (type === 'dynamic') { - this.showDynamicPlugins = true; - } else { - this.showDynamicPlugins = false; - //CHECK:how to call the action to update query param - this.args.model.type = 'static'; - this.args.changeType(); - } - } + // @action + // toggleType(type) { + // this.renderDynamicPlugins(type); + // } + // //show dynamic type radio cards -> aws and azure if the type is dynamic + // //call route action to update the query and rerender the model if static is selected + // renderDynamicPlugins(type) { + // if (type === 'dynamic') { + // this.showDynamicPlugins = true; + // } else { + // this.showDynamicPlugins = false; + // //CHECK:how to call the action to update query param + // // this.args.model.type = 'static'; + // // this.args.changeType(); + // } + // } } diff --git a/ui/admin/app/components/form/host-catalog/static/index.hbs b/ui/admin/app/components/form/host-catalog/static/index.hbs index 960ed5e2b..b0b607602 100644 --- a/ui/admin/app/components/form/host-catalog/static/index.hbs +++ b/ui/admin/app/components/form/host-catalog/static/index.hbs @@ -2,6 +2,8 @@ @onSubmit={{@submit}} @cancel={{@cancel}} @disabled={{@model.isSaving}} + @error={{@model.errors.base}} + @showEditToggle={{if @model.isNew false true}} as |form| > {{/if}} - - <:title>{{t 'form.type.label'}} - <:body> - - - - - - - {{#if @showDynamicPlugins}} + {{#if @model.isNew}} - <:title>{{t 'resources.host-catalog.form.provider-details'}} + <:title>{{t 'form.type.label'}} <:body> + + {{#if @model.isPlugin}} + + <:title>{{t 'resources.host-catalog.form.provider-details'}} + <:body> + + + + + + + {{/if}} {{/if}} {{#if (can 'save model' @model)}} diff --git a/ui/admin/app/controllers/scopes/scope/host-catalogs/new.js b/ui/admin/app/controllers/scopes/scope/host-catalogs/new.js index 3b0c5b729..182b9c423 100644 --- a/ui/admin/app/controllers/scopes/scope/host-catalogs/new.js +++ b/ui/admin/app/controllers/scopes/scope/host-catalogs/new.js @@ -1,23 +1,7 @@ import Controller from '@ember/controller'; -import { tracked } from '@glimmer/tracking'; -import { action } from '@ember/object'; export default class ScopesScopeHostCatalogsNewController extends Controller { // =attributes queryParams = ['type']; - @tracked showDynamicPlugins = false; - - @action - async toggleType(type) { - this.renderDynamicPlugins(type); - } - - renderDynamicPlugins(type) { - if (type !== 'static') { - this.showDynamicPlugins = true; - } else { - this.showDynamicPlugins = false; - } - } } diff --git a/ui/admin/app/routes/scopes/scope/host-catalogs/new.js b/ui/admin/app/routes/scopes/scope/host-catalogs/new.js index 53a2fea97..fef70cf13 100644 --- a/ui/admin/app/routes/scopes/scope/host-catalogs/new.js +++ b/ui/admin/app/routes/scopes/scope/host-catalogs/new.js @@ -6,12 +6,12 @@ export default class ScopesScopeHostCatalogsNewRoute extends Route { // =services @service router; + // =attributes queryParams = { type: { refreshModel: true, - replace: true, }, }; @@ -21,17 +21,13 @@ export default class ScopesScopeHostCatalogsNewRoute extends Route { * Creates a new unsaved host catalog belonging to the current scope. * @return {HostCatalogModel} */ - model(params) { + model() { const scopeModel = this.modelFor('scopes.scope'); - if (!params.type) params.type = 'static'; - return this.store.createRecord('host-catalog', { - compositeType: params.type, //static or aws or azure - scopeModel, - }); + return this.store.createRecord('host-catalog', { scopeModel }); } - afterModel(model) { - this.router.replaceWith({ queryParams: { type: model.compositeType } }); + afterModel(model, transition) { + this.changeType(transition.to.queryParams?.type); } /** @@ -40,6 +36,10 @@ export default class ScopesScopeHostCatalogsNewRoute extends Route { */ @action async changeType(type) { + const model = this.modelFor('scopes.scope.host-catalogs.new'); + if(!type) type = 'static'; // Unknown host catalog type defaults to 'static' + if (model.isUnknown) type = 'aws'; //Is this the default case for plugin type? + model.compositeType = type; await this.router.replaceWith({ queryParams: { type } }); } } diff --git a/ui/admin/app/templates/scopes/scope/host-catalogs/new.hbs b/ui/admin/app/templates/scopes/scope/host-catalogs/new.hbs index 983c1e86f..210eec22c 100644 --- a/ui/admin/app/templates/scopes/scope/host-catalogs/new.hbs +++ b/ui/admin/app/templates/scopes/scope/host-catalogs/new.hbs @@ -18,7 +18,7 @@ @model={{@model}} @submit={{route-action 'save' @model}} @cancel={{route-action 'cancel' @model}} - @changeType={{route-action 'changeType' @model.type}} + @changeType={{route-action 'changeType' @model}} />