Commit f11b4cb4 by NickG123 Committed by Mitsuhiro Tanda

Added a select box to templates that allows template values to be refreshed on refresh

parent 138c738d
...@@ -212,7 +212,7 @@ function (angular, $, _, moment) { ...@@ -212,7 +212,7 @@ function (angular, $, _, moment) {
var i, j, k; var i, j, k;
var oldVersion = this.schemaVersion; var oldVersion = this.schemaVersion;
var panelUpgrades = []; var panelUpgrades = [];
this.schemaVersion = 10; this.schemaVersion = 11;
if (oldVersion === this.schemaVersion) { if (oldVersion === this.schemaVersion) {
return; return;
...@@ -401,6 +401,15 @@ function (angular, $, _, moment) { ...@@ -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) { if (panelUpgrades.length === 0) {
return; return;
} }
......
...@@ -12,7 +12,7 @@ function (angular, _) { ...@@ -12,7 +12,7 @@ function (angular, _) {
var replacementDefaults = { var replacementDefaults = {
type: 'query', type: 'query',
datasource: null, datasource: null,
refresh: false, refresh: 'Never',
name: '', name: '',
options: [], options: [],
includeAll: false, includeAll: false,
......
...@@ -170,9 +170,9 @@ ...@@ -170,9 +170,9 @@
<input type="text" class="gf-form-input" ng-model='current.regex' placeholder="/.*-(.*)-.*/" ng-model-onblur ng-change="runQuery()"></input> <input type="text" class="gf-form-input" ng-model='current.regex' placeholder="/.*-(.*)-.*/" ng-model-onblur ng-change="runQuery()"></input>
</div> </div>
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label width-7">Update</span> <span class="gf-form-label width-7">Refresh</span>
<editor-checkbox text="On Dashboard Load" model="current.refresh"></editor-checkbox> <select class="input-large tight-form-input" ng-model="current.refresh" ng-options="f for f in ['Never', 'On Dashboard Load', 'On Time Change']"></select>
<tip>Check if you want values to be updated on dashboard load, will slow down dashboard load time</tip> <tip>When to update the values of this template, will slow down dashboard load / time change</tip>
</div> </div>
</div> </div>
......
...@@ -20,6 +20,17 @@ function (angular, _, kbn) { ...@@ -20,6 +20,17 @@ function (angular, _, kbn) {
} }
}, $rootScope); }, $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.init = function(dashboard) {
this.variables = dashboard.templating.list; this.variables = dashboard.templating.list;
templateSrv.init(this.variables); templateSrv.init(this.variables);
...@@ -60,7 +71,7 @@ function (angular, _, kbn) { ...@@ -60,7 +71,7 @@ function (angular, _, kbn) {
if (urlValue !== void 0) { if (urlValue !== void 0) {
return self.setVariableFromUrl(variable, urlValue).then(lock.resolve); 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() { return self.updateOptions(variable).then(function() {
if (_.isEmpty(variable.current) && variable.options.length) { if (_.isEmpty(variable.current) && variable.options.length) {
console.log("setting current for %s", variable.name); console.log("setting current for %s", variable.name);
......
...@@ -258,6 +258,6 @@ ...@@ -258,6 +258,6 @@
"annotations": { "annotations": {
"enable": false "enable": false
}, },
"refresh": false, "refresh": "Never",
"version": 6 "version": 6
} }
...@@ -194,7 +194,7 @@ define([ ...@@ -194,7 +194,7 @@ define([
}); });
it('dashboard schema version should be set to latest', function() { it('dashboard schema version should be set to latest', function() {
expect(model.schemaVersion).to.be(10); expect(model.schemaVersion).to.be(11);
}); });
}); });
......
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