Files
threshold-ui/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups.js
T

68 lines
1.9 KiB
JavaScript

import Route from '@ember/routing/route';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import loading from 'ember-loading/decorator';
import { confirm } from 'core/decorators/confirm';
import { notifySuccess, notifyError } from 'core/decorators/notify';
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends Route {
// =services
@service notify;
/**
*
* @returns {Promise{[ManagedGroupsModel]}}
*/
model() {
const authMethod = this.modelFor('scopes.scope.auth-methods.auth-method');
const { id: auth_method_id } = authMethod;
return this.store.query('managed-group', { auth_method_id });
}
// =actions
/**
* Rollback changes on a managed group.
* @param {ManagedGroupModel} managedGroup
*/
@action
cancel(managedGroup) {
const { isNew } = managedGroup;
managedGroup.rollbackAttributes();
if (isNew) {
this.transitionTo('scopes.scope.auth-methods.auth-method.managed-groups');
}
}
@action
@loading
@notifyError(({ message }) => message)
@notifySuccess(({ isNew }) =>
isNew ? 'notifications.create-success' : 'notifications.save-success'
)
async save(managedGroup) {
await managedGroup.save();
await this.transitionTo(
'scopes.scope.auth-methods.auth-method.managed-groups.managed-group',
managedGroup
);
this.refresh();
}
/**
* Delete a managed group in current scope and redirect to index
* @param {ManagedGroupModel} managed group
*/
@action
@loading
@confirm('questions.delete-confirm')
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.delete-success')
async deleteManagedGroup(managedGroup) {
await managedGroup.destroyRecord();
await this.replaceWith(
'scopes.scope.auth-methods.auth-method.managed-groups'
);
this.refresh();
}
}