From c70dd933c5c197c8a8383108d16d130fb4a3f14b Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 9 Jun 2015 14:32:15 -0800 Subject: [PATCH] Rough measurements search (WIP) --- app/models/measurement.js | 49 ++++++++----------- app/models/strain.js | 4 +- .../measurement-index-row/template.hbs | 6 +-- .../measurement-search-table/component.js | 32 ++++++++++++ .../measurement-search-table/template.hbs | 29 +++++++++++ app/pods/measurements/route.js | 36 ++++++++++++-- app/pods/measurements/template.hbs | 38 ++++++++++---- .../component-test.js | 19 +++++++ 8 files changed, 166 insertions(+), 47 deletions(-) create mode 100644 app/pods/components/measurement-search-table/component.js create mode 100644 app/pods/components/measurement-search-table/template.hbs create mode 100644 tests/unit/pods/components/measurement-search-table/component-test.js diff --git a/app/models/measurement.js b/app/models/measurement.js index 5ddb298..25e3072 100644 --- a/app/models/measurement.js +++ b/app/models/measurement.js @@ -1,5 +1,4 @@ import DS from 'ember-data'; -import Ember from 'ember'; export default DS.Model.extend({ strain: DS.belongsTo('strain', { async: true }), @@ -15,34 +14,28 @@ export default DS.Model.extend({ updatedAt: DS.attr('date'), createdBy: DS.attr('number'), updatedBy: DS.attr('number'), - computedType: Ember.computed('textMeasurementType', 'txtValue', 'numValue', function() { - if (this.get('textMeasurementType') && !this.get('txtValue') && !this.get('numValue')) { - return 'Fixed-text'; - } else if (!this.get('textMeasurementType') && this.get('txtValue') && !this.get('numValue')) { - return 'Free-text'; - } else if (!this.get('textMeasurementType') && !this.get('txtValue') && this.get('numValue')) { - return 'Numerical'; - } else { - return "error"; + // computedType: Ember.computed('textMeasurementType', 'txtValue', 'numValue', function() { + // if (this.get('textMeasurementType')) { + // return 'Fixed-text'; + // } + // if (this.get('txtValue')) { + // return 'Free-text'; + // } + // if (this.get('numValue')) { + // return 'Numerical'; + // } + // return "error"; + // }), + value: function() { + if (this.get('textMeasurementType')) { + return this.get('textMeasurementType'); } - }), - computedValue: Ember.computed('textMeasurementType', 'txtValue', 'numValue', function() { - var val; - if (this.get('computedType') === 'Fixed-text') { - val = this.get('textMeasurementType'); - } else if (this.get('computedType') === 'Free-text') { - val = this.get('txtValue'); - } else if (this.get('computedType') === 'Numerical') { - val = this.get('numValue'); - if (this.get('confidenceInterval')) { - val = val + ' ± ' + this.get('confidenceInterval'); - } - } else { - val = "error"; + if (this.get('txtValue')) { + return this.get('txtValue'); } - if (this.get('unitType')) { - val = val + ' ' + this.get('unitType'); + if (this.get('numValue')) { + return this.get('numValue'); } - return val; - }) + return "error"; + }.property('textMeasurementType', 'txtValue', 'numValue'), }); diff --git a/app/models/strain.js b/app/models/strain.js index 60d5d67..12c7196 100644 --- a/app/models/strain.js +++ b/app/models/strain.js @@ -17,7 +17,7 @@ export default DS.Model.extend({ updatedBy: DS.attr('number'), deletedBy: DS.attr('number'), totalMeasurements: DS.attr('number'), - fullName: Ember.computed('speciesName', 'strainName', function() { - return this.get('speciesName') + ' (' + this.get('strainName') + ')'; + fullName: Ember.computed('species.speciesName', 'strainName', function() { + return this.get('species.speciesName') + ' (strain ' + this.get('strainName') + ')'; }) }); diff --git a/app/pods/components/measurement-index-row/template.hbs b/app/pods/components/measurement-index-row/template.hbs index 23b22ab..fe9a6b6 100644 --- a/app/pods/components/measurement-index-row/template.hbs +++ b/app/pods/components/measurement-index-row/template.hbs @@ -1,11 +1,9 @@ - {{#link-to 'strains.show' data.strain.id}} - {{scientific-name strain=data.strain}} - {{/link-to}} + {{scientific-name strain=data.strain}} {{data.characteristic.characteristicName}} - {{{data.computedValue}}} + {{{data.value}}} diff --git a/app/pods/components/measurement-search-table/component.js b/app/pods/components/measurement-search-table/component.js new file mode 100644 index 0000000..693dd17 --- /dev/null +++ b/app/pods/components/measurement-search-table/component.js @@ -0,0 +1,32 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + isLoading: false, + actions: { + search: function() { + this.set('isLoading', true); + let strain = this.get('selectedStrain'); + let characteristic = this.get('selectedCharacteristic'); + if ((strain === 'all') && (characteristic === 'all')) { + this.store.findAll('measurement').then((measurements)=>{ + this.set('measurements', measurements); + }); + this.set('isLoading', false); + console.log(this.get('isLoading')); + return false; + } + let search = {}; + if (strain !== 'all') { + search['strain'] = strain; + } + if (characteristic !== 'all') { + search['characteristic'] = characteristic; + } + this.store.find('measurement', search).then((measurements)=>{ + this.set('measurements', measurements); + }); + this.set('isLoading', false); + return false; + } + }, +}); diff --git a/app/pods/components/measurement-search-table/template.hbs b/app/pods/components/measurement-search-table/template.hbs new file mode 100644 index 0000000..667312e --- /dev/null +++ b/app/pods/components/measurement-search-table/template.hbs @@ -0,0 +1,29 @@ +
+
+ {{search-button isLoading=isLoading action='search'}} +
+
+
+
+

Total matching measurements: {{measurements.length}}

+
+
+ +{{#if isLoading}} + {{loading-panel}} +{{else}} + + + + + + + + + + {{#each measurements as |measurement|}} + {{measurement-index-row data=measurement}} + {{/each}} + +
StrainCharacteristicValue
+{{/if}} diff --git a/app/pods/measurements/route.js b/app/pods/measurements/route.js index d393715..9dbfd63 100644 --- a/app/pods/measurements/route.js +++ b/app/pods/measurements/route.js @@ -4,18 +4,46 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi export default Ember.Route.extend(AuthenticatedRouteMixin, { model: function() { return Ember.RSVP.hash({ - measurements: this.store.findAll('measurement'), - species: this.store.findAll('species') + species: this.store.findAll('species'), + strains: this.store.findAll('strain'), + characteristics: this.store.findAll('characteristic'), }); }, setupController: function(controller, models) { var tableAttrs = [ { name: 'Strain', attr: 'strain.strainName' }, - { name: 'Characteristic', attr: 'characteristic.CharacteristicName' }, + { name: 'Characteristic', attr: 'characteristic.characteristicName' }, { name: 'Value', attr: 'computedValue'} ]; - controller.set('model', models); controller.set('tableAttrs', tableAttrs); controller.set('row', 'measurement-index-row'); + controller.set('measurements', []); + + // Set up search parameters + models.strains = models.strains.sortBy('fullName'); + let strains = models.strains.map((strain)=>{ + return Ember.Object.create({ + val: strain.get('id'), + lab: strain.get('fullName'), + }); + }); + strains.unshiftObjects(Ember.Object.create({ + val: 'all', + lab: 'All Strains', + })); + controller.set('strains', strains); + + models.characteristics = models.characteristics.sortBy('characteristicName'); + let characteristics = models.characteristics.map((characteristic)=>{ + return Ember.Object.create({ + val: characteristic.get('id'), + lab: characteristic.get('characteristicName'), + }); + }); + characteristics.unshiftObjects(Ember.Object.create({ + val: 'all', + lab: 'All Characteristics', + })); + controller.set('characteristics', characteristics); }, }); diff --git a/app/pods/measurements/template.hbs b/app/pods/measurements/template.hbs index 00d2ca6..87b6327 100644 --- a/app/pods/measurements/template.hbs +++ b/app/pods/measurements/template.hbs @@ -1,11 +1,31 @@

{{genus-name}} Measurements

-

Total measurements: {{model.length}}

+
+
+ Strains +
+
+ {{ + view "select" + content=strains + optionValuePath="content.val" + optionLabelPath="content.lab" + value=selectedStrain + }} +
+
+
+
+ Characteristics +
+
+ {{ + view "select" + content=characteristics + optionValuePath="content.val" + optionLabelPath="content.lab" + value=selectedCharacteristic + }} +
+
-{{ - view "select" - content=model.species - optionValuePath="content.id" - optionLabelPath="content.speciesName" -}} - -{{sortable-table content=model.measurements tableAttrs=tableAttrs row=row}} +{{measurement-search-table}} diff --git a/tests/unit/pods/components/measurement-search-table/component-test.js b/tests/unit/pods/components/measurement-search-table/component-test.js new file mode 100644 index 0000000..6ec5359 --- /dev/null +++ b/tests/unit/pods/components/measurement-search-table/component-test.js @@ -0,0 +1,19 @@ +import { moduleForComponent, test } from 'ember-qunit'; + +moduleForComponent('measurement-search-table', 'Unit | Component | measurement search table', { + // Specify the other units that are required for this test + // needs: ['component:foo', 'helper:bar'], + unit: true +}); + +test('it renders', function(assert) { + assert.expect(2); + + // Creates the component instance + var component = this.subject(); + assert.equal(component._state, 'preRender'); + + // Renders the component to the page + this.render(); + assert.equal(component._state, 'inDOM'); +});