Commit 18c57ea2 by utkarshcmu

Made opentsdb query_ctrl robust

parent a883424d
......@@ -224,7 +224,7 @@ function (angular, _, dateMath) {
this.getAggregators = function() {
if (aggregatorsPromise) { return aggregatorsPromise; }
aggregatorsPromise = this._get('/api/aggregators').then(function(result) {
aggregatorsPromise = this._get('/api/aggregators').then(function(result) {
if (result.data && _.isArray(result.data)) {
return result.data.sort();
}
......@@ -233,6 +233,19 @@ function (angular, _, dateMath) {
return aggregatorsPromise;
};
var filterTypesPromise = null;
this.getFilterTypes = function() {
if (filterTypesPromise) { return filterTypesPromise; }
filterTypesPromise = this._get('/api/config/filters').then(function(result) {
if (result.data) {
return Object.keys(result.data).sort();
}
return [];
});
return filterTypesPromise;
};
function transformMetricData(md, groupByTags, target, options) {
var metricLabel = createMetricLabel(md, target, groupByTags, options);
var dps = [];
......
......@@ -45,7 +45,15 @@ export class OpenTsQueryCtrl extends QueryCtrl {
}
this.datasource.getAggregators().then((aggs) => {
this.aggregators = aggs;
if (aggs.length !== 0) {
this.aggregators = aggs;
}
});
this.datasource.getFilterTypes().then((filterTypes) => {
if (filterTypes.length !== 0) {
this.filterTypes = filterTypes;
}
});
// needs to be defined here as it is called from typeahead
......@@ -135,7 +143,7 @@ export class OpenTsQueryCtrl extends QueryCtrl {
}
if (!this.target.currentFilterType) {
this.target.currentFilterType = 'literal_or';
this.target.currentFilterType = 'iliteral_or';
}
if (!this.target.currentFilterGroupBy) {
......
......@@ -17,6 +17,7 @@ describe('OpenTsQueryCtrl', function() {
ctx.panelCtrl = {panel: {}};
ctx.panelCtrl.refresh = sinon.spy();
ctx.datasource.getAggregators = sinon.stub().returns(ctx.$q.when([]));
ctx.datasource.getFilterTypes = sinon.stub().returns(ctx.$q.when([]));
ctx.ctrl = $controller(OpenTsQueryCtrl, {$scope: ctx.scope}, {
panelCtrl: ctx.panelCtrl,
......
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