feat: Update target routes for notify decorator

This commit is contained in:
Susmitha Girumala committed 2020-10-08 18:25:54 -04:00
1 parent 7758099ca4
commit 0684571564
3 files changed
+23 -40

No files matched your search

@@ -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 ScopesScopeProjectsProjectTargetsRoute extends Route {
// =services
@@ -41,20 +42,12 @@ export default class ScopesScopeProjectsProjectTargetsRoute extends Route {
*/
@action
@loading
@notifyError(({ message }) => message)
@notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success')
async save(target) {
const { isNew } = target;
try {
await target.save();
await this.transitionTo('scopes.scope.projects.project.targets.target', target);
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 target.save();
await this.transitionTo('scopes.scope.projects.project.targets.target', target);
this.refresh();
}
/**
@@ -64,15 +57,11 @@ export default class ScopesScopeProjectsProjectTargetsRoute extends Route {
@action
@loading
@confirm('questions.delete-confirm')
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.delete-success')
async delete(target) {
try {
await target.destroyRecord();
await this.replaceWith('scopes.scope.projects.project.targets');
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 target.destroyRecord();
await this.replaceWith('scopes.scope.projects.project.targets');
this.refresh();
}
}
@@ -3,6 +3,7 @@ import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { all } from 'rsvp';
import loading from 'ember-loading/decorator';
import { notifySuccess, notifyError } from '../../../../../../../decorators/notify';
export default class ScopesScopeProjectsProjectTargetsTargetAddHostSetsRoute extends Route {
// =services
@@ -72,17 +73,13 @@ export default class ScopesScopeProjectsProjectTargetsTargetAddHostSetsRoute ext
@action
@loading
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.add-success')
async save(target, hostSetIDs) {
try {
await target.addHostSets(hostSetIDs);
this.replaceWith(
'scopes.scope.projects.project.targets.target.host-sets'
);
this.notify.success(this.intl.t('notifications.add-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
await target.addHostSets(hostSetIDs);
this.replaceWith(
'scopes.scope.projects.project.targets.target.host-sets'
);
}
/**
@@ -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 ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extends Route {
// =services
@@ -57,14 +58,10 @@ export default class ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extend
@action
@loading
@confirm('questions.remove-confirm')
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.remove-success')
async removeHostSet(target, hostSet) {
try {
await target.removeHostSet(hostSet.id);
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 });
}
await target.removeHostSet(hostSet.id);
this.refresh();
}
}