From 9513b154946dd9bbce5a60caaee8b56710b170ed Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Wed, 9 Jan 2019 13:48:05 +0100 Subject: [PATCH] [ML] Fix missing $applyAsync() in AnomalyExplorer and Time Series Viewer (#28237) Part of #28189. Removes custom Promise code and fixes missing $applyAsync()s in AnomalyExplorer and Time Series Viewer. --- .../job_select_list/job_select_list_directive.js | 1 + x-pack/plugins/ml/public/explorer/explorer_controller.js | 7 +++++-- .../timeseriesexplorer/timeseriesexplorer_controller.js | 8 ++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/ml/public/components/job_select_list/job_select_list_directive.js b/x-pack/plugins/ml/public/components/job_select_list/job_select_list_directive.js index 6115618a1113d..6b907c2dbd5a9 100644 --- a/x-pack/plugins/ml/public/components/job_select_list/job_select_list_directive.js +++ b/x-pack/plugins/ml/public/components/job_select_list/job_select_list_directive.js @@ -117,6 +117,7 @@ module.directive('mlJobSelectList', function (Private) { } else { $scope.noJobsCreated = true; } + $scope.$applyAsync(); }).catch((resp) => { console.log('mlJobSelectList controller - error getting job info from ES:', resp); }); diff --git a/x-pack/plugins/ml/public/explorer/explorer_controller.js b/x-pack/plugins/ml/public/explorer/explorer_controller.js index e32b586800f92..7e8322a0941ee 100644 --- a/x-pack/plugins/ml/public/explorer/explorer_controller.js +++ b/x-pack/plugins/ml/public/explorer/explorer_controller.js @@ -25,7 +25,6 @@ import 'plugins/ml/components/job_select_list'; import { FilterBarQueryFilterProvider } from 'ui/filter_bar/query_filter'; import { parseInterval } from 'ui/utils/parse_interval'; -import { initPromise } from 'plugins/ml/util/promise'; import template from './explorer.html'; import uiRoutes from 'ui/routes'; @@ -64,7 +63,6 @@ uiRoutes CheckLicense: checkFullLicense, privileges: checkGetJobsPrivilege, indexPatterns: loadIndexPatterns, - initPromise: initPromise(true) } }); @@ -196,6 +194,7 @@ module.controller('MlExplorerController', function ( $scope.loading = false; } + $scope.$applyAsync(); }).catch((resp) => { console.log('Explorer - error getting job info from elasticsearch:', resp); }); @@ -291,6 +290,7 @@ module.controller('MlExplorerController', function ( restoreCellDataFromAppState(); updateExplorer(); } + $scope.$applyAsync(); }); }; @@ -647,6 +647,7 @@ module.controller('MlExplorerController', function ( loadTopInfluencers(jobIds, earliestMs, latestMs, filterInfluencers); } + $scope.$applyAsync(); }); } @@ -821,10 +822,12 @@ module.controller('MlExplorerController', function ( ).then((resp) => { // TODO - sort the influencers keys so that the partition field(s) are first. $scope.influencers = resp.influencers; + $scope.$applyAsync(); console.log('Explorer top influencers data set:', $scope.influencers); }); } else { $scope.influencers = {}; + $scope.$applyAsync(); } } diff --git a/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_controller.js b/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_controller.js index 8c67fe2e08162..5b88e463294ff 100644 --- a/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_controller.js +++ b/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_controller.js @@ -49,7 +49,6 @@ import { mlFieldFormatService } from 'plugins/ml/services/field_format_service'; import { JobSelectServiceProvider } from 'plugins/ml/components/job_select_list/job_select_service'; import { mlForecastService } from 'plugins/ml/services/forecast_service'; import { mlTimeSeriesSearchService } from 'plugins/ml/timeseriesexplorer/timeseries_search_service'; -import { initPromise } from 'plugins/ml/util/promise'; import { ANNOTATIONS_TABLE_DEFAULT_QUERY_SIZE, ANOMALIES_TABLE_DEFAULT_QUERY_SIZE @@ -67,7 +66,6 @@ uiRoutes privileges: checkGetJobsPrivilege, indexPatterns: loadIndexPatterns, mlNodeCount: getMlNodeCount, - initPromise: initPromise(true) } }); @@ -193,6 +191,7 @@ module.controller('MlTimeSeriesExplorerController', function ( $scope.loading = false; } + $scope.$applyAsync(); }).catch((resp) => { console.log('Time series explorer - error getting job info from elasticsearch:', resp); }); @@ -245,6 +244,10 @@ module.controller('MlTimeSeriesExplorerController', function ( $timeout(() => { $scope.$broadcast('render'); }, 0); + } else { + // Call $applyAsync() if for any reason the upper condition doesn't trigger the $timeout. + // We still want to trigger a scope update about the changes above the condition. + $scope.$applyAsync(); } } @@ -843,6 +846,7 @@ module.controller('MlTimeSeriesExplorerController', function ( entity.fieldValues = _.chain(resp.records).pluck('by_field_value').uniq().value(); } }); + $scope.$applyAsync(); } });