Commit 1da149d9 by Torkel Ödegaard

feat(annotations): annotations can now use a template variable as data source, closes #5054

parent 43ba563a
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"company": "Coding Instinct AB" "company": "Coding Instinct AB"
}, },
"name": "grafana", "name": "grafana",
"version": "3.0.2", "version": "3.0.3",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "http://github.com/grafana/grafana.git" "url": "http://github.com/grafana/grafana.git"
......
...@@ -66,14 +66,17 @@ function (angular, _, coreModule, config) { ...@@ -66,14 +66,17 @@ function (angular, _, coreModule, config) {
}; };
this.getAnnotationSources = function() { this.getAnnotationSources = function() {
return _.reduce(config.datasources, function(memo, value) { var sources = [];
this.addDataSourceVariables(sources);
_.each(config.datasources, function(value) {
if (value.meta && value.meta.annotations) { if (value.meta && value.meta.annotations) {
memo.push(value); sources.push(value);
} }
});
return memo; return sources;
}, []);
}; };
this.getMetricSources = function(options) { this.getMetricSources = function(options) {
...@@ -90,6 +93,23 @@ function (angular, _, coreModule, config) { ...@@ -90,6 +93,23 @@ function (angular, _, coreModule, config) {
}); });
if (!options || !options.skipVariables) { if (!options || !options.skipVariables) {
this.addDataSourceVariables(metricSources);
}
metricSources.sort(function(a, b) {
if (a.meta.builtIn || a.name > b.name) {
return 1;
}
if (a.name < b.name) {
return -1;
}
return 0;
});
return metricSources;
};
this.addDataSourceVariables = function(list) {
// look for data source variables // look for data source variables
for (var i = 0; i < templateSrv.variables.length; i++) { for (var i = 0; i < templateSrv.variables.length; i++) {
var variable = templateSrv.variables[i]; var variable = templateSrv.variables[i];
...@@ -101,26 +121,13 @@ function (angular, _, coreModule, config) { ...@@ -101,26 +121,13 @@ function (angular, _, coreModule, config) {
var ds = config.datasources[first]; var ds = config.datasources[first];
if (ds) { if (ds) {
metricSources.push({ list.push({
name: '$' + variable.name, name: '$' + variable.name,
value: '$' + variable.name, value: '$' + variable.name,
meta: ds.meta, meta: ds.meta,
}); });
} }
} }
}
metricSources.sort(function(a, b) {
if (a.meta.builtIn || a.name > b.name) {
return 1;
}
if (a.name < b.name) {
return -1;
}
return 0;
});
return metricSources;
}; };
this.init(); this.init();
......
...@@ -30,7 +30,7 @@ function (angular, _, $) { ...@@ -30,7 +30,7 @@ function (angular, _, $) {
$scope.datasourceChanged = function() { $scope.datasourceChanged = function() {
return datasourceSrv.get($scope.currentAnnotation.datasource).then(function(ds) { return datasourceSrv.get($scope.currentAnnotation.datasource).then(function(ds) {
$scope.currentDatasource = ds; $scope.currentDatasource = ds;
$scope.currentAnnotation.datasource = ds.name; $scope.currentAnnotation.datasource = $scope.currentAnnotation.datasource;
}); });
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment