ENH: Species and counts (#44)

Fixes #31
This commit is contained in:
Matthew Ryan Dillon 2017-11-19 17:15:47 -07:00 committed by GitHub
parent 93d70d3c95
commit bfae4422f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 78 additions and 17 deletions

View file

@ -0,0 +1,12 @@
import DS from 'ember-data';
const { Model, attr, belongsTo } = DS;
export default Model.extend({
sex: attr('string'),
count: attr('number'),
countEstimated: attr('boolean'),
collection: belongsTo('collection'),
species: belongsTo('species'),
});

View file

@ -2,7 +2,7 @@ import Ember from 'ember';
import DS from 'ember-data';
const { computed } = Ember;
const { Model, attr, belongsTo } = DS;
const { Model, attr, belongsTo, hasMany } = DS;
export const schema = {
displayName: attr('string'),
@ -12,11 +12,23 @@ export const schema = {
collectionEndDate: attr('string-null-to-empty'),
collectionEndTime: attr('string-null-to-empty'),
project: belongsTo('project'),
studyLocation: belongsTo('study-location'),
collectionMethod: belongsTo('collection-method'),
collectionType: belongsTo('collection-type'),
adfgPermit: belongsTo('adfg-permit'),
project: belongsTo('project'),
studyLocation: belongsTo('study-location'),
collectionMethod: belongsTo('collection-method'),
collectionType: belongsTo('collection-type'),
adfgPermit: belongsTo('adfg-permit'),
collectionSpecies: hasMany('collection-species', { async: false }),
species: computed.mapBy('collectionSpecies', 'species'),
speciesNames: computed.mapBy('species', 'commonName'),
counts: computed.mapBy('collectionSpecies', 'count'),
speciesAndCounts: computed('speciesNames', 'counts', function() {
const speciesNames = this.get('speciesNames');
let counts = this.get('counts');
counts = counts.map(c => c !== null ? c : 'No Count');
return speciesNames.map((n, i) => `${n} (${counts[i]})`).join(', ');
}),
};
export default Model.extend(Object.assign({}, schema, {

11
app/models/species.js Normal file
View file

@ -0,0 +1,11 @@
import DS from 'ember-data';
const { Model, attr } = DS;
export default Model.extend({
commonName: attr('string'),
genus: attr('string'),
species: attr('string'),
parasite: attr('boolean'),
sortOrder: attr('number'),
});