Refactor compare
This commit is contained in:
parent
6ad9ad17b8
commit
8bdc31f99e
7 changed files with 145 additions and 86 deletions
50
app/pods/protected/compare/results/controller.js
Normal file
50
app/pods/protected/compare/results/controller.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
queryParams: ['strain_ids', 'characteristic_ids'],
|
||||
|
||||
strains: function() {
|
||||
let strains = [];
|
||||
let strain_ids = this.get('strain_ids').split(',');
|
||||
strain_ids.forEach((id) => {
|
||||
strains.push(this.store.peekRecord('strain', id));
|
||||
})
|
||||
return strains;
|
||||
}.property('strain_ids'),
|
||||
|
||||
characteristics: function() {
|
||||
let characteristics = [];
|
||||
let characteristic_ids = this.get('characteristic_ids').split(',');
|
||||
characteristic_ids.forEach((id) => {
|
||||
characteristics.push(this.store.peekRecord('characteristic', id));
|
||||
})
|
||||
return characteristics;
|
||||
}.property('characteristic_ids'),
|
||||
|
||||
// Set up data table matrix
|
||||
data: function() {
|
||||
let characteristics = this.get('characteristics');
|
||||
let strains = this.get('strains');
|
||||
let measurements = this.get('model');
|
||||
let data = Ember.A();
|
||||
|
||||
characteristics.forEach((characteristic) => {
|
||||
let row = {
|
||||
characteristic: characteristic.get('characteristicName'),
|
||||
};
|
||||
|
||||
strains.forEach((strain) => {
|
||||
let meas = measurements.filterBy('strain.id', strain.get('id'))
|
||||
.filterBy('characteristic.id', characteristic.get('id'));
|
||||
if (!Ember.isEmpty(meas)) {
|
||||
row[strain.get('id')] = meas[0].get('value');
|
||||
} else {
|
||||
row[strain.get('id')] = '';
|
||||
}
|
||||
});
|
||||
data.pushObject(row);
|
||||
});
|
||||
return data;
|
||||
}.property('characteristics', 'strains'),
|
||||
|
||||
});
|
11
app/pods/protected/compare/results/route.js
Normal file
11
app/pods/protected/compare/results/route.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Route.extend({
|
||||
model: function(params) {
|
||||
let compare = this.controllerFor('protected.compare');
|
||||
compare.set('selectedStrains', params.strain_ids);
|
||||
compare.set('selectedCharacteristics', params.characteristic_ids);
|
||||
return this.store.query('measurement', params);
|
||||
},
|
||||
|
||||
});
|
26
app/pods/protected/compare/results/template.hbs
Normal file
26
app/pods/protected/compare/results/template.hbs
Normal file
|
@ -0,0 +1,26 @@
|
|||
<div class="overflow-div">
|
||||
<table class="flakes-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Characteristic</th>
|
||||
{{#each strains as |strain|}}
|
||||
<th>
|
||||
{{#link-to 'protected.strains.show' strain.id classBinding="data.typeStrain:type-strain"}}
|
||||
{{strain.fullNameMU}}
|
||||
{{/link-to}}
|
||||
</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>
|
Reference in a new issue