Rough in characteristic types, add meas optgroups

This commit is contained in:
Matthew Dillon 2015-06-16 15:47:29 -08:00
parent f17707fb6d
commit 3c1fca43b8
9 changed files with 126 additions and 20 deletions

View file

@ -0,0 +1,12 @@
import DS from 'ember-data';
export default DS.Model.extend({
characteristicTypeName: DS.attr('string'),
characteristics: DS.hasMany('characteristic', { async: true }),
createdAt: DS.attr('date'),
updatedAt: DS.attr('date'),
deletedAt: DS.attr('date'),
createdBy: DS.attr('number'),
updatedBy: DS.attr('number'),
deletedBy: DS.attr('number')
});

View file

@ -2,7 +2,7 @@ import DS from 'ember-data';
export default DS.Model.extend({
characteristicName: DS.attr('string'),
characteristicType: DS.attr('string'),
characteristicType: DS.belongsTo('characteristicType', { async: true }),
strains : DS.hasMany('strain', { async: true }),
measurements : DS.hasMany('measurements', { async: true }),
createdAt : DS.attr('date'),

View file

@ -3,14 +3,17 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi
export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function() {
return this.store.findAll('characteristic');
return Ember.RSVP.hash({
characteristicTypes: this.store.findAll('characteristic-type'),
characteristics: this.store.findAll('characteristic'),
});
},
setupController: function(controller, model) {
setupController: function(controller, models) {
var tableAttrs = [
{ name: 'Name', attr: 'characteristicName' },
{ name: 'Type', attr: 'characteristicType' }
{ name: 'Type', attr: 'characteristicType.characteristicTypeName' }
];
controller.set('model', model);
controller.set('model', models.characteristics);
controller.set('tableAttrs', tableAttrs);
controller.set('row', 'characteristic-index-row');
controller.set('sort', ['characteristicName']);

View file

@ -2,5 +2,5 @@
{{data.characteristicName}}
</td>
<td>
{{data.characteristicType}}
{{data.characteristicType.characteristicTypeName}}
</td>

View file

@ -4,25 +4,35 @@ import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixi
export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function() {
return Ember.RSVP.hash({
species: this.store.findAll('species'), // need this bc async
species: this.store.findAll('species'),
strains: this.store.findAll('strain'),
characteristicTypes: this.store.findAll('characteristic-type'),
characteristics: this.store.findAll('characteristic'),
});
},
setupController: function(controller, models) {
// Set up search parameters
let selects = [
{ model: 'strains', id: 'id', text: 'fullName' },
{ model: 'characteristics', id: 'id', text: 'characteristicName' },
{ 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) => {
return Ember.Object.create({
id: data.get(item.id),
text: data.get(item.text),
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,
};
});
controller.set(item.model, temp);
});

View file

@ -9,7 +9,7 @@
{{
select-2
multiple=true
content=strains
content=species
value=selectedStrains
optionValuePath="id"
placeholder="All strains"
@ -20,7 +20,7 @@
{{
select-2
multiple=true
content=characteristics
content=characteristicTypes
value=selectedCharacteristics
optionValuePath="id"
placeholder="All characteristics"