GUACAMOLE-723: Merge display connection selection menu only if multiple connections are available.

This commit is contained in:
Virtually Nick
2019-06-23 22:32:08 -04:00
committed by GitHub
2 changed files with 90 additions and 62 deletions

View File

@@ -280,9 +280,12 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
})(guacClientManager.getManagedClients());
/**
* Map of data source identifier to the root connection group of that data
* source, or null if the connection group hierarchy has not yet been
* loaded.
* The root connection groups of the connection hierarchy that should be
* presented to the user for selecting a different connection, as a map of
* data source identifier to the root connection group of that data
* source. This will be null if the connection group hierarchy has not yet
* been loaded or if the hierarchy is inapplicable due to only one
* connection or balancing group being available.
*
* @type Object.<String, ConnectionGroup>
*/
@@ -313,7 +316,13 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams
ConnectionGroup.ROOT_IDENTIFIER
)
.then(function rootGroupsRetrieved(rootConnectionGroups) {
// Store retrieved groups only if there are multiple connections or
// balancing groups available
var clientPages = userPageService.getClientPages(rootConnectionGroups);
if (clientPages.length > 1)
$scope.rootConnectionGroups = rootConnectionGroups;
}, requestService.WARN);
/**

View File

@@ -67,7 +67,6 @@ angular.module('navigation').factory('userPageService', ['$injector',
*/
var generateHomePage = function generateHomePage(rootGroups, permissions) {
var homePage = null;
var settingsPages = generateSettingsPages(permissions);
// If user has access to settings pages, return home page and skip
@@ -79,67 +78,87 @@ angular.module('navigation').factory('userPageService', ['$injector',
if (settingsPages.length > 2)
return SYSTEM_HOME_PAGE;
// Determine whether a connection or balancing group should serve as
// the home page
for (var dataSource in rootGroups) {
// Get corresponding root group
var rootGroup = rootGroups[dataSource];
// Get children
var connections = rootGroup.childConnections || [];
var connectionGroups = rootGroup.childConnectionGroups || [];
// Calculate total number of root-level objects
var totalRootObjects = connections.length + connectionGroups.length;
// If exactly one connection or balancing group is available, use
// that as the home page
if (homePage === null && totalRootObjects === 1) {
var clientPages = service.getClientPages(rootGroups);
return (clientPages.length === 1) ? clientPages[0] : SYSTEM_HOME_PAGE;
var connection = connections[0];
var connectionGroup = connectionGroups[0];
};
// Only one connection present, use as home page
if (connection) {
homePage = new PageDefinition({
/**
* Adds to the given array all pages that the current user may use to
* access connections or balancing groups that are descendants of the given
* connection group.
*
* @param {PageDefinition[]} clientPages
* The array that pages should be added to.
*
* @param {String} dataSource
* The data source containing the given connection group.
*
* @param {ConnectionGroup} connectionGroup
* The connection group ancestor of the connection or balancing group
* descendants whose pages should be added to the given array.
*/
var addClientPages = function addClientPages(clientPages, dataSource, connectionGroup) {
// Add pages for all child connections
angular.forEach(connectionGroup.childConnections, function addConnectionPage(connection) {
clientPages.push(new PageDefinition({
name : connection.name,
url : '/client/' + ClientIdentifier.toString({
dataSource : dataSource,
type : ClientIdentifier.Types.CONNECTION,
id : connection.identifier
})
}));
});
}
// Only one balancing group present, use as home page
if (connectionGroup
&& connectionGroup.type === ConnectionGroup.Type.BALANCING
&& _.isEmpty(connectionGroup.childConnections)
&& _.isEmpty(connectionGroup.childConnectionGroups)) {
homePage = new PageDefinition({
// Add pages for all child balancing groups, as well as the connectable
// descendants of all balancing groups of any type
angular.forEach(connectionGroup.childConnectionGroups, function addConnectionGroupPage(connectionGroup) {
if (connectionGroup.type === ConnectionGroup.Type.BALANCING) {
clientPages.push(new PageDefinition({
name : connectionGroup.name,
url : '/client/' + ClientIdentifier.toString({
dataSource : dataSource,
type : ClientIdentifier.Types.CONNECTION_GROUP,
id : connectionGroup.identifier
})
}));
}
addClientPages(clientPages, dataSource, connectionGroup);
});
};
/**
* Returns a full list of all pages that the current user may use to access
* a connection or balancing group, regardless of the depth of those
* connections/groups within the connection hierarchy.
*
* @param {Object.<String, ConnectionGroup>} rootGroups
* A map of all root connection groups visible to the current user,
* where each key is the identifier of the corresponding data source.
*
* @returns {PageDefinition[]}
* A list of all pages that the current user may use to access a
* connection or balancing group.
*/
service.getClientPages = function getClientPages(rootGroups) {
var clientPages = [];
// Determine whether a connection or balancing group should serve as
// the home page
for (var dataSource in rootGroups) {
addClientPages(clientPages, dataSource, rootGroups[dataSource]);
}
}
// Otherwise, a connection or balancing group cannot serve as the
// home page
else if (totalRootObjects >= 1) {
homePage = null;
break;
}
} // end for each data source
// Use default home page if no other is available
return homePage || SYSTEM_HOME_PAGE;
return clientPages;
};