Commit e36cdac5 by Torkel Ödegaard

fix(templating): fixed issue with templating when initalizing variables without any existing value

parent 0fc7405b
...@@ -43,6 +43,10 @@ function (angular, _, kbn) { ...@@ -43,6 +43,10 @@ function (angular, _, kbn) {
} }
}; };
this.variableInitialized = function(variable) {
this._index[variable.name] = variable;
};
this.getAdhocFilters = function(datasourceName) { this.getAdhocFilters = function(datasourceName) {
var variable = this._adhocVariables[datasourceName]; var variable = this._adhocVariables[datasourceName];
if (variable) { if (variable) {
......
...@@ -8,7 +8,6 @@ import {Variable, variableTypes} from './variable'; ...@@ -8,7 +8,6 @@ import {Variable, variableTypes} from './variable';
export class VariableSrv { export class VariableSrv {
dashboard: any; dashboard: any;
variables: any; variables: any;
variableLock: any;
/** @ngInject */ /** @ngInject */
constructor(private $rootScope, private $q, private $location, private $injector, private templateSrv) { constructor(private $rootScope, private $q, private $location, private $injector, private templateSrv) {
...@@ -18,7 +17,6 @@ export class VariableSrv { ...@@ -18,7 +17,6 @@ export class VariableSrv {
} }
init(dashboard) { init(dashboard) {
this.variableLock = {};
this.dashboard = dashboard; this.dashboard = dashboard;
// create working class models representing variables // create working class models representing variables
...@@ -30,7 +28,7 @@ export class VariableSrv { ...@@ -30,7 +28,7 @@ export class VariableSrv {
// init variables // init variables
for (let variable of this.variables) { for (let variable of this.variables) {
this.variableLock[variable.name] = this.$q.defer(); variable.initLock = this.$q.defer();
} }
var queryParams = this.$location.search(); var queryParams = this.$location.search();
...@@ -61,27 +59,27 @@ export class VariableSrv { ...@@ -61,27 +59,27 @@ export class VariableSrv {
processVariable(variable, queryParams) { processVariable(variable, queryParams) {
var dependencies = []; var dependencies = [];
var lock = this.variableLock[variable.name];
for (let otherVariable of this.variables) { for (let otherVariable of this.variables) {
if (variable.dependsOn(otherVariable)) { if (variable.dependsOn(otherVariable)) {
dependencies.push(this.variableLock[otherVariable.name].promise); dependencies.push(otherVariable.initLock.promise);
} }
} }
return this.$q.all(dependencies).then(() => { return this.$q.all(dependencies).then(() => {
var urlValue = queryParams['var-' + variable.name]; var urlValue = queryParams['var-' + variable.name];
if (urlValue !== void 0) { if (urlValue !== void 0) {
return variable.setValueFromUrl(urlValue).then(lock.resolve); return variable.setValueFromUrl(urlValue).then(variable.initLock.resolve);
} }
if (variable.refresh === 1 || variable.refresh === 2) { if (variable.refresh === 1 || variable.refresh === 2) {
return variable.updateOptions().then(lock.resolve); return variable.updateOptions().then(variable.initLock.resolve);
} }
lock.resolve(); variable.initLock.resolve();
}).finally(() => { }).finally(() => {
delete this.variableLock[variable.name]; this.templateSrv.variableInitialized(variable);
delete variable.initLock;
}); });
} }
...@@ -113,7 +111,7 @@ export class VariableSrv { ...@@ -113,7 +111,7 @@ export class VariableSrv {
variableUpdated(variable) { variableUpdated(variable) {
// if there is a variable lock ignore cascading update because we are in a boot up scenario // if there is a variable lock ignore cascading update because we are in a boot up scenario
if (this.variableLock[variable.name]) { if (variable.initLock) {
return this.$q.when(); return this.$q.when();
} }
......
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