diff --git a/public/app/features/templating/datasource_variable.ts b/public/app/features/templating/datasource_variable.ts index 3a297002900..d43c0dd486d 100644 --- a/public/app/features/templating/datasource_variable.ts +++ b/public/app/features/templating/datasource_variable.ts @@ -10,6 +10,7 @@ export class DatasourceVariable implements Variable { query: string; options: any; current: any; + refresh: any; defaults = { type: 'datasource', @@ -20,11 +21,13 @@ export class DatasourceVariable implements Variable { regex: '', options: [], query: '', + refresh: 1, }; /** @ngInject **/ constructor(private model, private datasourceSrv, private variableSrv) { assignModelProperties(this, model, this.defaults); + this.refresh = 1; } getModel() { diff --git a/public/app/features/templating/specs/variable_srv_init_specs.ts b/public/app/features/templating/specs/variable_srv_init_specs.ts index 8cac63135ca..533c70dfc25 100644 --- a/public/app/features/templating/specs/variable_srv_init_specs.ts +++ b/public/app/features/templating/specs/variable_srv_init_specs.ts @@ -62,6 +62,7 @@ describe('VariableSrv init', function() { options: [{text: "test", value: "test"}] }]; scenario.urlParams["var-apps"] = "new"; + scenario.metricSources = []; }); it('should update current value', () => { @@ -110,6 +111,30 @@ describe('VariableSrv init', function() { }); }); + describeInitScenario('when datasource variable is initialized', scenario => { + scenario.setup(() => { + scenario.variables = [{ + type: 'datasource', + query: 'graphite', + name: 'test', + current: {value: 'backend4_pee', text: 'backend4_pee'}, + regex: '/pee$/' + } + ]; + scenario.metricSources = [ + {name: 'backend1', meta: {id: 'influx'}}, + {name: 'backend2_pee', meta: {id: 'graphite'}}, + {name: 'backend3', meta: {id: 'graphite'}}, + {name: 'backend4_pee', meta: {id: 'graphite'}}, + ]; + }); + + it('should update current value', function() { + var variable = ctx.variableSrv.variables[0]; + expect(variable.options.length).to.be(2); + }); + }); + describeInitScenario('when template variable is present in url multiple times', scenario => { scenario.setup(() => { scenario.variables = [{