From 68c4ce34d5ceacaddb2c1a4d5d18a0bae4472cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 8 Aug 2017 17:08:35 +0200 Subject: [PATCH] fix: templating issue with data source variables, can now be used right away in other query variables and panels (without page reload), fixes #7510 --- public/app/core/services/datasource_srv.js | 4 ++++ public/app/features/templating/editor_ctrl.ts | 17 +++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/public/app/core/services/datasource_srv.js b/public/app/core/services/datasource_srv.js index d31a8a0f399..db8485bb2f1 100644 --- a/public/app/core/services/datasource_srv.js +++ b/public/app/core/services/datasource_srv.js @@ -129,6 +129,10 @@ function (angular, _, coreModule, config) { } var first = variable.current.value; + if (first === 'default') { + first = config.defaultDatasource; + } + var ds = config.datasources[first]; if (ds) { diff --git a/public/app/features/templating/editor_ctrl.ts b/public/app/features/templating/editor_ctrl.ts index 99c235ef24c..9ef5327e7cc 100644 --- a/public/app/features/templating/editor_ctrl.ts +++ b/public/app/features/templating/editor_ctrl.ts @@ -35,14 +35,6 @@ export class VariableEditorCtrl { $scope.init = function() { $scope.mode = 'list'; - $scope.datasources = _.filter(datasourceSrv.getMetricSources(), function(ds) { - return !ds.meta.mixed && ds.value !== null; - }); - - $scope.datasourceTypes = _($scope.datasources).uniqBy('meta.id').map(function(ds) { - return {text: ds.meta.name, value: ds.meta.id}; - }).value(); - $scope.variables = variableSrv.variables; $scope.reset(); @@ -130,6 +122,15 @@ export class VariableEditorCtrl { $scope.reset = function() { $scope.currentIsNew = true; $scope.current = variableSrv.createVariableFromModel({type: 'query'}); + + // this is done here in case a new data source type variable was added + $scope.datasources = _.filter(datasourceSrv.getMetricSources(), function(ds) { + return !ds.meta.mixed && ds.value !== null; + }); + + $scope.datasourceTypes = _($scope.datasources).uniqBy('meta.id').map(function(ds) { + return {text: ds.meta.name, value: ds.meta.id}; + }).value(); }; $scope.typeChanged = function() {