diff --git a/CHANGELOG.md b/CHANGELOG.md index 2157a33eb01..ce631a68907 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ - [Issue #2461](https://github.com/grafana/grafana/issues/2461). LDAP: Fix for ldap users with empty email address - [Issue #2484](https://github.com/grafana/grafana/issues/2484). Graphite: Fix bug when using series ref (#A-Z) and referenced series is hidden in query editor. +**Enhancements** +- [Issue #2477](https://github.com/grafana/grafana/issues/2477). InfluxDB: Added more condition operators (`<`, `>`, `<>`, `!~`), thx @thuck + # 2.1.0 (2015-08-04) **Data sources** diff --git a/public/app/directives/metric.segment.js b/public/app/directives/metric.segment.js index 4202cfdc332..c585be21291 100644 --- a/public/app/directives/metric.segment.js +++ b/public/app/directives/metric.segment.js @@ -68,7 +68,7 @@ function (angular, app, _, $) { else { // need to have long delay because the blur // happens long before the click event on the typeahead options - cancelBlur = setTimeout($scope.switchToLink, 50); + cancelBlur = setTimeout($scope.switchToLink, 100); } }; @@ -92,6 +92,7 @@ function (angular, app, _, $) { $scope.updater = function(value) { if (value === segment.value) { + console.log('cancel blur'); clearTimeout(cancelBlur); $input.focus(); return value; diff --git a/public/app/plugins/datasource/influxdb/queryBuilder.js b/public/app/plugins/datasource/influxdb/queryBuilder.js index 95c8bd1b4dd..c6306f20c66 100644 --- a/public/app/plugins/datasource/influxdb/queryBuilder.js +++ b/public/app/plugins/datasource/influxdb/queryBuilder.js @@ -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; diff --git a/public/app/plugins/datasource/influxdb/queryCtrl.js b/public/app/plugins/datasource/influxdb/queryCtrl.js index 52e9e8277d8..2772587ddf8 100644 --- a/public/app/plugins/datasource/influxdb/queryCtrl.js +++ b/public/app/plugins/datasource/influxdb/queryCtrl.js @@ -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'})); }); diff --git a/public/test/specs/influxdbQueryCtrl-specs.js b/public/test/specs/influxdbQueryCtrl-specs.js index 564ed6930ba..4eee85859b9 100644 --- a/public/test/specs/influxdbQueryCtrl-specs.js +++ b/public/test/specs/influxdbQueryCtrl-specs.js @@ -60,6 +60,10 @@ define([ expect(ctx.scope.target.tags[0].value).to.be('server1'); }); + it('should set tag operator', function() { + expect(ctx.scope.target.tags[0].operator).to.be('='); + }); + it('should add plus button for another filter', function() { expect(ctx.scope.tagSegments[3].fake).to.be(true); }); @@ -74,6 +78,7 @@ define([ it('should update operator', function() { expect(ctx.scope.tagSegments[1].value).to.be('=~'); + expect(ctx.scope.target.tags[0].operator).to.be('=~'); }); });