Refactor meas search -> component
This commit is contained in:
parent
3c1fca43b8
commit
adda1291c6
6 changed files with 106 additions and 72 deletions
48
app/pods/components/measurement-search-panel/component.js
Normal file
48
app/pods/components/measurement-search-panel/component.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
export default Ember.Component.extend({
|
||||
classNames: ["grid-1", "gutter-50"],
|
||||
|
||||
setup: function() {
|
||||
Ember.RSVP.hash({
|
||||
species: this.store.findAll('species'),
|
||||
strains: this.store.findAll('strain'),
|
||||
characteristicTypes: this.store.findAll('characteristic-type'),
|
||||
characteristics: this.store.findAll('characteristic'),
|
||||
}).then((models) => {
|
||||
// Set up search parameters
|
||||
let selects = [
|
||||
{ model: 'species', id: 'id', text: 'speciesName',
|
||||
children: 'strains', cid: 'id', ctext: 'fullName' },
|
||||
{ model: 'characteristicTypes', id: 'id', text: 'characteristicTypeName',
|
||||
children: 'characteristics', cid: 'id', ctext: 'characteristicName' },
|
||||
];
|
||||
|
||||
selects.forEach((item /*, index, enumerable*/) => {
|
||||
models[item.model] = models[item.model].filter((i) => {
|
||||
if (!Ember.isEmpty(i.get(item.children))) { return true; }
|
||||
});
|
||||
models[item.model] = models[item.model].sortBy(item.text);
|
||||
let temp = models[item.model].map((data) => {
|
||||
let temp_children = [];
|
||||
data.get(item.children).forEach((child) => {
|
||||
temp_children.push({id: child.get(item.cid), text: child.get(item.ctext)});
|
||||
});
|
||||
return {
|
||||
text: data.get(item.text),
|
||||
children: temp_children,
|
||||
};
|
||||
});
|
||||
this.set(item.model, temp);
|
||||
});
|
||||
});
|
||||
}.on('init'),
|
||||
|
||||
actions: {
|
||||
search: function() {
|
||||
let strains = this.get('selectedStrains'),
|
||||
characteristics = this.get('selectedCharacteristics');
|
||||
this.sendAction('search', strains, characteristics);
|
||||
},
|
||||
},
|
||||
});
|
33
app/pods/components/measurement-search-panel/template.hbs
Normal file
33
app/pods/components/measurement-search-panel/template.hbs
Normal file
|
@ -0,0 +1,33 @@
|
|||
<div class="span-1">
|
||||
<fieldset>
|
||||
<form>
|
||||
<ul>
|
||||
<li>
|
||||
<label>Strains</label>
|
||||
{{
|
||||
select-2
|
||||
multiple=true
|
||||
content=species
|
||||
value=selectedStrains
|
||||
optionValuePath="id"
|
||||
placeholder="All strains"
|
||||
}}
|
||||
</li>
|
||||
<li>
|
||||
<label>Characteristics</label>
|
||||
{{
|
||||
select-2
|
||||
multiple=true
|
||||
content=characteristicTypes
|
||||
value=selectedCharacteristics
|
||||
optionValuePath="id"
|
||||
placeholder="All characteristics"
|
||||
}}
|
||||
</li>
|
||||
<li>
|
||||
{{search-button isLoading=isLoading action='search'}}
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
</fieldset>
|
||||
</div>
|
Reference in a new issue