GUAC-586: Add data source support to guacGroupList.

This commit is contained in:
Michael Jumper
2015-08-31 16:55:23 -07:00
parent a68243765a
commit fb39588db5
3 changed files with 53 additions and 26 deletions

View File

@@ -32,11 +32,12 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList()
scope: { scope: {
/** /**
* The connection group to display. * The connection groups to display as a map of data source
* identifier to corresponding root group.
* *
* @type ConnectionGroup|Object * @type Object.<String, ConnectionGroup>
*/ */
connectionGroup : '=', connectionGroups : '=',
/** /**
* Arbitrary object which shall be made available to the connection * Arbitrary object which shall be made available to the connection
@@ -106,6 +107,8 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList()
*/ */
var connectionCount = {}; var connectionCount = {};
$scope.rootItems = [];
// Count active connections by connection identifier // Count active connections by connection identifier
activeConnectionService.getActiveConnections() activeConnectionService.getActiveConnections()
.success(function activeConnectionsRetrieved(activeConnections) { .success(function activeConnectionsRetrieved(activeConnections) {
@@ -173,29 +176,30 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList()
}; };
// Set contents whenever the connection group is assigned or changed // Set contents whenever the connection group is assigned or changed
$scope.$watch("connectionGroup", function setContents(connectionGroup) { $scope.$watch('connectionGroups', function setContents(connectionGroups) {
if (connectionGroup) { $scope.rootItems = [];
// Create item hierarchy, including connections only if they will be visible // If connection groups are given, add them to the interface
var rootItem = GroupListItem.fromConnectionGroup(connectionGroup, if (connectionGroups) {
angular.forEach(connectionGroups, function addConnectionGroup(connectionGroup, dataSource) {
var rootItem = GroupListItem.fromConnectionGroup(dataSource, connectionGroup,
!!$scope.connectionTemplate, countActiveConnections); !!$scope.connectionTemplate, countActiveConnections);
// If root group is to be shown, wrap that group as the child of a fake root group // If root group is to be shown, add it as a root item
if ($scope.showRootGroup) if ($scope.showRootGroup)
$scope.rootItem = new GroupListItem({ $scope.rootItems.push(rootItem);
isConnectionGroup : true,
isBalancing : false, // Otherwise, add its children as root items
children : [ rootItem ] else {
angular.forEach(rootItem.children, function addRootItem(child) {
$scope.rootItems.push(child);
});
}
}); });
// If not wrapped, only the descendants of the root will be shown
else
$scope.rootItem = rootItem;
} }
else
$scope.rootItem = null;
}); });

View File

@@ -57,7 +57,7 @@
</div> </div>
<!-- Pager for connections / groups --> <!-- Pager for connections / groups -->
<guac-pager page="childrenPage" items="rootItem.children | orderBy : 'name'" <guac-pager page="childrenPage" items="rootItems | orderBy : 'name'"
page-size="pageSize"></guac-pager> page-size="pageSize"></guac-pager>
</div> </div>

View File

@@ -39,6 +39,14 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
// Use empty object by default // Use empty object by default
template = template || {}; template = template || {};
/**
* The identifier of the data source associated with the connection or
* connection group this item represents.
*
* @type String
*/
this.dataSource = template.dataSource;
/** /**
* The unique identifier associated with the connection or connection * The unique identifier associated with the connection or connection
* group this item represents. * group this item represents.
@@ -124,6 +132,10 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
/** /**
* Creates a new GroupListItem using the contents of the given connection. * Creates a new GroupListItem using the contents of the given connection.
* *
* @param {String} dataSource
* The identifier of the data source containing the given connection
* group.
*
* @param {ConnectionGroup} connection * @param {ConnectionGroup} connection
* The connection whose contents should be represented by the new * The connection whose contents should be represented by the new
* GroupListItem. * GroupListItem.
@@ -136,7 +148,8 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
* @returns {GroupListItem} * @returns {GroupListItem}
* A new GroupListItem which represents the given connection. * A new GroupListItem which represents the given connection.
*/ */
GroupListItem.fromConnection = function fromConnection(connection, countActiveConnections) { GroupListItem.fromConnection = function fromConnection(dataSource,
connection, countActiveConnections) {
// Return item representing the given connection // Return item representing the given connection
return new GroupListItem({ return new GroupListItem({
@@ -145,6 +158,7 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
name : connection.name, name : connection.name,
identifier : connection.identifier, identifier : connection.identifier,
protocol : connection.protocol, protocol : connection.protocol,
dataSource : dataSource,
// Type information // Type information
isConnection : true, isConnection : true,
@@ -172,6 +186,10 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
* Creates a new GroupListItem using the contents and descendants of the * Creates a new GroupListItem using the contents and descendants of the
* given connection group. * given connection group.
* *
* @param {String} dataSource
* The identifier of the data source containing the given connection
* group.
*
* @param {ConnectionGroup} connectionGroup * @param {ConnectionGroup} connectionGroup
* The connection group whose contents and descendants should be * The connection group whose contents and descendants should be
* represented by the new GroupListItem and its descendants. * represented by the new GroupListItem and its descendants.
@@ -195,22 +213,26 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
* A new GroupListItem which represents the given connection group, * A new GroupListItem which represents the given connection group,
* including all descendants. * including all descendants.
*/ */
GroupListItem.fromConnectionGroup = function fromConnectionGroup(connectionGroup, GroupListItem.fromConnectionGroup = function fromConnectionGroup(dataSource,
includeConnections, countActiveConnections, countActiveConnectionGroups) { connectionGroup, includeConnections, countActiveConnections,
countActiveConnectionGroups) {
var children = []; var children = [];
// Add any child connections // Add any child connections
if (connectionGroup.childConnections && includeConnections !== false) { if (connectionGroup.childConnections && includeConnections !== false) {
connectionGroup.childConnections.forEach(function addChildConnection(child) { connectionGroup.childConnections.forEach(function addChildConnection(child) {
children.push(GroupListItem.fromConnection(child, countActiveConnections)); children.push(GroupListItem.fromConnection(dataSource, child,
countActiveConnections));
}); });
} }
// Add any child groups // Add any child groups
if (connectionGroup.childConnectionGroups) { if (connectionGroup.childConnectionGroups) {
connectionGroup.childConnectionGroups.forEach(function addChildGroup(child) { connectionGroup.childConnectionGroups.forEach(function addChildGroup(child) {
children.push(GroupListItem.fromConnectionGroup(child, includeConnections, countActiveConnections, countActiveConnectionGroups)); children.push(GroupListItem.fromConnectionGroup(dataSource,
child, includeConnections, countActiveConnections,
countActiveConnectionGroups));
}); });
} }
@@ -220,6 +242,7 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
// Identifying information // Identifying information
name : connectionGroup.name, name : connectionGroup.name,
identifier : connectionGroup.identifier, identifier : connectionGroup.identifier,
dataSource : dataSource,
// Type information // Type information
isConnection : false, isConnection : false,