diff --git a/app/authenticators/jwt-resolved.js b/app/authenticators/jwt-resolved.js index a6884ec..1417236 100644 --- a/app/authenticators/jwt-resolved.js +++ b/app/authenticators/jwt-resolved.js @@ -1,3 +1,4 @@ +// Note: this is here for user lockout authentication import Ember from 'ember'; import JwtTokenAuthenticator from 'simple-auth-token/authenticators/jwt'; diff --git a/app/initializers/custom-session.js b/app/initializers/custom-session.js index 08d48b8..011cd90 100644 --- a/app/initializers/custom-session.js +++ b/app/initializers/custom-session.js @@ -1,5 +1,3 @@ -import Ember from 'ember'; - export function initialize(container, application) { application.inject('session:custom', '_store', 'service:store'); } diff --git a/app/pods/protected/characteristics/show/controller.js b/app/pods/protected/characteristics/show/controller.js index cc45d06..2ed7872 100644 --- a/app/pods/protected/characteristics/show/controller.js +++ b/app/pods/protected/characteristics/show/controller.js @@ -3,7 +3,7 @@ import Ember from 'ember'; export default Ember.Controller.extend({ actions: { delete: function() { - this.get('model').destroyRecord() + this.get('model').destroyRecord(); this.transitionToRoute('protected.characteristics.index'); }, }, diff --git a/app/pods/protected/characteristics/show/measurements-table/component.js b/app/pods/protected/characteristics/show/measurements-table/component.js index 00d5dd4..1ca9d17 100644 --- a/app/pods/protected/characteristics/show/measurements-table/component.js +++ b/app/pods/protected/characteristics/show/measurements-table/component.js @@ -5,17 +5,27 @@ export default Ember.Component.extend({ return this.get('model.measurements.length') > 0; }.property('model.measurements'), - // TODO: this is way more complicated than it should be - measurementsTable: function() { - let measurements = this.get('model.measurements'); - let table = []; - measurements.forEach((measurement) => { - let row = {}; - row['measurement'] = measurement; - row['strain'] = this.store.peekRecord('strain', measurement.get('strain.id')); - table.push(row); - }); - return table; - }.property(), + sortParams: ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName'], + sortAsc: true, + paramsChanged: false, + sortedMeasurements: Ember.computed.sort('model.measurements', 'sortParams'), + + actions: { + changeSortParam: function(col) { + let sort = this.get('sortAsc') ? 'asc' : 'desc'; + let sortCol = `${col}:${sort}`; + this.set('sortParams', [sortCol]); + this.set('paramsChanged', true); + this.toggleProperty('sortAsc'); + return false; + }, + + resetSortParam: function() { + this.set('sortParams', ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName']); + this.set('paramsChanged', false); + this.set('sortAsc', true); + return false; + }, + }, }); diff --git a/app/pods/protected/characteristics/show/measurements-table/template.hbs b/app/pods/protected/characteristics/show/measurements-table/template.hbs index 1813ed8..8ee1a86 100644 --- a/app/pods/protected/characteristics/show/measurements-table/template.hbs +++ b/app/pods/protected/characteristics/show/measurements-table/template.hbs @@ -1,14 +1,19 @@ {{#if measurementsPresent}} +{{#if paramsChanged}} + +{{/if}} - - - + + + - {{#each measurementsTable as |row|}} + {{#each sortedMeasurements as |row|}} {{/each}} diff --git a/app/pods/protected/strains/show/measurements-table-row/component.js b/app/pods/protected/strains/show/measurements-table-row/component.js index d17a831..9c151fb 100644 --- a/app/pods/protected/strains/show/measurements-table-row/component.js +++ b/app/pods/protected/strains/show/measurements-table-row/component.js @@ -36,6 +36,10 @@ export default Ember.Component.extend({ }, delete: function() { + let char = this.get('row.characteristic'); + if (char.get('isNew')) { + char.destroyRecord(); + } this.get('row').destroyRecord(); } diff --git a/app/pods/protected/strains/show/measurements-table-row/template.hbs b/app/pods/protected/strains/show/measurements-table-row/template.hbs index 1c6cc07..a26fef4 100644 --- a/app/pods/protected/strains/show/measurements-table-row/template.hbs +++ b/app/pods/protected/strains/show/measurements-table-row/template.hbs @@ -1,4 +1,5 @@ {{#if isEditing}} + {{/if}} {{else}} +
StrainValueNotesStrainValueNotes
{{#link-to 'protected.strains.show' row.strain.id}} @@ -16,10 +21,10 @@ {{/link-to}} - {{row.measurement.value}} + {{row.value}} - {{row.measurement.notes}} + {{row.notes}}
{{ select-2 @@ -28,6 +29,9 @@ + {{{row.characteristic.characteristicTypeName}}} + {{#link-to 'protected.characteristics.show' row.characteristic.id}} {{{row.characteristic.characteristicName}}} diff --git a/app/pods/protected/strains/show/measurements-table/component.js b/app/pods/protected/strains/show/measurements-table/component.js index 8d8e31d..07d94c6 100644 --- a/app/pods/protected/strains/show/measurements-table/component.js +++ b/app/pods/protected/strains/show/measurements-table/component.js @@ -12,6 +12,8 @@ export default Ember.Component.extend({ }.on('didInsertElement'), sortParams: ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName'], + sortAsc: true, + paramsChanged: false, sortedMeasurements: Ember.computed.sort('model.measurements', 'sortParams'), actions: { @@ -24,6 +26,22 @@ export default Ember.Component.extend({ }); this.get('model.measurements').addObject(m); }, + + changeSortParam: function(col) { + let sort = this.get('sortAsc') ? 'asc' : 'desc'; + let sortCol = `${col}:${sort}`; + this.set('sortParams', [sortCol]); + this.set('paramsChanged', true); + this.toggleProperty('sortAsc'); + return false; + }, + + resetSortParam: function() { + this.set('sortParams', ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName']); + this.set('paramsChanged', false); + this.set('sortAsc', true); + return false; + }, }, }); diff --git a/app/pods/protected/strains/show/measurements-table/template.hbs b/app/pods/protected/strains/show/measurements-table/template.hbs index 2f30a9e..a9a45dd 100644 --- a/app/pods/protected/strains/show/measurements-table/template.hbs +++ b/app/pods/protected/strains/show/measurements-table/template.hbs @@ -7,24 +7,32 @@ {{/if}} {{#if measurementsPresent}} +{{#if paramsChanged}} + +{{/if}} {{#if canEdit}} - + + {{else}} - + + {{/if}} - - - + + + + {{#if canEdit}} {{/if}} diff --git a/app/pods/protected/users/edit/route.js b/app/pods/protected/users/edit/route.js index e11116f..3a943b8 100644 --- a/app/pods/protected/users/edit/route.js +++ b/app/pods/protected/users/edit/route.js @@ -7,7 +7,7 @@ export default Ember.Route.extend({ let user_id = transition.params['protected.users.edit'].user_id; this.get('session.currentUser').then((user) => { - if (user.get('id') !== user_id || user.get('isAdmin')) { + if (user.get('id') !== user_id && !user.get('isAdmin')) { this.transitionTo('protected.users.index'); } }); diff --git a/app/pods/protected/users/show/route.js b/app/pods/protected/users/show/route.js index e812128..33eeba7 100644 --- a/app/pods/protected/users/show/route.js +++ b/app/pods/protected/users/show/route.js @@ -9,7 +9,7 @@ export default Ember.Route.extend({ if (!currentUser.get('isAdmin') && currentUser.get('id') !== user_id) { this.transitionTo('protected.users.index'); } - }) + }); }, model: function(params) { diff --git a/app/pods/protected/users/user-form/component.js b/app/pods/protected/users/user-form/component.js index d5ce463..0a706f3 100644 --- a/app/pods/protected/users/user-form/component.js +++ b/app/pods/protected/users/user-form/component.js @@ -1,10 +1,6 @@ import Ember from 'ember'; export default Ember.Component.extend({ - isAdmin: Ember.computed('currentUser', function() { - return this.get('currentUser.role') == 'A'; - }), - roles: Ember.String.w('A R W'), actions: { diff --git a/app/pods/protected/users/user-form/template.hbs b/app/pods/protected/users/user-form/template.hbs index a872aae..c6209a9 100644 --- a/app/pods/protected/users/user-form/template.hbs +++ b/app/pods/protected/users/user-form/template.hbs @@ -16,7 +16,7 @@
- {{#if isAdmin}} + {{#if session.currentUser.isAdmin}}
CharacteristicValueNotesTypeCharacteristicValueNotesEdit