diff --git a/public/app/features/dashboard/dashboardSrv.js b/public/app/features/dashboard/dashboardSrv.js index 01c5787481b..e8216165486 100644 --- a/public/app/features/dashboard/dashboardSrv.js +++ b/public/app/features/dashboard/dashboardSrv.js @@ -212,7 +212,7 @@ function (angular, $, _, moment) { var i, j, k; var oldVersion = this.schemaVersion; var panelUpgrades = []; - this.schemaVersion = 10; + this.schemaVersion = 11; if (oldVersion === this.schemaVersion) { return; @@ -401,6 +401,15 @@ function (angular, $, _, moment) { }); } + if (oldVersion < 11) { + // update template variables + for (i = 0 ; i < this.templating.list.length; i++) { + var templateVariable = this.templating.list[i]; + if (templateVariable.refresh) { templateVariable.refresh = 'On Dashboard Load'; } + if (!templateVariable.refresh) { templateVariable.refresh = 'Never'; } + } + } + if (panelUpgrades.length === 0) { return; } diff --git a/public/app/features/templating/editorCtrl.js b/public/app/features/templating/editorCtrl.js index 46a3072090d..1b31ce9cf1a 100644 --- a/public/app/features/templating/editorCtrl.js +++ b/public/app/features/templating/editorCtrl.js @@ -12,7 +12,7 @@ function (angular, _) { var replacementDefaults = { type: 'query', datasource: null, - refresh: false, + refresh: 'Never', name: '', options: [], includeAll: false, diff --git a/public/app/features/templating/partials/editor.html b/public/app/features/templating/partials/editor.html index 64541868f3b..d7591086b5c 100644 --- a/public/app/features/templating/partials/editor.html +++ b/public/app/features/templating/partials/editor.html @@ -170,9 +170,9 @@
- Update - - Check if you want values to be updated on dashboard load, will slow down dashboard load time + Refresh + + When to update the values of this template, will slow down dashboard load / time change
diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index 51895ff1ebf..c1086a2a62a 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -20,6 +20,17 @@ function (angular, _, kbn) { } }, $rootScope); + $rootScope.onAppEvent('refresh', function() { + var promises = []; + for (var i = 0; i < self.variables.length; i++) { + var variable = self.variables[i]; + if (variable.refresh === 'On Time Change') { + promises.push(self.updateOptions(variable)); + } + } + return $q.all(promises); + }, $rootScope); + this.init = function(dashboard) { this.variables = dashboard.templating.list; templateSrv.init(this.variables); @@ -60,7 +71,7 @@ function (angular, _, kbn) { if (urlValue !== void 0) { return self.setVariableFromUrl(variable, urlValue).then(lock.resolve); } - else if (variable.refresh) { + else if (variable.refresh === 'On Dashboard Load' || variable.refresh === 'On Time Change') { return self.updateOptions(variable).then(function() { if (_.isEmpty(variable.current) && variable.options.length) { console.log("setting current for %s", variable.name); diff --git a/public/dashboards/template_vars.json b/public/dashboards/template_vars.json index fbf2ae0dc9d..53dd5e3cfbf 100644 --- a/public/dashboards/template_vars.json +++ b/public/dashboards/template_vars.json @@ -258,6 +258,6 @@ "annotations": { "enable": false }, - "refresh": false, + "refresh": "Never", "version": 6 } diff --git a/public/test/specs/dashboardSrv-specs.js b/public/test/specs/dashboardSrv-specs.js index 8f455864650..86f54f274fb 100644 --- a/public/test/specs/dashboardSrv-specs.js +++ b/public/test/specs/dashboardSrv-specs.js @@ -194,7 +194,7 @@ define([ }); it('dashboard schema version should be set to latest', function() { - expect(model.schemaVersion).to.be(10); + expect(model.schemaVersion).to.be(11); }); });