feat: Create an account

This commit is contained in:
Susmitha Girumala committed 2020-09-14 17:43:07 -04:00
1 parent f657970a35
commit 3030d87abc
12 files changed
+201 -2

No files matched your search

@@ -46,6 +46,23 @@
{{/if}}
</form.textarea>
<form.input
@name="login_name"
@type="text"
@value={{@model.attributes.login_name}}
@label={{t "form.label.identification"}}
@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.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@submitText={{t "actions.save"}}
@@ -0,0 +1,88 @@
<Rose::Form
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@error={{@model.errors.base}}
as |form|
>
<form.input
@value={{t (concat 'account.types.' @model.type)}}
@label={{t "form.label.type"}}
readonly={{true}}
@disabled={{true}} />
<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.input
@name="login_name"
@type="text"
@value={{@model.attributes.login_name}}
@label={{t "form.label.identification"}}
@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.input
@name="password"
@type="password"
@value={{@model.attributes.password}}
@label={{t "form.label.password"}}
@error={{@model.errors.name}}
readonly={{false}}
autocomplete="new-password"
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.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@submitText={{t "actions.save"}}
@cancelText={{t "actions.cancel"}} />
</Rose::Form>
@@ -64,7 +64,6 @@
{{/if}}
</form.input>
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@submitText={{t "actions.save"}}
+1
View File
@@ -75,6 +75,7 @@ Router.map(function () {
this.route('auth-method', { path: ':auth_method_id' }, function() {
this.route('accounts', function() {
this.route('account', { path: ':account_id' }, function() {});
this.route('new');
});
});
this.route('new');
@@ -27,7 +27,9 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route
*/
@action
cancel(account) {
const { isNew } = account;
account.rollbackAttributes();
if (isNew) this.transitionTo('scopes.scope.auth-methods.auth-method.accounts');
}
/**
@@ -36,11 +38,12 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route
*/
@action
async save(account) {
const { isNew } = account;
try {
await account.save();
this.refresh();
this.notify.success(
this.intl.t('notify.save-success')
this.intl.t(isNew ? 'notify.create-success' : 'notify.save-success')
);
this.transitionTo('scopes.scope.auth-methods.auth-method.accounts.account', account);
} catch (error) {
@@ -0,0 +1,43 @@
import Route from '@ember/routing/route';
export default class ScopesScopeAuthMethodsAuthMethodAccountsNewRoute extends Route {
// =methods
/**
* Creates a new unsaved account in current scope.
* @return {AccountModel}
*/
model() {
const { id: auth_method_id } =
this.modelFor('scopes.scope.auth-methods.auth-method');
return this.store.createRecord('account', {
type: 'password',
auth_method_id
});
}
/**
* Renders new account templates for header, navigation, and action page sections.
* @override
*/
renderTemplate() {
super.renderTemplate(...arguments);
this.render('scopes/scope/auth-methods/auth-method/accounts/new/-header', {
into: 'scopes/scope/auth-methods/auth-method',
outlet: 'header'
});
this.render('_empty', {
into: 'scopes/scope/auth-methods/auth-method',
outlet: 'actions'
});
this.render('_empty', {
into: 'scopes/scope/auth-methods/auth-method',
outlet: 'navigation'
});
}
}
@@ -1,4 +1,10 @@
<Rose::Dropdown @text="{{t 'actions.manage'}}" @dropdownRight={{true}} as |dropdown|>
<dropdown.link
@route="scopes.scope.auth-methods.auth-method.accounts.new"
@model={{@model}}
>
{{t "actions.add-account"}}
</dropdown.link>
<dropdown.button
@style="danger"
@disabled={{@model.canSave}}
@@ -0,0 +1,5 @@
<Form::Account::Password
@model={{@model}}
@submit={{route-action "save" @model}}
@cancel={{route-action "cancel" @model}}
/>
@@ -0,0 +1 @@
<h2>{{t "titles.new"}}</h2>
@@ -0,0 +1,24 @@
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/account/password', function(hooks) {
setupRenderingTest(hooks);
test('it renders', async function (assert) {
this.submit = () => {};
this.cancel = () => {};
this.model = { type: 'password' };
await render(hbs`
<Form::Account::Password
@model={{this.model}}
@submit={{this.submit}}
@cancel={{this.cancel}}
/>`);
assert.ok(find('form'));
});
});
@@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Route | scopes/scope/auth-methods/auth-method/accounts/new', function(hooks) {
setupTest(hooks);
test('it exists', function(assert) {
let route = this.owner.lookup('route:scopes/scope/auth-methods/auth-method/accounts/new');
assert.ok(route);
});
});
+1
View File
@@ -28,6 +28,7 @@ actions:
add-principals: Add Principals
add-members: Add Members
add-hosts: Add Hosts
add-account: Create Account
auth:
titles:
no-scopes: No Scopes Available