diff --git a/public/app/features/panel/query_editor.ts b/public/app/features/panel/query_editor.ts index 5b493362762..7a5c6126740 100644 --- a/public/app/features/panel/query_editor.ts +++ b/public/app/features/panel/query_editor.ts @@ -9,7 +9,7 @@ function metricsQueryEditor(dynamicDirectiveSrv, datasourceSrv) { directive: scope => { let datasource = scope.target.datasource || scope.ctrl.panel.datasource; return datasourceSrv.get(datasource).then(ds => { - scope.ctrl.datasource = ds; + scope.datasource = ds; if (!scope.target.refId) { scope.target.refId = 'A'; diff --git a/public/app/plugins/datasource/graphite/query_ctrl.js b/public/app/plugins/datasource/graphite/query_ctrl.js index ab113465262..55083aefaa2 100644 --- a/public/app/plugins/datasource/graphite/query_ctrl.js +++ b/public/app/plugins/datasource/graphite/query_ctrl.js @@ -12,6 +12,7 @@ function (angular, _, config, gfunc, Parser) { module.controller('GraphiteQueryCtrl', function($scope, uiSegmentSrv, templateSrv) { var panelCtrl = $scope.panelCtrl = $scope.ctrl; + var datasource = $scope.datasource; $scope.init = function() { if ($scope.target) { @@ -126,7 +127,7 @@ function (angular, _, config, gfunc, Parser) { } var path = getSegmentPathUpTo(fromIndex + 1); - return panelCtrl.datasource.metricFindQuery(path) + return datasource.metricFindQuery(path) .then(function(segments) { if (segments.length === 0) { if (path !== '') { @@ -160,7 +161,7 @@ function (angular, _, config, gfunc, Parser) { $scope.getAltSegments = function (index) { var query = index === 0 ? '*' : getSegmentPathUpTo(index) + '.*'; - return panelCtrl.datasource.metricFindQuery(query).then(function(segments) { + return datasource.metricFindQuery(query).then(function(segments) { var altSegments = _.map(segments, function(segment) { return uiSegmentSrv.newSegment({ value: segment.text, expandable: segment.expandable }); }); diff --git a/public/app/plugins/datasource/graphite/specs/query_ctrl_specs.ts b/public/app/plugins/datasource/graphite/specs/query_ctrl_specs.ts index bdf339e0d27..195e872efc7 100644 --- a/public/app/plugins/datasource/graphite/specs/query_ctrl_specs.ts +++ b/public/app/plugins/datasource/graphite/specs/query_ctrl_specs.ts @@ -19,14 +19,13 @@ describe('GraphiteQueryCtrl', function() { ctx.scope = $rootScope.$new(); ctx.scope.ctrl = {panel: ctx.panel}; ctx.panelCtrl = ctx.scope.ctrl; + ctx.scope.datasource = ctx.datasource; + ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([])); ctx.controller = $controller('GraphiteQueryCtrl', {$scope: ctx.scope}); })); beforeEach(function() { ctx.scope.target = {target: 'aliasByNode(scaleToSeconds(test.prod.*,1),2)'}; - - ctx.panelCtrl.datasource = ctx.datasource; - ctx.panelCtrl.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([])); }); describe('init', function() { @@ -36,7 +35,7 @@ describe('GraphiteQueryCtrl', function() { }); it('should validate metric key exists', function() { - expect(ctx.panelCtrl.datasource.metricFindQuery.getCall(0).args[0]).to.be('test.prod.*'); + expect(ctx.scope.datasource.metricFindQuery.getCall(0).args[0]).to.be('test.prod.*'); }); it('should delete last segment if no metrics are found', function() { @@ -51,7 +50,7 @@ describe('GraphiteQueryCtrl', function() { describe('when adding function', function() { beforeEach(function() { ctx.scope.target.target = 'test.prod.*.count'; - ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}])); + ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}])); ctx.scope.init(); ctx.scope.$digest(); @@ -75,7 +74,7 @@ describe('GraphiteQueryCtrl', function() { describe('when adding function before any metric segment', function() { beforeEach(function() { ctx.scope.target.target = ''; - ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: true}])); + ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: true}])); ctx.scope.init(); ctx.scope.$digest(); ctx.scope.addFunction(gfunc.getFuncDef('asPercent')); @@ -89,7 +88,7 @@ describe('GraphiteQueryCtrl', function() { describe('when initalizing target without metric expression and only function', function() { beforeEach(function() { ctx.scope.target.target = 'asPercent(#A, #B)'; - ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([])); + ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([])); ctx.scope.init(); ctx.scope.$digest(); }); @@ -107,7 +106,7 @@ describe('GraphiteQueryCtrl', function() { describe('when initializing a target with single param func using variable', function() { beforeEach(function() { ctx.scope.target.target = 'movingAverage(prod.count, $var)'; - ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([])); + ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([])); ctx.scope.init(); ctx.scope.$digest(); }); @@ -125,7 +124,7 @@ describe('GraphiteQueryCtrl', function() { describe('when initalizing target without metric expression and function with series-ref', function() { beforeEach(function() { ctx.scope.target.target = 'asPercent(metric.node.count, #A)'; - ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([])); + ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([])); ctx.scope.init(); ctx.scope.$digest(); ctx.scope.$parent = { get_data: sinon.spy() }; @@ -143,7 +142,7 @@ describe('GraphiteQueryCtrl', function() { describe('when getting altSegments and metricFindQuery retuns empty array', function() { beforeEach(function() { ctx.scope.target.target = 'test.count'; - ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([])); + ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([])); ctx.scope.init(); ctx.scope.getAltSegments(1).then(function(results) { ctx.altSegments = results; @@ -159,7 +158,7 @@ describe('GraphiteQueryCtrl', function() { describe('targetChanged', function() { beforeEach(function() { - ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}])); + ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}])); ctx.scope.init(); ctx.scope.$digest(); diff --git a/public/app/plugins/datasource/influxdb/partials/query.editor.html b/public/app/plugins/datasource/influxdb/partials/query.editor.html index 6bc7d402087..3322be6c423 100644 --- a/public/app/plugins/datasource/influxdb/partials/query.editor.html +++ b/public/app/plugins/datasource/influxdb/partials/query.editor.html @@ -16,15 +16,15 @@
  • - +
  • diff --git a/public/app/plugins/datasource/influxdb/query_ctrl.js b/public/app/plugins/datasource/influxdb/query_ctrl.js index f7f17beb459..fee1d5d1c77 100644 --- a/public/app/plugins/datasource/influxdb/query_ctrl.js +++ b/public/app/plugins/datasource/influxdb/query_ctrl.js @@ -16,6 +16,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) { module.controller('InfluxQueryCtrl', function($scope, templateSrv, $q, uiSegmentSrv) { var panelCtrl = $scope.ctrl; + var datasource = $scope.datasource; $scope.panelCtrl = panelCtrl; $scope.init = function() { @@ -23,7 +24,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) { $scope.target = $scope.target; $scope.queryModel = new InfluxQuery($scope.target); - $scope.queryBuilder = new InfluxQueryBuilder($scope.target, panelCtrl.datasource.database); + $scope.queryBuilder = new InfluxQueryBuilder($scope.target, datasource.database); $scope.groupBySegment = uiSegmentSrv.newPlusButton(); $scope.resultFormats = [ {text: 'Time series', value: 'time_series'}, @@ -77,7 +78,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) { $scope.getGroupByOptions = function() { var query = $scope.queryBuilder.buildExploreQuery('TAG_KEYS'); - return panelCtrl.datasource.metricFindQuery(query) + return datasource.metricFindQuery(query) .then(function(tags) { var options = []; if (!$scope.queryModel.hasFill()) { @@ -137,7 +138,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) { $scope.getPolicySegments = function() { var policiesQuery = $scope.queryBuilder.buildExploreQuery('RETENTION POLICIES'); - return panelCtrl.datasource.metricFindQuery(policiesQuery) + return datasource.metricFindQuery(policiesQuery) .then($scope.transformToSegments(false)) .then(null, $scope.handleQueryError); }; @@ -153,19 +154,19 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) { $scope.getMeasurements = function () { var query = $scope.queryBuilder.buildExploreQuery('MEASUREMENTS'); - return panelCtrl.datasource.metricFindQuery(query) + return datasource.metricFindQuery(query) .then($scope.transformToSegments(true), $scope.handleQueryError); }; $scope.getPartOptions = function(part) { if (part.def.type === 'field') { var fieldsQuery = $scope.queryBuilder.buildExploreQuery('FIELDS'); - return panelCtrl.datasource.metricFindQuery(fieldsQuery) + return datasource.metricFindQuery(fieldsQuery) .then($scope.transformToSegments(true), $scope.handleQueryError); } if (part.def.type === 'tag') { var tagsQuery = $scope.queryBuilder.buildExploreQuery('TAG_KEYS'); - return panelCtrl.datasource.metricFindQuery(tagsQuery) + return datasource.metricFindQuery(tagsQuery) .then($scope.transformToSegments(true), $scope.handleQueryError); } }; @@ -213,7 +214,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) { addTemplateVars = true; } - return panelCtrl.datasource.metricFindQuery(query) + return datasource.metricFindQuery(query) .then($scope.transformToSegments(addTemplateVars)) .then(function(results) { if (segment.type === 'key') { @@ -226,7 +227,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) { $scope.getFieldSegments = function() { var fieldsQuery = $scope.queryBuilder.buildExploreQuery('FIELDS'); - return panelCtrl.datasource.metricFindQuery(fieldsQuery) + return datasource.metricFindQuery(fieldsQuery) .then($scope.transformToSegments(false)) .then(null, $scope.handleQueryError); }; diff --git a/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts b/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts index 16077513d7b..778f08e1352 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts @@ -15,6 +15,8 @@ describe('InfluxDBQueryCtrl', function() { ctx.$q = $q; ctx.scope = $rootScope.$new(); ctx.scope.ctrl = {panel: ctx.panel}; + ctx.scope.datasource = ctx.datasource; + ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([])); ctx.panelCtrl = ctx.scope.ctrl; ctx.controller = $controller('InfluxQueryCtrl', {$scope: ctx.scope}); })); @@ -22,8 +24,6 @@ describe('InfluxDBQueryCtrl', function() { beforeEach(function() { ctx.scope.target = {}; ctx.panelCtrl.refresh = sinon.spy(); - ctx.panelCtrl.datasource = ctx.datasource; - ctx.panelCtrl.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([])); }); describe('init', function() {