[ML] Adds $applyAsync calls to angular based new jobs pages (#28325)

* [ML] Adds $applyAsync calls to angular based new jobs pages

* removing tab character

* removing tab characters
This commit is contained in:
James Gowdy 2019-01-09 15:21:30 +00:00 committed by GitHub
parent 68a7cbd79f
commit 22877ebf8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 124 additions and 48 deletions

View file

@ -18,7 +18,6 @@ import { checkFindFileStructurePrivilege } from 'plugins/ml/privilege/check_priv
import { getMlNodeCount } from 'plugins/ml/ml_nodes_check/check_ml_nodes';
import { loadNewJobDefaults } from 'plugins/ml/jobs/new_job/utils/new_job_defaults';
import { loadIndexPatterns } from '../util/index_utils';
import { initPromise } from 'plugins/ml/util/promise';
import { FileDataVisualizerPage } from './file_datavisualizer';
import uiRoutes from 'ui/routes';
@ -35,7 +34,6 @@ uiRoutes
indexPatterns: loadIndexPatterns,
mlNodeCount: getMlNodeCount,
loadNewJobDefaults,
initPromise: initPromise(true)
}
});

View file

@ -38,7 +38,6 @@ import {
import { mlJobService } from 'plugins/ml/services/job_service';
import { mlMessageBarService } from 'plugins/ml/components/messagebar/messagebar_service';
import { ml } from 'plugins/ml/services/ml_api_service';
import { initPromise } from 'plugins/ml/util/promise';
uiRoutes
.when('/jobs/new_job/advanced', {
@ -52,7 +51,6 @@ uiRoutes
savedSearch: loadCurrentSavedSearch,
checkMlNodesAvailable,
loadNewJobDefaults,
initPromise: initPromise(true)
}
})
.when('/jobs/new_job/advanced/:jobId', {
@ -66,7 +64,6 @@ uiRoutes
savedSearch: loadCurrentSavedSearch,
checkMlNodesAvailable,
loadNewJobDefaults,
initPromise: initPromise(true)
}
});
@ -389,6 +386,9 @@ module.controller('MlNewJob',
loadFields()
.catch(() => {
// No need to do anything here as loadFields handles the displaying of any errors.
})
.then(() => {
$scope.$applyAsync();
});
};
@ -826,6 +826,9 @@ module.controller('MlNewJob',
}
);
$scope.ui.cardinalityValidator.status = STATUS.FAILED;
})
.then(() => {
$scope.$applyAsync();
});
}
@ -1122,6 +1125,9 @@ module.controller('MlNewJob',
getCustomUrlSelection();
getCategorizationFilterSelection();
$scope.ui.jsonText = angular.toJson($scope.job, true);
setTimeout(() => {
$scope.$applyAsync();
}, 0);
}
// add new custom URL
@ -1389,11 +1395,15 @@ module.controller('MlNewJob',
})
.catch(function (resp) {
$scope.ui.dataPreview = angular.toJson(resp, true);
})
.then(() => {
$scope.$applyAsync();
});
} else {
$scope.ui.dataPreview = i18n('xpack.ml.newJob.advanced.dataPreview.datafeedDoesNotExistLabel', {
defaultMessage: 'Datafeed does not exist'
});
$scope.$applyAsync();
}
}

View file

@ -40,11 +40,13 @@ module.directive('mlBucketSpanEstimator', function (i18n) {
console.log('Bucket span could not be estimated', error);
$scope.ui.bucketSpanEstimator.status = STATUS.FAILED;
$scope.ui.bucketSpanEstimator.message = 'Bucket span could not be estimated';
$scope.$applyAsync();
};
$scope.guessBucketSpan = function () {
$scope.ui.bucketSpanEstimator.status = STATUS.RUNNING;
$scope.ui.bucketSpanEstimator.message = '';
$scope.$applyAsync();
// we need to create a request object here because $scope.formConfig
// includes objects with methods which might break the required
@ -91,6 +93,7 @@ module.directive('mlBucketSpanEstimator', function (i18n) {
if (notify && typeof $scope.bucketSpanFieldChange === 'function') {
$scope.bucketSpanFieldChange();
}
$scope.$applyAsync();
})
.catch(errorHandler);
};

View file

@ -77,7 +77,10 @@ module.directive('mlEnableModelPlotCheckbox', function (i18n) {
$scope.ui.showAdvanced = true;
}
})
.catch(errorHandler);
.catch(errorHandler)
.then(() => {
$scope.$applyAsync();
});
}
// Re-validate cardinality for updated fields/splitField

View file

@ -43,7 +43,11 @@ module.directive('mlPostSaveOptions', function (Private, i18n) {
};
$scope.apply = function () {
postSaveService.apply($scope.jobId, $scope.runInRealtime, $scope.createWatch, i18n);
postSaveService.apply($scope.jobId, $scope.runInRealtime, $scope.createWatch, i18n)
.catch()
.then(() => {
$scope.$applyAsync();
});
};
}
};

View file

@ -37,7 +37,8 @@ class PostSaveService {
const datafeedId = mlJobService.getDatafeedId(jobId);
mlJobService.openJob(jobId)
.finally(() => {
.catch()
.then(() => {
mlJobService.startDatafeed(datafeedId, jobId, 0, undefined)
.then(() => {
this.status.realtimeJob = this.STATUS.SAVED;
@ -56,14 +57,24 @@ class PostSaveService {
}
apply(jobId, runInRealtime, createWatch, i18n) {
if (runInRealtime) {
this.startRealtimeJob(jobId, i18n)
.then(() => {
if (createWatch) {
mlCreateWatchService.createNewWatch(jobId);
}
});
}
return new Promise((resolve) => {
if (runInRealtime) {
this.startRealtimeJob(jobId, i18n)
.then(() => {
if (createWatch) {
mlCreateWatchService.createNewWatch(jobId)
.catch()
.then(() => {
resolve();
});
} else {
resolve();
}
});
} else {
resolve();
}
});
}
}

View file

@ -48,11 +48,13 @@ module.directive('mlCreateWatch', function () {
}
// load elasticsearch settings to see if email has been configured
ml.getNotificationSettings().then((resp) => {
if (_.has(resp, 'defaults.xpack.notification.email')) {
$scope.ui.emailEnabled = true;
}
});
ml.getNotificationSettings()
.then((resp) => {
if (_.has(resp, 'defaults.xpack.notification.email')) {
$scope.ui.emailEnabled = true;
$scope.$applyAsync();
}
});
// check to see whether a watch for this job has already been created.
// display a warning if it has.
@ -62,6 +64,9 @@ module.directive('mlCreateWatch', function () {
})
.catch(() => {
$scope.ui.watchAlreadyExists = false;
})
.then(() => {
$scope.$applyAsync();
});
}
};

View file

@ -40,7 +40,6 @@ import { preLoadJob } from 'plugins/ml/jobs/new_job/simple/components/utils/prep
import { MultiMetricJobServiceProvider } from './create_job_service';
import { FullTimeRangeSelectorServiceProvider } from 'plugins/ml/components/full_time_range_selector/full_time_range_selector_service';
import { mlMessageBarService } from 'plugins/ml/components/messagebar/messagebar_service';
import { initPromise } from 'plugins/ml/util/promise';
import { ml } from 'plugins/ml/services/ml_api_service';
import template from './create_job.html';
import { timefilter } from 'ui/timefilter';
@ -56,7 +55,6 @@ uiRoutes
savedSearch: loadCurrentSavedSearch,
checkMlNodesAvailable,
loadNewJobDefaults,
initPromise: initPromise(true)
}
});
@ -351,13 +349,13 @@ module
mlMultiMetricJobService.clearChartData();
// $scope.chartStates.eventRate = CHART_STATE.LOADING;
setFieldsChartStates(CHART_STATE.LOADING);
if (Object.keys($scope.formConfig.fields).length) {
$scope.ui.showFieldCharts = true;
mlMultiMetricJobService.getLineChartResults($scope.formConfig, thisLoadTimestamp)
.then((resp) => {
$scope.$applyAsync();
loadDocCountData(resp.detectors);
})
.catch((resp) => {
@ -365,6 +363,7 @@ module
_.each($scope.formConfig.fields, (field, id) => {
$scope.chartStates.fields[id] = CHART_STATE.NO_RESULTS;
});
$scope.$applyAsync();
});
} else {
$scope.ui.showFieldCharts = false;
@ -382,13 +381,16 @@ module
$scope.chartData.lastLoadTimestamp = null;
chartDataUtils.updateChartMargin($scope.chartData);
$scope.$broadcast('render');
$scope.chartStates.eventRate = (resp.totalResults) ? CHART_STATE.LOADED : CHART_STATE.NO_RESULTS;
$scope.$broadcast('render');
}
})
.catch((resp) => {
$scope.chartStates.eventRate = CHART_STATE.NO_RESULTS;
msgs.error(resp.message);
})
.then(() => {
$scope.$applyAsync();
});
}
};
@ -397,6 +399,7 @@ module
_.each($scope.chartStates.fields, (chart, key) => {
$scope.chartStates.fields[key] = state;
});
$scope.$applyAsync();
}
function showSparseDataCheckbox() {
@ -508,7 +511,6 @@ module
// as it may have failed because we've hit the limit of open jobs
saveNewDatafeed(job, false);
});
})
.catch((resp) => {
// save failed
@ -518,6 +520,7 @@ module
}),
resp.resp
);
$scope.$applyAsync();
});
} else {
// show the advanced section as the model memory limit is invalid
@ -532,7 +535,6 @@ module
function saveNewDatafeed(job, startDatafeedAfterSave) {
mlJobService.saveNewDatafeed(job.datafeed_config, job.job_id)
.then(() => {
if (startDatafeedAfterSave) {
mlMultiMetricJobService.startDatafeed($scope.formConfig)
.then(() => {
@ -566,7 +568,12 @@ module
}),
resp
);
})
.then(() => {
$scope.$applyAsync();
});
} else {
$scope.$applyAsync();
}
})
.catch((resp) => {
@ -576,6 +583,7 @@ module
}),
resp
);
$scope.$applyAsync();
});
}
};
@ -596,6 +604,7 @@ module
.then((state) => {
if (state === 'stopped') {
console.log('Stopping poll because datafeed state is: ' + state);
$scope.$applyAsync();
$scope.$broadcast('render-results');
forceStop = true;
}
@ -642,6 +651,7 @@ module
// fade the bar chart once we have results
toggleSwimlaneVisibility();
}
$scope.$applyAsync();
$scope.$broadcast('render-results');
}
@ -693,7 +703,11 @@ module
$scope.stopJob = function () {
// setting the status to STOPPING disables the stop button
$scope.jobState = JOB_STATE.STOPPING;
mlMultiMetricJobService.stopDatafeed($scope.formConfig);
mlMultiMetricJobService.stopDatafeed($scope.formConfig)
.catch()
.then(() => {
$scope.$applyAsync();
});
};
$scope.moveToAdvancedJobCreation = function () {

View file

@ -40,7 +40,6 @@ import { preLoadJob } from 'plugins/ml/jobs/new_job/simple/components/utils/prep
import { PopulationJobServiceProvider } from './create_job_service';
import { FullTimeRangeSelectorServiceProvider } from 'plugins/ml/components/full_time_range_selector/full_time_range_selector_service';
import { mlMessageBarService } from 'plugins/ml/components/messagebar/messagebar_service';
import { initPromise } from 'plugins/ml/util/promise';
import template from './create_job.html';
import { timefilter } from 'ui/timefilter';
@ -55,7 +54,6 @@ uiRoutes
savedSearch: loadCurrentSavedSearch,
checkMlNodesAvailable,
loadNewJobDefaults,
initPromise: initPromise(true)
}
});
@ -359,13 +357,13 @@ module
mlPopulationJobService.clearChartData();
// $scope.chartStates.eventRate = CHART_STATE.LOADING;
setFieldsChartStates(CHART_STATE.LOADING);
if ($scope.formConfig.fields.length) {
$scope.ui.showFieldCharts = true;
mlPopulationJobService.getLineChartResults($scope.formConfig, thisLoadTimestamp)
.then((resp) => {
$scope.$applyAsync();
loadDocCountData(resp.detectors);
})
.catch((resp) => {
@ -374,6 +372,7 @@ module
const id = field.id;
$scope.chartStates.fields[id] = CHART_STATE.NO_RESULTS;
});
$scope.$applyAsync();
});
} else {
$scope.ui.showFieldCharts = false;
@ -391,13 +390,16 @@ module
$scope.chartData.lastLoadTimestamp = null;
chartDataUtils.updateChartMargin($scope.chartData);
$scope.$broadcast('render');
$scope.chartStates.eventRate = (resp.totalResults) ? CHART_STATE.LOADED : CHART_STATE.NO_RESULTS;
$scope.$broadcast('render');
}
})
.catch((resp) => {
$scope.chartStates.eventRate = CHART_STATE.NO_RESULTS;
msgs.error(resp.message);
})
.then(() => {
$scope.$applyAsync();
});
}
};
@ -406,6 +408,7 @@ module
_.each($scope.chartStates.fields, (chart, key) => {
$scope.chartStates.fields[key] = state;
});
$scope.$applyAsync();
}
function drawCards(fieldIndex, animate = true) {
@ -531,7 +534,6 @@ module
// as it may have failed because we've hit the limit of open jobs
saveNewDatafeed(job, false);
});
})
.catch((resp) => {
// save failed
@ -541,6 +543,7 @@ module
}),
resp.resp
);
$scope.$applyAsync();
});
} else {
// show the advanced section as the model memory limit is invalid
@ -555,7 +558,6 @@ module
function saveNewDatafeed(job, startDatafeedAfterSave) {
mlJobService.saveNewDatafeed(job.datafeed_config, job.job_id)
.then(() => {
if (startDatafeedAfterSave) {
mlPopulationJobService.startDatafeed($scope.formConfig)
.then(() => {
@ -589,7 +591,12 @@ module
}),
resp
);
})
.then(() => {
$scope.$applyAsync();
});
} else {
$scope.$applyAsync();
}
})
.catch((resp) => {
@ -599,6 +606,7 @@ module
}),
resp
);
$scope.$applyAsync();
});
}
};
@ -619,6 +627,7 @@ module
.then((state) => {
if (state === 'stopped') {
console.log('Stopping poll because datafeed state is: ' + state);
$scope.$applyAsync();
$scope.$broadcast('render-results');
forceStop = true;
}
@ -665,6 +674,7 @@ module
// fade the bar chart once we have results
toggleSwimlaneVisibility();
}
$scope.$applyAsync();
$scope.$broadcast('render-results');
}
@ -716,7 +726,11 @@ module
$scope.stopJob = function () {
// setting the status to STOPPING disables the stop button
$scope.jobState = JOB_STATE.STOPPING;
mlPopulationJobService.stopDatafeed($scope.formConfig);
mlPopulationJobService.stopDatafeed($scope.formConfig)
.catch()
.then(() => {
$scope.$applyAsync();
});
};
$scope.moveToAdvancedJobCreation = function () {

View file

@ -23,7 +23,6 @@ import { mlJobService } from 'plugins/ml/services/job_service';
import { CreateRecognizerJobsServiceProvider } from './create_job_service';
import { mlMessageBarService } from 'plugins/ml/components/messagebar/messagebar_service';
import { ml } from 'plugins/ml/services/ml_api_service';
import { initPromise } from 'plugins/ml/util/promise';
import template from './create_job.html';
import { timefilter } from 'ui/timefilter';
@ -37,7 +36,6 @@ uiRoutes
indexPattern: loadCurrentIndexPattern,
savedSearch: loadCurrentSavedSearch,
checkMlNodesAvailable,
initPromise: initPromise(true)
}
});
@ -222,6 +220,7 @@ module
// if they do, they are marked as such and greyed out.
checkIfKibanaObjectsExist($scope.formConfig.kibanaObjects);
}
$scope.$applyAsync();
});
}
@ -329,6 +328,7 @@ module
})
);
}
$scope.$applyAsync();
});
}
@ -352,6 +352,7 @@ module
})
);
}
$scope.$applyAsync();
});
});
}
@ -372,6 +373,7 @@ module
obj.saveState = SAVE_STATE.SAVING;
});
});
$scope.$applyAsync();
}
function startDatafeeds() {
@ -450,6 +452,9 @@ module
job.errors.push(err.message);
job.runningState = DATAFEED_STATE.FAILED;
reject(err);
})
.then(() => {
$scope.$applyAsync();
});
}
});
@ -516,7 +521,10 @@ module
jobIds,
$scope.formConfig.start,
$scope.formConfig.end,
'explorer');
'explorer'
);
$scope.$applyAsync();
};

View file

@ -40,7 +40,6 @@ import { preLoadJob } from 'plugins/ml/jobs/new_job/simple/components/utils/prep
import { SingleMetricJobServiceProvider } from './create_job_service';
import { FullTimeRangeSelectorServiceProvider } from 'plugins/ml/components/full_time_range_selector/full_time_range_selector_service';
import { mlMessageBarService } from 'plugins/ml/components/messagebar/messagebar_service';
import { initPromise } from 'plugins/ml/util/promise';
import template from './create_job.html';
@ -57,7 +56,6 @@ uiRoutes
savedSearch: loadCurrentSavedSearch,
checkMlNodesAvailable,
loadNewJobDefaults,
initPromise: initPromise(true)
}
});
@ -365,6 +363,7 @@ module
$scope.ui.dirty = false;
$scope.chartState = CHART_STATE.LOADING;
$scope.$applyAsync();
mlSingleMetricJobService.getLineChartResults($scope.formConfig)
.then((resp) => {
@ -374,8 +373,9 @@ module
msgs.error(resp.message);
$scope.chartState = CHART_STATE.NO_RESULTS;
})
.finally(() => {
.then(() => {
$scope.$broadcast('render');
$scope.$applyAsync();
});
}
};
@ -417,6 +417,7 @@ module
msgs.error(i18n('xpack.ml.newJob.simple.singleMetric.saveFailedErrorMessage', {
defaultMessage: 'Save failed: '
}), resp.resp);
$scope.$applyAsync();
});
} else {
// show the advanced section as the model memory limit is invalid
@ -462,7 +463,12 @@ module
msgs.error(i18n('xpack.ml.newJob.simple.singleMetric.datafeedNotStartedErrorMessage', {
defaultMessage: 'Could not start datafeed: '
}), resp);
})
.then(() => {
$scope.$applyAsync();
});
} else {
$scope.$applyAsync();
}
})
.catch((resp) => {
@ -488,6 +494,7 @@ module
console.log('Stopping poll because datafeed state is: ' + state);
$scope.$broadcast('render-results');
forceStop = true;
$scope.$applyAsync();
}
run();
});
@ -537,10 +544,11 @@ module
ignoreModel = true;
}
})
.finally(() => {
.then(() => {
jobCheck();
});
}
$scope.$applyAsync();
});
}
}
@ -560,12 +568,15 @@ module
// any jitters in the chart caused by previously loading the model mid job.
$scope.chartData.model = [];
reloadModelChart()
.finally(() => {
.catch()
.then(() => {
$scope.chartData.percentComplete = 100;
$scope.$broadcast('render-results');
$scope.$applyAsync();
});
} else {
$scope.$broadcast('render-results');
$scope.$applyAsync();
}
}

View file

@ -18,7 +18,6 @@ import { preConfiguredJobRedirect } from 'plugins/ml/jobs/new_job/wizard/preconf
import { checkCreateJobsPrivilege, checkFindFileStructurePrivilege } from 'plugins/ml/privilege/check_privilege';
import { loadIndexPatterns, getIndexPatterns } from 'plugins/ml/util/index_utils';
import { checkMlNodesAvailable } from 'plugins/ml/ml_nodes_check/check_ml_nodes';
import { initPromise } from 'plugins/ml/util/promise';
import template from './index_or_search.html';
import { timefilter } from 'ui/timefilter';
@ -37,7 +36,6 @@ uiRoutes
indexPatterns: loadIndexPatterns,
preConfiguredJobRedirect,
checkMlNodesAvailable,
initPromise: initPromise(true),
nextStepPath: () => '#/jobs/new_job/step/job_type',
}
});
@ -50,7 +48,6 @@ uiRoutes
CheckLicense: checkBasicLicense,
privileges: checkFindFileStructurePrivilege,
indexPatterns: loadIndexPatterns,
initPromise: initPromise(true),
nextStepPath: () => '#jobs/new_job/datavisualizer',
}
});

View file

@ -19,7 +19,6 @@ import { SearchItemsProvider } from 'plugins/ml/jobs/new_job/utils/new_job_utils
import { loadCurrentIndexPattern, loadCurrentSavedSearch, timeBasedIndexCheck } from 'plugins/ml/util/index_utils';
import { addItemToRecentlyAccessed } from 'plugins/ml/util/recently_accessed';
import { checkMlNodesAvailable } from 'plugins/ml/ml_nodes_check/check_ml_nodes';
import { initPromise } from 'plugins/ml/util/promise';
import template from './job_type.html';
import { timefilter } from 'ui/timefilter';
@ -33,7 +32,6 @@ uiRoutes
indexPattern: loadCurrentIndexPattern,
savedSearch: loadCurrentSavedSearch,
checkMlNodesAvailable,
initPromise: initPromise(true)
}
});