ENH: Collection Edit (parity with reading) (#48)

This commit is contained in:
Matthew Ryan Dillon 2017-11-30 15:51:16 -07:00 committed by GitHub
parent bfae4422f4
commit cb3bc081a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 337 additions and 121 deletions

View file

@ -5,7 +5,7 @@ const { Model, attr, belongsTo } = DS;
export default Model.extend({
sex: attr('string'),
count: attr('number'),
countEstimated: attr('boolean'),
countEstimated: attr('boolean', { defaultValue: false }),
collection: belongsTo('collection'),
species: belongsTo('species'),

View file

@ -4,7 +4,7 @@ import DS from 'ember-data';
const { computed } = Ember;
const { Model, attr, belongsTo, hasMany } = DS;
export const schema = {
export default Model.extend({
displayName: attr('string'),
numberOfTraps: attr('number'),
collectionStartDate: attr('string-null-to-empty'),
@ -18,20 +18,22 @@ export const schema = {
collectionType: belongsTo('collection-type'),
adfgPermit: belongsTo('adfg-permit'),
collectionSpecies: hasMany('collection-species', { async: false }),
collectionSpecies: hasMany('collection-species'),
// computed
species: computed.mapBy('collectionSpecies', 'species'),
speciesNames: computed.mapBy('species', 'commonName'),
counts: computed.mapBy('collectionSpecies', 'count'),
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, {
startDateTime: computed('collectionStartDate', 'collectionStartTime',
function() { return this._mergeDateTime('Start'); }),
@ -43,4 +45,4 @@ export default Model.extend(Object.assign({}, schema, {
const time = this.get(`collection${timepoint}Time`);
return `${date} ${time}`.trim();
},
}));
});