Redirect back if deleting from image details

If deleting from the image details view, the user stuck on an empty
page, instead of redirecting back to the list of remaining images.

Change-Id: I9a2f5b7325e037c4b57cd01afc2bbcfca51e6e83
Closes-Bug: #1704118
This commit is contained in:
Lajos Katona 2017-08-04 15:25:15 +02:00
parent 3af1d420ff
commit 34732d262f
2 changed files with 35 additions and 3 deletions

View File

@ -89,6 +89,13 @@
ctrl.itemName = ctrl.resourceType.itemName(response.data);
}
function loadIndexView() {
spinnerService.hideModalSpinner();
ctrl.showDetails = false;
var url = navigationsService.getActivePanelUrl();
$location.url(url);
}
function actionSuccessHandler(result) {
// The action has completed (for whatever "complete" means to that
// action. Notice the view doesn't really need to know the semantics of the
@ -96,11 +103,14 @@
// That return includes the id and type of each created, updated, deleted
// and failed item.
// Currently just refreshes the display each time.
if (result) {
if (result.failed && result.deleted &&
result.failed.length === 0 && result.deleted.length > 0) {
loadIndexView();
} else if (result) {
spinnerService.showModalSpinner(gettext('Please Wait'));
ctrl.showDetails = false;
ctrl.context.loadPromise = ctrl.resourceType.load(ctrl.context.identifier);
ctrl.context.loadPromise.then(loadData);
return ctrl.context.loadPromise.then(loadData);
}
}
}

View File

@ -45,7 +45,8 @@
navigationsService = {
expandNavigationByUrl: function() { return ['Project', 'Compute', 'Images']; },
setBreadcrumb: angular.noop
setBreadcrumb: angular.noop,
getActivePanelUrl: function() { return 'project/fancypanel'; }
};
ctrl = $controller("RoutedDetailsViewController", {
@ -113,6 +114,27 @@
expect(ctrl.showDetails).toBe(true);
});
it('handles deleted results and redirect back to index view', function() {
spyOn(actionResultService, 'getIdsOfType').and.returnValue([1, 2, 3]);
spyOn(navigationsService, 'getActivePanelUrl');
var result = $q.defer();
result.resolve({created: [], updated: [], deleted: ['image1'], failed: []});
ctrl.resultHandler(result.promise);
$timeout.flush();
expect(ctrl.showDetails).toBe(false);
expect(navigationsService.getActivePanelUrl).toHaveBeenCalled();
});
it('handles general results and do not redirect back to index view', function() {
spyOn(navigationsService, 'getActivePanelUrl');
var result = $q.defer();
result.resolve({created: [], updated: ['image1'], deleted: [], failed: []});
ctrl.resultHandler(result.promise);
$timeout.flush();
expect(ctrl.showDetails).toBe(false);
expect(navigationsService.getActivePanelUrl).not.toHaveBeenCalled();
});
});
});