From f11b4cb4817df7d3bc03946ee65f92ab1658349e Mon Sep 17 00:00:00 2001 From: NickG123 Date: Thu, 10 Dec 2015 23:14:37 -0500 Subject: [PATCH 1/3] Added a select box to templates that allows template values to be refreshed on refresh --- public/app/features/dashboard/dashboardSrv.js | 11 ++++++++++- public/app/features/templating/editorCtrl.js | 2 +- public/app/features/templating/partials/editor.html | 6 +++--- public/app/features/templating/templateValuesSrv.js | 13 ++++++++++++- public/dashboards/template_vars.json | 2 +- public/test/specs/dashboardSrv-specs.js | 2 +- 6 files changed, 28 insertions(+), 8 deletions(-) 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); }); }); From ba1e1532ace60aa6d051e6d9e520f21783c58fa9 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Tue, 8 Mar 2016 18:13:40 +0900 Subject: [PATCH 2/3] change option name more clearly --- public/app/features/templating/partials/editor.html | 2 +- public/app/features/templating/templateValuesSrv.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/app/features/templating/partials/editor.html b/public/app/features/templating/partials/editor.html index d7591086b5c..3028bfa8a36 100644 --- a/public/app/features/templating/partials/editor.html +++ b/public/app/features/templating/partials/editor.html @@ -171,7 +171,7 @@
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 c1086a2a62a..4e5530b82f7 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -24,7 +24,7 @@ function (angular, _, kbn) { var promises = []; for (var i = 0; i < self.variables.length; i++) { var variable = self.variables[i]; - if (variable.refresh === 'On Time Change') { + if (variable.refresh === 'On Time Change and Dashboard Load') { promises.push(self.updateOptions(variable)); } } @@ -71,7 +71,7 @@ function (angular, _, kbn) { if (urlValue !== void 0) { return self.setVariableFromUrl(variable, urlValue).then(lock.resolve); } - else if (variable.refresh === 'On Dashboard Load' || variable.refresh === 'On Time Change') { + else if (variable.refresh === 'On Dashboard Load' || variable.refresh === 'On Time Change and Dashboard Load') { return self.updateOptions(variable).then(function() { if (_.isEmpty(variable.current) && variable.options.length) { console.log("setting current for %s", variable.name); From aff4bf8f6cfb25af9acda5e0cb07fb13db139c96 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Wed, 9 Mar 2016 01:47:38 +0900 Subject: [PATCH 3/3] minor refactoring --- public/app/features/dashboard/dashboardSrv.js | 5 ++--- .../app/features/templating/templateValuesSrv.js | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/public/app/features/dashboard/dashboardSrv.js b/public/app/features/dashboard/dashboardSrv.js index e8216165486..ff53eb93f70 100644 --- a/public/app/features/dashboard/dashboardSrv.js +++ b/public/app/features/dashboard/dashboardSrv.js @@ -403,11 +403,10 @@ function (angular, $, _, moment) { if (oldVersion < 11) { // update template variables - for (i = 0 ; i < this.templating.list.length; i++) { - var templateVariable = this.templating.list[i]; + _.each(this.templating.list, function(templateVariable) { if (templateVariable.refresh) { templateVariable.refresh = 'On Dashboard Load'; } if (!templateVariable.refresh) { templateVariable.refresh = 'Never'; } - } + }); } if (panelUpgrades.length === 0) { diff --git a/public/app/features/templating/templateValuesSrv.js b/public/app/features/templating/templateValuesSrv.js index 4e5530b82f7..e5861ad12c1 100644 --- a/public/app/features/templating/templateValuesSrv.js +++ b/public/app/features/templating/templateValuesSrv.js @@ -21,13 +21,13 @@ 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 and Dashboard Load') { - promises.push(self.updateOptions(variable)); - } - } + 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(); return $q.all(promises); }, $rootScope);