ENH: IACUC and ADFG Permits (and search reset) (#43)

Fixes #30
This commit is contained in:
Matthew Ryan Dillon 2017-11-14 08:30:12 -07:00 committed by GitHub
parent 17651e071e
commit 93d70d3c95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 85 additions and 14 deletions

View file

@ -8,11 +8,15 @@ export default Component.extend({
columns: [
{ label: 'Project', valuePath: 'project.name', },
{ label: 'IACUC', valuePath: 'project.iacucNumber', },
{ label: 'Region', valuePath: 'studyLocation.site.region.name', },
{ label: 'Site', valuePath: 'studyLocation.site.name', },
{ label: 'Study Location', valuePath: 'studyLocation.code', },
{ label: 'Method', valuePath: 'collectionMethod.code', },
{ label: 'Type', valuePath: 'collectionType.name', },
{ label: '# of Traps', valuePath: 'numberOfTraps', },
{ label: 'Start', valuePath: 'startDateTime', },
{ label: 'End', valuePath: 'endDateTime', },
{ label: 'ADFG Permit', valuePath: 'adfgPermit.name', },
],
});

View file

@ -8,6 +8,7 @@ export default Component.extend({
columns: [
{ label: 'Project', valuePath: 'project.name', },
{ label: 'IACUC', valuePath: 'project.iacucNumber', },
{ label: 'Region', valuePath: 'studyLocation.site.region.name', },
{ label: 'Site', valuePath: 'studyLocation.site.name', },
{ label: 'Study Location', valuePath: 'studyLocation.code', },
@ -15,5 +16,6 @@ export default Component.extend({
{ label: '# of Traps', valuePath: 'numberOfTraps', },
{ label: 'Start', valuePath: 'startDateTime', },
{ label: 'End', valuePath: 'endDateTime', },
{ label: 'ADFG Permit', valuePath: 'adfgPermit.name', },
],
});

View file

@ -6,25 +6,28 @@ const { Controller, computed, get, set } = Ember;
export default Controller.extend({
queryParams: ['page', 'project', 'region', 'site', 'study_location',
'collection_method', 'number_of_traps', 'collection_start_date',
'collection_end_date'],
'collection_end_date', 'adfg_permit'],
page: 1,
project: [],
region: [],
site: [],
study_location: [],
collection_method: [],
adfg_permit: [],
number_of_traps: '',
collection_start_date: '',
collection_end_date: '',
options: computed('projectOptions', 'regionOptions', 'siteOptions',
'studyLocationOptions', 'collectionMethodOptions', function() {
'studyLocationOptions', 'collectionMethodOptions',
'adfgPermitOptions', function() {
return {
projects: this.get('projectOptions'),
regions: this.get('regionOptions'),
sites: this.get('siteOptions'),
studyLocations: this.get('studyLocationOptions'),
collectionMethods: this.get('collectionMethodOptions'),
adfgPermits: this.get('adfgPermitOptions'),
};
}),
@ -42,12 +45,21 @@ export default Controller.extend({
createCollection() {
this.transitionToRoute('collections.create');
},
resetFilter() {
set(this, 'page', 1);
['project', 'region', 'site', 'study_location', 'collection_method', 'adfg_permit'].forEach((field) => {
set(this, field, []);
});
['number_of_traps', 'collection_start_date', 'collection_end_date'].forEach((field) => {
set(this, field, '');
});
},
changeFilter(filter) {
// Need to reset the page so that things don't get weird
set(this, 'page', 1);
const filterModelFields = ['project', 'region', 'site', 'study_location',
'collection_method'];
'collection_method', 'adfg_permit'];
filterModelFields.forEach((field) => {
let fields = get(filter, field);

10
app/models/adfg-permit.js Normal file
View file

@ -0,0 +1,10 @@
import DS from 'ember-data';
const { Model, attr, hasMany } = DS;
export default Model.extend({
name: attr('string'),
sortOrder: attr('number'),
collection: hasMany('collection'),
});

View file

@ -16,6 +16,7 @@ export const schema = {
studyLocation: belongsTo('study-location'),
collectionMethod: belongsTo('collection-method'),
collectionType: belongsTo('collection-type'),
adfgPermit: belongsTo('adfg-permit'),
};
export default Model.extend(Object.assign({}, schema, {

View file

@ -14,12 +14,13 @@ export default Route.extend({
number_of_traps: { refreshModel: true },
collection_start_date: { refreshModel: true },
collection_end_date: { refreshModel: true },
adfg_permit: { refreshModel: true },
},
model(params) {
const store = this.get('store');
const opts = {
include: 'project,study-location,study-location.site,site,collection-method',
include: 'project,study-location,study-location.site,site,collection-method,adfg-permit',
};
return RSVP.hash({
@ -28,6 +29,7 @@ export default Route.extend({
siteOptions: store.findAll('site'),
studyLocationOptions: store.findAll('study-location'),
collectionMethodOptions: store.findAll('collection-method'),
adfgPermitOptions: store.findAll('adfg-permit'),
model: store.query('collection', Object.assign(params, opts)),
});
},
@ -53,6 +55,9 @@ export default Route.extend({
let collectionMethod = controller.get('collection_method');
collectionMethod = collectionMethod.map(id => store.peekRecord('collection-method', id));
let adfgPermit = controller.get('adfg_permit');
adfgPermit = adfgPermit.map(id => store.peekRecord('adfg-permit', id));
const numberOfTraps = controller.get('number_of_traps');
const collectionStartDate = controller.get('collection_start_date');
const collectionEndDate = controller.get('collection_end_date');
@ -66,6 +71,7 @@ export default Route.extend({
number_of_traps: numberOfTraps,
collection_start_date: collectionStartDate,
collection_end_date: collectionEndDate,
adfg_permit: adfgPermit,
}
controller.set('filters', filter);
},

View file

@ -4,6 +4,7 @@
filters=filters
options=options
changeFilter=(action 'changeFilter')
resetFilter=(action 'resetFilter')
changePage=(action 'changePage')
onRowClick=(action 'rowClick')
createCollection=(action 'createCollection')

View file

@ -64,7 +64,7 @@
</div>
<div class="row">
<div class="col-md-3">
<div class="col-md-4">
<label>Collection Methods</label>
{{#power-select-multiple
options=options.collectionMethods
@ -76,11 +76,26 @@
{{collectionMethod.name}}
{{/power-select-multiple}}
</div>
<div class="col-md-3">
<div class="col-md-4">
<label>Number of Traps</label>
{{input type="text" class="form-control" value=filters.number_of_traps}}
</div>
<div class="col-md-3">
<div class="col-md-4">
<label>ADFG Permit</label>
{{#power-select-multiple
options=options.adfgPermits
selected=filters.adfg_permit
onchange=(action (mut filters.adfg_permit))
searchField='name'
as |adfgPermit|
}}
{{adfgPermit.name}}
{{/power-select-multiple}}
</div>
</div>
<div class="row">
<div class="col-md-6">
<label>Start Date</label>
{{
pikaday-input
@ -91,7 +106,7 @@
class='form-control'
}}
</div>
<div class="col-md-3">
<div class="col-md-6">
<label>End Date</label>
{{
pikaday-input
@ -106,12 +121,20 @@
<div class="row top-buffer">
<div class="col-md-12">
<div class="btn-group">
{{
action-button
isSuccess=true
label='Search'
onClick=(action changeFilter filters)
}}
{{
action-button
isWarning=true
label='Reset'
onClick=(action resetFilter)
}}
</div>
</div>
</div>
</div>

View file

@ -0,0 +1,12 @@
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('adfg-permit', 'Unit | Model | adfg permit', {
// Specify the other units that are required for this test.
needs: []
});
test('it exists', function(assert) {
let model = this.subject();
// let store = this.store();
assert.ok(!!model);
});