cleaning up measurements table
This commit is contained in:
		
							parent
							
								
									046fea2dbb
								
							
						
					
					
						commit
						33d325a4b0
					
				
					 14 changed files with 102 additions and 260 deletions
				
			
		| 
						 | 
				
			
			@ -1,26 +0,0 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
 | 
			
		||||
export default Ember.Component.extend({
 | 
			
		||||
  actions: {
 | 
			
		||||
    search: function() {
 | 
			
		||||
      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);
 | 
			
		||||
        });
 | 
			
		||||
        return;
 | 
			
		||||
      }
 | 
			
		||||
      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);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -1,34 +0,0 @@
 | 
			
		|||
<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}}
 | 
			
		||||
  {{!-- This doesn't work yet, something is blocking --}}
 | 
			
		||||
  {{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|}}
 | 
			
		||||
        <tr>
 | 
			
		||||
          <td>{{{measurement.strain.fullNameMU}}}</td>
 | 
			
		||||
          <td>{{measurement.characteristic.characteristicName}}</td>
 | 
			
		||||
          <td>{{{measurement.value}}}</td>
 | 
			
		||||
        </tr>
 | 
			
		||||
      {{/each}}
 | 
			
		||||
    </tbody>
 | 
			
		||||
  </table>
 | 
			
		||||
{{/if}}
 | 
			
		||||
							
								
								
									
										15
									
								
								app/pods/measurements/controller.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								app/pods/measurements/controller.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
 | 
			
		||||
export default Ember.Controller.extend({
 | 
			
		||||
  actions: {
 | 
			
		||||
    search: function() {
 | 
			
		||||
      let search = {
 | 
			
		||||
        strain: this.get('selectedStrains'),
 | 
			
		||||
        characteristic: this.get('selectedCharacteristics'),
 | 
			
		||||
      };
 | 
			
		||||
      this.store.find('measurement', search).then((measurements)=>{
 | 
			
		||||
        this.set('measurements', measurements);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -4,39 +4,28 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi
 | 
			
		|||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
 | 
			
		||||
  model: function() {
 | 
			
		||||
    return Ember.RSVP.hash({
 | 
			
		||||
      species: this.store.findAll('species'),
 | 
			
		||||
      species: this.store.findAll('species'), // need this bc async
 | 
			
		||||
      strains: this.store.findAll('strain'),
 | 
			
		||||
      characteristics: this.store.findAll('characteristic'),
 | 
			
		||||
    });
 | 
			
		||||
  },
 | 
			
		||||
  setupController: function(controller, models) {
 | 
			
		||||
    controller.set('measurements', []);
 | 
			
		||||
 | 
			
		||||
    // Set up search parameters
 | 
			
		||||
    models.strains = models.strains.sortBy('fullName');
 | 
			
		||||
    let strains = models.strains.map((strain)=>{
 | 
			
		||||
      return Ember.Object.create({
 | 
			
		||||
        id: strain.get('id'),
 | 
			
		||||
        text: strain.get('fullName'),
 | 
			
		||||
      });
 | 
			
		||||
    });
 | 
			
		||||
    strains.unshiftObjects(Ember.Object.create({
 | 
			
		||||
      id: 'all',
 | 
			
		||||
      text: 'All Strains',
 | 
			
		||||
    }));
 | 
			
		||||
    controller.set('strains', strains);
 | 
			
		||||
    let selects = [
 | 
			
		||||
      { model: 'strains', id: 'id', text: 'fullName' },
 | 
			
		||||
      { model: 'characteristics', id: 'id', text: 'characteristicName' },
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    models.characteristics = models.characteristics.sortBy('characteristicName');
 | 
			
		||||
    let characteristics = models.characteristics.map((characteristic)=>{
 | 
			
		||||
      return Ember.Object.create({
 | 
			
		||||
        id: characteristic.get('id'),
 | 
			
		||||
        text: characteristic.get('characteristicName'),
 | 
			
		||||
    selects.forEach((item, index, enumerable) => {
 | 
			
		||||
      models[item.model] = models[item.model].sortBy(item.text);
 | 
			
		||||
      let temp = models[item.model].map((data) => {
 | 
			
		||||
        return Ember.Object.create({
 | 
			
		||||
          id: data.get(item.id),
 | 
			
		||||
          text: data.get(item.text),
 | 
			
		||||
        });
 | 
			
		||||
      });
 | 
			
		||||
      controller.set(item.model, temp);
 | 
			
		||||
    });
 | 
			
		||||
    characteristics.unshiftObjects(Ember.Object.create({
 | 
			
		||||
      id: 'all',
 | 
			
		||||
      text: 'All Characteristics',
 | 
			
		||||
    }));
 | 
			
		||||
    controller.set('characteristics', characteristics);
 | 
			
		||||
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,37 +1,61 @@
 | 
			
		|||
<h2>{{genus-name}} Measurements</h2>
 | 
			
		||||
<div class="grid-12 gutter-50">
 | 
			
		||||
  <div class="span-4">
 | 
			
		||||
    Strains
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="span-8">
 | 
			
		||||
    {{
 | 
			
		||||
      select-2
 | 
			
		||||
      multiple=true
 | 
			
		||||
      content=strains
 | 
			
		||||
      value=selectedStrains
 | 
			
		||||
      optionValuePath="id"
 | 
			
		||||
      placeholder="Choose a strain"
 | 
			
		||||
    }}
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
<div class="grid-12 gutter-50">
 | 
			
		||||
  <div class="span-4">
 | 
			
		||||
    Characteristics
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="span-8">
 | 
			
		||||
    {{
 | 
			
		||||
      select-2
 | 
			
		||||
      multiple=true
 | 
			
		||||
      content=characteristics
 | 
			
		||||
      value=selectedCharacteristic
 | 
			
		||||
      optionValuePath="id"
 | 
			
		||||
      placeholder="Choose a characteristic"
 | 
			
		||||
    }}
 | 
			
		||||
<div class="grid-1 gutter-50">
 | 
			
		||||
  <div class="span-1">
 | 
			
		||||
    <fieldset>
 | 
			
		||||
      <form>
 | 
			
		||||
        <ul>
 | 
			
		||||
          <li>
 | 
			
		||||
            <label>Species</label>
 | 
			
		||||
            {{
 | 
			
		||||
              select-2
 | 
			
		||||
              multiple=true
 | 
			
		||||
              content=strains
 | 
			
		||||
              value=selectedStrains
 | 
			
		||||
              optionValuePath="id"
 | 
			
		||||
              placeholder="All strains"
 | 
			
		||||
            }}
 | 
			
		||||
          </li>
 | 
			
		||||
          <li>
 | 
			
		||||
            <label>Characteristics</label>
 | 
			
		||||
            {{
 | 
			
		||||
              select-2
 | 
			
		||||
              multiple=true
 | 
			
		||||
              content=characteristics
 | 
			
		||||
              value=selectedCharacteristics
 | 
			
		||||
              optionValuePath="id"
 | 
			
		||||
              placeholder="Choose a characteristic"
 | 
			
		||||
            }}
 | 
			
		||||
          </li>
 | 
			
		||||
          <li>
 | 
			
		||||
            {{search-button isLoading=isLoading action='search'}}
 | 
			
		||||
          </li>
 | 
			
		||||
        </ul>
 | 
			
		||||
      </form>
 | 
			
		||||
    </fieldset>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
{{
 | 
			
		||||
  measurement-search-table
 | 
			
		||||
  selectedStrain=selectedStrain
 | 
			
		||||
  selectedCharacteristic=selectedCharacteristic
 | 
			
		||||
}}
 | 
			
		||||
<div class="grid-12 gutter-50">
 | 
			
		||||
  <div class="span-12">
 | 
			
		||||
    <h3>Total matching measurements: {{measurements.length}}</h3>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<table class="flakes-table">
 | 
			
		||||
  <thead>
 | 
			
		||||
    <tr>
 | 
			
		||||
      <th>Strain</th>
 | 
			
		||||
      <th>Characteristic</th>
 | 
			
		||||
      <th>Value</th>
 | 
			
		||||
    </tr>
 | 
			
		||||
  </thead>
 | 
			
		||||
  <tbody>
 | 
			
		||||
    {{#each measurements as |measurement|}}
 | 
			
		||||
      <tr>
 | 
			
		||||
        <td>{{{measurement.strain.fullNameMU}}}</td>
 | 
			
		||||
        <td>{{measurement.characteristic.characteristicName}}</td>
 | 
			
		||||
        <td>{{{measurement.value}}}</td>
 | 
			
		||||
      </tr>
 | 
			
		||||
    {{/each}}
 | 
			
		||||
  </tbody>
 | 
			
		||||
</table>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,10 @@
 | 
			
		|||
  padding: 2em 0em 0em 0em;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.select2-container {
 | 
			
		||||
  width: 100%;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.flakes-table thead tr th span {
 | 
			
		||||
  cursor: pointer;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue