Permalink
Browse files

fix(build): add criteriaBuilder to build

  • Loading branch information...
VMBindraban
VMBindraban committed Aug 1, 2016
1 parent d19672c commit de562eb25953d15303bbb88cda53dc20a2e82ad3
@@ -1,6 +1,6 @@
{
"name": "aurelia-filter",
"version": "0.0.2",
"version": "0.0.3",
"description": "A plugin for aurelia to populate search/filter criteria. Works well with aurelia-orm.",
"keywords": [
"aurelia",
@@ -22,7 +22,10 @@ var paths = {
useTypeScriptForDTS: false,
importsToAdd: [], // eg. non-concated local imports in the main file as they will get removed during the build process
importsToIgnoreForDts: ['extend', 'humane-js'], // imports that are only used internally. no need to d.ts export them
jsResources: [appRoot + 'filter.js'], // js to transpile, but not be concated and keeping their relative path
jsResources: [
appRoot + 'filter.js',
appRoot + 'criteriaBuilder.js'
], // js to transpile, but not be concated and keeping their relative path
resources: appRoot + '{**/*.css,**/*.html}',
sort: true,
concat: true
@@ -1,22 +1,10 @@
define(['exports', 'extend', 'aurelia-view-manager'], function (exports, _extend, _aureliaViewManager) {
define(['exports', 'aurelia-view-manager'], function (exports, _aureliaViewManager) {
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CriteriaBuilder = undefined;
exports.configure = configure;

var _extend2 = _interopRequireDefault(_extend);

function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}



function configure(aurelia) {
aurelia.plugin('aurelia-form');

@@ -26,95 +14,4 @@ define(['exports', 'extend', 'aurelia-view-manager'], function (exports, _extend

aurelia.globalResources('./filter');
}

var CriteriaBuilder = exports.CriteriaBuilder = function () {
function CriteriaBuilder() {

}

CriteriaBuilder.prototype.updateCriteria = function updateCriteria() {
var _this = this;

var blocks = [];

this.filters.forEach(function (block, index) {
var filtersParsed = {};

block.forEach(function (filter) {
if (!_this.hasValue(filter.data.value)) {
return;
}

filtersParsed = (0, _extend2.default)(filtersParsed, _this.parseField(filter.data.field, _this.parseOperator(filter.data)));
});

blocks.push(filtersParsed);
});

var criteriaWhere = blocks.length > 1 ? { where: { or: blocks } } : { where: blocks[0] };
var currentSort = this.criteria.sort || {};

this.criteria = Object.assign(criteriaWhere, { sort: currentSort });
};

CriteriaBuilder.prototype.parseOperator = function parseOperator(filter) {
var _ref;

switch (filter.operator) {
case 'equals':
return filter.value;
case 'between':
return this.parseBetween(filter);
case 'in':
return this.toArray(filter.value);
case '!':
filter.operator = '!';
filter.value = this.toArray(filter.value);
break;
default:
break;
}

return _ref = {}, _ref[filter.operator] = filter.value, _ref;
};

CriteriaBuilder.prototype.parseBetween = function parseBetween(data) {
var _ref2;

var valueOperator = arguments.length <= 1 || arguments[1] === undefined ? '>=' : arguments[1];
var betweenOperator = arguments.length <= 2 || arguments[2] === undefined ? '<=' : arguments[2];

if (!this.hasValue(data.between)) {
return;
}

return _ref2 = {}, _ref2[valueOperator] = data.value, _ref2[betweenOperator] = data.between, _ref2;
};

CriteriaBuilder.prototype.parseField = function parseField(fieldName, data) {
var _ref4;

fieldName = fieldName.split('.');

if (fieldName.length > 1) {
var _fieldName$, _ref3;

return _ref3 = {}, _ref3[fieldName[0]] = (_fieldName$ = {}, _fieldName$[fieldName[1]] = data, _fieldName$), _ref3;
}

return _ref4 = {}, _ref4[fieldName[0]] = data, _ref4;
};

CriteriaBuilder.prototype.toArray = function toArray(value) {
return value.split(',').map(function (i) {
return i.trim();
});
};

CriteriaBuilder.prototype.hasValue = function hasValue(value) {
return typeof value !== 'undefined' && value !== '';
};

return CriteriaBuilder;
}();
});
@@ -5,7 +5,7 @@ define(['exports', './aurelia-filter'], function (exports, _aureliaFilter) {
value: true
});
Object.keys(_aureliaFilter).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key === "default") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
@@ -18,6 +18,8 @@ export declare class Filter extends CriteriaBuilder {
fieldElement: any;
operatorElement: any;
valueElement: any;

// button group styling issue
constructor();
attached(): any;
parseCriteria(criteriaWhere?: any): any;
@@ -1,4 +1,3 @@
import extend from 'extend';
import {Config} from 'aurelia-view-manager';

export function configure(aurelia) {
@@ -10,80 +9,3 @@ export function configure(aurelia) {

aurelia.globalResources('./filter');
}

export class CriteriaBuilder {

updateCriteria() {
let blocks = [];

this.filters.forEach((block, index) => {
let filtersParsed = {};

block.forEach(filter => {
if (!this.hasValue(filter.data.value)) {
return;
}

filtersParsed = extend(filtersParsed, this.parseField(filter.data.field, this.parseOperator(filter.data)));
});

blocks.push(filtersParsed);
});

let criteriaWhere = (blocks.length > 1) ? {where: {or: blocks}} : {where: blocks[0]};
let currentSort = this.criteria.sort || {};

this.criteria = Object.assign(criteriaWhere, {sort: currentSort});
}

parseOperator(filter) {
switch (filter.operator) {
case 'equals':
return filter.value;
case 'between':
return this.parseBetween(filter);
case 'in':
return this.toArray(filter.value);
case '!':
// not-in
filter.operator = '!';
filter.value = this.toArray(filter.value);
break;
default:
break;
}

return {[filter.operator]: filter.value};
}

parseBetween(data, valueOperator = '>=', betweenOperator = '<=') {
if (!this.hasValue(data.between)) {
return;
}

return {
[valueOperator]: data.value,
[betweenOperator]: data.between
};
}

parseField(fieldName, data) {
fieldName = fieldName.split('.');

if (fieldName.length > 1) {
return {[fieldName[0]]: {[fieldName[1]]: data}};
}

return {[fieldName[0]]: data};
}

toArray(value) {
return value.split(',').map(i => {
return i.trim();
});
}

hasValue(value) {
return typeof value !== 'undefined' && value !== '';
}
}
@@ -3,19 +3,10 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CriteriaBuilder = undefined;
exports.configure = configure;

var _extend = require('extend');

var _extend2 = _interopRequireDefault(_extend);

var _aureliaViewManager = require('aurelia-view-manager');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }



function configure(aurelia) {
aurelia.plugin('aurelia-form');

@@ -24,95 +15,4 @@ function configure(aurelia) {
});

aurelia.globalResources('./filter');
}

var CriteriaBuilder = exports.CriteriaBuilder = function () {
function CriteriaBuilder() {

}

CriteriaBuilder.prototype.updateCriteria = function updateCriteria() {
var _this = this;

var blocks = [];

this.filters.forEach(function (block, index) {
var filtersParsed = {};

block.forEach(function (filter) {
if (!_this.hasValue(filter.data.value)) {
return;
}

filtersParsed = (0, _extend2.default)(filtersParsed, _this.parseField(filter.data.field, _this.parseOperator(filter.data)));
});

blocks.push(filtersParsed);
});

var criteriaWhere = blocks.length > 1 ? { where: { or: blocks } } : { where: blocks[0] };
var currentSort = this.criteria.sort || {};

this.criteria = Object.assign(criteriaWhere, { sort: currentSort });
};

CriteriaBuilder.prototype.parseOperator = function parseOperator(filter) {
var _ref;

switch (filter.operator) {
case 'equals':
return filter.value;
case 'between':
return this.parseBetween(filter);
case 'in':
return this.toArray(filter.value);
case '!':
filter.operator = '!';
filter.value = this.toArray(filter.value);
break;
default:
break;
}

return _ref = {}, _ref[filter.operator] = filter.value, _ref;
};

CriteriaBuilder.prototype.parseBetween = function parseBetween(data) {
var _ref2;

var valueOperator = arguments.length <= 1 || arguments[1] === undefined ? '>=' : arguments[1];
var betweenOperator = arguments.length <= 2 || arguments[2] === undefined ? '<=' : arguments[2];

if (!this.hasValue(data.between)) {
return;
}

return _ref2 = {}, _ref2[valueOperator] = data.value, _ref2[betweenOperator] = data.between, _ref2;
};

CriteriaBuilder.prototype.parseField = function parseField(fieldName, data) {
var _ref4;

fieldName = fieldName.split('.');

if (fieldName.length > 1) {
var _fieldName$, _ref3;

return _ref3 = {}, _ref3[fieldName[0]] = (_fieldName$ = {}, _fieldName$[fieldName[1]] = data, _fieldName$), _ref3;
}

return _ref4 = {}, _ref4[fieldName[0]] = data, _ref4;
};

CriteriaBuilder.prototype.toArray = function toArray(value) {
return value.split(',').map(function (i) {
return i.trim();
});
};

CriteriaBuilder.prototype.hasValue = function hasValue(value) {
return typeof value !== 'undefined' && value !== '';
};

return CriteriaBuilder;
}();
}
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
var _aureliaFilter = require('./aurelia-filter');

Object.keys(_aureliaFilter).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key === "default") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
Oops, something went wrong.

0 comments on commit de562eb

Please sign in to comment.