91 lines
3.3 KiB
JavaScript
91 lines
3.3 KiB
JavaScript
import Route from '@ember/routing/route';
|
|
|
|
export default Route.extend({
|
|
model() {
|
|
let me = this;
|
|
let parentController = me.controllerFor(me.getParentRouteName());
|
|
let strCriteria = parentController.get('criteria');
|
|
let criteria;
|
|
if (strCriteria) {
|
|
criteria = JSON.parse(strCriteria).map(c => {
|
|
return {
|
|
col: c[0],
|
|
op: c[1],
|
|
val: c[2]
|
|
}
|
|
});
|
|
}
|
|
|
|
if (!criteria || !criteria.length) {
|
|
criteria = [{
|
|
col: 'year',
|
|
op: 'eq'
|
|
}];
|
|
}
|
|
|
|
return {
|
|
tableOptions: parentController.get('tableOptions'),
|
|
|
|
dateAddedList: parentController.get('model.dateAddedList'),
|
|
countryCodeList: parentController.get('model.countryCodeList'),
|
|
stateList: parentController.get('model.stateList'),
|
|
cityList: parentController.get('model.cityList'),
|
|
regionList: parentController.get('model.regionList'),
|
|
msList: parentController.get('model.msList'),
|
|
salespersonList: parentController.get('model.salespersonList'),
|
|
statusList: parentController.get('model.statusList'),
|
|
|
|
criteria: criteria,
|
|
cols: [{col: 'name', name: 'Name'},
|
|
{col: 'dateAdded', name: 'Date Added'},
|
|
{col: 'year', name: 'Year'},
|
|
{col: 'ytdSale', name: 'YTD Sale'},
|
|
{col: 'sumYtdSales', name: 'Sum YTD Sales'},
|
|
{col: 'countryCode', name: 'Country'},
|
|
{col: 'state', name: 'State'},
|
|
{col: 'city', name: 'City'},
|
|
{col: 'ms', name: 'MS'},
|
|
{col: 'region', name: 'Region'},
|
|
{col: 'salesperson', name: 'Salesperson'},
|
|
{col: 'status', name: 'Status'},
|
|
],
|
|
ops: [{op: 'eq', name: '='},
|
|
{op: 'gt', name: '>'},
|
|
{op: 'lt', name: '<'},
|
|
{op: 'gte', name: '>='},
|
|
{op: 'lte', name: '<='},
|
|
{op: 'ne', name: '<>'},
|
|
{op: 'like', name: 'Like'}
|
|
]
|
|
};
|
|
},
|
|
actions: {
|
|
addCriterion() {
|
|
console.info('Add Criterion.');
|
|
this.get('controller.model.criteria').pushObject({
|
|
col: 'name',
|
|
op: 'eq'
|
|
});
|
|
},
|
|
removeCriterion(criterion) {
|
|
console.info('Route Remove Criterion: ', criterion);
|
|
this.get('controller.model.criteria').removeObject(criterion);
|
|
},
|
|
query() {
|
|
let me = this;
|
|
let parentRouteName = me.getParentRouteName();
|
|
console.log('parent route:', parentRouteName);
|
|
const parentController = me.controllerFor(parentRouteName);
|
|
let criteria = me.get('controller.model.criteria');
|
|
parentController.set('criteria',
|
|
JSON.stringify(criteria.filter(c => c.val)
|
|
.map(c => [c.col, c.op, c.val])));
|
|
me.transitionTo(parentRouteName);
|
|
}
|
|
},
|
|
getParentRouteName() {
|
|
return this.get('parentRouteName') ||
|
|
this.get('routeName').replace(/\.[^.]+$/, '');
|
|
}
|
|
});
|