Skip to content

Commit

Permalink
#18 Clean task and observable tabs when tasks or observables get deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Nov 18, 2016
1 parent f06694c commit dbd4a19
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
7 changes: 7 additions & 0 deletions ui/app/scripts/controllers/case/CaseMainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@
field: 'status'
});

$scope.$on('tasks:task-removed', function(event, task) {
CaseTabsSrv.removeTab('task-' + task.id);
});
$scope.$on('observables:observable-removed', function(event, observable) {
CaseTabsSrv.removeTab('observable-' + observable.id);
});

$scope.openTab = function(tabName) {
var tab = CaseTabsSrv.getTab(tabName),
params = angular.extend({}, $state.params, tab.params || {});
Expand Down
6 changes: 4 additions & 2 deletions ui/app/scripts/controllers/case/CaseObservablesCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,12 @@

};

$scope.dropArtifact = function(artifact) {
$scope.dropArtifact = function(observable) {
// TODO check result !
CaseArtifactSrv.api().delete({
artifactId: artifact.id
artifactId: observable.id
}, function() {
$scope.$emit('observables:observable-removed', observable);
});
};

Expand Down
4 changes: 3 additions & 1 deletion ui/app/scripts/controllers/case/CaseTasksCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
'taskId': task.id
}, {
status: 'Cancel'
}, function() {}, function(response) {
}, function() {
$scope.$emit('tasks:task-removed', task);
}, function(response) {
AlertSrv.error('taskList', response.data, response.status);
});
});
Expand Down
10 changes: 7 additions & 3 deletions ui/app/scripts/services/CaseTabsSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@
},

removeTab: function(tab) {
var currentIsActive = tabs[tab].active;
var tabItem = tabs[tab];

if(!tabItem) {
return;
}

var currentIsActive = tabItem.active;

delete tabs[tab];

if (currentIsActive) {
console.log('Closing active tab, switch to details');
return true;
} else {
console.log('Closing non active tab, stay in current tab');
return false;
}

Expand Down

0 comments on commit dbd4a19

Please sign in to comment.