// Generated by CoffeeScript 1.12.7
/**
* Volume filter
* @module
*/
'use strict';
app.directive('slotFilter', [
'constantService', function(constants) {
return {
restrict: 'E',
templateUrl: 'volume/filter.html',
link: function($scope) {
var filter, join, make, makeFilter, old, ops;
filter = $scope.filter;
join = function(o, op, e) {
if (o) {
return o + op + e;
} else {
return e;
}
};
ops = {
'': function(o) {
return o;
},
any: function(o) {
return o || 'false';
},
"true": function(o) {
return join(o, '&&', '!v');
},
"false": function(o) {
return join(o, '&&', 'v');
},
two: function(o) {
return join(o, '&&', 'v!==2');
},
eq: function(o, x) {
return join(o, '&&', x ? 'v!=' + JSON.stringify(x) : 'v');
},
ne: function(o, x) {
return join(o, '||', 'v==' + JSON.stringify(x));
},
gt: function(o, x) {
return join(o, '||', 'v<=' + JSON.stringify(x));
},
ge: function(o, x) {
return join(o, '||', 'v<' + JSON.stringify(x));
},
lt: function(o, x) {
return join(o, '||', 'v>=' + JSON.stringify(x));
},
le: function(o, x) {
return join(o, '||', 'v>' + JSON.stringify(x));
},
contains: function(o, x) {
return join(o, '||', '!(v&&v.includes(' + JSON.stringify(x) + '))');
}
};
makeFilter = function(key) {
var any, c, cats, ci, e, exp, f, indicate, j, len, m, mets, record, ref, ref1;
exp = ['var v,i,c'];
cats = {
slot: {}
};
ci = 0;
any = false;
ref = filter.list;
for (j = 0, len = ref.length; j < len; j++) {
f = ref[j];
if (!f.op) {
continue;
}
any = true;
c = f.category.id;
if (!(c in cats)) {
cats[c] = {
$index: ci++
};
}
m = f.metric.id;
cats[c][m] = ops[f.op](cats[c][m], f.value);
}
if (!any) {
return;
}
indicate = function(mets, any) {
mets.indicator = ops[any ? 'two' : 'any'](mets.indicator);
return any;
};
record = function(mets, rv, age, brk) {
var e;
any = false;
for (m in mets) {
e = mets[m];
if (!(e && m !== '$index' && m !== 'indicator')) {
continue;
}
any = true;
if (m === 'age') {
exp.push('v=' + age);
} else {
exp.push('v=' + rv + '.measures[' + m + ']');
if (constants.metric[m].assumed) {
exp.push('if(v==null)v=' + JSON.stringify(constants.metric[m].assumed));
}
}
exp.push('if(' + e + ')' + brk);
}
return indicate(mets, any);
};
if (key && key !== 'slot') {
if (mets = cats[key]) {
exp.push('if(x){');
exp.push('v=' + (record(mets, 'x', 'undefined', 'return') ? 2 : 1));
exp.push('}else v=0', 'if(' + mets.indicator + ')return');
}
if (Object.keys(mets = cats.slot).length) {
exp.push('c=0', 'for(i=0;i<y.length;i++){c=1');
any = false;
for (m in mets) {
e = mets[m];
if (!(e && m !== 'indicator')) {
continue;
}
any = true;
exp.push('v=y[i].' + m, 'if(' + e + ')continue');
}
if (indicate(mets, any)) {
exp.push('c=2', 'break');
}
exp.push('}', 'v=c', 'if(' + mets.indicator + ')return');
}
} else {
ref1 = cats.slot;
for (m in ref1) {
e = ref1[m];
if (e) {
exp.push('v=x.' + m, 'if(' + e + ')return');
}
}
if (ci) {
exp.push('var r');
exp.push('c=new Uint8Array(new ArrayBuffer(' + ci + '))', 'for(i=0;i<y.length;i++){if(!(r=y[i].record)){continue');
for (c in cats) {
mets = cats[c];
if (!(c !== 'slot')) {
continue;
}
exp.push('}else if(r.category===' + c + '){if(!c[' + mets.$index + '])c[' + mets.$index + ']=1');
if (record(mets, 'r', 'y[i].age', 'continue')) {
exp.push('c[' + mets.$index + ']=2');
}
}
exp.push('}}');
for (c in cats) {
mets = cats[c];
if (c !== 'slot') {
exp.push('v=c[' + mets.$index + ']', 'if(' + mets.indicator + ')return');
}
}
}
}
exp.push('return true;');
exp = exp.join(';');
if (DEBUG) {
console.log(exp);
}
return exp;
};
make = function(f) {
return f && new Function('x', 'y', f);
};
old = void 0;
filter.make = function(key) {
return make(old = makeFilter(key || this.key));
};
filter.change = function() {
var f;
f = makeFilter(this.key);
if (f === old) {
return;
}
old = f;
filter.update(make(f));
};
filter.remove = function(i) {
this.list.splice(i, 1);
return filter.change();
};
$scope.filterCompleter = function(f, input) {
var i, j, len, match, o, results;
i = input.toLowerCase();
match = (function() {
var j, len, ref, results;
ref = f.metric.options;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
o = ref[j];
if (o.toLowerCase().startsWith(i)) {
results.push(o);
}
}
return results;
})();
switch (match.length) {
case 0:
return input;
case 1:
return match[0];
default:
results = [];
for (i = j = 0, len = match.length; j < len; i = ++j) {
o = match[i];
results.push({
text: o,
select: function() {
f.value = this.text;
filter.change();
return this.text;
},
"default": input && i === 0
});
}
return results;
}
};
filter.change();
}
};
}
]);
//# sourceMappingURL=filter.js.map