Rough cut: compare.
This commit is contained in:
		
							parent
							
								
									adda1291c6
								
							
						
					
					
						commit
						30f8e89c40
					
				
					 10 changed files with 140 additions and 9 deletions
				
			
		
							
								
								
									
										8
									
								
								app/helpers/get-property.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								app/helpers/get-property.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
 | 
			
		||||
// This will be unneccesary when ember 2.0 lands
 | 
			
		||||
export function getProperty(params) {
 | 
			
		||||
  return Ember.get(params[0], params[1]);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default Ember.HTMLBars.makeBoundHelper(getProperty);
 | 
			
		||||
| 
						 | 
				
			
			@ -4,18 +4,21 @@
 | 
			
		|||
    {{/link-to}}
 | 
			
		||||
    {{#if session.isAuthenticated}}
 | 
			
		||||
      <ul>
 | 
			
		||||
        {{#link-to 'compare' tagName='li' href=false}}
 | 
			
		||||
          {{link-to 'Compare' 'compare'}}
 | 
			
		||||
        {{/link-to}}
 | 
			
		||||
        {{#link-to 'measurements' tagName='li' href=false}}
 | 
			
		||||
          {{link-to 'Measurements' 'measurements'}}
 | 
			
		||||
        {{/link-to}}
 | 
			
		||||
        {{#link-to 'characteristics' tagName='li' href=false}}
 | 
			
		||||
          {{link-to 'Characteristics' 'characteristics'}}
 | 
			
		||||
        {{/link-to}}
 | 
			
		||||
        {{#link-to 'species' tagName='li' href=false}}
 | 
			
		||||
          {{link-to 'Species' 'species'}}
 | 
			
		||||
        {{/link-to}}
 | 
			
		||||
        {{#link-to 'strains' tagName='li' href=false}}
 | 
			
		||||
          {{link-to 'Strains' 'strains'}}
 | 
			
		||||
        {{/link-to}}
 | 
			
		||||
        {{#link-to 'characteristics' tagName='li' href=false}}
 | 
			
		||||
          {{link-to 'Characteristics' 'characteristics'}}
 | 
			
		||||
        {{/link-to}}
 | 
			
		||||
        {{#link-to 'measurements' tagName='li' href=false}}
 | 
			
		||||
          {{link-to 'Measurements' 'measurements'}}
 | 
			
		||||
        {{/link-to}}
 | 
			
		||||
        {{#link-to 'about' tagName='li' href=false}}
 | 
			
		||||
          {{link-to 'About' 'about'}}
 | 
			
		||||
        {{/link-to}}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										47
									
								
								app/pods/compare/controller.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								app/pods/compare/controller.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,47 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
 | 
			
		||||
export default Ember.Controller.extend({
 | 
			
		||||
  strains: [],
 | 
			
		||||
  dataEmpty: true,
 | 
			
		||||
 | 
			
		||||
  actions: {
 | 
			
		||||
    search: function(selectedStrains, selectedCharacteristics) {
 | 
			
		||||
      if (Ember.isEmpty(selectedStrains) || Ember.isEmpty(selectedCharacteristics)) {
 | 
			
		||||
        this.set('dataEmpty', true);
 | 
			
		||||
        return false;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      let data = Ember.A();
 | 
			
		||||
      let strains = [];
 | 
			
		||||
      selectedStrains.forEach((strain) => {
 | 
			
		||||
        let s = this.store.getById('strain', strain);
 | 
			
		||||
        strains.pushObject(s);
 | 
			
		||||
      })
 | 
			
		||||
      this.set('strains', strains);
 | 
			
		||||
 | 
			
		||||
      this.store.find('measurement', {
 | 
			
		||||
        strain: selectedStrains,
 | 
			
		||||
        characteristic: selectedCharacteristics,
 | 
			
		||||
      }).then((measurements) => {
 | 
			
		||||
        selectedCharacteristics.forEach((characteristic) => {
 | 
			
		||||
          let char = this.store.getById('characteristic', characteristic);
 | 
			
		||||
          let row = {
 | 
			
		||||
            characteristic: char.get('characteristicName'),
 | 
			
		||||
          };
 | 
			
		||||
          selectedStrains.forEach((strain) => {
 | 
			
		||||
            let meas = measurements.filterBy('strain.id', strain)
 | 
			
		||||
              .filterBy('characteristic.id', characteristic);
 | 
			
		||||
            if (!Ember.isEmpty(meas)) {
 | 
			
		||||
              row[strain] = meas[0].get('value');
 | 
			
		||||
            } else {
 | 
			
		||||
              row[strain] = '';
 | 
			
		||||
            }
 | 
			
		||||
          });
 | 
			
		||||
          data.pushObject(row);
 | 
			
		||||
        });
 | 
			
		||||
        this.set('data', data);
 | 
			
		||||
        this.set('dataEmpty', false);
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
							
								
								
									
										4
									
								
								app/pods/compare/route.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								app/pods/compare/route.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
 | 
			
		||||
 | 
			
		||||
export default Ember.Route.extend(AuthenticatedRouteMixin);
 | 
			
		||||
							
								
								
									
										32
									
								
								app/pods/compare/template.hbs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								app/pods/compare/template.hbs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,32 @@
 | 
			
		|||
<h2>{{genus-name}} - Compare Strains</h2>
 | 
			
		||||
 | 
			
		||||
{{measurement-search-panel search='search'}}
 | 
			
		||||
 | 
			
		||||
{{#if dataEmpty}}
 | 
			
		||||
  <div class="flakes-message information">
 | 
			
		||||
    Please select one or more strains and one or more characteristics.
 | 
			
		||||
  </div>
 | 
			
		||||
{{else}}
 | 
			
		||||
<div>
 | 
			
		||||
  <table class="flakes-table">
 | 
			
		||||
    <thead>
 | 
			
		||||
      <tr>
 | 
			
		||||
        <th>Characteristic</th>
 | 
			
		||||
        {{#each strains as |strain|}}
 | 
			
		||||
          <th>{{strain.fullNameMU}}</th>
 | 
			
		||||
        {{/each}}
 | 
			
		||||
      </tr>
 | 
			
		||||
    </thead>
 | 
			
		||||
    <tbody>
 | 
			
		||||
      {{#each data as |row|}}
 | 
			
		||||
        <tr>
 | 
			
		||||
          <td>{{row.characteristic}}</td>
 | 
			
		||||
          {{#each strains as |strain|}}
 | 
			
		||||
            <td>{{get-property row strain.id}}</td>
 | 
			
		||||
          {{/each}}
 | 
			
		||||
        </tr>
 | 
			
		||||
      {{/each}}
 | 
			
		||||
    </tbody>
 | 
			
		||||
  </table>
 | 
			
		||||
</div>
 | 
			
		||||
{{/if}}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,8 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin';
 | 
			
		||||
 | 
			
		||||
export default Ember.Route.extend(AuthenticatedRouteMixin);
 | 
			
		||||
export default Ember.Route.extend(AuthenticatedRouteMixin, {
 | 
			
		||||
  beforeModel: function() {
 | 
			
		||||
    this.transitionTo('compare');
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,8 @@ Router.map(function() {
 | 
			
		|||
  this.route('about');
 | 
			
		||||
  this.route('characteristics');
 | 
			
		||||
  this.route('users');
 | 
			
		||||
  this.route('measurements');
 | 
			
		||||
  this.route('compare');
 | 
			
		||||
 | 
			
		||||
  this.route('species', function() {
 | 
			
		||||
    this.route('new');
 | 
			
		||||
| 
						 | 
				
			
			@ -19,8 +21,6 @@ Router.map(function() {
 | 
			
		|||
    this.route('new');
 | 
			
		||||
    this.route('show', { path: ':strain_id' });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  this.route('measurements');
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
export default Router;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue