Skip to content

Commit

Permalink
Merge pull request #1074 from eclipse/CHE-945
Browse files Browse the repository at this point in the history
CHE-945: [dashboard] improve workspaces removal message
  • Loading branch information
Oleksii Kurinnyi committed Apr 26, 2016
2 parents e304a6b + 5b6d4e6 commit b0151e9
Showing 1 changed file with 29 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,16 @@ export class ListWorkspacesCtrl {

let confirmationPromise = this.showDeleteWorkspacesConfirmation(queueLength);
confirmationPromise.then(() => {
let numberToDelete = queueLength;
let isError = false;
let deleteWorkspacePromises = [];
let workspaceName;

checkedWorkspacesKeys.forEach((workspaceId) => {
this.workspacesSelectedStatus[workspaceId] = false;

let workspace = this.cheWorkspace.getWorkspaceById(workspaceId);
workspaceName = workspace.config.name;
let stoppedStatusPromise = this.cheWorkspace.fetchStatusChange(workspaceId, 'STOPPED');

// stop workspace if it's status is RUNNING
Expand All @@ -233,29 +238,32 @@ export class ListWorkspacesCtrl {
}

// delete stopped workspace
stoppedStatusPromise
.then(() => {
return this.cheWorkspace.deleteWorkspaceConfig(workspaceId);
})
.then(() => {
queueLength--;
if (!queueLength) {
if (isError) {
this.cheNotification.showError('Delete failed.');
} else {
this.cheNotification.showInfo('Has been successfully removed.');
}
}
}, (error) => {
let promise = stoppedStatusPromise.then(() => {
return this.cheWorkspace.deleteWorkspaceConfig(workspaceId);
}).then(() => {
queueLength--;
if (!queueLength) {
this.cheNotification('Delete failed.');
}
this.$log.error(error);
})
.then(() => {
this.getUserWorkspaces();
},
(error) => {
isError = true;
this.$log.error('Cannot delete workspace: ', error);
});
deleteWorkspacePromises.push(promise);
});

this.$q.all(deleteWorkspacePromises).finally(() => {
this.getUserWorkspaces();

if (isError) {
this.cheNotification.showError('Delete failed.');
}
else {
if (numberToDelete === 1) {
this.cheNotification.showInfo(workspaceName + ' has been removed.');
}
else {
this.cheNotification.showInfo('Selected workspaces have been removed.');
}
}
});
});
}
Expand Down

0 comments on commit b0151e9

Please sign in to comment.