diff --git a/src/app/services/templateSrv.js b/src/app/services/templateSrv.js
index 26263780406..f8247d1c5cb 100644
--- a/src/app/services/templateSrv.js
+++ b/src/app/services/templateSrv.js
@@ -58,6 +58,7 @@ function (angular, _) {
if (self._templateData[g1 || g2]) {
return '' + match + '';
}
+ return match;
});
};
diff --git a/src/app/services/templateValuesSrv.js b/src/app/services/templateValuesSrv.js
index e1dc2b89741..52d3f51ccb3 100644
--- a/src/app/services/templateValuesSrv.js
+++ b/src/app/services/templateValuesSrv.js
@@ -71,13 +71,20 @@ function (angular, _, kbn) {
return $q.all(promises);
};
- this.updateOptions = function(variable) {
- if (variable.type === 'interval') {
- variable.options = _.map(variable.query.split(','), function(text) {
- return { text: text, value: text };
- });
+ this._updateNonQueryVariable = function(variable) {
+ // extract options in comma seperated string
+ variable.options = _.map(variable.query.split(/[\s,]+/), function(text) {
+ return { text: text, value: text };
+ });
+ if (variable.type === 'interval') {
self.updateAutoInterval(variable);
+ }
+ };
+
+ this.updateOptions = function(variable) {
+ if (variable.type !== 'query') {
+ self._updateNonQueryVariable(variable);
self.setVariableValue(variable, variable.options[0]);
return $q.when([]);
}
diff --git a/src/test/specs/templateSrv-specs.js b/src/test/specs/templateSrv-specs.js
index ecd046ac8fe..ac711dce66a 100644
--- a/src/test/specs/templateSrv-specs.js
+++ b/src/test/specs/templateSrv-specs.js
@@ -55,6 +55,11 @@ define([
expect(result).to.be('this $test ok');
});
+ it('should ignore if variables does not exist', function() {
+ var result = _templateSrv.highlightVariablesAsHtml('this $google ok');
+ expect(result).to.be('this $google ok');
+ });
+
});
describe('updateTemplateData with simple value', function() {
diff --git a/src/test/specs/templateValuesSrv-specs.js b/src/test/specs/templateValuesSrv-specs.js
index abf44442db5..f1faa8d595a 100644
--- a/src/test/specs/templateValuesSrv-specs.js
+++ b/src/test/specs/templateValuesSrv-specs.js
@@ -86,6 +86,24 @@ define([
});
});
+ describeUpdateVariable('update custom variable', function(scenario) {
+ scenario.setup(function() {
+ scenario.variable = { type: 'custom', query: 'hej, hop, asd', name: 'test'};
+ });
+
+ it('should update options array', function() {
+ expect(scenario.variable.options.length).to.be(3);
+ expect(scenario.variable.options[0].text).to.be('hej');
+ expect(scenario.variable.options[1].value).to.be('hop');
+ });
+
+ it('should set $__auto_interval', function() {
+ var call = ctx.templateSrv.setGrafanaVariable.getCall(0);
+ expect(call.args[0]).to.be('$__auto_interval');
+ expect(call.args[1]).to.be('12h');
+ });
+ });
+
describeUpdateVariable('basic query variable', function(scenario) {
scenario.setup(function() {
scenario.variable = { type: 'query', query: 'apps.*', name: 'test' };