ENH: Collection filterings (#42)

Fixes #21
Fixes #28
Fixes #34
This commit is contained in:
Matthew Ryan Dillon 2017-11-10 11:18:33 -07:00 committed by GitHub
parent 695eb65806
commit 17651e071e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 296 additions and 8 deletions

View file

@ -1,14 +1,72 @@
import Ember from 'ember';
const { Route } = Ember;
const { Route, RSVP } = Ember;
export default Route.extend({
queryParams: {
// qps are snake_case for the django api
page: { refreshModel: true },
project: { refreshModel: true },
region: { refreshModel: true },
site: { refreshModel: true },
study_location: { refreshModel: true },
collection_method: { refreshModel: true },
number_of_traps: { refreshModel: true },
collection_start_date: { refreshModel: true },
collection_end_date: { refreshModel: true },
},
model(params) {
const include = {include: 'project,study-location,collection-method,collection-type'};
return this.get('store').query('collection', Object.assign(params, include));
const store = this.get('store');
const opts = {
include: 'project,study-location,study-location.site,site,collection-method',
};
return RSVP.hash({
projectOptions: store.findAll('project'),
regionOptions: store.findAll('region'),
siteOptions: store.findAll('site'),
studyLocationOptions: store.findAll('study-location'),
collectionMethodOptions: store.findAll('collection-method'),
model: store.query('collection', Object.assign(params, opts)),
});
},
setupController(controller, models) {
this._super(...arguments);
controller.setProperties(models);
const store = this.get('store');
let project = controller.get('project');
project = project.map(id => store.peekRecord('project', id));
let region = controller.get('region');
region = region.map(id => store.peekRecord('region', id));
let site = controller.get('site');
site = site.map(id => store.peekRecord('site', id));
let studyLocation = controller.get('study_location');
studyLocation = studyLocation.map(id => store.peekRecord('study-location', id));
let collectionMethod = controller.get('collection_method');
collectionMethod = collectionMethod.map(id => store.peekRecord('collection-method', id));
const numberOfTraps = controller.get('number_of_traps');
const collectionStartDate = controller.get('collection_start_date');
const collectionEndDate = controller.get('collection_end_date');
let filter = {
project,
region,
site,
study_location: studyLocation,
collection_method: collectionMethod,
number_of_traps: numberOfTraps,
collection_start_date: collectionStartDate,
collection_end_date: collectionEndDate,
}
controller.set('filters', filter);
},
});