From 34732d262fcff8ac65dd92e66fd7ed5b92ddc61f Mon Sep 17 00:00:00 2001 From: Lajos Katona Date: Fri, 4 Aug 2017 15:25:15 +0200 Subject: [PATCH] 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 --- .../details/routed-details-view.controller.js | 14 +++++++++-- .../routed-details-view.controller.spec.js | 24 ++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/horizon/static/framework/widgets/details/routed-details-view.controller.js b/horizon/static/framework/widgets/details/routed-details-view.controller.js index d2a1ee60d5..edd2fea4b9 100644 --- a/horizon/static/framework/widgets/details/routed-details-view.controller.js +++ b/horizon/static/framework/widgets/details/routed-details-view.controller.js @@ -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); } } } diff --git a/horizon/static/framework/widgets/details/routed-details-view.controller.spec.js b/horizon/static/framework/widgets/details/routed-details-view.controller.spec.js index 27ff02522c..6e9e99dcce 100644 --- a/horizon/static/framework/widgets/details/routed-details-view.controller.spec.js +++ b/horizon/static/framework/widgets/details/routed-details-view.controller.spec.js @@ -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(); + }); + }); });