From 1a91e0baf62f08651ace34eb39bdee8e6835c945 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Wed, 26 Sep 2018 13:22:20 +0200 Subject: [PATCH] stackdriver: update aggregation and alignment before refreshing when changing metric --- .../partials/query.aggregation.html | 4 +- .../stackdriver/query_aggregation_ctrl.ts | 54 +++++++++++-------- .../datasource/stackdriver/query_ctrl.ts | 1 + 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/public/app/plugins/datasource/stackdriver/partials/query.aggregation.html b/public/app/plugins/datasource/stackdriver/partials/query.aggregation.html index f48d0d9f565..d0eb33f649c 100755 --- a/public/app/plugins/datasource/stackdriver/partials/query.aggregation.html +++ b/public/app/plugins/datasource/stackdriver/partials/query.aggregation.html @@ -2,7 +2,7 @@
-
@@ -20,7 +20,7 @@
-
diff --git a/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts b/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts index f1c86aede9a..ad0b048713b 100644 --- a/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts +++ b/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts @@ -20,57 +20,65 @@ export class StackdriverAggregationCtrl { target: any; alignOptions: any[]; aggOptions: any[]; - refresh: () => void; - constructor($scope) { - this.aggOptions = options.aggOptions; - this.alignOptions = options.alignOptions; - $scope.alignmentPeriods = options.alignmentPeriods; - $scope.getAlignOptions = this.getAlignOptions; - $scope.getAggOptions = this.getAggOptions; - $scope.onAlignmentChange = this.onAlignmentChange; - $scope.onAggregationChange = this.onAggregationChange; - this.refresh = $scope.refresh; + constructor(private $scope) { + $scope.aggOptions = options.aggOptions; + this.setAggOptions(); + this.setAlignOptions(); + $scope.onAlignmentChange = this.onAlignmentChange.bind(this); + $scope.onAggregationChange = this.onAggregationChange.bind(this); + $scope.$on('metricTypeChange', this.setAlignOptions.bind(this)); } onAlignmentChange(newVal: string) { if (newVal === 'ALIGN_NONE') { - this.target.aggregation.crossSeriesReducer = 'REDUCE_NONE'; + this.$scope.target.aggregation.crossSeriesReducer = 'REDUCE_NONE'; } - this.refresh(); + this.$scope.refresh(); } onAggregationChange(newVal: string) { - if (newVal !== 'REDUCE_NONE' && this.target.aggregation.perSeriesAligner === 'ALIGN_NONE') { + if (newVal !== 'REDUCE_NONE' && this.$scope.target.aggregation.perSeriesAligner === 'ALIGN_NONE') { const newAlignmentOption = options.alignOptions.find( o => o.value !== 'ALIGN_NONE' && - o.valueTypes.indexOf(this.target.valueType) !== -1 && - o.metricKinds.indexOf(this.target.metricKind) !== -1 + o.valueTypes.indexOf(this.$scope.target.valueType) !== -1 && + o.metricKinds.indexOf(this.$scope.target.metricKind) !== -1 ); - this.target.aggregation.perSeriesAligner = newAlignmentOption ? newAlignmentOption.value : ''; + this.$scope.target.aggregation.perSeriesAligner = newAlignmentOption ? newAlignmentOption.value : ''; } - this.refresh(); + this.$scope.refresh(); } - getAlignOptions() { - return !this.target.valueType + setAlignOptions() { + this.$scope.alignOptions = !this.$scope.target.valueType ? [] : options.alignOptions.filter(i => { return ( - i.valueTypes.indexOf(this.target.valueType) !== -1 && i.metricKinds.indexOf(this.target.metricKind) !== -1 + i.valueTypes.indexOf(this.$scope.target.valueType) !== -1 && + i.metricKinds.indexOf(this.$scope.target.metricKind) !== -1 ); }); + if (!this.$scope.alignOptions.find(o => o.value === this.$scope.target.aggregation.perSeriesAligner)) { + const newValue = this.$scope.alignOptions.find(o => o.value !== 'ALIGN_NONE'); + this.$scope.target.aggregation.perSeriesAligner = newValue ? newValue.value : ''; + } } - getAggOptions() { - return !this.target.metricKind + setAggOptions() { + this.$scope.aggOptions = !this.$scope.target.metricKind ? [] : options.aggOptions.filter(i => { return ( - i.valueTypes.indexOf(this.target.valueType) !== -1 && i.metricKinds.indexOf(this.target.metricKind) !== -1 + i.valueTypes.indexOf(this.$scope.target.valueType) !== -1 && + i.metricKinds.indexOf(this.$scope.target.metricKind) !== -1 ); }); + + if (!this.$scope.aggOptions.find(o => o.value === this.$scope.target.aggregation.crossSeriesReducer)) { + const newValue = this.$scope.aggOptions.find(o => o.value !== 'REDUCE_NONE'); + this.$scope.target.aggregation.crossSeriesReducer = newValue ? newValue.value : ''; + } } } diff --git a/public/app/plugins/datasource/stackdriver/query_ctrl.ts b/public/app/plugins/datasource/stackdriver/query_ctrl.ts index c6629748a3a..7f9b473a15a 100644 --- a/public/app/plugins/datasource/stackdriver/query_ctrl.ts +++ b/public/app/plugins/datasource/stackdriver/query_ctrl.ts @@ -194,6 +194,7 @@ export class StackdriverQueryCtrl extends QueryCtrl { const { valueType, metricKind } = this.metricDescriptors.find(m => m.type === this.target.metricType); this.target.valueType = valueType; this.target.metricKind = metricKind; + this.$scope.$broadcast('metricTypeChange'); this.refresh(); this.getLabels(); }