From 4a5b753fd8d4b9e4f67f6ef0c10ad287fafd5248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 9 Mar 2016 13:10:02 +0100 Subject: [PATCH] feat(templating): refactoring of the refresh values of #4281 --- public/app/features/dashboard/dashboardSrv.js | 4 +-- public/app/features/templating/editorCtrl.js | 8 ++++- .../features/templating/partials/editor.html | 4 +-- .../features/templating/templateValuesSrv.js | 31 ++++++++++--------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/public/app/features/dashboard/dashboardSrv.js b/public/app/features/dashboard/dashboardSrv.js index ff53eb93f70..fbd950e60b6 100644 --- a/public/app/features/dashboard/dashboardSrv.js +++ b/public/app/features/dashboard/dashboardSrv.js @@ -404,8 +404,8 @@ function (angular, $, _, moment) { if (oldVersion < 11) { // update template variables _.each(this.templating.list, function(templateVariable) { - if (templateVariable.refresh) { templateVariable.refresh = 'On Dashboard Load'; } - if (!templateVariable.refresh) { templateVariable.refresh = 'Never'; } + if (templateVariable.refresh) { templateVariable.refresh = 1; } + if (!templateVariable.refresh) { templateVariable.refresh = 0; } }); } diff --git a/public/app/features/templating/editorCtrl.js b/public/app/features/templating/editorCtrl.js index 1b31ce9cf1a..b2916e1bcc7 100644 --- a/public/app/features/templating/editorCtrl.js +++ b/public/app/features/templating/editorCtrl.js @@ -12,13 +12,19 @@ function (angular, _) { var replacementDefaults = { type: 'query', datasource: null, - refresh: 'Never', + refresh: 0, name: '', options: [], includeAll: false, multi: false, }; + $scope.refreshOptions = [ + {value: 0, text: "Never"}, + {value: 1, text: "On Dashboard Load"}, + {value: 2, text: "On Time Range Change"}, + ]; + $scope.init = function() { $scope.mode = 'list'; diff --git a/public/app/features/templating/partials/editor.html b/public/app/features/templating/partials/editor.html index bbdabe92fb8..7bd1fd0940f 100644 --- a/public/app/features/templating/partials/editor.html +++ b/public/app/features/templating/partials/editor.html @@ -171,8 +171,8 @@
Refresh - - When to update the values of this template, will slow down dashboard load / time change + + When to update the values of this variable, will slow down dashboard load / time change
diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index e5861ad12c1..4ccbefefdef 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -13,22 +13,25 @@ function (angular, _, kbn) { function getNoneOption() { return { text: 'None', value: '', isNone: true }; } - $rootScope.onAppEvent('time-range-changed', function() { - var variable = _.findWhere(self.variables, { type: 'interval' }); - if (variable) { - self.updateAutoInterval(variable); - } - }, $rootScope); - + // update time variant variables $rootScope.onAppEvent('refresh', function() { - var promises = _.chain(self.variables) - .filter(function(variable) { - return variable.refresh === 'On Time Change and Dashboard Load'; - }) - .map(function(variable) { - return self.updateOptions(variable); - }).value(); + + // look for interval variables + var intervalVariable = _.findWhere(self.variables, { type: 'interval' }); + if (intervalVariable) { + self.updateAutoInterval(intervalVariable); + } + + // update variables with refresh === 2 + var promises = self.variables + .filter(function(variable) { + return variable.refresh === 2; + }).map(function(variable) { + return self.updateOptions(variable); + }); + return $q.all(promises); + }, $rootScope); this.init = function(dashboard) {