feat: 🎸 add new org functionality

This commit is contained in:
Randall Morey committed 2020-08-17 12:25:07 -04:00
1 parent 11e94aa0c3
commit 2a49d4601f
5 files changed
+194 -1

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
<Rose::Form
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@error={{@model.errors.base}}
as |form|
>
<form.input
@name="name"
@type="name"
@value={{@model.name}}
@label={{t "form.label.name"}}
@error={{@model.errors.name}}
readonly={{false}}
as |field|>
{{#if @model.errors.name}}
<field.errors as |errors|>
{{#each @model.errors.name as |error|}}
<errors.message>{{error.message}}</errors.message>
{{/each}}
</field.errors>
{{/if}}
</form.input>
<form.textarea
@name="description"
@type="description"
@value={{@model.description}}
@label={{t "form.label.description"}}
@error={{@model.errors.description}}
disabled={{@model.isSaving}}
readonly={{false}}
as |field|>
{{#if @model.errors.description}}
<field.errors as |errors|>
{{#each @model.errors.description as |error|}}
<errors.message>{{error.message}}</errors.message>
{{/each}}
</field.errors>
{{/if}}
</form.textarea>
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@submitText={{t "actions.save"}}
@cancelText={{t "actions.cancel"}} />
</Rose::Form>
+41
View File
@@ -1,7 +1,14 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
export default class ScopesScopeOrgsRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
/**
@@ -12,4 +19,38 @@ export default class ScopesScopeOrgsRoute extends Route {
return this.store.query('scope', { scope_id: 'global' });
}
// =actions
/**
* Rollback changes on org.
* @param {ScopeModel} org
*/
@action
cancel(org) {
const { isNew } = org;
org.rollbackAttributes();
if (isNew) this.transitionTo('scopes.scope.orgs');
}
/**
* Handle save org.
* @param {ScopeModel} org
* @param {Event} e
*/
@action
async save(org) {
const { isNew } = org;
try {
await org.save();
this.refresh();
this.notify.success(
this.intl.t(isNew ? 'notify.create-success' : 'notify.save-success')
);
this.transitionTo('scopes.scope', org);
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
}
}
@@ -11,7 +11,11 @@
</page.header>
<page.body>
<Form::Org
@model={{@model}}
@submit={{route-action "save" @model}}
@cancel={{route-action "cancel" @model}}
/>
</page.body>
</Rose::Layout::Page>
+76
View File
@@ -0,0 +1,76 @@
import { module, test } from 'qunit';
//import { visit, currentURL, click, fillIn, find } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
//import a11yAudit from 'ember-a11y-testing/test-support/audit';
//import { Response } from 'miragejs';
import {
//authenticateSession,
// These are left here intentionally for future reference.
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
module('Acceptance | org', function (hooks) {
setupApplicationTest(hooks);
setupMirage(hooks);
// let org;
// let orgID;
// let orgsURL;
// let newOrgURL;
// let existingOrg;
// let existingOrgURL;
// let getOrgScopesCount;
// let getFirstOrgScope;
// let initialOrgScopesCount;
//
// hooks.beforeEach(function () {
// authenticateSession({});
//
// });
test('visiting orgs', async function (assert) {
assert.expect(0);
});
test('visiting orgs within a org scope redirects to the parent org scope', async function (assert) {
assert.expect(0);
});
test('can create new orgs', async function (assert) {
assert.expect(0);
});
test('can cancel create new orgs', async function (assert) {
assert.expect(0);
});
test('saving a new org with invalid fields displays error messages', async function (assert) {
assert.expect(0);
});
test('can save changes to existing org', async function (assert) {
assert.expect(0);
});
test('can cancel changes to existing org', async function (assert) {
assert.expect(0);
});
test('can delete org', async function (assert) {
assert.expect(0);
});
test('saving an existing org with invalid fields displays error messages', async function (assert) {
assert.expect(0);
});
test('errors are displayed when save org fails', async function (assert) {
assert.expect(0);
});
test('errors are displayed when delete org fails', async function (assert) {
assert.expect(0);
});
});
@@ -0,0 +1,23 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, find } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | form/org', function(hooks) {
setupRenderingTest(hooks);
test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });
this.submit = () => {};
this.cancel = () => {};
await render(hbs`
<Form::Org
@submit={{this.submit}}
@cancel={{this.cancel}}
/>`);
assert.ok(find('form'));
});
});