refactor(influxdb): refactoring of PR 2477, added unit tests, #2477

This commit is contained in:
Torkel Ödegaard
2015-08-10 09:09:39 +02:00
parent ca6476a57f
commit e7fc72067a
5 changed files with 33 additions and 14 deletions

View File

@@ -10,18 +10,26 @@ function (_) {
function renderTagCondition (tag, index) {
var str = "";
var operator = (tag.operator || '=');
var operator = tag.operator;
var value = tag.value;
if (index > 0) {
str = (tag.condition || 'AND') + ' ';
}
if (tag.value && (operator === '=~' || operator === '!~') && /^\/.*\/$/.test(tag.value)) {
return str + '"' + tag.key + '"' + ' ' + operator + ' ' + tag.value;
} else if (tag.value && /^\/.*\/$/.test(tag.value)) {
return str + '"' + tag.key + '"' + ' =~ ' + tag.value;
if (!operator) {
if (/^\/.*\/$/.test(tag.value)) {
operator = '=~';
} else {
operator = '=';
}
}
return str + '"' + tag.key + '" ' + operator + " '" + tag.value + "'";
// quote value unless regex
if (operator !== '=~' && operator !== '!~') {
value = "'" + value + "'";
}
return str + '"' + tag.key + '" ' + operator + ' ' + value;
}
var p = InfluxQueryBuilder.prototype;

View File

@@ -31,17 +31,19 @@ function (angular, _, InfluxQueryBuilder) {
$scope.tagSegments = [];
_.each(target.tags, function(tag) {
if (!tag.operator) {
if (/^\/.*\/$/.test(tag.value)) {
tag.operator = "=~";
} else {
tag.operator = '=';
}
}
if (tag.condition) {
$scope.tagSegments.push(MetricSegment.newCondition(tag.condition));
}
$scope.tagSegments.push(new MetricSegment({value: tag.key, type: 'key', cssClass: 'query-segment-key' }));
if (tag.operator) {
$scope.tagSegments.push(MetricSegment.newOperator(tag.operator));
} else if (/^\/.*\/$/.test(tag.value)) {
$scope.tagSegments.push(MetricSegment.newOperator('=~'));
} else {
$scope.tagSegments.push(MetricSegment.newOperator('='));
}
$scope.tagSegments.push(MetricSegment.newOperator(tag.operator));
$scope.tagSegments.push(new MetricSegment({value: tag.value, type: 'value', cssClass: 'query-segment-value'}));
});