diff --git a/app/helpers/equal.js b/app/helpers/equal.js index db3e867..a003400 100644 --- a/app/helpers/equal.js +++ b/app/helpers/equal.js @@ -1,7 +1,9 @@ import Ember from 'ember'; +const { Helper: { helper } } = Ember; + export function equalHelper(params) { return params[0] === params[1]; } -export default Ember.HTMLBars.makeBoundHelper(equalHelper); +export default helper(equalHelper); diff --git a/app/mirage/config.js b/app/mirage/config.js index c03b469..3982c0c 100644 --- a/app/mirage/config.js +++ b/app/mirage/config.js @@ -2,7 +2,7 @@ export default function() { // Don't use mirage for development (for now) this.urlPrefix = 'http://127.0.0.1:8901'; this.namespace = '/api'; - this.passthrough(); + this.passthrough('http://localhost:4200/**', 'http://127.0.0.1:8901/**'); } export function testConfig() { diff --git a/app/mixins/save-model.js b/app/mixins/save-model.js index 53efda9..8d3b233 100644 --- a/app/mixins/save-model.js +++ b/app/mixins/save-model.js @@ -16,6 +16,7 @@ export default Mixin.create({ if (model.get('hasDirtyAttributes')) { model.save().then((model) => { + this.get('flashMessages').clearMessages(); this.transitionToRoute(fallbackRoute, model); }, () => { ajaxError(model.get('errors'), this.get('flashMessages')); diff --git a/app/mixins/setup-metadata.js b/app/mixins/setup-metadata.js index 183f93f..bdfd886 100644 --- a/app/mixins/setup-metadata.js +++ b/app/mixins/setup-metadata.js @@ -5,10 +5,12 @@ const { Mixin, inject: { service }} = Ember; export default Mixin.create({ currentUser: service('session-account'), metaData: null, + isAdmin: null, setupMetaDataOnInit: Ember.on('init', function() { this.get('currentUser.account').then((user) => { this.set('metaData', user.get('metaData')); + this.set('isAdmin', user.get('isAdmin')); }); }), }); diff --git a/app/pods/protected/characteristics/edit/controller.js b/app/pods/protected/characteristics/edit/controller.js index 0b83924..aff45e1 100644 --- a/app/pods/protected/characteristics/edit/controller.js +++ b/app/pods/protected/characteristics/edit/controller.js @@ -6,5 +6,5 @@ const { Controller } = Ember; export default Controller.extend(SaveModel, { // Required for SaveModel mixin fallbackRouteSave: 'protected.characteristics.show', - fallbackRouteCancel: 'protected.characteristics.index', + fallbackRouteCancel: 'protected.characteristics.show', }); diff --git a/app/pods/protected/users/edit/controller.js b/app/pods/protected/users/edit/controller.js index 955c328..283631c 100644 --- a/app/pods/protected/users/edit/controller.js +++ b/app/pods/protected/users/edit/controller.js @@ -1,40 +1,10 @@ import Ember from 'ember'; -import ajaxError from '../../../../utils/ajax-error'; +import SaveModel from '../../../../mixins/save-model'; -export default Ember.Controller.extend({ - actions: { - save: function() { - let user = this.get('model'); +const { Controller } = Ember; - if (user.get('hasDirtyAttributes')) { - let attrs = user.changedAttributes(), roleChanged = false; - if (attrs.role) { - roleChanged = true; - } - user.save().then((user) => { - this.get('flashMessages').clearMessages(); - if (roleChanged) { - // Need to clear the store so that canEdit and canAdd - // attributes reflect the new role. - this.get('store').unloadAll(); - } - this.transitionToRoute('protected.users.show', user); - }, () => { - ajaxError(user.get('errors'), this.get('flashMessages')); - }); - } else { - this.transitionToRoute('protected.users.show', user); - } - }, - - cancel: function() { - let user = this.get('model'); - - user.get('errors').clear(); - user.rollbackAttributes(); - - this.transitionToRoute('protected.users.show', user); - }, - - }, +export default Controller.extend(SaveModel, { + // Required for SaveModel mixin + fallbackRouteSave: 'protected.users.show', + fallbackRouteCancel: 'protected.users.show', }); diff --git a/app/pods/protected/users/edit/route.js b/app/pods/protected/users/edit/route.js index b95bdb2..c91288e 100644 --- a/app/pods/protected/users/edit/route.js +++ b/app/pods/protected/users/edit/route.js @@ -1,8 +1,12 @@ import Ember from 'ember'; -export default Ember.Route.extend({ - currentUser: Ember.inject.service('session-account'), +const { Route, inject: { service } } = Ember; +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) { this._super(transition); @@ -16,7 +20,7 @@ export default Ember.Route.extend({ }, model: function(params) { - return this.store.findRecord('user', params.user_id, { reload: true }); + return this.store.findRecord('user', params.user_id); }, }); diff --git a/app/pods/protected/users/edit/template.hbs b/app/pods/protected/users/edit/template.hbs index e53c6e8..60cbe0d 100644 --- a/app/pods/protected/users/edit/template.hbs +++ b/app/pods/protected/users/edit/template.hbs @@ -1,7 +1,6 @@ {{ protected/users/user-form user=model - currentUser=currentUser.account - save="save" - cancel="cancel" + on-save=(action "save") + on-cancel=(action "cancel") }} diff --git a/app/pods/protected/users/show/user-card/component.js b/app/pods/protected/users/show/user-card/component.js index 41dcaef..00e3164 100644 --- a/app/pods/protected/users/show/user-card/component.js +++ b/app/pods/protected/users/show/user-card/component.js @@ -5,7 +5,9 @@ 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'); + user: null, + + isUser: computed('user.id', 'currentUser.account.id', function() { + return this.get('user.id') === this.get('currentUser.account.id'); }), }); diff --git a/app/pods/protected/users/show/user-card/template.hbs b/app/pods/protected/users/show/user-card/template.hbs index 6aa0d84..5ced125 100644 --- a/app/pods/protected/users/show/user-card/template.hbs +++ b/app/pods/protected/users/show/user-card/template.hbs @@ -44,7 +44,7 @@ {{/if}}