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 @@