From e6c6cac212b93ee405716f034532724e3fd7f463 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 5 Nov 2015 12:40:10 -0700 Subject: [PATCH] MetaData mixin --- app/mixins/setup-metadata.js | 14 ++++++++++++++ .../species/index/species-table/component.js | 14 +++----------- .../protected/species/species-form/component.js | 13 +++---------- 3 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 app/mixins/setup-metadata.js diff --git a/app/mixins/setup-metadata.js b/app/mixins/setup-metadata.js new file mode 100644 index 0000000..183f93f --- /dev/null +++ b/app/mixins/setup-metadata.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; + +const { Mixin, inject: { service }} = Ember; + +export default Mixin.create({ + currentUser: service('session-account'), + metaData: null, + + setupMetaDataOnInit: Ember.on('init', function() { + this.get('currentUser.account').then((user) => { + this.set('metaData', user.get('metaData')); + }); + }), +}); diff --git a/app/pods/protected/species/index/species-table/component.js b/app/pods/protected/species/index/species-table/component.js index fea0c08..d58f509 100644 --- a/app/pods/protected/species/index/species-table/component.js +++ b/app/pods/protected/species/index/species-table/component.js @@ -1,19 +1,11 @@ import Ember from 'ember'; +import SetupMetaData from '../../../../../mixins/setup-metadata'; -const { Component, inject: { service }} = Ember; +const { Component } = Ember; -export default Component.extend({ - currentUser: service('session-account'), - - metaData: null, +export default Component.extend(SetupMetaData, { species: null, - setupMetaDataOnInit: Ember.on('init', function() { - this.get('currentUser.account').then((user) => { - this.set('metaData', user.get('metaData')); - }); - }), - sortParams: ['speciesName', 'strainCount'], sortedSpecies: Ember.computed.sort('species', 'sortParams'), diff --git a/app/pods/protected/species/species-form/component.js b/app/pods/protected/species/species-form/component.js index 290e6e5..d7d319f 100644 --- a/app/pods/protected/species/species-form/component.js +++ b/app/pods/protected/species/species-form/component.js @@ -1,10 +1,9 @@ import Ember from 'ember'; +import SetupMetaData from '../../../../mixins/setup-metadata'; -const { Component, inject: { service } } = Ember; - -export default Component.extend({ - currentUser: service('session-account'), +const { Component } = Ember; +export default Component.extend(SetupMetaData, { // Read-only attributes species: null, isNew: null, @@ -31,12 +30,6 @@ export default Component.extend({ this.set('isNew', this.get('species.isNew')); }), - setupMetaDataOnInit: Ember.on('init', function() { - this.get('currentUser.account').then((user) => { - this.set('metaData', user.get('metaData')); - }); - }), - updateField: function(property, value) { this.set(property, value); // Manually compare against passed in value