Working on users

This commit is contained in:
Matthew Dillon 2015-09-09 16:49:48 -07:00
parent be8a842c67
commit 425dd689ae
7 changed files with 117 additions and 5 deletions

View file

@ -12,4 +12,17 @@ export default DS.Model.extend({
isAdmin: function() {
return this.get('role') === 'A';
}.property('role'),
fullRole: function() {
let role = this.get('role');
if (role === 'R') {
return 'Read-Only';
} else if (role === 'W') {
return 'Write';
} else if (role === 'A') {
return 'Admin';
} else {
return 'Error';
}
}.property('role'),
});

View file

@ -24,7 +24,7 @@
{{/link-to}}
</ul>
<p class="foot">
{{session.currentUser.name}}<br>
{{link-to session.currentUser.name 'protected.users.show' session.currentUser.id}}<br>
<a {{action 'invalidateSession'}}>Logout</a>
</p>
{{else}}

View file

@ -1,6 +1,15 @@
import Ember from 'ember';
export default Ember.Route.extend({
beforeModel: function(transition) {
this._super(transition);
this.get('session.currentUser').then((user) => {
if (!user.get('isAdmin')) {
this.transitionTo('protected.index');
}
});
},
model: function() {
return this.store.findAll('user');
},

View file

@ -1,3 +1,33 @@
{{#each model as |user|}}
{{user.email}}<br>
<h2>{{genus-name}} Users</h2>
<h3>Total users: {{model.length}}</h3>
<table class="flakes-table">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Role</th>
<th>Date Registered</th>
</tr>
</thead>
<tbody>
{{#each model as |row|}}
<tr>
<td>
{{#link-to 'protected.users.show' row}}
{{row.name}}
{{/link-to}}
</td>
<td>
{{row.email}}
</td>
<td>
{{row.fullRole}}
</td>
<td>
{{null-time row.createdAt 'LL'}}
</td>
</tr>
{{/each}}
</tbody>
</table>

View file

@ -0,0 +1,8 @@
import Ember from 'ember';
export default Ember.Route.extend({
model: function(params) {
return this.store.findRecord('user', params.user_id, { reload: true });
},
});

View file

@ -0,0 +1,49 @@
<div class="span-1">
<fieldset class="flakes-information-box {{if isEditing 'is-editing'}}">
<legend>
{{model.name}}
</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-3 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>
<dl class="span-1">
<dt>Record Deleted</dt>
<dd>{{null-time model.deletedAt 'LL'}}</dd>
</dl>
</div>
</fieldset>
</div>
<br>
{{#link-to 'protected.users.show' model.id class="button-gray smaller"}}
Change Password (Does nothing at the moment)
{{/link-to}}
{{#if model.canEdit}}
<br>
{{#link-to 'protected.user.edit' model.id class="button-gray smaller"}}
Edit
{{/link-to}}
{{/if}}

View file

@ -19,7 +19,10 @@ Router.map(function() {
this.route('protected', { path: '/' }, function() {
this.route('about');
this.route('users');
this.route('users', function() {
this.route('show', { path: ':user_id' });
this.route('edit', { path: ':user_id/edit' });
});
this.route('compare', function() {
this.route('results');