Skip to content

Commit

Permalink
Jkmarx/fix analysis auto call bug (#3292)
Browse files Browse the repository at this point in the history
* Cancel time when destory and avoid reinitializing the ctrl.

* Remove unused helper method.

* Remove unused unit tests.
  • Loading branch information
jkmarx committed Mar 29, 2019
1 parent 2e9157b commit 18fc94d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
15 changes: 4 additions & 11 deletions refinery/ui/source/js/analysis-monitor/ctrls/ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function AnalysisMonitorCtrl (
vm.initializedFlag = {};
vm.openAnalysisDeleteModal = openAnalysisDeleteModal;

vm.$onDestroy = function () {
$timeout.cancel(vm.timerList);
};

// On data set browser analysis tab, method set timer and refreshes the
// analysis list and refreshes details for running analyses.
vm.updateAnalysesList = function () {
Expand All @@ -34,10 +38,6 @@ function AnalysisMonitorCtrl (
};

vm.timerList = $timeout(vm.updateAnalysesList, 15000);
// Cancels timer when away from analyses tab
$scope.$on('refinery/analyze-tab-inactive', function () {
$timeout.cancel(vm.timerList);
});

return analysisMonitorFactory.getAnalysesList(param)
.then(function (response) {
Expand All @@ -57,7 +57,6 @@ function AnalysisMonitorCtrl (
$timeout.cancel(vm.timerList);

vm.updateAnalysesList().then(function () {
$rootScope.$broadcast('rf/cancelAnalysis');
// Removes flag because list is updated
vm.setCancelAnalysisFlag(false, uuid);
});
Expand All @@ -75,12 +74,6 @@ function AnalysisMonitorCtrl (
}
};

vm.cancelTimerRunningList = function () {
if (typeof vm.timerRunList !== 'undefined') {
$timeout.cancel(vm.timerRunList);
}
};

/**
* @name getRunningAnalyses
* @desc Helper function to update running analyses with details
Expand Down
18 changes: 2 additions & 16 deletions refinery/ui/source/js/analysis-monitor/ctrls/ctrl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ describe('Controller: AnalysisMonitorCtrl', function () {
var factory;
var fakeUuid = 'x508x83x-x9xx-4740-x9x7-x7x0x631280x';
var fakeInvalidUuid = 'xxxxx';
var timeout;

beforeEach(module('refineryApp'));
beforeEach(module('refineryAnalysisMonitor'));
beforeEach(inject(function (
$controller, $rootScope, $timeout, $window, analysisMonitorFactory
$controller, $rootScope, $window, analysisMonitorFactory
) {
ctrl = $controller('AnalysisMonitorCtrl', {
$scope: $rootScope.$new()
Expand Down Expand Up @@ -111,9 +110,7 @@ describe('Controller: AnalysisMonitorCtrl', function () {
});

describe('Helper functions', function () {
beforeEach(inject(function ($timeout) {
timeout = $timeout;

beforeEach(inject(function () {
ctrl.analysesDetail[fakeUuid] = {
refineryImport: [{
status: 'PROGRESS',
Expand Down Expand Up @@ -161,17 +158,6 @@ describe('Controller: AnalysisMonitorCtrl', function () {
.toEqual(ctrl.analysesList.length);
});

it('cancelTimerRunningList method is function', function () {
expect(angular.isFunction(ctrl.cancelTimerRunningList)).toBe(true);
});

it('cancelTimerRunningList method cancel timerRunList', function () {
ctrl.timerRunList = timeout(10);
expect(typeof ctrl.timerRunList.$$state.value).toEqual('undefined');
ctrl.cancelTimerRunningList();
expect(ctrl.timerRunList.$$state.value).toEqual('canceled');
});

it('setAnalysesLoadingFlag method is function', function () {
expect(angular.isFunction(ctrl.setAnalysesLoadingFlag)).toBe(true);
});
Expand Down
4 changes: 1 addition & 3 deletions refinery/ui/source/js/data-set-nav/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ function refineryDataSetNavConfig (
templateUrl: function () {
// unit tests redefine $window and thus make it unusable here
return window.getStaticUrl('partials/analysis-monitor/views/analyses-tab.html');
},
controller: 'AnalysisMonitorCtrl',
controllerAs: 'AMCtrl'
}
},
'^\/data_sets\/.*\/$',
true
Expand Down

0 comments on commit 18fc94d

Please sign in to comment.