chore: 🤖 Refactor group CRUD+L to /scopes/:scope_id
This commit is contained in:
18 files changed
+297
-2
No files matched your search
@@ -17,6 +17,10 @@ Router.map(function () {
|
|||||||
this.route('user', { path: ':user_id' }, function () {});
|
this.route('user', { path: ':user_id' }, function () {});
|
||||||
this.route('new');
|
this.route('new');
|
||||||
});
|
});
|
||||||
|
this.route('groups', function () {
|
||||||
|
this.route('group', { path: ':group_id' }, function () {});
|
||||||
|
this.route('new');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
// =actions
|
||||||
/**
|
/**
|
||||||
* Rollback changes on user.
|
* Rollback changes on an user.
|
||||||
* @param {UserModel} user
|
* @param {UserModel} user
|
||||||
*/
|
*/
|
||||||
@action
|
@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 {UserModel} user
|
||||||
* @param {Event} e
|
* @param {Event} e
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
<nav.link @route="scopes.scope.users">
|
<nav.link @route="scopes.scope.users">
|
||||||
{{t "resources.users"}}
|
{{t "resources.users"}}
|
||||||
</nav.link>
|
</nav.link>
|
||||||
|
<nav.link @route="scopes.scope.groups">
|
||||||
|
{{t "resources.groups"}}
|
||||||
|
</nav.link>
|
||||||
</Rose::Nav::Sidebar>
|
</Rose::Nav::Sidebar>
|
||||||
|
|
||||||
{{outlet "sidebar"}}
|
{{outlet "sidebar"}}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{{title (t "resources.groups")}}
|
||||||
|
|
||||||
|
{{outlet}}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{{title @model.displayName}}
|
||||||
|
|
||||||
|
{{outlet}}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<Rose::Layout::Page as |page|>
|
||||||
|
|
||||||
|
<page.breadcrumbs>
|
||||||
|
<BreadCrumbs />
|
||||||
|
</page.breadcrumbs>
|
||||||
|
|
||||||
|
<page.header>
|
||||||
|
<h2>{{t "resources.group"}}</h2>
|
||||||
|
</page.header>
|
||||||
|
|
||||||
|
<page.navigation>
|
||||||
|
<Rose::Nav::Tabs as |nav|>
|
||||||
|
<nav.link @route='scopes.scope.groups.group'>
|
||||||
|
{{t 'titles.details'}}
|
||||||
|
</nav.link>
|
||||||
|
</Rose::Nav::Tabs>
|
||||||
|
</page.navigation>
|
||||||
|
|
||||||
|
<page.body>
|
||||||
|
<Form::Project
|
||||||
|
@model={{@model}}
|
||||||
|
@submit={{route-action "save" @model}}
|
||||||
|
@cancel={{route-action "cancel" @model}}
|
||||||
|
/>
|
||||||
|
<Rose::Separator />
|
||||||
|
<Rose::Button
|
||||||
|
@style="warning"
|
||||||
|
@disabled={{@model.canSave}}
|
||||||
|
{{on "click" (route-action "delete" @model)}}
|
||||||
|
>
|
||||||
|
{{t 'actions.delete'}}
|
||||||
|
</Rose::Button>
|
||||||
|
</page.body>
|
||||||
|
|
||||||
|
</Rose::Layout::Page>
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
<Rose::Layout::Page as |page|>
|
||||||
|
|
||||||
|
<page.breadcrumbs>
|
||||||
|
<BreadCrumbs />
|
||||||
|
</page.breadcrumbs>
|
||||||
|
|
||||||
|
<page.header>
|
||||||
|
<h2>{{t "resources.groups"}}</h2>
|
||||||
|
</page.header>
|
||||||
|
|
||||||
|
<page.actions>
|
||||||
|
{{#if @model}}
|
||||||
|
<Rose::LinkButton @route="scopes.scope.groups.new" @style="primary">{{t 'titles.new'}}</Rose::LinkButton>
|
||||||
|
{{/if}}
|
||||||
|
</page.actions>
|
||||||
|
|
||||||
|
<page.body>
|
||||||
|
|
||||||
|
{{#if @model}}
|
||||||
|
|
||||||
|
<Rose::Table as |table|>
|
||||||
|
<table.header as |header|>
|
||||||
|
<header.row as |row|>
|
||||||
|
<row.cell>{{t 'form.label.name'}}</row.cell>
|
||||||
|
<row.cell>{{t 'form.label.description'}}</row.cell>
|
||||||
|
</header.row>
|
||||||
|
</table.header>
|
||||||
|
<table.body as |body|>
|
||||||
|
{{#each @model as |group|}}
|
||||||
|
<body.row as |row|>
|
||||||
|
<row.cell>
|
||||||
|
<LinkTo
|
||||||
|
@route="scopes.scope.groups.group"
|
||||||
|
@model={{group}}
|
||||||
|
>
|
||||||
|
{{group.name}}
|
||||||
|
</LinkTo>
|
||||||
|
</row.cell>
|
||||||
|
<row.cell>{{group.description}}</row.cell>
|
||||||
|
</body.row>
|
||||||
|
{{/each}}
|
||||||
|
</table.body>
|
||||||
|
</Rose::Table>
|
||||||
|
|
||||||
|
{{else}}
|
||||||
|
|
||||||
|
<Rose::Layout::Centered>
|
||||||
|
<Rose::Message @title={{t 'titles.groups-welcome'}} as |message|>
|
||||||
|
<message.description>
|
||||||
|
{{t 'descriptions.groups-welcome'}}
|
||||||
|
</message.description>
|
||||||
|
<message.link @route="scopes.scope.groups.new">
|
||||||
|
<Rose::Icon @name="plus-circle-outline" />
|
||||||
|
{{t 'titles.new'}}
|
||||||
|
</message.link>
|
||||||
|
</Rose::Message>
|
||||||
|
</Rose::Layout::Centered>
|
||||||
|
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
</page.body>
|
||||||
|
|
||||||
|
</Rose::Layout::Page>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{{title (t 'titles.new')}}
|
||||||
|
|
||||||
|
<Rose::Layout::Page as |page|>
|
||||||
|
|
||||||
|
<page.breadcrumbs>
|
||||||
|
<BreadCrumbs />
|
||||||
|
</page.breadcrumbs>
|
||||||
|
|
||||||
|
<page.header>
|
||||||
|
<h2>{{t "titles.new"}}</h2>
|
||||||
|
</page.header>
|
||||||
|
|
||||||
|
<page.body>
|
||||||
|
<Form::Group
|
||||||
|
@model={{@model}}
|
||||||
|
@submit={{route-action "save" @model}}
|
||||||
|
@cancel={{route-action "cancel" @model}}
|
||||||
|
/>
|
||||||
|
</page.body>
|
||||||
|
|
||||||
|
</Rose::Layout::Page>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupTest } from 'ember-qunit';
|
||||||
|
|
||||||
|
module('Unit | Route | scopes/scope/groups', function (hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
|
test('it exists', function (assert) {
|
||||||
|
let route = this.owner.lookup('route:scopes/scope/groups');
|
||||||
|
assert.ok(route);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupTest } from 'ember-qunit';
|
||||||
|
|
||||||
|
module('Unit | Route | scopes/scope/groups/group', function (hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
|
test('it exists', function (assert) {
|
||||||
|
let route = this.owner.lookup('route:scopes/scope/groups/group');
|
||||||
|
assert.ok(route);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupTest } from 'ember-qunit';
|
||||||
|
|
||||||
|
module('Unit | Route | scopes/scope/groups/group/index', function (hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
|
test('it exists', function (assert) {
|
||||||
|
let route = this.owner.lookup('route:scopes/scope/groups/group/index');
|
||||||
|
assert.ok(route);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupTest } from 'ember-qunit';
|
||||||
|
|
||||||
|
module('Unit | Route | scopes/scope/groups/index', function (hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
|
test('it exists', function (assert) {
|
||||||
|
let route = this.owner.lookup('route:scopes/scope/groups/index');
|
||||||
|
assert.ok(route);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupTest } from 'ember-qunit';
|
||||||
|
|
||||||
|
module('Unit | Route | scopes/scope/groups/new', function (hooks) {
|
||||||
|
setupTest(hooks);
|
||||||
|
|
||||||
|
test('it exists', function (assert) {
|
||||||
|
let route = this.owner.lookup('route:scopes/scope/groups/new');
|
||||||
|
assert.ok(route);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user