2018-09-25 07:42:47 -05:00
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import * as options from './constants';
|
2018-09-26 10:50:08 -05:00
|
|
|
import kbn from 'app/core/utils/kbn';
|
2018-09-25 07:42:47 -05:00
|
|
|
|
|
|
|
export class StackdriverAggregation {
|
|
|
|
constructor() {
|
|
|
|
return {
|
|
|
|
templateUrl: 'public/app/plugins/datasource/stackdriver/partials/query.aggregation.html',
|
|
|
|
controller: 'StackdriverAggregationCtrl',
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
|
|
|
target: '=',
|
2018-09-26 10:50:08 -05:00
|
|
|
alignmentPeriod: '<',
|
2018-09-25 07:42:47 -05:00
|
|
|
refresh: '&',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class StackdriverAggregationCtrl {
|
2018-09-26 06:22:20 -05:00
|
|
|
constructor(private $scope) {
|
|
|
|
$scope.aggOptions = options.aggOptions;
|
|
|
|
this.setAggOptions();
|
|
|
|
this.setAlignOptions();
|
2018-09-26 08:03:44 -05:00
|
|
|
$scope.alignmentPeriods = options.alignmentPeriods;
|
2018-09-26 10:50:08 -05:00
|
|
|
$scope.formatAlignmentText = this.formatAlignmentText.bind(this);
|
2018-09-26 06:42:53 -05:00
|
|
|
$scope.$on('metricTypeChanged', this.setAlignOptions.bind(this));
|
2018-09-25 07:42:47 -05:00
|
|
|
}
|
|
|
|
|
2018-09-26 06:22:20 -05:00
|
|
|
setAlignOptions() {
|
|
|
|
this.$scope.alignOptions = !this.$scope.target.valueType
|
2018-09-26 04:17:24 -05:00
|
|
|
? []
|
2018-09-25 07:42:47 -05:00
|
|
|
: options.alignOptions.filter(i => {
|
|
|
|
return (
|
2018-09-26 06:22:20 -05:00
|
|
|
i.valueTypes.indexOf(this.$scope.target.valueType) !== -1 &&
|
|
|
|
i.metricKinds.indexOf(this.$scope.target.metricKind) !== -1
|
2018-09-25 07:42:47 -05:00
|
|
|
);
|
|
|
|
});
|
2018-09-26 06:22:20 -05:00
|
|
|
if (!this.$scope.alignOptions.find(o => o.value === this.$scope.target.aggregation.perSeriesAligner)) {
|
2018-09-27 07:43:30 -05:00
|
|
|
this.$scope.target.aggregation.perSeriesAligner =
|
|
|
|
this.$scope.alignOptions.length > 0 ? this.$scope.alignOptions[0].value : '';
|
2018-09-26 06:22:20 -05:00
|
|
|
}
|
2018-09-25 07:42:47 -05:00
|
|
|
}
|
|
|
|
|
2018-09-26 06:22:20 -05:00
|
|
|
setAggOptions() {
|
|
|
|
this.$scope.aggOptions = !this.$scope.target.metricKind
|
2018-09-26 04:17:24 -05:00
|
|
|
? []
|
2018-09-25 07:42:47 -05:00
|
|
|
: options.aggOptions.filter(i => {
|
|
|
|
return (
|
2018-09-26 06:22:20 -05:00
|
|
|
i.valueTypes.indexOf(this.$scope.target.valueType) !== -1 &&
|
|
|
|
i.metricKinds.indexOf(this.$scope.target.metricKind) !== -1
|
2018-09-25 07:42:47 -05:00
|
|
|
);
|
|
|
|
});
|
2018-09-26 06:22:20 -05:00
|
|
|
|
|
|
|
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 : '';
|
|
|
|
}
|
2018-09-25 07:42:47 -05:00
|
|
|
}
|
2018-09-26 10:50:08 -05:00
|
|
|
|
|
|
|
formatAlignmentText() {
|
|
|
|
const selectedAlignment = this.$scope.alignOptions.find(
|
|
|
|
ap => ap.value === this.$scope.target.aggregation.perSeriesAligner
|
|
|
|
);
|
|
|
|
return `${kbn.secondsToHms(this.$scope.alignmentPeriod)} interval (${selectedAlignment.text})`;
|
|
|
|
}
|
2018-09-25 07:42:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
angular.module('grafana.controllers').directive('stackdriverAggregation', StackdriverAggregation);
|
|
|
|
angular.module('grafana.controllers').controller('StackdriverAggregationCtrl', StackdriverAggregationCtrl);
|