From 6ff188e4d93f62ceeca4bbb6fbe7af96382aeb18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 4 Sep 2014 17:34:36 +0200 Subject: [PATCH] test for adding syntax in addition to [[variable]] --- src/app/controllers/graphiteTarget.js | 2 +- src/app/partials/panelgeneral.html | 8 ++++++-- src/app/services/influxdb/influxdbDatasource.js | 3 --- src/app/services/templateSrv.js | 10 ++++++---- src/css/less/overrides.less | 3 ++- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/app/controllers/graphiteTarget.js b/src/app/controllers/graphiteTarget.js index 5d7aa4e0132..23f7cd5b598 100644 --- a/src/app/controllers/graphiteTarget.js +++ b/src/app/controllers/graphiteTarget.js @@ -165,7 +165,7 @@ function (angular, _, config, gfunc, Parser) { _.each(templateSrv.variables, function(variable) { $scope.altSegments.unshift(new MetricSegment({ type: 'template', - value: '[[' + variable.name + ']]', + value: '$' + variable.name + ']]', expandable: true, })); }); diff --git a/src/app/partials/panelgeneral.html b/src/app/partials/panelgeneral.html index e2398663d69..40b46ca0618 100644 --- a/src/app/partials/panelgeneral.html +++ b/src/app/partials/panelgeneral.html @@ -4,8 +4,12 @@
-
+
+
+ +
+
- \ No newline at end of file + diff --git a/src/app/services/influxdb/influxdbDatasource.js b/src/app/services/influxdb/influxdbDatasource.js index b90476f6bf2..f316340fd91 100644 --- a/src/app/services/influxdb/influxdbDatasource.js +++ b/src/app/services/influxdb/influxdbDatasource.js @@ -19,9 +19,6 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) { this.username = datasource.username; this.password = datasource.password; this.name = datasource.name; - this.templateSettings = { - interpolate : /\[\[([\s\S]+?)\]\]/g, - }; this.saveTemp = _.isUndefined(datasource.save_temp) ? true : datasource.save_temp; this.saveTempTTL = _.isUndefined(datasource.save_temp_ttl) ? '30d' : datasource.save_temp_ttl; diff --git a/src/app/services/templateSrv.js b/src/app/services/templateSrv.js index 720b732ebc8..9e9dafe2c95 100644 --- a/src/app/services/templateSrv.js +++ b/src/app/services/templateSrv.js @@ -8,10 +8,12 @@ function (angular, _) { var module = angular.module('grafana.services'); module.service('templateSrv', function($q, $routeParams) { + var self = this; this.init = function(variables) { this.templateSettings = { interpolate : /\[\[([\s\S]+?)\]\]/g }; this.variables = variables; + this.regex = /\$(\w+)|\[\[([\s\S]+?)\]\]/g; this.updateTemplateData(true); }; @@ -39,11 +41,11 @@ function (angular, _) { }; this.replace = function(target) { - if (!target || target.indexOf('[[') === -1) { - return target; - } + if (!target) { return; } - return _.template(target, this._templateData, this.templateSettings); + return target.replace(this.regex, function(match, g1, g2) { + return self._templateData[g1 || g2] || match; + }); }; }); diff --git a/src/css/less/overrides.less b/src/css/less/overrides.less index b91960687ee..605bc9a4cf0 100644 --- a/src/css/less/overrides.less +++ b/src/css/less/overrides.less @@ -66,7 +66,8 @@ code, pre { } .panel { - display: inline-table; + display: inline-block; + float: left; vertical-align: top; }