Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiselect for instance deletion #3268

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@
"CREATE-TIME": "Created",
"END-TIME": "Ended",
"STATUS": "Status"
},
"ACTION": {
"DELETE":"Delete process instance(s)"
},
"POPUP": {
"DELETE":{
"TITLE": "Delete process instance(s)",
"MESSAGE-DELETE":"Are you sure you want to delete {{total}} process instances",
"CONFIRM-DELETE": "Delete process instance(s)",
"DELETE-REASON": "Terminated and removed in bulk",
"DELETE-FAILED": "Termination or removal of process instances failed"
}
}
},
"TASK": {
Expand Down Expand Up @@ -810,6 +822,10 @@
"DELETED": "Process instance '{{id}}' deleted successfully.",
"TERMINATED": "Process instance '{{id}}' terminated successfully."
},
"PROCESS-INSTANCES": {
"DELETED": "{{count}} Processes deleted successfully.",
"TERMINATED": "{{count}} Processes terminated successfully."
},
"TASK": {
"DELETED": "Task '{{id}}' deleted successfully.",
"COMPLETED": "Task '{{id}}' completed successfully.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright 2005-2015 Alfresco Software, Ltd.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -16,18 +16,26 @@

/* Controllers */

flowableAdminApp.controller('ProcessInstancesController', ['$rootScope', '$scope', '$http', '$timeout', '$location', '$translate', '$q', 'gridConstants',
function ($rootScope, $scope, $http, $timeout, $location, $translate, $q, gridConstants) {
flowableAdminApp.controller('ProcessInstancesController', ['$rootScope', '$scope', '$http','$route', '$timeout', '$location', '$modal', '$translate', '$q', 'gridConstants',
function ($rootScope, $scope, $http, $route, $timeout, $location, $modal, $translate, $q, gridConstants) {

$rootScope.navigation = {main: 'process-engine', sub: 'instances'};

$scope.filter = {};
$scope.processInstances = {};
$scope.definitionCacheLoaded = false;

$scope.variableFilterTypes = FlowableAdmin.Utils.variableFilterTypes;
$scope.variableFilterOperators = FlowableAdmin.Utils.variableFilterOperators;

$scope.moveToInstanceButtonTemplate = `
<div class="ui-grid-cell-contents d-flex justify-content-center">
<button type="button" class="btn btn-default btn-sm" ng-click="processInstanceSelected(row.entity.id)">
<i class="glyphicon glyphicon-pencil"></i>
</button>
</div>
`

var filterConfig = {
url: FlowableAdmin.Config.adminContextRoot + 'rest/admin/process-instances',
method: 'POST',
Expand Down Expand Up @@ -58,7 +66,7 @@ flowableAdminApp.controller('ProcessInstancesController', ['$rootScope', '$scope
{name: 'PROCESS-INSTANCES.SORT.ID', id: 'processInstanceId'},
{name: 'PROCESS-INSTANCES.SORT.START-TIME', id: 'startTime'}
],

options: {
finished: [
{name: 'PROCESS-INSTANCES.FILTER.STATUS-ANY', value: ''},
Expand Down Expand Up @@ -101,10 +109,10 @@ flowableAdminApp.controller('ProcessInstancesController', ['$rootScope', '$scope
$rootScope.filters.instanceFilter = $scope.filter;
}

$scope.processInstanceSelected = function(processInstance) {
if (processInstance && processInstance.getProperty('id')) {
$location.path('/process-instance/' + processInstance.getProperty('id'));
}
$scope.processInstanceSelected = function(id) {
if(!id) return;

$location.path('/process-instance/' + id);
};

if(!$scope.filter.properties.variables) {
Expand Down Expand Up @@ -225,16 +233,18 @@ flowableAdminApp.controller('ProcessInstancesController', ['$rootScope', '$scope
data: 'processInstances.data',
enableRowReordering: true,
enableColumnResize: true,
multiSelect: false,
keepLastSelected : false,
showSelectionCheckbox: true,
selectWithCheckboxOnly: false,
selectedItems: [],
rowHeight: 36,
afterSelectionChange: $scope.processInstanceSelected,
columnDefs: [
{ field: 'id', displayName: headers[0], cellTemplate: gridConstants.defaultTemplate},
{ field: 'businessKey', displayName: headers[1], cellTemplate: gridConstants.defaultTemplate},
{ field: 'processDefinition.name', displayName: headers[2], cellTemplate: gridConstants.defaultTemplate},
{ field: 'startTime', displayName: headers[3], cellTemplate: gridConstants.dateTemplate},
{ field: 'endTime', displayName: headers[4], cellTemplate: gridConstants.dateTemplate}]
{ field: 'endTime', displayName: headers[4], cellTemplate: gridConstants.dateTemplate},
{ field: 'actions', displayName: "", cellTemplate: $scope.moveToInstanceButtonTemplate, width: 40}
]
};
});

Expand All @@ -256,7 +266,7 @@ flowableAdminApp.controller('ProcessInstancesController', ['$rootScope', '$scope
if ($scope.filter.processDefinition && $scope.filter.processDefinition !== '-1') {
$scope.filter.properties.processDefinitionId = $scope.filter.processDefinition;
$scope.filter.refresh();

} else {
var tempProcessDefinitionId = $scope.filter.properties.processDefinitionId;
$scope.filter.properties.processDefinitionId = null;
Expand All @@ -270,4 +280,99 @@ flowableAdminApp.controller('ProcessInstancesController', ['$rootScope', '$scope
$scope.filter.refresh();
});

}]);
// Dialogs
$scope.deleteProcessInstances = function () {
var action = "delete";

var modalInstance = $modal.open({
templateUrl: 'views/process-instances-delete-popup.html',
controller: 'DeleteProcessesModalInstanceCtrl',
resolve: {
processes: function () {
return $scope.gridInstances.selectedItems;
},
action: function () {
return action;
}
}
});

modalInstance.result.then(function (deleteProcessInstances) {
if (deleteProcessInstances) {
$scope.addAlert($translate.instant('ALERT.PROCESS-INSTANCES.DELETED', $scope.gridInstances.selectedItems.length), 'info');
$route.reload();
}
});
};
}]);

flowableAdminApp.controller('DeleteProcessesModalInstanceCtrl',
['$rootScope', '$scope', '$modalInstance', '$http', '$translate', '$window', 'processes', 'action',
function ($rootScope, $scope, $modalInstance, $http, $translate, $window, processes, action) {

$scope.processes = processes;
$scope.action = action;
$scope.status = {
loading: false,
progress: 0,
successfullyTerminated: [],
successfullyDeleted: [],
failed: []
};
$scope.model = {};
$scope.openInNewWindow = function(absUrl, id) {
var url = absUrl + id;
$window.open(url, "_blank");
}

$scope.ok = async function () {
$scope.status.loading = true;
var dataForPost = {action: "terminate", deleteReason: $translate.instant('PROCESS-INSTANCES.POPUP.DELETE.DELETE-REASON')};

// terminate
var terminatedPromises = Promise.all(
$scope.processes.map( async process => {
await $http({
method: 'POST', url: FlowableAdmin.Config.adminContextRoot + 'rest/admin/process-instances/' + process.id,
data: dataForPost
}).success(function (data, status, headers, config) {
$scope.status.successfullyTerminated.push(process);
}).error(function (data, status, headers, config) {
$scope.status.failed.push(process);
});
})
)
await terminatedPromises;

// delete all succesfully terminated
dataForPost.action = "delete"
var deletedPromises = Promise.all(
$scope.status.successfullyTerminated.map(async process => {
await $http({
method: 'POST', url: FlowableAdmin.Config.adminContextRoot + 'rest/admin/process-instances/' + process.id,
data: dataForPost
}).success(function (data, status, headers, config) {
$scope.status.successfullyDeleted.push(process);
$scope.status.progress = parseInt(
(parseInt($scope.status.successfullyDeleted.length) /
parseInt($scope.processes.length) * 100).toFixed(0)
);
}).error(function (data, status, headers, config) {
$scope.status.failed.push(process);
});
})
)
await deletedPromises;
$scope.status.loading = false;

if($scope.status.failed.length == 0){
$modalInstance.close(true);
}
};

$scope.cancel = function () {
if (!$scope.status.loading) {
$modalInstance.dismiss('cancel');
}
};
}]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="modal-header-wrapper">
<div class="modal-header">
<div class="pull-right">
<a class="action" ng-click="cancel()">&times; {{'GENERAL.ACTION.CANCEL-AND-CLOSE' | translate}}</a>
</div>
<h2>{{'PROCESS-INSTANCES.POPUP.DELETE.TITLE' | translate}}</h2>
</div>
</div>
<div class="modal-body">
<p ng-show="status.failed == 0">{{'PROCESS-INSTANCES.POPUP.DELETE.MESSAGE-DELETE' | translate:{total: processes.length} }}</p>
<progressbar value="status.progress" ng-show="status.failed == 0"></progressbar>

<p ng-show="status.failed.length > 0">{{'PROCESS-INSTANCES.POPUP.DELETE.DELETE-FAILED' | translate }}</p>
<ol ng-show="status.failed.length > 0">
<li ng-repeat="failedProcess in status.failed">
<a role="link" ng-click="openInNewWindow('#/process-instance/', failedProcess.id)">{{failedProcess.processDefinition.key}} ({{failedProcess.id}})</a>
</li>
</ol>
</div>

<div class="modal-footer-wrapper">
<div class="modal-footer">
<div class="pull-right">
<button type="button" class="btn btn-sm btn-default" ng-click="cancel()" ng-disabled="status.loading"
translate="GENERAL.ACTION.CANCEL">
</button>
<button type="button" class="btn btn-sm btn-danger" ng-click="ok()" ng-disabled="status.loading">
{{'PROCESS-INSTANCES.POPUP.DELETE.CONFIRM-DELETE' | translate}}
</button>
</div>
<loading-indicator></loading-indicator>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<div class="col-md-8">
<div class="component">
<div class="title">
<div class="btn-group btn-group-sm pull-right">
<button type="button" class="btn btn-danger btn-sm" ng-click="deleteProcessInstances()" ng-disabled="!gridInstances.selectedItems.length"
translate="PROCESS-INSTANCES.ACTION.DELETE">
</button>
</div>

<div class="btn-group btn-group-sm pull-right">
<div class="btn-group btn-group-sm">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"
Expand Down