refactored users/show

This commit is contained in:
Matthew Dillon 2015-11-05 20:24:07 -07:00
parent e6510992dc
commit b742ddbb51
5 changed files with 84 additions and 64 deletions

View file

@ -1,9 +1,9 @@
import Ember from 'ember'; import Ember from 'ember';
import DeleteModel from '../../../../mixins/delete-model';
export default Ember.Controller.extend({ const { Controller } = Ember;
currentUser: Ember.inject.service('session-account'),
isUser: Ember.computed('model.id', 'currentUser.account.id', function() { export default Controller.extend(DeleteModel, {
return this.get('model.id') === this.get('currentUser.account.id'); // Required for DeleteModel mixin
}), transitionRoute: 'protected.index',
}); });

View file

@ -1,21 +1,25 @@
import Ember from 'ember'; import Ember from 'ember';
export default Ember.Route.extend({ const { Route, inject: { service } } = Ember;
currentUser: Ember.inject.service('session-account'),
export default Route.extend({
currentUser: service('session-account'),
// Not using ElevatedAccess Mixin because the rules for viewing user accounts
// is slightly different.
beforeModel: function(transition) { beforeModel: function(transition) {
this._super(transition); this._super(transition);
this.get('currentUser.account').then((currentUser) => { this.get('currentUser.account').then((user) => {
let user_id = transition.params['protected.users.show'].user_id; const user_id = transition.params['protected.users.show'].user_id;
if (!currentUser.get('isAdmin') && currentUser.get('id') !== user_id) { if (!user.get('isAdmin') && user.get('id') !== user_id) {
this.transitionTo('protected.users.index'); this.transitionTo('protected.users.index');
} }
}); });
}, },
model: function(params) { model: function(params) {
return this.store.findRecord('user', params.user_id, { reload: true }); return this.store.findRecord('user', params.user_id);
}, },
}); });

View file

@ -1,53 +1,5 @@
<div class="span-1"> {{
<fieldset class="flakes-information-box"> protected/users/show/user-card
<legend> user=model
{{model.name}} on-delete=(action 'delete')
</legend> }}
{{! ROW 1 }}
<div class="grid-2 gutter-20">
<dl class="span-1">
<dt>Email</dt>
<dd>
{{model.email}}
</dd>
</dl>
<dl class="span-1">
<dt>Role</dt>
<dd>
{{model.fullRole}}
</dd>
</dl>
</div>
{{! ROW 2 }}
<div class="grid-2 gutter-20">
<dl class="span-1">
<dt>Record Created</dt>
<dd>{{null-time model.createdAt 'LL'}}</dd>
</dl>
<dl class="span-1">
<dt>Record Updated</dt>
<dd>{{null-time model.updatedAt 'LL'}}</dd>
</dl>
</div>
</fieldset>
</div>
<br>
<div class="grid-2 gutter-20">
{{#if isUser}}
<div class="span-1">
{{#link-to 'protected.users.changepassword' model.id class="button-gray smaller"}}
Change Password
{{/link-to}}
</div>
{{/if}}
<div class="span-1">
{{#if model.canEdit}}
{{#link-to 'protected.users.edit' model.id class="button-gray smaller"}}
Edit
{{/link-to}}
{{/if}}
</div>
</div>

View file

@ -0,0 +1,11 @@
import Ember from 'ember';
const { Component, computed, inject: { service } } = Ember;
export default Component.extend({
currentUser: service('session-account'),
isUser: computed('model.id', 'currentUser.account.id', function() {
return this.get('model.id') === this.get('currentUser.account.id');
}),
});

View file

@ -0,0 +1,53 @@
<div class="span-1">
<fieldset class="flakes-information-box">
<legend>
{{user.name}}
</legend>
{{! ROW 1 }}
<div class="grid-2 gutter-20">
<dl class="span-1">
<dt>Email</dt>
<dd>
{{user.email}}
</dd>
</dl>
<dl class="span-1">
<dt>Role</dt>
<dd>
{{user.fullRole}}
</dd>
</dl>
</div>
{{! ROW 2 }}
<div class="grid-2 gutter-20">
<dl class="span-1">
<dt>Record Created</dt>
<dd>{{null-time user.createdAt 'LL'}}</dd>
</dl>
<dl class="span-1">
<dt>Record Updated</dt>
<dd>{{null-time user.updatedAt 'LL'}}</dd>
</dl>
</div>
</fieldset>
</div>
<br>
<div class="grid-2 gutter-20">
{{#if isUser}}
<div class="span-1">
{{#link-to 'protected.users.changepassword' user.id class="button-gray smaller"}}
Change Password
{{/link-to}}
</div>
{{/if}}
<div class="span-1">
{{#if model.canEdit}}
{{#link-to 'protected.users.edit' user.id class="button-gray smaller"}}
Edit
{{/link-to}}
{{/if}}
</div>
</div>