mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Added a select box to templates that allows template values to be refreshed on refresh
This commit is contained in:
parent
138c738db9
commit
f11b4cb481
@ -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;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ function (angular, _) {
|
||||
var replacementDefaults = {
|
||||
type: 'query',
|
||||
datasource: null,
|
||||
refresh: false,
|
||||
refresh: 'Never',
|
||||
name: '',
|
||||
options: [],
|
||||
includeAll: false,
|
||||
|
@ -170,9 +170,9 @@
|
||||
<input type="text" class="gf-form-input" ng-model='current.regex' placeholder="/.*-(.*)-.*/" ng-model-onblur ng-change="runQuery()"></input>
|
||||
</div>
|
||||
<div class="gf-form">
|
||||
<span class="gf-form-label width-7">Update</span>
|
||||
<editor-checkbox text="On Dashboard Load" model="current.refresh"></editor-checkbox>
|
||||
<tip>Check if you want values to be updated on dashboard load, will slow down dashboard load time</tip>
|
||||
<span class="gf-form-label width-7">Refresh</span>
|
||||
<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>When to update the values of this template, will slow down dashboard load / time change</tip>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -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);
|
||||
|
@ -258,6 +258,6 @@
|
||||
"annotations": {
|
||||
"enable": false
|
||||
},
|
||||
"refresh": false,
|
||||
"refresh": "Never",
|
||||
"version": 6
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user