changes to using an array for mavg options

This commit is contained in:
carl bergquist 2015-12-09 13:55:06 +01:00
parent f51d74fa68
commit d3ff4bf75e
2 changed files with 12 additions and 9 deletions

View File

@ -13,14 +13,21 @@ function (angular, _, queryDef) {
$scope.metricAggTypes = queryDef.metricAggTypes;
$scope.extendedStats = queryDef.extendedStats;
$scope.mavgOptions = [];
$scope.init = function() {
$scope.agg = metricAggs[$scope.index];
$scope.validateModel();
$scope.updateMavgOptions();
};
$scope.updateMavgOptions = function() {
$scope.mavgOptions = queryDef.getMovingAverageSourceOptions($scope.target);
};
$rootScope.onAppEvent('elastic-query-updated', function() {
$scope.index = _.indexOf(metricAggs, $scope.agg);
$scope.updateMavgOptions();
$scope.validateModel();
}, $scope);
@ -30,14 +37,15 @@ function (angular, _, queryDef) {
$scope.settingsLinkText = '';
$scope.aggDef = _.findWhere($scope.metricAggTypes, {value: $scope.agg.type});
if (!$scope.agg.field) {
if (!$scope.agg.field && $scope.agg.type !== 'moving_avg') {
$scope.agg.field = 'select field';
}
switch($scope.agg.type) {
case 'moving_avg': {
$scope.agg.mavgSource = $scope.agg.mavgSource || 'Basec on metric';
$scope.agg.mavgSource = $scope.agg.mavgSource || 'Metric to apply moving average';
$scope.settingsLinkText = 'Moving average options';
$scope.agg.field = $scope.agg.mavgSource;
break;
}
case 'percentiles': {
@ -70,7 +78,7 @@ function (angular, _, queryDef) {
$scope.toggleOptions = function() {
$scope.showOptions = !$scope.showOptions;
$scope.updateMovingAverageOptions();
$scope.updateMavgOptions();
};
$scope.onChangeInternal = function() {
@ -88,11 +96,6 @@ function (angular, _, queryDef) {
return $scope.getFields({$fieldType: 'number'});
};
$scope.mavgSourceOptions = function() {
return $q.when(queryDef.getMovingAverageSourceOptions($scope.target))
.then(uiSegmentSrv.transformToSegments(false));
};
$scope.addMetricAgg = function() {
var addIndex = metricAggs.length;

View File

@ -33,7 +33,7 @@
Based on
</li>
<li>
<metric-segment-model property="agg.mavgSource" get-options="mavgSourceOptions()" on-change="onChangeInternal()" css-class="last"></metric-segment-model>
<metric-segment-model property="agg.mavgSource" options="mavgOptions" on-change="onChangeInternal()" css-class="last"></metric-segment-model>
</li>
</ul>
<div class="clearfix"></div>