diff --git a/app/models/characteristic.js b/app/models/characteristic.js index 766fdbf..ea6a6d5 100644 --- a/app/models/characteristic.js +++ b/app/models/characteristic.js @@ -1,14 +1,16 @@ import DS from 'ember-data'; -export default DS.Model.extend({ - characteristicName : DS.attr('string'), - characteristicTypeName: DS.attr('string'), - strains : DS.hasMany('strain', { async: false }), - measurements : DS.hasMany('measurements', { async: false }), - createdAt : DS.attr('date'), - updatedAt : DS.attr('date'), - createdBy : DS.attr('number'), - updatedBy : DS.attr('number'), - sortOrder : DS.attr('number'), - canEdit : DS.attr('boolean'), +const { Model, attr, hasMany } = DS; + +export default Model.extend({ + characteristicName : attr('string'), + characteristicTypeName: attr('string'), + strains : hasMany('strain', { async: false }), + measurements : hasMany('measurements', { async: false }), + createdAt : attr('date'), + updatedAt : attr('date'), + createdBy : attr('number'), + updatedBy : attr('number'), + sortOrder : attr('number'), + canEdit : attr('boolean'), }); diff --git a/app/models/measurement.js b/app/models/measurement.js index 41a7644..009aa8b 100644 --- a/app/models/measurement.js +++ b/app/models/measurement.js @@ -1,15 +1,17 @@ import DS from 'ember-data'; -export default DS.Model.extend({ - strain : DS.belongsTo('strain', { async: false }), - characteristic : DS.belongsTo('characteristic', { async: false }), - value : DS.attr('string'), - confidenceInterval : DS.attr('number'), - unitType : DS.attr('string'), - notes : DS.attr('string'), - testMethod : DS.attr('string'), - createdAt : DS.attr('date'), - updatedAt : DS.attr('date'), - createdBy : DS.attr('number'), - updatedBy : DS.attr('number'), +const { Model, belongsTo, attr } = DS; + +export default Model.extend({ + strain : belongsTo('strain', { async: false }), + characteristic : belongsTo('characteristic', { async: false }), + value : attr('string'), + confidenceInterval : attr('number'), + unitType : attr('string'), + notes : attr('string'), + testMethod : attr('string'), + createdAt : attr('date'), + updatedAt : attr('date'), + createdBy : attr('number'), + updatedBy : attr('number'), }); diff --git a/app/models/species.js b/app/models/species.js index bb27451..7581d10 100644 --- a/app/models/species.js +++ b/app/models/species.js @@ -2,20 +2,23 @@ import DS from 'ember-data'; import config from '../config/environment'; import Ember from 'ember'; -export default DS.Model.extend({ - speciesName : DS.attr('string'), - typeSpecies : DS.attr('boolean'), - etymology : DS.attr('string'), - genusName : DS.attr('string', { defaultValue: config.APP.genus }), - strains : DS.hasMany('strain', { async: false }), - totalStrains: DS.attr('number'), - createdAt : DS.attr('date'), - updatedAt : DS.attr('date'), - createdBy : DS.attr('number'), - updatedBy : DS.attr('number'), - sortOrder : DS.attr('number'), - canEdit : DS.attr('boolean'), +const { Model, attr, hasMany } = DS; +export default Model.extend({ + speciesName : attr('string'), + typeSpecies : attr('boolean'), + etymology : attr('string'), + genusName : attr('string', { defaultValue: config.APP.genus }), + strains : hasMany('strain', { async: false }), + totalStrains: attr('number'), + createdAt : attr('date'), + updatedAt : attr('date'), + createdBy : attr('number'), + updatedBy : attr('number'), + sortOrder : attr('number'), + canEdit : attr('boolean'), + + // TODO: move this to component/helper speciesNameMU: function() { return Ember.String.htmlSafe(`${this.get('speciesName')}`); }.property('speciesName').readOnly(), diff --git a/app/models/strain.js b/app/models/strain.js index 0c59f2f..b202a78 100644 --- a/app/models/strain.js +++ b/app/models/strain.js @@ -1,34 +1,39 @@ import DS from 'ember-data'; import Ember from 'ember'; -export default DS.Model.extend({ - measurements : DS.hasMany('measurements', { async: false }), - characteristics : DS.hasMany('characteristics', { async: false }), - species : DS.belongsTo('species', { async: false }), - strainName : DS.attr('string'), - typeStrain : DS.attr('boolean'), - accessionNumbers : DS.attr('string'), - genbank : DS.attr('string'), - wholeGenomeSequence: DS.attr('string'), - isolatedFrom : DS.attr('string'), - notes : DS.attr('string'), - createdAt : DS.attr('date'), - updatedAt : DS.attr('date'), - createdBy : DS.attr('number'), - updatedBy : DS.attr('number'), - totalMeasurements : DS.attr('number'), - sortOrder : DS.attr('number'), - canEdit : DS.attr('boolean'), +const { Model, hasMany, belongsTo, attr } = DS; +export default Model.extend({ + measurements : hasMany('measurements', { async: false }), + characteristics : hasMany('characteristics', { async: false }), + species : belongsTo('species', { async: false }), + strainName : attr('string'), + typeStrain : attr('boolean'), + accessionNumbers : attr('string'), + genbank : attr('string'), + wholeGenomeSequence: attr('string'), + isolatedFrom : attr('string'), + notes : attr('string'), + createdAt : attr('date'), + updatedAt : attr('date'), + createdBy : attr('number'), + updatedBy : attr('number'), + totalMeasurements : attr('number'), + sortOrder : attr('number'), + canEdit : attr('boolean'), + + // TODO: move this to component/helper strainNameMU: function() { let type = this.get('typeStrain') ? 'T' : ''; return Ember.String.htmlSafe(`${this.get('strainName')}${type}`); }.property('strainName', 'typeStrain').readOnly(), + // TODO: move this to component/helper fullName: Ember.computed('species', 'strainName', function() { return `${this.get('species.speciesName')} ${this.get('strainNameMU')}`; }), + // TODO: move this to component/helper fullNameMU: function() { return Ember.String.htmlSafe(`${this.get('species.speciesName')} ${this.get('strainNameMU')}`); }.property('species', 'strainNameMU').readOnly(), diff --git a/app/models/user.js b/app/models/user.js index 198f451..89b7c0f 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -1,29 +1,32 @@ import Ember from 'ember'; import DS from 'ember-data'; -export default DS.Model.extend({ - email : DS.attr('string'), - password : DS.attr('string'), - name : DS.attr('string'), - role : DS.attr('string'), - canEdit : DS.attr('boolean'), - createdAt: DS.attr('date'), - updatedAt: DS.attr('date'), +const { Model, attr } = DS; +const { computed } = Ember; - isAdmin: function() { +export default Model.extend({ + email : attr('string'), + password : attr('string'), + name : attr('string'), + role : attr('string'), + canEdit : attr('boolean'), + createdAt: attr('date'), + updatedAt: attr('date'), + + isAdmin: computed('role', function() { return this.get('role') === 'A'; - }.property('role'), + }), - isWriter: function() { + isWriter: computed('role', function() { return this.get('role') === 'W'; - }.property('role'), + }), - isReader: function() { + isReader: computed('role', function() { return this.get('role') === 'R'; - }.property('role'), + }), - fullRole: function() { - let role = this.get('role'); + fullRole: computed('role', function() { + const role = this.get('role'); if (role === 'R') { return 'Read-Only'; } else if (role === 'W') { @@ -33,13 +36,13 @@ export default DS.Model.extend({ } else { return 'Error'; } - }.property('role'), + }), - canWrite: Ember.computed('role', function() { + canWrite: computed('role', function() { return this.get('role') !== 'R'; }), - metaData: Ember.computed('canWrite', function() { + metaData: computed('canWrite', function() { return { 'canAdd': this.get('canWrite') }; }), diff --git a/app/pods/application/adapter.js b/app/pods/application/adapter.js index 96daa1a..0d7ed91 100644 --- a/app/pods/application/adapter.js +++ b/app/pods/application/adapter.js @@ -1,7 +1,9 @@ import DS from 'ember-data'; import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin'; -export default DS.RESTAdapter.extend(DataAdapterMixin, { +const { RESTAdapter } = DS; + +export default RESTAdapter.extend(DataAdapterMixin, { authorizer: 'authorizer:application', namespace: function() { diff --git a/app/pods/application/route.js b/app/pods/application/route.js index ca03050..e677da9 100644 --- a/app/pods/application/route.js +++ b/app/pods/application/route.js @@ -1,7 +1,9 @@ import Ember from 'ember'; import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'; -export default Ember.Route.extend(ApplicationRouteMixin, { +const { Route } = Ember; + +export default Route.extend(ApplicationRouteMixin, { actions: { invalidateSession: function() { this.get('session').invalidate().then(() => { @@ -9,7 +11,5 @@ export default Ember.Route.extend(ApplicationRouteMixin, { return true; }); }, - }, - }); diff --git a/app/pods/not-found/route.js b/app/pods/not-found/route.js index 5be93bf..c14f72d 100644 --- a/app/pods/not-found/route.js +++ b/app/pods/not-found/route.js @@ -1,8 +1,10 @@ import Ember from 'ember'; -export default Ember.Route.extend({ +const { Route } = Ember; + +export default Route.extend({ redirect: function() { - let url = this.router.location.formatURL('/not-found'); + const url = this.router.location.formatURL('/not-found'); if (window.location.pathname !== url) { this.transitionTo('/not-found'); diff --git a/app/pods/protected/route.js b/app/pods/protected/route.js index b1cdc95..64bc25d 100644 --- a/app/pods/protected/route.js +++ b/app/pods/protected/route.js @@ -1,9 +1,12 @@ import Ember from 'ember'; import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; -export default Ember.Route.extend(AuthenticatedRouteMixin, { +const { Route } = Ember; + +export default Route.extend(AuthenticatedRouteMixin, { actions: { - error: function() { + error: function(err) { + console.log(err); this.transitionTo('/not-found'); }, diff --git a/app/serializers/application.js b/app/serializers/application.js index 52f555e..d40a2bf 100644 --- a/app/serializers/application.js +++ b/app/serializers/application.js @@ -1,19 +1,22 @@ import DS from 'ember-data'; import Ember from 'ember'; -export default DS.RESTSerializer.extend({ +const { RESTSerializer } = DS; +const { isNone } = Ember; + +export default RESTSerializer.extend({ isNewSerializerAPI: true, serializeBelongsTo: function(snapshot, json, relationship) { - var key = relationship.key; - var belongsTo = snapshot.belongsTo(key); + let key = relationship.key; + const belongsTo = snapshot.belongsTo(key); key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo", "serialize") : key; - json[key] = Ember.isNone(belongsTo) ? belongsTo : +belongsTo.record.id; + json[key] = isNone(belongsTo) ? belongsTo : +belongsTo.record.id; }, serializeHasMany: function(snapshot, json, relationship) { - var key = relationship.key; - var hasMany = snapshot.hasMany(key); + let key = relationship.key; + const hasMany = snapshot.hasMany(key); key = this.keyForRelationship ? this.keyForRelationship(key, "hasMany", "serialize") : key; json[key] = [];