From fbfbdf19d1bbddf92ddb1b38137b2136c8401a28 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 10 Nov 2015 15:42:20 -0700 Subject: [PATCH] WIP --- app/pods/protected/strains/edit/controller.js | 8 ++++ app/pods/protected/strains/edit/template.hbs | 1 + .../measurements-table-row/component.js | 3 +- .../strains/measurements-table/component.js | 47 ++++++++++--------- .../strains/measurements-table/template.hbs | 20 ++++---- .../strains/show/strain-card/template.hbs | 2 +- .../strains/strain-form/component.js | 5 ++ .../strains/strain-form/template.hbs | 5 +- 8 files changed, 54 insertions(+), 37 deletions(-) diff --git a/app/pods/protected/strains/edit/controller.js b/app/pods/protected/strains/edit/controller.js index a44ea40..d3640c7 100644 --- a/app/pods/protected/strains/edit/controller.js +++ b/app/pods/protected/strains/edit/controller.js @@ -7,4 +7,12 @@ export default Controller.extend(SaveModel, { // Required for SaveModel mixin fallbackRouteSave: 'protected.strains.show', fallbackRouteCancel: 'protected.strains.show', + + actions: { + addCharacteristic: function() { + return this.store.createRecord('measurement', { + characteristic: this.store.createRecord('characteristic', { sortOrder: -999 }), + }); + }, + }, }); diff --git a/app/pods/protected/strains/edit/template.hbs b/app/pods/protected/strains/edit/template.hbs index 1ae2d5b..c36aa54 100644 --- a/app/pods/protected/strains/edit/template.hbs +++ b/app/pods/protected/strains/edit/template.hbs @@ -2,6 +2,7 @@ protected/strains/strain-form strain=model speciesList=speciesList + add-characteristic=(action "addCharacteristic") on-save=(action "save") on-cancel=(action "cancel") }} diff --git a/app/pods/protected/strains/measurements-table-row/component.js b/app/pods/protected/strains/measurements-table-row/component.js index 8ad1ba7..c6983d7 100644 --- a/app/pods/protected/strains/measurements-table-row/component.js +++ b/app/pods/protected/strains/measurements-table-row/component.js @@ -1,11 +1,12 @@ import Ember from 'ember'; -import ajaxError from '../../../../../utils/ajax-error'; +import ajaxError from '../../../../utils/ajax-error'; const { Component } = Ember; export default Component.extend({ tagName: 'tr', isEditing: false, + allCharacteristics: null, oldCharacteristicId: function() { let json = this.get('row').toJSON(); diff --git a/app/pods/protected/strains/measurements-table/component.js b/app/pods/protected/strains/measurements-table/component.js index 6cbf880..a83e25e 100644 --- a/app/pods/protected/strains/measurements-table/component.js +++ b/app/pods/protected/strains/measurements-table/component.js @@ -1,48 +1,49 @@ import Ember from 'ember'; -const { Component } = Ember; +const { Component, computed } = Ember; +const { sort } = computed; export default Component.extend({ - measurementsPresent: function() { - return this.get('model.measurements.length') > 0; - }.property('model.measurements'), - - fetchCharacteristics: function() { - if (this.get('canEdit')) { - this.store.findAll('characteristic'); - } - }.on('didInsertElement'), + // Passed in + strain: null, + allCharacteristics: null, + canEdit: false, + canAdd: false, + "add-characteristic": null, + // Properties sortParams: ['characteristic.characteristicTypeName', 'characteristic.sortOrder', 'characteristic.characteristicName'], sortAsc: true, paramsChanged: false, - sortedMeasurements: Ember.computed.sort('model.measurements', 'sortParams'), + sortedMeasurements: sort('strain.measurements', 'sortParams'), + measurementsPresent: computed('strain.measurements', function() { + return this.get('strain.measurements.length') > 0; + }), + + // TODO: remove this + // fetchCharacteristics: function() { + // if (this.get('canEdit')) { + // this.store.findAll('characteristic'); + // } + // }.on('didInsertElement'), actions: { addCharacteristic: function() { - const c = this.store.createRecord('characteristic', { - sortOrder: -999 - }); - const m = this.store.createRecord('measurement', { - characteristic: c - }); - this.get('model.measurements').addObject(m); + const newChar = this.attrs['add-characteristic'](); + this.get('strain.measurements').addObject(newChar); }, changeSortParam: function(col) { - let sort = this.get('sortAsc') ? 'asc' : 'desc'; - let sortCol = `${col}:${sort}`; - this.set('sortParams', [sortCol]); + const sort = this.get('sortAsc') ? 'asc' : 'desc'; + this.set('sortParams', [`${col}:${sort}`]); 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/measurements-table/template.hbs b/app/pods/protected/strains/measurements-table/template.hbs index 25b0c27..3f635f1 100644 --- a/app/pods/protected/strains/measurements-table/template.hbs +++ b/app/pods/protected/strains/measurements-table/template.hbs @@ -1,17 +1,17 @@ {{#if canAdd}} -
- -

+
+ +

{{/if}} {{#if measurementsPresent}} -{{#if paramsChanged}} - -{{/if}} + {{#if paramsChanged}} + + {{/if}} {{#if canEdit}} diff --git a/app/pods/protected/strains/show/strain-card/template.hbs b/app/pods/protected/strains/show/strain-card/template.hbs index 86e281f..995326a 100644 --- a/app/pods/protected/strains/show/strain-card/template.hbs +++ b/app/pods/protected/strains/show/strain-card/template.hbs @@ -75,7 +75,7 @@
{{ protected/strains/measurements-table - model=strain + strain=strain canEdit=false canAdd=false }} diff --git a/app/pods/protected/strains/strain-form/component.js b/app/pods/protected/strains/strain-form/component.js index b5544f3..11ef764 100644 --- a/app/pods/protected/strains/strain-form/component.js +++ b/app/pods/protected/strains/strain-form/component.js @@ -14,6 +14,7 @@ export default Component.extend(SetupMetaData, { "on-save": null, "on-cancel": null, "on-update": null, + "add-characteristic": null, // Property mapping propertiesList: ['strainName', 'typeStrain', 'species', 'isolatedFrom', 'accessionNumbers', 'genbank', 'wholeGenomeSequence', 'notes'], @@ -54,6 +55,10 @@ export default Component.extend(SetupMetaData, { return this.attrs['on-cancel'](); }, + addCharacteristic: function() { + return this.attrs['add-characteristic'](); + }, + strainNameDidChange: function(value) { this.updateField('strainName', value); }, diff --git a/app/pods/protected/strains/strain-form/template.hbs b/app/pods/protected/strains/strain-form/template.hbs index 908020f..21e5bcf 100644 --- a/app/pods/protected/strains/strain-form/template.hbs +++ b/app/pods/protected/strains/strain-form/template.hbs @@ -52,9 +52,10 @@
{{ protected/strains/measurements-table - model=strain + strain=strain + add-characteristic=(action "addCharacteristic") canEdit=strain.canEdit - canAdd=canAdd + canAdd=metaData.canAdd }}