Rough measurements search (WIP)
This commit is contained in:
		
							parent
							
								
									1976b49608
								
							
						
					
					
						commit
						c70dd933c5
					
				
					 8 changed files with 166 additions and 47 deletions
				
			
		| 
						 | 
				
			
			@ -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'),
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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') + ')';
 | 
			
		||||
  })
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,9 @@
 | 
			
		|||
<td>
 | 
			
		||||
  {{#link-to 'strains.show' data.strain.id}}
 | 
			
		||||
    {{scientific-name strain=data.strain}}
 | 
			
		||||
  {{/link-to}}
 | 
			
		||||
  {{scientific-name strain=data.strain}}
 | 
			
		||||
</td>
 | 
			
		||||
<td>
 | 
			
		||||
  {{data.characteristic.characteristicName}}
 | 
			
		||||
</td>
 | 
			
		||||
<td>
 | 
			
		||||
  {{{data.computedValue}}}
 | 
			
		||||
  {{{data.value}}}
 | 
			
		||||
</td>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										32
									
								
								app/pods/components/measurement-search-table/component.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								app/pods/components/measurement-search-table/component.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										29
									
								
								app/pods/components/measurement-search-table/template.hbs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/pods/components/measurement-search-table/template.hbs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
<div class="grid-12 gutter-50">
 | 
			
		||||
  <div class="span-12">
 | 
			
		||||
    {{search-button isLoading=isLoading action='search'}}
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
<div class="grid-12 gutter-50">
 | 
			
		||||
  <div class="span-12">
 | 
			
		||||
    <h3>Total matching measurements: {{measurements.length}}</h3>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
{{#if isLoading}}
 | 
			
		||||
  {{loading-panel}}
 | 
			
		||||
{{else}}
 | 
			
		||||
  <table class="flakes-table">
 | 
			
		||||
    <thead>
 | 
			
		||||
      <tr>
 | 
			
		||||
        <th>Strain</th>
 | 
			
		||||
        <th>Characteristic</th>
 | 
			
		||||
        <th>Value</th>
 | 
			
		||||
      </tr>
 | 
			
		||||
    </thead>
 | 
			
		||||
    <tbody>
 | 
			
		||||
      {{#each measurements as |measurement|}}
 | 
			
		||||
        {{measurement-index-row data=measurement}}
 | 
			
		||||
      {{/each}}
 | 
			
		||||
    </tbody>
 | 
			
		||||
  </table>
 | 
			
		||||
{{/if}}
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,31 @@
 | 
			
		|||
<h2>{{genus-name}} Measurements</h2>
 | 
			
		||||
<h3>Total measurements: {{model.length}}</h3>
 | 
			
		||||
<div class="grid-12 gutter-50">
 | 
			
		||||
  <div class="span-4">
 | 
			
		||||
    Strains
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="span-8">
 | 
			
		||||
    {{
 | 
			
		||||
      view "select"
 | 
			
		||||
      content=strains
 | 
			
		||||
      optionValuePath="content.val"
 | 
			
		||||
      optionLabelPath="content.lab"
 | 
			
		||||
      value=selectedStrain
 | 
			
		||||
    }}
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
<div class="grid-12 gutter-50">
 | 
			
		||||
  <div class="span-4">
 | 
			
		||||
    Characteristics
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="span-8">
 | 
			
		||||
    {{
 | 
			
		||||
      view "select"
 | 
			
		||||
      content=characteristics
 | 
			
		||||
      optionValuePath="content.val"
 | 
			
		||||
      optionLabelPath="content.lab"
 | 
			
		||||
      value=selectedCharacteristic
 | 
			
		||||
    }}
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
{{
 | 
			
		||||
  view "select"
 | 
			
		||||
  content=model.species
 | 
			
		||||
  optionValuePath="content.id"
 | 
			
		||||
  optionLabelPath="content.speciesName"
 | 
			
		||||
}}
 | 
			
		||||
 | 
			
		||||
{{sortable-table content=model.measurements tableAttrs=tableAttrs row=row}}
 | 
			
		||||
{{measurement-search-table}}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue