From f7442851c4b85a6a091635f0930c07dbd43cf8fb Mon Sep 17 00:00:00 2001 From: Tatiana Ovchinnikova Date: Mon, 30 Nov 2020 14:00:49 -0600 Subject: [PATCH] Add WEBROOT to ngdetails navigation Default index URL for angular details page doesn't consider WEBROOT while building navigations. That is why refreshing details page or opening it in a new tab works perfectly when WEBROOT is "/" and fails for apache deployment where WEBROOT is "/dashboard/". This patch adds WEBROOT to index URL and builds a proper navigation. Closes-Bug: #1902821 Change-Id: Id609e5499cc8f53dbae36febc945568e45d291f3 --- .../framework/util/navigations/navigations.service.js | 9 +++++++++ .../util/navigations/navigations.service.spec.js | 7 +++++++ .../widgets/details/routed-details-view.controller.js | 9 +++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/horizon/static/framework/util/navigations/navigations.service.js b/horizon/static/framework/util/navigations/navigations.service.js index 8da8746c0b..5d7a3571ff 100644 --- a/horizon/static/framework/util/navigations/navigations.service.js +++ b/horizon/static/framework/util/navigations/navigations.service.js @@ -25,6 +25,7 @@ collapseAllNavigation: collapseAllNavigation, expandNavigationByUrl: expandNavigationByUrl, setBreadcrumb: setBreadcrumb, + setAbsoluteURI: setAbsoluteURI, isNavigationExists: isNavigationExists }; @@ -107,6 +108,14 @@ }); } + /* set absolute uri */ + function setAbsoluteURI(webroot, url) { + if (webroot.endsWith("/") && url.startsWith("/")) { + webroot = webroot.slice(0, -1); + } + return webroot + url; + } + /* check whether navigation exists from url */ function isNavigationExists(url) { return angular.element("a.openstack-panel[href='" + url + "']").length ? true : false; diff --git a/horizon/static/framework/util/navigations/navigations.service.spec.js b/horizon/static/framework/util/navigations/navigations.service.spec.js index 8a83a6430e..6e4e51d2aa 100644 --- a/horizon/static/framework/util/navigations/navigations.service.spec.js +++ b/horizon/static/framework/util/navigations/navigations.service.spec.js @@ -160,6 +160,13 @@ }); }); + describe('setAbsoluteURI', function() { + it('sets absolute uri', function() { + var url = service.setAbsoluteURI('/dashboard/', '/project/images/'); + expect(url).toBe('/dashboard/project/images/'); + }); + }); + describe('isNavigationExists', function() { it('returns true if navigation for specified URL exists', function() { var result = service.isNavigationExists('/project/images/'); 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 739dc5d7eb..cea3e4102c 100644 --- a/horizon/static/framework/widgets/details/routed-details-view.controller.js +++ b/horizon/static/framework/widgets/details/routed-details-view.controller.js @@ -28,7 +28,8 @@ 'horizon.framework.widgets.modal-wait-spinner.service', '$location', '$q', - '$routeParams' + '$routeParams', + '$window' ]; function controller( @@ -39,7 +40,8 @@ spinnerService, $location, $q, - $routeParams + $routeParams, + $window ) { var ctrl = this; @@ -69,6 +71,9 @@ // get defaultIndexUrl var url = resourceType.getDefaultIndexUrl(); + // add webroot + var webroot = $window.WEBROOT; + url = navigationsService.setAbsoluteURI(webroot, url); // if querystring has 'nav' parameter, overwrite the url var query = $location.search(); if (query.hasOwnProperty("nav")) {