Rough measurements search (WIP)

This commit is contained in:
Matthew Dillon 2015-06-09 14:32:15 -08:00
parent 1976b49608
commit c70dd933c5
8 changed files with 166 additions and 47 deletions

View file

@ -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>

View 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;
}
},
});

View 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}}

View file

@ -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);
},
});

View file

@ -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}}