|
|
|
@ -46,6 +46,8 @@ Object.defineProperty(tree.Filterset.prototype, 'cloneWith', {
|
|
|
|
|
var additions;
|
|
|
|
|
for (var id in other) {
|
|
|
|
|
var status = this.addable(other[id]);
|
|
|
|
|
// status is true, false or null. if it's null we don't fail this
|
|
|
|
|
// clone nor do we add the filter.
|
|
|
|
|
if (status === false) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -58,7 +60,9 @@ Object.defineProperty(tree.Filterset.prototype, 'cloneWith', {
|
|
|
|
|
|
|
|
|
|
// Adding the other filters doesn't make this filterset invalid, but it
|
|
|
|
|
// doesn't add anything to it either.
|
|
|
|
|
if (!additions) return null;
|
|
|
|
|
if (!additions) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We can successfully add all filters. Now clone the filterset and add the
|
|
|
|
|
// new rules.
|
|
|
|
@ -66,7 +70,7 @@ Object.defineProperty(tree.Filterset.prototype, 'cloneWith', {
|
|
|
|
|
|
|
|
|
|
// We can add the rules that are already present without going through the
|
|
|
|
|
// add function as a Filterset is always in it's simplest canonical form.
|
|
|
|
|
for (var id in this) {
|
|
|
|
|
for (id in this) {
|
|
|
|
|
clone[id] = this[id];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -79,20 +83,21 @@ Object.defineProperty(tree.Filterset.prototype, 'cloneWith', {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true when the new filter can be added, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
// Returns true when the new filter can be added, false otherwise.
|
|
|
|
|
// It can also return null, and on the other side we test for === true or
|
|
|
|
|
// false
|
|
|
|
|
Object.defineProperty(tree.Filterset.prototype, 'addable', {
|
|
|
|
|
enumerable: false,
|
|
|
|
|
value: function(filter) {
|
|
|
|
|
var key = filter.key, value = filter.val;
|
|
|
|
|
var key = filter.key,
|
|
|
|
|
value = filter.val;
|
|
|
|
|
|
|
|
|
|
switch (filter.op) {
|
|
|
|
|
case '=':
|
|
|
|
|
if (key + '=' in this) return (this[key + '='].val != value) ? false : null;
|
|
|
|
|
if (key + '!=' + value in this) return false;
|
|
|
|
|
if (key + '>' in this && this[key + '>'].val >= value) return false;
|
|
|
|
|
if (key + '<' in this && this[key + '<'].val <= value) return false;
|
|
|
|
|
if (key + '>' in this && this[key + '>'].val >= value) return false;
|
|
|
|
|
if (key + '<' in this && this[key + '<'].val <= value) return false;
|
|
|
|
|
if (key + '>=' in this && this[key + '>='].val > value) return false;
|
|
|
|
|
if (key + '<=' in this && this[key + '<='].val < value) return false;
|
|
|
|
|
return true;
|
|
|
|
@ -103,8 +108,8 @@ Object.defineProperty(tree.Filterset.prototype, 'addable', {
|
|
|
|
|
case '!=':
|
|
|
|
|
if (key + '=' in this) return (this[key + '='].val == value) ? false : null;
|
|
|
|
|
if (key + '!=' + value in this) return null;
|
|
|
|
|
if (key + '>' in this && this[key + '>'].val >= value) return null;
|
|
|
|
|
if (key + '<' in this && this[key + '<'].val <= value) return null;
|
|
|
|
|
if (key + '>' in this && this[key + '>'].val >= value) return null;
|
|
|
|
|
if (key + '<' in this && this[key + '<'].val <= value) return null;
|
|
|
|
|
if (key + '>=' in this && this[key + '>='].val > value) return null;
|
|
|
|
|
if (key + '<=' in this && this[key + '<='].val < value) return null;
|
|
|
|
|
return true;
|
|
|
|
@ -150,11 +155,11 @@ Object.defineProperty(tree.Filterset.prototype, 'addable', {
|
|
|
|
|
Object.defineProperty(tree.Filterset.prototype, 'add', {
|
|
|
|
|
enumerable: false,
|
|
|
|
|
value: function(filter) {
|
|
|
|
|
var key = filter.key;
|
|
|
|
|
var key = filter.key, id;
|
|
|
|
|
|
|
|
|
|
switch (filter.op) {
|
|
|
|
|
case '=':
|
|
|
|
|
for (var id in this) {
|
|
|
|
|
for (id in this) {
|
|
|
|
|
if (this[id].key == key) {
|
|
|
|
|
delete this[id];
|
|
|
|
|
}
|
|
|
|
@ -174,7 +179,7 @@ Object.defineProperty(tree.Filterset.prototype, 'add', {
|
|
|
|
|
// If there are other filters that are also >
|
|
|
|
|
// but are less than this one, they don't matter, so
|
|
|
|
|
// remove them.
|
|
|
|
|
for (var id in this) {
|
|
|
|
|
for (id in this) {
|
|
|
|
|
if (this[id].key == key && this[id].val <= filter.val) {
|
|
|
|
|
delete this[id];
|
|
|
|
|
}
|
|
|
|
@ -183,7 +188,7 @@ Object.defineProperty(tree.Filterset.prototype, 'add', {
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '>=':
|
|
|
|
|
for (var id in this) {
|
|
|
|
|
for (id in this) {
|
|
|
|
|
if (this[id].key == key && this[id].val < filter.val) {
|
|
|
|
|
delete this[id];
|
|
|
|
|
}
|
|
|
|
@ -199,7 +204,7 @@ Object.defineProperty(tree.Filterset.prototype, 'add', {
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '<':
|
|
|
|
|
for (var id in this) {
|
|
|
|
|
for (id in this) {
|
|
|
|
|
if (this[id].key == key && this[id].val >= filter.val) {
|
|
|
|
|
delete this[id];
|
|
|
|
|
}
|
|
|
|
@ -208,7 +213,7 @@ Object.defineProperty(tree.Filterset.prototype, 'add', {
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '<=':
|
|
|
|
|
for (var id in this) {
|
|
|
|
|
for (id in this) {
|
|
|
|
|
if (this[id].key == key && this[id].val > filter.val) {
|
|
|
|
|
delete this[id];
|
|
|
|
|
}
|
|
|
|
|