diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs.js index c8fce1129..ab01b5b7e 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs.js +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs.js @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import loading from 'ember-loading/decorator'; import { confirm } from '../../../../../decorators/confirm'; +import { notifySuccess, notifyError } from '../../../../../decorators/notify'; export default class ScopesScopeProjectsProjectHostCatalogsRoute extends Route { // =services @@ -41,23 +42,15 @@ export default class ScopesScopeProjectsProjectHostCatalogsRoute extends Route { */ @action @loading + @notifyError(({ message }) => message) + @notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success') async save(hostCatalog) { - const { isNew } = hostCatalog; - try { - await hostCatalog.save(); - await this.transitionTo( - 'scopes.scope.projects.project.host-catalogs.host-catalog', - hostCatalog - ); - this.refresh(); - this.notify.success( - this.intl.t(isNew ? 'notifications.create-success' : 'notifications.save-success') - ); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - throw error; - } + await hostCatalog.save(); + await this.transitionTo( + 'scopes.scope.projects.project.host-catalogs.host-catalog', + hostCatalog + ); + this.refresh(); } /** @@ -67,15 +60,11 @@ export default class ScopesScopeProjectsProjectHostCatalogsRoute extends Route { @action @loading @confirm('questions.delete-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') async delete(hostCatalog) { - try { - await hostCatalog.destroyRecord(); - await this.replaceWith('scopes.scope.projects.project.host-catalogs'); - this.refresh(); - this.notify.success(this.intl.t('notifications.delete-success')); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + await hostCatalog.destroyRecord(); + await this.replaceWith('scopes.scope.projects.project.host-catalogs'); + this.refresh(); } } diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets.js index 3c003bd50..380250c3e 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets.js +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets.js @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import loading from 'ember-loading/decorator'; import { confirm } from '../../../../../../../decorators/confirm'; +import { notifySuccess, notifyError } from '../../../../../../../decorators/notify'; export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsRoute extends Route { // =services @@ -46,23 +47,15 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsRo */ @action @loading + @notifyError(({ message }) => message) + @notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success') async save(hostSet) { - try { - const { isNew } = hostSet; - await hostSet.save(); - await this.transitionTo( - 'scopes.scope.projects.project.host-catalogs.host-catalog.host-sets.host-set', - hostSet - ); - this.refresh(); - this.notify.success( - this.intl.t(isNew ? 'notifications.create-success' : 'notifications.save-success') - ); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - throw error; - } + await hostSet.save(); + await this.transitionTo( + 'scopes.scope.projects.project.host-catalogs.host-catalog.host-sets.host-set', + hostSet + ); + this.refresh(); } /** @@ -72,16 +65,12 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsRo @action @loading @confirm('questions.delete-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') async deleteHostSet(hostSet) { - try { - await hostSet.destroyRecord(); - await this.replaceWith( - 'scopes.scope.projects.project.host-catalogs.host-catalog.host-sets' - ); - this.notify.success(this.intl.t('notifications.delete-success')); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + await hostSet.destroyRecord(); + await this.replaceWith( + 'scopes.scope.projects.project.host-catalogs.host-catalog.host-sets' + ); } } diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets/host-set/add-hosts.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets/host-set/add-hosts.js index d892490ab..3b398fcec 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets/host-set/add-hosts.js +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets/host-set/add-hosts.js @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import { hash } from 'rsvp'; import loading from 'ember-loading/decorator'; +import { notifySuccess, notifyError } from '../../../../../../../../../decorators/notify'; export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsHostSetAddHostsRoute extends Route { // =services @@ -70,17 +71,13 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsHo */ @action @loading + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.add-success') async addHosts(hostSet, hostIDs) { - try { - await hostSet.addHosts(hostIDs); - await this.replaceWith( - 'scopes.scope.projects.project.host-catalogs.host-catalog.host-sets.host-set.hosts' - ); - this.notify.success(this.intl.t('notifications.add-success')); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + await hostSet.addHosts(hostIDs); + await this.replaceWith( + 'scopes.scope.projects.project.host-catalogs.host-catalog.host-sets.host-set.hosts' + ); } /** diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets/host-set/hosts.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets/host-set/hosts.js index a4476caf1..8b4a5514d 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets/host-set/hosts.js +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/host-sets/host-set/hosts.js @@ -4,6 +4,7 @@ import { action } from '@ember/object'; import { inject as service } from '@ember/service'; import loading from 'ember-loading/decorator'; import { confirm } from '../../../../../../../../../decorators/confirm'; +import { notifySuccess, notifyError } from '../../../../../../../../../decorators/notify'; export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsHostSetHostsRoute extends Route { // =services @@ -39,20 +40,16 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsHo @action @loading @confirm('questions.remove-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.remove-success') async removeHost(hostSet, host) { - try { - const scopeID = this.modelFor('scopes.scope.projects.project').id; - const hostCatalogID = this.modelFor( - 'scopes.scope.projects.project.host-catalogs.host-catalog' - ).id; - await hostSet.removeHost(host.id, { - adapterOptions: { scopeID, hostCatalogID }, - }); - this.refresh(); - this.notify.success(this.intl.t('notifications.remove-success')); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + const scopeID = this.modelFor('scopes.scope.projects.project').id; + const hostCatalogID = this.modelFor( + 'scopes.scope.projects.project.host-catalogs.host-catalog' + ).id; + await hostSet.removeHost(host.id, { + adapterOptions: { scopeID, hostCatalogID }, + }); + this.refresh(); } } diff --git a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/hosts.js b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/hosts.js index 86b7e1c75..9b9732e2a 100644 --- a/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/hosts.js +++ b/ui/core/app/routes/scopes/scope/projects/project/host-catalogs/host-catalog/hosts.js @@ -3,6 +3,7 @@ import { inject as service } from '@ember/service'; import { action } from '@ember/object'; import loading from 'ember-loading/decorator'; import { confirm } from '../../../../../../../decorators/confirm'; +import { notifySuccess, notifyError } from '../../../../../../../decorators/notify'; export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostsRoute extends Route { // =services @@ -46,23 +47,15 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostsRoute */ @action @loading + @notifyError(({ message }) => message) + @notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success') async save(host) { - try { - const { isNew } = host; - await host.save(); - await this.transitionTo( - 'scopes.scope.projects.project.host-catalogs.host-catalog.hosts.host', - host - ); - this.refresh(); - this.notify.success( - this.intl.t(isNew ? 'notifications.create-success' : 'notifications.save-success') - ); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - throw error; - } + await host.save(); + await this.transitionTo( + 'scopes.scope.projects.project.host-catalogs.host-catalog.hosts.host', + host + ); + this.refresh(); } /** @@ -72,17 +65,13 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostsRoute @action @loading @confirm('questions.delete-confirm') + @notifyError(({ message }) => message, { catch: true }) + @notifySuccess('notifications.delete-success') async deleteHost(host) { - try { - await host.destroyRecord(); - await this.replaceWith( - 'scopes.scope.projects.project.host-catalogs.host-catalog.hosts' - ); - this.refresh(); - this.notify.success(this.intl.t('notifications.delete-success')); - } catch (error) { - // TODO: replace with translated strings - this.notify.error(error.message, { closeAfter: null }); - } + await host.destroyRecord(); + await this.replaceWith( + 'scopes.scope.projects.project.host-catalogs.host-catalog.hosts' + ); + this.refresh(); } }