mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(templating): making progress on adhoc template variable, #6038
This commit is contained in:
parent
83b9db51e3
commit
94e5001c0e
@ -21,7 +21,7 @@ export class AdHocFiltersCtrl {
|
|||||||
if (this.variable.value && !_.isArray(this.variable.value)) {
|
if (this.variable.value && !_.isArray(this.variable.value)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let tag of this.variable.value) {
|
for (let tag of this.variable.tags) {
|
||||||
if (this.segments.length > 0) {
|
if (this.segments.length > 0) {
|
||||||
this.segments.push(this.uiSegmentSrv.newCondition('AND'));
|
this.segments.push(this.uiSegmentSrv.newCondition('AND'));
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ export class AdHocFiltersCtrl {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.$rootScope.$broadcast('refresh');
|
this.$rootScope.$broadcast('refresh');
|
||||||
this.variable.value = tags;
|
this.variable.tags = tags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +189,7 @@ function (angular, _, $, kbn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (variable.type === 'adhoc') {
|
if (variable.type === 'adhoc') {
|
||||||
|
variable.current = {};
|
||||||
variable.options = [];
|
variable.options = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ export default class InfluxDatasource {
|
|||||||
// apply add hoc filters
|
// apply add hoc filters
|
||||||
for (let variable of this.templateSrv.variables) {
|
for (let variable of this.templateSrv.variables) {
|
||||||
if (variable.type === 'adhoc' && variable.datasource === this.name) {
|
if (variable.type === 'adhoc' && variable.datasource === this.name) {
|
||||||
for (let tag of variable.value) {
|
for (let tag of variable.tags) {
|
||||||
if (tag.key !== undefined && tag.value !== undefined) {
|
if (tag.key !== undefined && tag.value !== undefined) {
|
||||||
target.tags.push({key: tag.key, value: tag.value, condition: 'AND'});
|
target.tags.push({key: tag.key, value: tag.value, condition: 'AND'});
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ define([
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('when template variable is present in url', function() {
|
describe('when template variable is present in url', function() {
|
||||||
|
describe('and setting simple variable', function() {
|
||||||
var variable = {
|
var variable = {
|
||||||
name: 'apps',
|
name: 'apps',
|
||||||
current: {text: "test", value: "test"},
|
current: {text: "test", value: "test"},
|
||||||
@ -49,6 +50,24 @@ define([
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('and setting adhoc variable', function() {
|
||||||
|
var variable = {name: 'filters', type: 'adhoc'};
|
||||||
|
|
||||||
|
beforeEach(function(done) {
|
||||||
|
var dashboard = { templating: { list: [variable] } };
|
||||||
|
var urlParams = {};
|
||||||
|
urlParams["var-filters"] = "hostname|gt|server2";
|
||||||
|
ctx.$location.search = sinon.stub().returns(urlParams);
|
||||||
|
ctx.service.init(dashboard).then(function() { done(); });
|
||||||
|
ctx.$rootScope.$digest();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should update current value', function() {
|
||||||
|
expect(variable.tags[0]).to.eq({tag: 'hostname', value: 'server2'});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('when template variable is present in url multiple times', function() {
|
describe('when template variable is present in url multiple times', function() {
|
||||||
var variable = {
|
var variable = {
|
||||||
name: 'apps',
|
name: 'apps',
|
||||||
|
Loading…
Reference in New Issue
Block a user