Browse Source

stackdriver: broadcasting through $scope doesnt work anymore since query_filter_ctrl is now a sibling directive to query_aggregation_ctrl, so broadcasting is now done using $rootScope

Erik Sundell 7 năm trước cách đây
mục cha
commit
5bc6d857a7

+ 5 - 1
public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts

@@ -32,7 +32,11 @@ export class StackdriverAggregationCtrl {
     this.alignOptions = options.alignOptions;
     this.setAggOptions();
     this.setAlignOptions();
-    $scope.$on('metricTypeChanged', this.setAlignOptions.bind(this));
+    const self = this;
+    $scope.$on('metricTypeChanged', () => {
+      self.setAggOptions();
+      self.setAlignOptions();
+    });
   }
 
   setAlignOptions() {

+ 2 - 2
public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts

@@ -41,7 +41,7 @@ export class StackdriverFilterCtrl {
   datasource: any;
 
   /** @ngInject */
-  constructor(private $scope, private uiSegmentSrv, private templateSrv) {
+  constructor(private $scope, private uiSegmentSrv, private templateSrv, private $rootScope) {
     this.datasource = $scope.datasource;
     this.target = $scope.target;
     this.metricType = $scope.defaultDropdownValue;
@@ -180,7 +180,7 @@ export class StackdriverFilterCtrl {
     this.target.unit = unit;
     this.target.valueType = valueType;
     this.target.metricKind = metricKind;
-    this.$scope.$broadcast('metricTypeChanged');
+    this.$rootScope.$broadcast('metricTypeChanged');
   }
 
   async getGroupBys(segment, index, removeText?: string, removeUsed = true) {

+ 1 - 1
public/app/plugins/datasource/stackdriver/specs/query_filter_ctrl.test.ts

@@ -420,7 +420,7 @@ function createCtrlWithFakes(existingFilters?: string[]) {
     refresh: () => {},
   };
 
-  return new StackdriverFilterCtrl(scope, fakeSegmentServer, new TemplateSrvStub());
+  return new StackdriverFilterCtrl(scope, fakeSegmentServer, new TemplateSrvStub(), { $broadcast: param => {} });
 }
 
 function createTarget(existingFilters?: string[]) {