diff --git a/openstack_dashboard/static/app/core/trunks/details/overview.controller.js b/openstack_dashboard/static/app/core/trunks/details/overview.controller.js index d9e9528fc1..de325ee4f3 100644 --- a/openstack_dashboard/static/app/core/trunks/details/overview.controller.js +++ b/openstack_dashboard/static/app/core/trunks/details/overview.controller.js @@ -25,6 +25,7 @@ 'horizon.app.core.trunks.resourceType', 'horizon.framework.conf.resource-type-registry.service', 'horizon.app.core.openstack-service-api.userSession', + 'horizon.app.core.trunks.service', '$scope' ]; @@ -32,6 +33,7 @@ trunkResourceTypeCode, registry, userSession, + trunksService, $scope ) { var ctrl = this; @@ -52,7 +54,8 @@ priority: 1, sortDefault: true}, {id: 'segmentation_id', title: gettext('Segmentation ID'), priority: 1, sortDefault: true}, - {id: 'port_id', title: gettext('Port ID'), priority: 1} + {id: 'port_id', title: gettext('Port ID'), priority: 1, + urlFunction: trunksService.getPortDetailsPath} ] }; diff --git a/openstack_dashboard/static/app/core/trunks/trunks.module.js b/openstack_dashboard/static/app/core/trunks/trunks.module.js index fc5a0de377..e5922dcd8a 100644 --- a/openstack_dashboard/static/app/core/trunks/trunks.module.js +++ b/openstack_dashboard/static/app/core/trunks/trunks.module.js @@ -66,7 +66,8 @@ }) .append({ id: 'port_id', - priority: 1 + priority: 1, + urlFunction: trunksService.getPortDetailsPath }) .append({ id: 'subport_count', diff --git a/openstack_dashboard/static/app/core/trunks/trunks.service.js b/openstack_dashboard/static/app/core/trunks/trunks.service.js index ada8a74091..f0047fe0de 100644 --- a/openstack_dashboard/static/app/core/trunks/trunks.service.js +++ b/openstack_dashboard/static/app/core/trunks/trunks.service.js @@ -38,10 +38,16 @@ * but do not need to be restricted to such use. Each exposed function * is documented below. */ - function trunksService(neutron, userSession, detailRoute, $location, $window) { + function trunksService( + neutron, + userSession, + detailRoute, + $location, + $window) { return { getDetailsPath: getDetailsPath, + getPortDetailsPath: getPortDetailsPath, getTrunksPromise: getTrunksPromise, getTrunkPromise: getTrunkPromise }; @@ -62,6 +68,27 @@ return detailsPath; } + /* + * @ngdoc function + * @name getPortDetailsPath + * @param item {Object} - the trunk object or the relevant subport details + * object + * @description + * Given a trunk object, returns back url for the trunk's parent port or + * subport detail page, for example: + * /project/networks/ports/uuid/detail + */ + function getPortDetailsPath(item) { + // Note(lajos Katona): the $location.url() can give back /projct/trunks or + // in case of calling from ngdetails page + // /ngdetails/OS::Neutron::Trunk/uuid?nav=%2Fadmin%2Ftrunks%2F + var isAdminFromLocation = $location.url().indexOf('admin') >= 1; + + var dashboardUrl = isAdminFromLocation ? 'admin' : 'project'; + var webRoot = $window.WEBROOT; + return webRoot + dashboardUrl + '/networks/ports/' + item.port_id + '/detail'; + } + /* * @ngdoc function * @name getTrunksPromise diff --git a/openstack_dashboard/static/app/core/trunks/trunks.service.spec.js b/openstack_dashboard/static/app/core/trunks/trunks.service.spec.js index 379895be33..f169ed43f3 100644 --- a/openstack_dashboard/static/app/core/trunks/trunks.service.spec.js +++ b/openstack_dashboard/static/app/core/trunks/trunks.service.spec.js @@ -87,5 +87,38 @@ }); + describe('getDetailsPath', function() { + + it('returns path for loading details for a given trunk', function() { + var trunk = {id: 1}; + var path = service.getDetailsPath(trunk); + expect(path).toMatch('ngdetails'); + expect(path).toMatch(trunk.id.toString()); + }); + + }); + + describe('getPortDetailsPath', function() { + + it('returns url to port\'s detail page for non-admin user', function() { + spyOn(_location_, 'url').and.returnValue('/project/trunks'); + + var trunk = {id: 1, port_id: 2}; + var path = service.getPortDetailsPath(trunk); + expect(path).toMatch('detail'); + expect(path).toMatch(trunk.port_id.toString()); + }); + + it('returns url to port\'s detail page for admin user', function() { + spyOn(_location_, 'url').and.returnValue('/admin/trunks'); + + var trunk = {id: 1, port_id: 2}; + var path = service.getPortDetailsPath(trunk); + expect(path).toMatch('detail'); + expect(path).toMatch(trunk.port_id.toString()); + }); + + }); + }); })();