From c87bd953d905b45082a3991b964e4e903ac01e81 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sat, 3 Mar 2018 12:10:12 -0700 Subject: [PATCH] ENH: Convert sex fields to lookup (#76) --- .travis.yml | 2 +- app/components/collection/detail-container.js | 2 +- app/controllers/collections/create.js | 4 +++- app/controllers/collections/detail/edit.js | 4 +++- app/models/collection-species.js | 2 +- app/models/sex.js | 8 ++++++++ app/routes/collections/create.js | 1 + app/routes/collections/detail/edit.js | 1 + .../components/collection/create-container.hbs | 10 +++++++++- package.json | 5 ++++- 10 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 app/models/sex.js diff --git a/.travis.yml b/.travis.yml index 895b134..de8dc13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ branches: only: - master node_js: - - "6" + - "9" sudo: required dist: trusty addons: diff --git a/app/components/collection/detail-container.js b/app/components/collection/detail-container.js index 28057bb..66f9ba1 100644 --- a/app/components/collection/detail-container.js +++ b/app/components/collection/detail-container.js @@ -22,7 +22,7 @@ export default Component.extend({ { label: 'Species', valuePath: 'species.commonName' }, { label: 'Count', valuePath: 'count' }, { label: 'Count Estimated?', valuePath: 'countEstimated' }, - { label: 'Sex', valuePath: 'sex' }, + { label: 'Sex', valuePath: 'sex.name' }, ], envMeasColumns: [ diff --git a/app/controllers/collections/create.js b/app/controllers/collections/create.js index beb3511..9234268 100644 --- a/app/controllers/collections/create.js +++ b/app/controllers/collections/create.js @@ -16,7 +16,8 @@ export default Controller.extend(ValidationMixin, { options: computed('projectOptions', 'studyLocationOptions', 'collectionTypeOptions', 'collectionMethodOptions', - 'speciesOptions', 'adfgPermitOptions', function() { + 'speciesOptions', 'adfgPermitOptions', 'sexOptions', + function() { return { projects: this.get('projectOptions'), studyLocations: this.get('studyLocationOptions'), @@ -24,6 +25,7 @@ export default Controller.extend(ValidationMixin, { collectionMethods: this.get('collectionMethodOptions'), species: this.get('speciesOptions'), adfgPermits: this.get('adfgPermitOptions'), + sexes: this.get('sexOptions'), }; }), diff --git a/app/controllers/collections/detail/edit.js b/app/controllers/collections/detail/edit.js index 309a93c..6133707 100644 --- a/app/controllers/collections/detail/edit.js +++ b/app/controllers/collections/detail/edit.js @@ -16,7 +16,8 @@ export default Controller.extend(ValidationMixin, { options: computed('projectOptions', 'studyLocationOptions', 'collectionTypeOptions', 'collectionMethodOptions', - 'speciesOptions', 'adfgPermitOptions', function() { + 'speciesOptions', 'adfgPermitOptions', 'sexOptions', + function() { return { projects: this.get('projectOptions'), studyLocations: this.get('studyLocationOptions'), @@ -24,6 +25,7 @@ export default Controller.extend(ValidationMixin, { collectionMethods: this.get('collectionMethodOptions'), species: this.get('speciesOptions'), adfgPermits: this.get('adfgPermitOptions'), + sexes: this.get('sexOptions'), }; }), diff --git a/app/models/collection-species.js b/app/models/collection-species.js index 72d7c55..5839d7c 100644 --- a/app/models/collection-species.js +++ b/app/models/collection-species.js @@ -3,7 +3,7 @@ import DS from 'ember-data'; const { Model, attr, belongsTo } = DS; export default Model.extend({ - sex: attr('string'), + sex: belongsTo('sex'), count: attr('number'), countEstimated: attr('boolean', { defaultValue: false }), diff --git a/app/models/sex.js b/app/models/sex.js new file mode 100644 index 0000000..6f3b265 --- /dev/null +++ b/app/models/sex.js @@ -0,0 +1,8 @@ +import DS from 'ember-data'; + +const { Model, attr } = DS; + +export default Model.extend({ + name: attr('string'), + sortOrder: attr('number'), +}); diff --git a/app/routes/collections/create.js b/app/routes/collections/create.js index f31deb6..a0d9830 100644 --- a/app/routes/collections/create.js +++ b/app/routes/collections/create.js @@ -12,6 +12,7 @@ export default Route.extend({ collectionMethodOptions: store.findAll('collection-method'), speciesOptions: store.findAll('species'), adfgPermitOptions: store.findAll('adfg-permit'), + sexOptions: store.findAll('sex'), }); }, diff --git a/app/routes/collections/detail/edit.js b/app/routes/collections/detail/edit.js index 47edc53..7cd72a8 100644 --- a/app/routes/collections/detail/edit.js +++ b/app/routes/collections/detail/edit.js @@ -13,6 +13,7 @@ export default Route.extend({ collectionMethodOptions: store.findAll('collection-method'), speciesOptions: store.findAll('species'), adfgPermitOptions: store.findAll('adfg-permit'), + sexOptions: store.findAll('sex'), }); }, diff --git a/app/templates/components/collection/create-container.hbs b/app/templates/components/collection/create-container.hbs index c0c9fa0..0167738 100644 --- a/app/templates/components/collection/create-container.hbs +++ b/app/templates/components/collection/create-container.hbs @@ -143,7 +143,15 @@ {{#validated-field property='sex' changeset=cs.changeset}} - {{input value=cs.changeset.sex}} + {{#power-select + options=options.sexes + selected=cs.changeset.sex + onchange=(action (mut cs.changeset.sex)) + searchField='name' + as |sex| + }} + {{sex.name}} + {{/power-select}} {{/validated-field}} diff --git a/package.json b/package.json index 426909c..9617213 100644 --- a/package.json +++ b/package.json @@ -54,5 +54,8 @@ "engines": { "node": "^4.5 || 6.* || >= 7.*" }, - "private": true + "private": true, + "dependencies": { + "npm": "^5.7.1" + } }