Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
fix(build): add criteriaBuilder to build
Browse files Browse the repository at this point in the history
  • Loading branch information
VMBindraban committed Aug 1, 2016
1 parent d19672c commit de562eb
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 577 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion build/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
105 changes: 1 addition & 104 deletions dist/amd/aurelia-filter.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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;
}();
});
2 changes: 1 addition & 1 deletion dist/amd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
2 changes: 2 additions & 0 deletions dist/aurelia-filter.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
78 changes: 0 additions & 78 deletions dist/aurelia-filter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import extend from 'extend';
import {Config} from 'aurelia-view-manager';

export function configure(aurelia) {
Expand All @@ -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 !== '';
}
}
102 changes: 1 addition & 101 deletions dist/commonjs/aurelia-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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;
}();
}
2 changes: 1 addition & 1 deletion dist/commonjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit de562eb

Please sign in to comment.