Merge pull request #182 from hashicorp/ICU-580-view-an-account

View an account
This commit is contained in:
Randall Morey authored and GitHub committed 2020-09-16 09:57:35 -04:00
commit 614c4cd444
17 files changed
+254 -42

No files matched your search

@@ -0,0 +1,53 @@
<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.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@submitText={{t "actions.save"}}
@cancelText={{t "actions.cancel"}} />
</Rose::Form>
+3 -1
View File
@@ -73,7 +73,9 @@ Router.map(function () {
this.route('auth-methods', function() {
this.route('auth-method', { path: ':auth_method_id' }, function() {
this.route('accounts');
this.route('accounts', function() {
this.route('account', { path: ':account_id' }, function() {});
});
});
this.route('new');
});
@@ -4,7 +4,7 @@ export default class ScopesScopeAuthMethodsAuthMethodRoute extends Route {
// =methods
/**
* Load a single auth-method in current scope.
* Load an auth method by ID.
* @param {object} params
* @param {string} params.auth_method_id
* @return {authMethodModel}
@@ -1,15 +1,53 @@
import Route from '@ember/routing/route';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route {
// =services
@service intl;
@service notify;
// =methods
/**
* Returns accounts in current auth method.
* Returns accounts for the current auth method.
* @return {Promise{[AccountModel]}}
*/
model() {
const { id: auth_method_id } = this.modelFor('scopes.scope.auth-methods.auth-method');
const { id: auth_method_id } =
this.modelFor('scopes.scope.auth-methods.auth-method');
return this.store.query('account', { auth_method_id });
}
// =actions
/**
* Rollback changes on an account.
* @param {AccountModel} account
*/
@action
cancel(account) {
account.rollbackAttributes();
}
/**
* Save an account in current scope.
* @param {AccountModel} account
*/
@action
async save(account) {
try {
await account.save();
await this.refresh();
await this.transitionTo('scopes.scope.auth-methods.auth-method.accounts.account', account);
this.notify.success(
this.intl.t('notify.save-success')
);
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
}
}
@@ -0,0 +1,40 @@
import Route from '@ember/routing/route';
export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountRoute extends Route {
// =methods
/**
* Load an account by ID.
* @param {object} params
* @param {string} params.account_id
* @return {AccountModel}
*/
model({ account_id }) {
return this.store.findRecord('account', account_id, { reload: true });
}
/**
* Renders the route-set specific page sections
* @override
*/
renderTemplate() {
super.renderTemplate(...arguments);
this.render('scopes/scope/auth-methods/auth-method/accounts/account/-header', {
into: 'scopes/scope/auth-methods/auth-method',
outlet: 'header'
});
this.render('-empty', {
into: 'scopes/scope/auth-methods/auth-method',
outlet: 'actions'
});
this.render('scopes/scope/auth-methods/auth-method/accounts/account/-navigation', {
into: 'scopes/scope/auth-methods/auth-method',
outlet: 'navigation'
});
}
}
@@ -0,0 +1,4 @@
import Route from '@ember/routing/route';
export default class ScopesScopeAuthMethodsAuthMethodAccountsAccountIndexRoute extends Route {
}
@@ -1,4 +1,6 @@
<h2>{{t "resources.auth-method"}}</h2>
{{!--
<Rose::Badge>
{{t (concat 'auth.method-types.' @model.type)}}
</Rose::Badge>
</Rose::Badge>
--}}
@@ -1,37 +1,3 @@
{{title (t 'titles.accounts')}}
{{#if @model}}
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.label.name'}}</row.headerCell>
<row.headerCell>{{t 'form.label.id'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each @model as |account|}}
<body.row as |row|>
<row.headerCell>
{{account.name}}
<p>{{account.description}}</p>
</row.headerCell>
<row.cell>
<code>{{account.id}}</code>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
{{else}}
<Rose::Layout::Centered>
<Rose::Message @title={{t "titles.auth-method-accounts-welcome"}} as |message|>
<message.description>
{{t "descriptions.auth-method-accounts-welcome"}}
</message.description>
</Rose::Message>
</Rose::Layout::Centered>
{{/if}}
{{outlet}}
@@ -0,0 +1,4 @@
<h2>{{t "resources.account"}}</h2>
<Rose::Badge>
{{t (concat 'account.types.' @model.type)}}
</Rose::Badge>
@@ -0,0 +1,5 @@
<Rose::Nav::Tabs as |nav|>
<nav.link @route='scopes.scope.auth-methods.auth-method.accounts.account.index'>
{{t 'titles.details'}}
</nav.link>
</Rose::Nav::Tabs>
@@ -0,0 +1,5 @@
<Form::Account
@model={{@model}}
@submit={{route-action "save" @model}}
@cancel={{route-action "cancel" @model}}
/>
@@ -0,0 +1,40 @@
{{#if @model}}
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.label.name'}}</row.headerCell>
<row.headerCell>{{t 'form.label.id'}}</row.headerCell>
</header.row>
</table.header>
<table.body as |body|>
{{#each @model as |account|}}
<body.row as |row|>
<row.headerCell>
<LinkTo
@route="scopes.scope.auth-methods.auth-method.accounts.account"
@model={{account.id}}
>
{{account.name}}
</LinkTo>
<p>{{account.description}}</p>
</row.headerCell>
<row.cell>
<code>{{account.id}}</code>
</row.cell>
</body.row>
{{/each}}
</table.body>
</Rose::Table>
{{else}}
<Rose::Layout::Centered>
<Rose::Message @title={{t "titles.accounts-welcome"}} as |message|>
<message.description>
{{t "descriptions.accounts-welcome"}}
</message.description>
</Rose::Message>
</Rose::Layout::Centered>
{{/if}}
@@ -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/index', function(hooks) {
setupRenderingTest(hooks);
test('it renders', async function (assert) {
this.submit = () => {};
this.cancel = () => {};
this.model = { type: 'password' };
await render(hbs`
<Form::AuthMethod
@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/account', function(hooks) {
setupTest(hooks);
test('it exists', function(assert) {
let route = this.owner.lookup('route:scopes/scope/auth-methods/auth-method/accounts/account');
assert.ok(route);
});
});
@@ -0,0 +1,11 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Route | scopes/scope/auth-methods/auth-method/accounts/account/index', function(hooks) {
setupTest(hooks);
test('it exists', function(assert) {
let route = this.owner.lookup('route:scopes/scope/auth-methods/auth-method/accounts/account/index');
assert.ok(route);
});
});
+8 -2
View File
@@ -47,6 +47,9 @@ target:
host:
types:
static: Static
account:
types:
password: Password
resources:
user: User
users: Users
@@ -68,6 +71,8 @@ resources:
hosts: Hosts
target: Target
targets: Targets
accounts: Accounts
account: Account
titles:
iam: IAM
new: New
@@ -103,7 +108,8 @@ titles:
group-members-welcome: Welcome to Members
no-available-users: No Users Available
accounts: Accounts
auth-method-accounts-welcome: Welcome to Accounts
account: Account
accounts-welcome: Welcome to Accounts
descriptions:
host-catalogs: Overview of collections of hosts and host sets.
empty-set: There are no items to display yet. You may be able to add items or try back later.
@@ -124,7 +130,7 @@ descriptions:
no-principals-available: Principals are not available for assignment.
group-members-welcome: Users belonging to this group appear here.
no-available-users: No users are available to add to this group.
auth-method-accounts-welcome: No accounts are available in this auth method.
accounts-welcome: No accounts are available in this auth method.
states:
info: Info
success: Success