Add links to trunk parent and subports

Add link to the parent port's detail page on the table view of trunks
panel, and add link to the subport's details page from the trunk details
page.

Closes-Bug: #1746082
Change-Id: I66fc525e02a8b4c5c77ed2e663c644e8e2e1a805
This commit is contained in:
Lajos Katona 2017-12-01 15:04:20 +01:00
parent 3af1d420ff
commit 3c55bcea40
4 changed files with 67 additions and 3 deletions

View File

@ -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}
]
};

View File

@ -66,7 +66,8 @@
})
.append({
id: 'port_id',
priority: 1
priority: 1,
urlFunction: trunksService.getPortDetailsPath
})
.append({
id: 'subport_count',

View File

@ -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

View File

@ -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());
});
});
});
})();