diff --git a/guacamole/src/main/webapp/app/groupList/directives/guacGroupList.js b/guacamole/src/main/webapp/app/groupList/directives/guacGroupList.js index 1ba9e8dc1..d5ba313d4 100644 --- a/guacamole/src/main/webapp/app/groupList/directives/guacGroupList.js +++ b/guacamole/src/main/webapp/app/groupList/directives/guacGroupList.js @@ -88,11 +88,58 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList() }, templateUrl: 'app/groupList/templates/guacGroupList.html', - controller: ['$scope', '$injector', '$interval', function guacGroupListController($scope, $injector, $interval) { + controller: ['$scope', '$injector', function guacGroupListController($scope, $injector) { - // Get required types + // Required services + var activeConnectionService = $injector.get('activeConnectionService'); + + // Required types var GroupListItem = $injector.get('GroupListItem'); + /** + * The number of active connections associated with a given + * connection identifier. If this information is unknown, or there + * are no active connections for a given identifier, no number will + * be stored. + * + * @type Object. + */ + var connectionCount = {}; + + // Count active connections by connection identifier + activeConnectionService.getActiveConnections() + .success(function activeConnectionsRetrieved(activeConnections) { + + // Count each active connection by identifier + angular.forEach(activeConnections, function addActiveConnection(activeConnection) { + + // If counter already exists, increment + var identifier = activeConnection.connectionIdentifier; + if (connectionCount[identifier]) + connectionCount[identifier]++; + + // Otherwise, initialize counter to 1 + else + connectionCount[identifier] = 1; + + }); + + }); + + /** + * Returns the number of active usages of a given connection. + * + * @param {Connection} connection + * The connection whose active connections should be counted. + * + * @returns {Number} + * The number of currently-active usages of the given + * connection. + */ + var countActiveConnections = function countActiveConnections(connection) { + return connectionCount[connection.identifier]; + }; + /** * Returns whether the given item represents a connection that can * be displayed. If there is no connection template, then no @@ -131,7 +178,8 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList() if (connectionGroup) { // Create item hierarchy, including connections only if they will be visible - var rootItem = GroupListItem.fromConnectionGroup(connectionGroup, !!$scope.connectionTemplate); + var rootItem = GroupListItem.fromConnectionGroup(connectionGroup, + !!$scope.connectionTemplate, countActiveConnections); // If root group is to be shown, wrap that group as the child of a fake root group if ($scope.showRootGroup) @@ -161,7 +209,7 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList() $scope.toggleExpanded = function toggleExpanded(groupListItem) { groupListItem.isExpanded = !groupListItem.isExpanded; }; - + }] }; diff --git a/guacamole/src/main/webapp/app/groupList/types/GroupListItem.js b/guacamole/src/main/webapp/app/groupList/types/GroupListItem.js index 4e70dc245..aa9a0f0de 100644 --- a/guacamole/src/main/webapp/app/groupList/types/GroupListItem.js +++ b/guacamole/src/main/webapp/app/groupList/types/GroupListItem.js @@ -102,12 +102,14 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio this.isExpanded = template.isExpanded; /** - * The number of currently active users for this connection or + * Returns the number of currently active users for this connection or * connection group, if known. * * @type Number */ - this.activeConnections = template.activeConnections; + this.getActiveConnections = template.getActiveConnections || (function getActiveConnections() { + return null; + }); /** * The connection or connection group whose data is exposed within @@ -126,10 +128,15 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio * The connection whose contents should be represented by the new * GroupListItem. * + * @param {Function} [countActiveConnections] + * A getter which returns the current number of active connections for + * the given connection. If omitted, the number of active connections + * known at the time this function was called is used instead. + * * @returns {GroupListItem} * A new GroupListItem which represents the given connection. */ - GroupListItem.fromConnection = function fromConnection(connection) { + GroupListItem.fromConnection = function fromConnection(connection, countActiveConnections) { // Return item representing the given connection return new GroupListItem({ @@ -144,7 +151,15 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio isConnectionGroup : false, // Count of currently active connections using this connection - activeConnections : connection.activeConnections, + getActiveConnections : function getActiveConnections() { + + // Use getter, if provided + if (countActiveConnections) + return countActiveConnections(connection); + + return connection.activeConnections; + + }, // Wrapped item wrappedItem : connection @@ -165,26 +180,37 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio * Whether connections should be included in the contents of the * resulting GroupListItem. By default, connections are included. * + * @param {Function} [countActiveConnections] + * A getter which returns the current number of active connections for + * the given connection. If omitted, the number of active connections + * known at the time this function was called is used instead. + * + * @param {Function} [countActiveConnectionGroups] + * A getter which returns the current number of active connections for + * the given connection group. If omitted, the number of active + * connections known at the time this function was called is used + * instead. + * * @returns {GroupListItem} * A new GroupListItem which represents the given connection group, * including all descendants. */ GroupListItem.fromConnectionGroup = function fromConnectionGroup(connectionGroup, - includeConnections) { + includeConnections, countActiveConnections, countActiveConnectionGroups) { var children = []; // Add any child connections if (connectionGroup.childConnections && includeConnections !== false) { connectionGroup.childConnections.forEach(function addChildConnection(child) { - children.push(GroupListItem.fromConnection(child)); + children.push(GroupListItem.fromConnection(child, countActiveConnections)); }); } // Add any child groups if (connectionGroup.childConnectionGroups) { connectionGroup.childConnectionGroups.forEach(function addChildGroup(child) { - children.push(GroupListItem.fromConnectionGroup(child, includeConnections)); + children.push(GroupListItem.fromConnectionGroup(child, includeConnections, countActiveConnections, countActiveConnectionGroups)); }); } @@ -204,7 +230,16 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio children : children, // Count of currently active connection groups using this connection - activeConnections : connectionGroup.activeConnections, + getActiveConnections : function getActiveConnections() { + + // Use getter, if provided + if (countActiveConnectionGroups) + return countActiveConnectionGroups(connectionGroup); + + return connectionGroup.activeConnections; + + }, + // Wrapped item wrappedItem : connectionGroup diff --git a/guacamole/src/main/webapp/app/home/templates/connection.html b/guacamole/src/main/webapp/app/home/templates/connection.html index 4e91fd62d..9187c4f25 100644 --- a/guacamole/src/main/webapp/app/home/templates/connection.html +++ b/guacamole/src/main/webapp/app/home/templates/connection.html @@ -21,7 +21,7 @@ THE SOFTWARE. --> -
+
@@ -32,8 +32,8 @@ {{item.name}} - - {{'HOME.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.activeConnections}'}} + + {{'HOME.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.getActiveConnections()}'}}
diff --git a/guacamole/src/main/webapp/app/manage/templates/connection.html b/guacamole/src/main/webapp/app/manage/templates/connection.html index cd0950b92..b96e3dfa7 100644 --- a/guacamole/src/main/webapp/app/manage/templates/connection.html +++ b/guacamole/src/main/webapp/app/manage/templates/connection.html @@ -21,7 +21,7 @@ THE SOFTWARE. --> -
+
@@ -32,8 +32,8 @@ {{item.name}} - - {{'MANAGE_CONNECTION.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.activeConnections}'}} + + {{'MANAGE_CONNECTION.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.getActiveConnections()}'}}