chore: 🤖 Refactor group CRUD+L to /scopes/:scope_id
This commit is contained in:
18 files changed
+297
-2
No files matched your search
@@ -0,0 +1,72 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
export default class ScopesScopeGroupsRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service intl;
|
||||
@service notify;
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Load all groups under current scope
|
||||
* @return {Promise[GroupModel]}
|
||||
*/
|
||||
async model() {
|
||||
return this.store.findAll('group', this.scopeAdapterOptions());
|
||||
}
|
||||
|
||||
// =actions
|
||||
/**
|
||||
* Rollback changes on a group.
|
||||
* @param {GroupModel} group
|
||||
*/
|
||||
@action
|
||||
cancel(group) {
|
||||
const { isNew } = group;
|
||||
group.rollbackAttributes();
|
||||
if (isNew) this.transitionTo('scopes.scope.groups');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a group in current scope.
|
||||
* @param {GroupModel} group
|
||||
*/
|
||||
@action
|
||||
async save(group) {
|
||||
try {
|
||||
await group.save(this.scopeAdapterOptions());
|
||||
this.refresh();
|
||||
this.notify.success(this.intl.t('notify.save-success'));
|
||||
this.transitionTo('scopes.scope.groups.group', group);
|
||||
} catch (error) {
|
||||
//TODO: replace with translated strings
|
||||
this.notify.error(error.message, { closeAfter: null });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a group in current scope and redirect to index
|
||||
* @param {GroupModel} group
|
||||
*/
|
||||
@action
|
||||
async delete(group) {
|
||||
try {
|
||||
await group.destroyRecord(this.scopeAdapterOptions());
|
||||
this.refresh();
|
||||
this.transitionTo('scopes.scope.groups');
|
||||
this.notify.success(this.intl.t('notify.group.delete-success'));
|
||||
} catch (error) {
|
||||
//TODO: replace with translated strings
|
||||
this.notify.error(error.message, { closeAfter: null });
|
||||
}
|
||||
}
|
||||
|
||||
scopeAdapterOptions() {
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
const adapterOptions = { scopeID: scope_id };
|
||||
return { adapterOptions };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeGroupsGroupRoute extends Route {
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Load a group in current scope.
|
||||
* @param {object} params
|
||||
* @param {string} params.group_id
|
||||
* @return {groupModel}
|
||||
*/
|
||||
async model({ group_id }) {
|
||||
const { id: scope_id } = this.modelFor('scopes.scope');
|
||||
const adapterOptions = { scopeID: scope_id };
|
||||
return this.store.findRecord('group', group_id, { adapterOptions });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeGroupsGroupIndexRoute extends Route {}
|
||||
@@ -0,0 +1,3 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeGroupsIndexRoute extends Route {}
|
||||
@@ -0,0 +1,13 @@
|
||||
import Route from '@ember/routing/route';
|
||||
|
||||
export default class ScopesScopeGroupsNewRoute extends Route {
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Creates a new unsaved group.
|
||||
* @return {GroupModel}
|
||||
*/
|
||||
model() {
|
||||
return this.store.createRecord('group');
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ export default class ScopesScopeUsersRoute extends Route {
|
||||
|
||||
// =actions
|
||||
/**
|
||||
* Rollback changes on user.
|
||||
* Rollback changes on an user.
|
||||
* @param {UserModel} user
|
||||
*/
|
||||
@action
|
||||
@@ -31,7 +31,7 @@ export default class ScopesScopeUsersRoute extends Route {
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a user in current scope.
|
||||
* Save an user in current scope.
|
||||
* @param {UserModel} user
|
||||
* @param {Event} e
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user