diff --git a/CHANGELOG.md b/CHANGELOG.md index f00957dc9a8..6b8cd4f7128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Enhancements * **Singlestat**: Support for gauges in singlestat panel. closes [#3688](https://github.com/grafana/grafana/pull/3688) +* **Templating**: Support for data source as variable, closes [#816](https://github.com/grafana/grafana/pull/816) ### Bug fixes * **InfluxDB 0.12**: Fixed issue templating and `show tag values` query only returning tags for first measurement, fixes [#4726](https://github.com/grafana/grafana/issues/4726) diff --git a/public/app/core/services/datasource_srv.js b/public/app/core/services/datasource_srv.js index e5fe9627bcc..2c3a043ac6c 100644 --- a/public/app/core/services/datasource_srv.js +++ b/public/app/core/services/datasource_srv.js @@ -102,8 +102,8 @@ function (angular, _, coreModule, config) { if (ds) { metricSources.push({ - name: '[[' + variable.name + ']]', - value: '[[' + variable.name + ']]', + name: '$' + variable.name, + value: '$' + variable.name, meta: ds.meta, }); } diff --git a/public/app/core/services/segment_srv.js b/public/app/core/services/segment_srv.js index a0b85a8bfb2..d05a2bb011f 100644 --- a/public/app/core/services/segment_srv.js +++ b/public/app/core/services/segment_srv.js @@ -19,7 +19,7 @@ function (angular, _, coreModule) { if (_.isString(options)) { this.value = options; - this.html = $sce.trustAsHtml(this.value); + this.html = $sce.trustAsHtml(templateSrv.highlightVariablesAsHtml(this.value)); return; } diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index d5d074f0c6d..dc878c19c08 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -63,7 +63,9 @@ function (angular, _, kbn) { // determine our dependencies. if (variable.type === "query") { _.forEach(this.variables, function(v) { - if (templateSrv.containsVariable(variable.query, v.name)) { + // both query and datasource can contain variable + if (templateSrv.containsVariable(variable.query, v.name) || + templateSrv.containsVariable(variable.datasource, v.name)) { dependencies.push(self.variableLock[v.name].promise); } }); @@ -149,7 +151,8 @@ function (angular, _, kbn) { if (otherVariable === updatedVariable) { return; } - if (templateSrv.containsVariable(otherVariable.query, updatedVariable.name)) { + if (templateSrv.containsVariable(otherVariable.query, updatedVariable.name) || + templateSrv.containsVariable(otherVariable.datasource, updatedVariable.name)) { return self.updateOptions(otherVariable); } });