Skip to content

Commit

Permalink
#1821 Add case bulk close and reopen
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Mar 9, 2021
1 parent 8f2664d commit c3258ca
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
81 changes: 80 additions & 1 deletion frontend/app/scripts/controllers/case/CaseListCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.controller('CaseListCtrl', CaseListCtrl)
.controller('CaseBulkDeleteModalCtrl', CaseBulkDeleteModalCtrl);

function CaseListCtrl($scope, $q, $state, $window, $uibModal, StreamQuerySrv, FilteringSrv, SecuritySrv, StreamStatSrv, PaginatedQuerySrv, EntitySrv, CaseSrv, UserSrv, AuthenticationSrv, CaseResolutionStatus, NotificationSrv, Severity, Tlp, CortexSrv) {
function CaseListCtrl($scope, $rootScope, $q, $uibModal, StreamQuerySrv, FilteringSrv, SecuritySrv, ModalUtilsSrv, PaginatedQuerySrv, EntitySrv, CaseSrv, UserSrv, AuthenticationSrv, CaseResolutionStatus, CaseImpactStatus, NotificationSrv, CortexSrv) {
var self = this;

this.openEntity = EntitySrv.open;
Expand Down Expand Up @@ -138,6 +138,7 @@
// Handle close menu item
temp = _.uniq(_.pluck(self.selection, 'status'));
self.menu.close = temp.length === 1 && temp[0] === 'Open';
self.menu.reopen = temp.length === 1 && temp[0] === 'Resolved';

self.menu.delete = self.selection.length > 0;
};
Expand Down Expand Up @@ -330,6 +331,84 @@
}
}
});

modal.result.catch(function(err) {
if(err && !_.isString(err)) {
NotificationSrv.error('Case Remove', err.data, err.status);
}
})
}

this.bulkReopen = function() {
return ModalUtilsSrv.confirm('Reopen cases', 'Are you sure you want to reopen the selected cases?', {
okText: 'Yes, proceed'
}).then(function() {
var ids = _.pluck(self.selection, '_id');

return CaseSrv.bulkUpdate(ids, {status: 'Open'})
.then(function(/*responses*/) {
NotificationSrv.log('Selected cases have been reopened successfully', 'success');
})
.catch(function(err) {
NotificationSrv.error('Bulk reopen cases', err.data, err.status);
});
});
}

this.closeCase = function(caze) {
var scope = $rootScope.$new();

scope.CaseResolutionStatus = CaseResolutionStatus;
scope.CaseImpactStatus = CaseImpactStatus;
scope.caseId = caze._id;
scope.updateField = function(data) {
return CaseSrv.update({
caseId: caze._id
}, data)
.$promise
.then(function(/*response*/) {
return caze;
});
};

var modal = $uibModal.open({
scope: scope,
templateUrl: 'views/partials/case/case.close.html',
controller: 'CaseCloseModalCtrl',
size: 'lg',
resolve: {
caze: function() {
return angular.copy(caze);
}
}
})

return modal.result.catch(function(err){
if(err && !_.isString(err)) {
NotificationSrv.error('Case bulk close', err.data, err.status);
}
});
}

$scope.updateField = function(data) {
return CaseSrv.update({
caseId: caseId
}, data).$promise;
};

this.bulkClose = function() {
return ModalUtilsSrv.confirm('Close cases', 'Are you sure you want to close the selected ' + self.selection.length+' case(s)?', {
okText: 'Yes, proceed'
}).then(function() {
return self.selection.reduce(function(initialPromise, nextCase) {
return initialPromise
.then(self.closeCase(nextCase));
}, $q.resolve());
}).catch(function(err){
if(err && !_.isString(err)) {
NotificationSrv.error('Case bulk close', err.data, err.status);
}
});
}

this.getCaseResponders = function(caze, force) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/scripts/controllers/case/CaseMainCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
var defer = $q.defer();

CaseSrv.update({
caseId: caseId
caseId: $scope.caseId
}, data, function(/*response*/) {
//UtilsSrv.shallowClearAndCopy(response, $scope.caze);
defer.resolve($scope.caze);
Expand Down
6 changes: 6 additions & 0 deletions frontend/app/views/partials/case/list/toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
<li ng-if="$vm.menu.unflag">
<a href ng-click="$vm.bulkFlag(false)"><i class="fa fa-flag-o"></i> Remove flag</a>
</li>
<li ng-if="$vm.menu.reopen">
<a href ng-click="$vm.bulkReopen()"><i class="fa fa-folder-open"></i> Reopen</a>
</li>
<li ng-if="$vm.menu.close">
<a href ng-click="$vm.bulkClose()"><i class="fa fa-folder"></i> Close</a>
</li>
<li ng-if="$vm.menu.delete" class="divider"></li>
<li>
<a href ng-click="$vm.bulkRemove()"><i class="fa fa-trash"></i> Delete</a>
Expand Down

0 comments on commit c3258ca

Please sign in to comment.