Compare, begin components

This commit is contained in:
Matthew Dillon 2015-11-11 17:07:45 -07:00
parent 2beabf817c
commit 268ab18cf6
8 changed files with 122 additions and 92 deletions

View file

@ -1,3 +1,5 @@
import Ember from 'ember';
export default Ember.Route.extend({});
const { Route } = Ember;
export default Route.extend({});

View file

@ -1,41 +1,11 @@
import Ember from 'ember';
export default Ember.Controller.extend({
const { Controller } = Ember;
export default Controller.extend({
actions: {
search: function() {
let query = {
strain_ids: this.get('selectedStrains'),
characteristic_ids: this.get('selectedCharacteristics'),
};
this.transitionToRoute('protected.compare.results', {queryParams: query});
search: function(query) {
this.transitionToRoute('protected.compare.results', { queryParams: query });
},
selectAllStrains: function() {
let strains = this.get('strains');
let strain_ids = [];
strains.forEach((strain) => {
strain_ids.push(strain.id);
});
this.set('selectedStrains', strain_ids.join(","));
},
deselectAllStrains: function() {
this.set('selectedStrains', '');
},
selectAllCharacteristics: function() {
let chars = this.get('characteristics');
let char_ids = [];
chars.forEach((char) => {
char_ids.push(char.id);
});
this.set('selectedCharacteristics', char_ids.join(","));
},
deselectAllCharacteristics: function() {
this.set('selectedCharacteristics', '');
},
}
});

View file

@ -1,6 +1,8 @@
import Ember from 'ember';
export default Ember.Route.extend({
const { Route } = Ember;
export default Route.extend({
model: function() {
return this.store.findAll('characteristic');
},

View file

@ -0,0 +1,49 @@
import Ember from 'ember';
const { Component } = Ember;
export default Component.extend({
characteristics: null,
strains: null,
"on-search": null,
selectedStrains: null,
selectedCharacteristics: null,
actions: {
search: function() {
const query = {
strain_ids: this.get('selectedStrains'),
characteristic_ids: this.get('selectedCharacteristics'),
};
this.attrs['on-search'](query);
},
selectAllStrains: function() {
const strains = this.get('strains');
const strain_ids = [];
strains.forEach((strain) => {
strain_ids.push(strain.get('id'));
});
this.set('selectedStrains', strain_ids.join(","));
},
deselectAllStrains: function() {
this.set('selectedStrains', '');
},
selectAllCharacteristics: function() {
const chars = this.get('characteristics');
const char_ids = [];
chars.forEach((char) => {
char_ids.push(char.get('id'));
});
this.set('selectedCharacteristics', char_ids.join(","));
},
deselectAllCharacteristics: function() {
this.set('selectedCharacteristics', '');
},
},
});

View file

@ -0,0 +1,53 @@
<div class="span-1">
<fieldset>
<form {{action 'search' on='submit'}}>
<ul>
<li>
<label>Strains</label>
{{
select-2
multiple=true
content=strains
value=selectedStrains
optionValuePath="id"
optionLabelPath="fullNameMU"
placeholder="Select one or more strains"
}}
</li>
<li>
<button class="action button-green smaller right" {{action 'selectAllStrains'}}>
Select All
</button>
<button class="action button-red smaller right" {{action 'deselectAllStrains'}}>
Deselect All
</button>
</li>
<li>
<label>Characteristics</label>
{{
select-2
multiple=true
content=characteristics
value=selectedCharacteristics
optionValuePath="id"
optionLabelPath="characteristicName"
placeholder="Select one or more characteristics"
}}
</li>
<li>
<button class="action button-green smaller right" {{action 'selectAllCharacteristics'}}>
Select All
</button>
<button class="action button-red smaller right" {{action 'deselectAllCharacteristics'}}>
Deselect All
</button>
</li>
<li>
<button type="submit" class="action button-gray smaller right">
Search
</button>
</li>
</ul>
</form>
</fieldset>
</div>

View file

@ -1,57 +1,10 @@
<h2>{{genus-name}} - Compare Strains</h2>
<div class="span-1">
<fieldset>
<form {{action 'search' on='submit'}}>
<ul>
<li>
<label>Strains</label>
{{
select-2
multiple=true
content=strains
value=selectedStrains
optionValuePath="id"
optionLabelPath="fullNameMU"
placeholder="Select one or more strains"
}}
</li>
<li>
<button class="action button-green smaller right" {{action 'selectAllStrains'}}>
Select All
</button>
<button class="action button-red smaller right" {{action 'deselectAllStrains'}}>
Deselect All
</button>
</li>
<li>
<label>Characteristics</label>
{{
select-2
multiple=true
content=characteristics
value=selectedCharacteristics
optionValuePath="id"
optionLabelPath="characteristicName"
placeholder="Select one or more characteristics"
}}
</li>
<li>
<button class="action button-green smaller right" {{action 'selectAllCharacteristics'}}>
Select All
</button>
<button class="action button-red smaller right" {{action 'deselectAllCharacteristics'}}>
Deselect All
</button>
</li>
<li>
<button type="submit" class="action button-gray smaller right">
Search
</button>
</li>
</ul>
</form>
</fieldset>
</div>
{{
protected/compare/select-form
characteristics=characteristics
strains=strains
on-search=(action "search")
}}
{{outlet}}

View file

@ -1,6 +1,8 @@
import Ember from 'ember';
export default Ember.Route.extend({
const { Route } = Ember;
export default Route.extend({
beforeModel: function(transition) {
this._super(transition);
this.transitionTo('protected.compare');

View file

@ -1 +0,0 @@
Welcome