diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index 375283b6a7d..02ce3cf21ed 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -43,7 +43,7 @@ class MetricsPanelCtrl extends PanelCtrl { // hookup initial data fetch this.$timeout(() => { if (!this.skipDataOnInit) { - this.getData(); + this.refresh(); } }, 30);; } @@ -163,7 +163,7 @@ class MetricsPanelCtrl extends PanelCtrl { } }; - issueQueries() { + issueQueries(datasource) { if (!this.panel.targets || this.panel.targets.length === 0) { return this.$q.when([]); } @@ -182,7 +182,7 @@ class MetricsPanelCtrl extends PanelCtrl { }; this.setTimeQueryStart(); - return this.datasource.query(metricsQuery).then(results => { + return datasource.query(metricsQuery).then(results => { this.setTimeQueryEnd(); if (this.dashboard.snapshot) { diff --git a/public/app/partials/metrics.html b/public/app/partials/metrics.html index 390f5627486..8a7eb1bfd71 100644 --- a/public/app/partials/metrics.html +++ b/public/app/partials/metrics.html @@ -18,7 +18,7 @@
diff --git a/public/app/plugins/datasource/graphite/query_ctrl.js b/public/app/plugins/datasource/graphite/query_ctrl.js index 89286c53e1c..ab113465262 100644 --- a/public/app/plugins/datasource/graphite/query_ctrl.js +++ b/public/app/plugins/datasource/graphite/query_ctrl.js @@ -209,7 +209,7 @@ function (angular, _, config, gfunc, Parser) { $scope.targetTextChanged = function() { parseTarget(); - $scope.ctrl.getData(); + panelCtrl.refresh(); }; $scope.targetChanged = function() { @@ -223,7 +223,7 @@ function (angular, _, config, gfunc, Parser) { if ($scope.target.target !== oldTarget) { if ($scope.segments[$scope.segments.length - 1].value !== 'select metric') { - $scope.ctrl.getData(); + panelCtrl.refresh(); } } }; 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 7473c1ea188..bdf339e0d27 100644 --- a/public/app/plugins/datasource/graphite/specs/query_ctrl_specs.ts +++ b/public/app/plugins/datasource/graphite/specs/query_ctrl_specs.ts @@ -14,13 +14,19 @@ describe('GraphiteQueryCtrl', function() { beforeEach(angularMocks.module('grafana.services')); beforeEach(ctx.providePhase()); - beforeEach(ctx.createControllerPhase('GraphiteQueryCtrl')); + beforeEach(angularMocks.inject(($rootScope, $controller, $q) => { + ctx.$q = $q; + ctx.scope = $rootScope.$new(); + ctx.scope.ctrl = {panel: ctx.panel}; + ctx.panelCtrl = ctx.scope.ctrl; + ctx.controller = $controller('GraphiteQueryCtrl', {$scope: ctx.scope}); + })); beforeEach(function() { ctx.scope.target = {target: 'aliasByNode(scaleToSeconds(test.prod.*,1),2)'}; - ctx.scope.datasource = ctx.datasource; - ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([])); + ctx.panelCtrl.datasource = ctx.datasource; + ctx.panelCtrl.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([])); }); describe('init', function() { @@ -30,7 +36,7 @@ describe('GraphiteQueryCtrl', function() { }); it('should validate metric key exists', function() { - expect(ctx.scope.datasource.metricFindQuery.getCall(0).args[0]).to.be('test.prod.*'); + expect(ctx.panelCtrl.datasource.metricFindQuery.getCall(0).args[0]).to.be('test.prod.*'); }); it('should delete last segment if no metrics are found', function() { @@ -45,11 +51,11 @@ describe('GraphiteQueryCtrl', function() { describe('when adding function', function() { beforeEach(function() { ctx.scope.target.target = 'test.prod.*.count'; - ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}])); + ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}])); ctx.scope.init(); ctx.scope.$digest(); - ctx.scope.$parent = { get_data: sinon.spy() }; + ctx.panelCtrl.refresh = sinon.spy(); ctx.scope.addFunction(gfunc.getFuncDef('aliasByNode')); }); @@ -61,19 +67,17 @@ describe('GraphiteQueryCtrl', function() { expect(ctx.scope.target.target).to.be('aliasByNode(test.prod.*.count, 2)'); }); - it('should call get_data', function() { - expect(ctx.scope.$parent.get_data.called).to.be(true); + it('should call refresh', function() { + expect(ctx.panelCtrl.refresh.called).to.be(true); }); }); describe('when adding function before any metric segment', function() { beforeEach(function() { ctx.scope.target.target = ''; - ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: true}])); + ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: true}])); ctx.scope.init(); ctx.scope.$digest(); - - ctx.scope.$parent = { get_data: sinon.spy() }; ctx.scope.addFunction(gfunc.getFuncDef('asPercent')); }); @@ -85,10 +89,9 @@ describe('GraphiteQueryCtrl', function() { describe('when initalizing target without metric expression and only function', function() { beforeEach(function() { ctx.scope.target.target = 'asPercent(#A, #B)'; - ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([])); + ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([])); ctx.scope.init(); ctx.scope.$digest(); - ctx.scope.$parent = { get_data: sinon.spy() }; }); it('should not add select metric segment', function() { @@ -104,10 +107,9 @@ 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.scope.datasource.metricFindQuery.returns(ctx.$q.when([])); + ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([])); ctx.scope.init(); ctx.scope.$digest(); - ctx.scope.$parent = { get_data: sinon.spy() }; }); it('should add 2 segments', function() { @@ -123,7 +125,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.scope.datasource.metricFindQuery.returns(ctx.$q.when([])); + ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([])); ctx.scope.init(); ctx.scope.$digest(); ctx.scope.$parent = { get_data: sinon.spy() }; @@ -141,13 +143,12 @@ describe('GraphiteQueryCtrl', function() { describe('when getting altSegments and metricFindQuery retuns empty array', function() { beforeEach(function() { ctx.scope.target.target = 'test.count'; - ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([])); + ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([])); ctx.scope.init(); ctx.scope.getAltSegments(1).then(function(results) { ctx.altSegments = results; }); ctx.scope.$digest(); - ctx.scope.$parent = { get_data: sinon.spy() }; }); it('should have no segments', function() { @@ -158,11 +159,11 @@ describe('GraphiteQueryCtrl', function() { describe('targetChanged', function() { beforeEach(function() { - ctx.scope.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}])); + ctx.panelCtrl.datasource.metricFindQuery.returns(ctx.$q.when([{expandable: false}])); ctx.scope.init(); ctx.scope.$digest(); - ctx.scope.$parent = { get_data: sinon.spy() }; + ctx.panelCtrl.refresh = sinon.spy(); ctx.scope.target.target = ''; ctx.scope.targetChanged(); }); @@ -171,8 +172,8 @@ describe('GraphiteQueryCtrl', function() { expect(ctx.scope.target.target).to.be('aliasByNode(scaleToSeconds(test.prod.*, 1), 2)'); }); - it('should call get_data', function() { - expect(ctx.scope.$parent.get_data.called).to.be(true); + it('should call panelCtrl.refresh', function() { + expect(ctx.panelCtrl.refresh.called).to.be(true); }); }); }); diff --git a/public/app/plugins/panel/graph/graph_ctrl.ts b/public/app/plugins/panel/graph/graph_ctrl.ts index c242c0ae537..c552a543452 100644 --- a/public/app/plugins/panel/graph/graph_ctrl.ts +++ b/public/app/plugins/panel/graph/graph_ctrl.ts @@ -129,7 +129,7 @@ class GraphCtrl extends MetricsPanelCtrl { refreshData(datasource) { this.annotationsPromise = this.annotationsSrv.getAnnotations(this.dashboard); - return this.issueQueries() + return this.issueQueries(datasource) .then(res => this.dataHandler(res)) .catch(err => { this.seriesList = []; diff --git a/public/app/plugins/panel/graph/seriesOverridesCtrl.js b/public/app/plugins/panel/graph/seriesOverridesCtrl.js index 265e99af223..4b89de684e3 100644 --- a/public/app/plugins/panel/graph/seriesOverridesCtrl.js +++ b/public/app/plugins/panel/graph/seriesOverridesCtrl.js @@ -1,13 +1,11 @@ define([ 'angular', 'jquery', - 'app/app', 'lodash', -], function(angular, jquery, app, _) { +], function(angular, jquery, _) { 'use strict'; - var module = angular.module('grafana.panels.graph', []); - app.useModule(module); + var module = angular.module('grafana.controllers'); module.controller('SeriesOverridesCtrl', function($scope, $element, popoverSrv) { $scope.overrideMenu = []; diff --git a/public/app/plugins/panel/graph/specs/graph_ctrl_specs.ts b/public/app/plugins/panel/graph/specs/graph_ctrl_specs.ts index 73e47863f80..9bdd7c3df79 100644 --- a/public/app/plugins/panel/graph/specs/graph_ctrl_specs.ts +++ b/public/app/plugins/panel/graph/specs/graph_ctrl_specs.ts @@ -2,15 +2,10 @@ import {describe, beforeEach, it, sinon, expect, angularMocks} from '../../../../../test/lib/common'; -import 'app/features/panel/panel_srv'; -import 'app/features/panel/panel_helper'; - import angular from 'angular'; -import {GraphCtrl} from '../module'; +import {GraphCtrl} from '../graph_ctrl'; import helpers from '../../../../../test/specs/helpers'; -angular.module('grafana.controllers').controller('GraphCtrl', GraphCtrl); - describe('GraphCtrl', function() { var ctx = new helpers.ControllerTestContext(); @@ -18,7 +13,7 @@ describe('GraphCtrl', function() { beforeEach(angularMocks.module('grafana.controllers')); beforeEach(ctx.providePhase()); - beforeEach(ctx.createControllerPhase('GraphCtrl')); + beforeEach(ctx.createPanelController(GraphCtrl)); describe('get_data with 2 series', function() { beforeEach(function() { @@ -29,25 +24,23 @@ describe('GraphCtrl', function() { { target: 'test.cpu2', datapoints: [[1, 10]]} ] })); - ctx.scope.render = sinon.spy(); - ctx.scope.refreshData(ctx.datasource); + ctx.ctrl.render = sinon.spy(); + ctx.ctrl.refreshData(ctx.datasource); ctx.scope.$digest(); }); it('should send time series to render', function() { - var data = ctx.scope.render.getCall(0).args[0]; + var data = ctx.ctrl.render.getCall(0).args[0]; expect(data.length).to.be(2); }); describe('get_data failure following success', function() { beforeEach(function() { ctx.datasource.query = sinon.stub().returns(ctx.$q.reject('Datasource Error')); - ctx.scope.refreshData(ctx.datasource); + ctx.ctrl.refreshData(ctx.datasource); ctx.scope.$digest(); }); }); - }); - }); diff --git a/public/app/plugins/panel/graph/specs/graph_specs.ts b/public/app/plugins/panel/graph/specs/graph_specs.ts index e07033583b7..d943bc62ac4 100644 --- a/public/app/plugins/panel/graph/specs/graph_specs.ts +++ b/public/app/plugins/panel/graph/specs/graph_specs.ts @@ -23,11 +23,13 @@ describe('grafanaGraph', function() { })); beforeEach(angularMocks.inject(function($rootScope, $compile) { + var ctrl: any = {}; var scope = $rootScope.$new(); + scope.ctrl = ctrl; var element = angular.element("