From 1011d4237ebe055a969e14076c69cddd43cf0578 Mon Sep 17 00:00:00 2001 From: Tatiana Ovchinnikova Date: Tue, 13 Sep 2022 12:23:04 -0500 Subject: Fix redirect after deleting from details page On apache environments, when WEBROOT is "/dashboard/" and not "/", redirection after deleting from Angular details page is broken. If we go to image/key pair/server group/etc details page, and delete it from this page, redirect url is "/dashboard/dashboard/project/..." instead of "/dashboard/project/..." This patch switches from using WEBROOT depentent panel navigation to getting default index url directly from details view controller. It also cleans up a work around that was implemented for some pages. Change-Id: I6bd06ea479f473a319f8100cbf8d168424b62461 --- .../widgets/details/routed-details-view.controller.js | 6 +++--- .../widgets/details/routed-details-view.controller.spec.js | 8 ++++---- .../static/app/core/keypairs/actions/delete.service.js | 8 -------- .../app/core/server_groups/actions/delete.action.service.js | 7 ------- .../core/server_groups/actions/delete.action.service.spec.js | 4 ++-- .../static/app/core/trunks/actions/delete.action.service.js | 11 ----------- 6 files changed, 9 insertions(+), 35 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 cea3e4102..879b1311d 100644 --- a/horizon/static/framework/widgets/details/routed-details-view.controller.js +++ b/horizon/static/framework/widgets/details/routed-details-view.controller.js @@ -113,7 +113,7 @@ function loadIndexView() { spinnerService.hideModalSpinner(); ctrl.showDetails = false; - var url = navigationsService.getActivePanelUrl(); + var url = ctrl.resourceType.getDefaultIndexUrl(); $location.url(url); } @@ -124,8 +124,8 @@ // That return includes the id and type of each created, updated, deleted // and failed item. // Currently just refreshes the display each time. - if (result.failed && result.deleted && - result.failed.length === 0 && result.deleted.length > 0) { + if ((angular.isUndefined(result)) || (result.failed && result.deleted && + result.failed.length === 0 && result.deleted.length > 0)) { loadIndexView(); } else if (result) { spinnerService.showModalSpinner(gettext('Please Wait')); 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 a765af331..02b51028b 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 @@ -162,23 +162,23 @@ it('handles deleted results and redirect back to index view', function() { spyOn(actionResultService, 'getIdsOfType').and.returnValue([1, 2, 3]); - spyOn(navigationsService, 'getActivePanelUrl'); + spyOn(ctrl.resourceType, 'getDefaultIndexUrl'); 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(); + expect(ctrl.resourceType.getDefaultIndexUrl).toHaveBeenCalled(); }); it('handles general results and do not redirect back to index view', function() { - spyOn(navigationsService, 'getActivePanelUrl'); + spyOn(ctrl.resourceType, 'getDefaultIndexUrl'); 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(); + expect(ctrl.resourceType.getDefaultIndexUrl).not.toHaveBeenCalled(); }); }); diff --git a/openstack_dashboard/static/app/core/keypairs/actions/delete.service.js b/openstack_dashboard/static/app/core/keypairs/actions/delete.service.js index a053ee544..439249088 100644 --- a/openstack_dashboard/static/app/core/keypairs/actions/delete.service.js +++ b/openstack_dashboard/static/app/core/keypairs/actions/delete.service.js @@ -81,14 +81,6 @@ deleteModalResult.fail.forEach(function markFailed(item) { actionResult.failed(resourceType, item.context.id); }); - - var path = '/project/key_pairs'; - if ($location.url() !== path && actionResult.result.failed.length === 0 && - actionResult.result.deleted.length > 0) { - $location.path(path); - } else { - return actionResult.result; - } } function labelize(count) { diff --git a/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.js b/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.js index 51b8b2285..6d1a325c7 100644 --- a/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.js +++ b/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.js @@ -79,13 +79,6 @@ deleteModalResult.fail.forEach(function markFailed(item) { actionResult.failed(serverGroupResourceType, item.context.id); }); - var path = '/project/server_groups'; - if ($location.url() !== path && actionResult.result.failed.length === 0 && - actionResult.result.deleted.length > 0) { - $location.path(path); - } else { - return actionResult.result; - } } function labelize(count) { diff --git a/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.spec.js b/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.spec.js index 2105a9061..9575caf38 100644 --- a/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.spec.js +++ b/openstack_dashboard/static/app/core/server_groups/actions/delete.action.service.spec.js @@ -135,7 +135,8 @@ function testDeleteResult() { $location.path("ngdetails/OS::Nova::ServerGroup/1"); - $httpBackend.expectGET('/static/app/core/server_groups/panel.html').respond({}); + $httpBackend.expectGET('/static/framework/widgets/details/routed-details-view.html') + .respond({}); var servergroup = {id: 1, name: 'sg1'}; deferredModal.resolve({fail: [], pass:[{data:{"data": "", "status": "204"}, context:servergroup}]}); @@ -147,7 +148,6 @@ var deleteFunction = contextArg.deleteEntity; deleteFunction(servergroup.id); expect(novaAPI.deleteServerGroup).toHaveBeenCalledWith(servergroup.id, true); - expect($location.path()).toEqual("/project/server_groups"); } }); // end of delete modal diff --git a/openstack_dashboard/static/app/core/trunks/actions/delete.action.service.js b/openstack_dashboard/static/app/core/trunks/actions/delete.action.service.js index bef4dd273..b695e3bfd 100644 --- a/openstack_dashboard/static/app/core/trunks/actions/delete.action.service.js +++ b/openstack_dashboard/static/app/core/trunks/actions/delete.action.service.js @@ -82,17 +82,6 @@ result.fail.forEach(function markFailed(item) { actionResult.failed(resourceType, item.context.id); }); - - var path = "admin/trunks"; - if ($location.url().indexOf("admin") === -1) { - path = "project/trunks"; - } - if ($location.url() !== path && actionResult.result.failed.length === 0 && - actionResult.result.deleted.length > 0) { - $location.path(path); - } else { - return actionResult.result; - } } } -- cgit v1.2.1