mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
GUAC-586: Use data source when determining active user count.
This commit is contained in:
@@ -93,45 +93,38 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList()
|
|||||||
|
|
||||||
// Required services
|
// Required services
|
||||||
var activeConnectionService = $injector.get('activeConnectionService');
|
var activeConnectionService = $injector.get('activeConnectionService');
|
||||||
|
var dataSourceService = $injector.get('dataSourceService');
|
||||||
|
|
||||||
// Required types
|
// Required types
|
||||||
var GroupListItem = $injector.get('GroupListItem');
|
var GroupListItem = $injector.get('GroupListItem');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of active connections associated with a given
|
* Map of data source identifier to the number of active
|
||||||
* connection identifier. If this information is unknown, or there
|
* connections associated with a given connection identifier.
|
||||||
* are no active connections for a given identifier, no number will
|
* If this information is unknown, or there are no active
|
||||||
* be stored.
|
* connections for a given identifier, no number will be stored.
|
||||||
*
|
*
|
||||||
* @type Object.<String, Number>
|
* @type Object.<String, Object.<String, Number>>
|
||||||
*/
|
*/
|
||||||
var connectionCount = {};
|
var connectionCount = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A list of all items which should appear at the root level. As
|
||||||
|
* connections and connection groups from multiple data sources may
|
||||||
|
* be included in a guacGroupList, there may be multiple root
|
||||||
|
* items, even if the root connection group is shown.
|
||||||
|
*
|
||||||
|
* @type GroupListItem[]
|
||||||
|
*/
|
||||||
$scope.rootItems = [];
|
$scope.rootItems = [];
|
||||||
|
|
||||||
// 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.
|
* Returns the number of active usages of a given connection.
|
||||||
*
|
*
|
||||||
|
* @param {String} dataSource
|
||||||
|
* The identifier of the data source containing the given
|
||||||
|
* connection.
|
||||||
|
*
|
||||||
* @param {Connection} connection
|
* @param {Connection} connection
|
||||||
* The connection whose active connections should be counted.
|
* The connection whose active connections should be counted.
|
||||||
*
|
*
|
||||||
@@ -139,8 +132,8 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList()
|
|||||||
* The number of currently-active usages of the given
|
* The number of currently-active usages of the given
|
||||||
* connection.
|
* connection.
|
||||||
*/
|
*/
|
||||||
var countActiveConnections = function countActiveConnections(connection) {
|
var countActiveConnections = function countActiveConnections(dataSource, connection) {
|
||||||
return connectionCount[connection.identifier];
|
return connectionCount[dataSource][connection.identifier];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,12 +171,22 @@ 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('connectionGroups', function setContents(connectionGroups) {
|
$scope.$watch('connectionGroups', function setContents(connectionGroups) {
|
||||||
|
|
||||||
|
// Reset stored data
|
||||||
|
var dataSources = [];
|
||||||
$scope.rootItems = [];
|
$scope.rootItems = [];
|
||||||
|
connectionCount = {};
|
||||||
|
|
||||||
// If connection groups are given, add them to the interface
|
// If connection groups are given, add them to the interface
|
||||||
if (connectionGroups) {
|
if (connectionGroups) {
|
||||||
|
|
||||||
|
// Add each provided connection group
|
||||||
angular.forEach(connectionGroups, function addConnectionGroup(connectionGroup, dataSource) {
|
angular.forEach(connectionGroups, function addConnectionGroup(connectionGroup, dataSource) {
|
||||||
|
|
||||||
|
// Prepare data source for active connection counting
|
||||||
|
dataSources.push(dataSource);
|
||||||
|
connectionCount[dataSource] = {};
|
||||||
|
|
||||||
|
// Create root item for current connection group
|
||||||
var rootItem = GroupListItem.fromConnectionGroup(dataSource, connectionGroup,
|
var rootItem = GroupListItem.fromConnectionGroup(dataSource, connectionGroup,
|
||||||
!!$scope.connectionTemplate, countActiveConnections);
|
!!$scope.connectionTemplate, countActiveConnections);
|
||||||
|
|
||||||
@@ -199,6 +202,32 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList()
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Count active connections by connection identifier
|
||||||
|
dataSourceService.apply(
|
||||||
|
activeConnectionService.getActiveConnections,
|
||||||
|
dataSources
|
||||||
|
)
|
||||||
|
.then(function activeConnectionsRetrieved(activeConnectionMap) {
|
||||||
|
|
||||||
|
// Within each data source, count each active connection by identifier
|
||||||
|
angular.forEach(activeConnectionMap, function addActiveConnections(activeConnections, dataSource) {
|
||||||
|
angular.forEach(activeConnections, function addActiveConnection(activeConnection) {
|
||||||
|
|
||||||
|
// If counter already exists, increment
|
||||||
|
var identifier = activeConnection.connectionIdentifier;
|
||||||
|
if (connectionCount[dataSource][identifier])
|
||||||
|
connectionCount[dataSource][identifier]++;
|
||||||
|
|
||||||
|
// Otherwise, initialize counter to 1
|
||||||
|
else
|
||||||
|
connectionCount[dataSource][identifier] = 1;
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -143,7 +143,9 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
|
|||||||
* @param {Function} [countActiveConnections]
|
* @param {Function} [countActiveConnections]
|
||||||
* A getter which returns the current number of active connections for
|
* A getter which returns the current number of active connections for
|
||||||
* the given connection. If omitted, the number of active connections
|
* the given connection. If omitted, the number of active connections
|
||||||
* known at the time this function was called is used instead.
|
* known at the time this function was called is used instead. This
|
||||||
|
* function will be passed, in order, the data source identifier and
|
||||||
|
* the connection in question.
|
||||||
*
|
*
|
||||||
* @returns {GroupListItem}
|
* @returns {GroupListItem}
|
||||||
* A new GroupListItem which represents the given connection.
|
* A new GroupListItem which represents the given connection.
|
||||||
@@ -169,7 +171,7 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
|
|||||||
|
|
||||||
// Use getter, if provided
|
// Use getter, if provided
|
||||||
if (countActiveConnections)
|
if (countActiveConnections)
|
||||||
return countActiveConnections(connection);
|
return countActiveConnections(dataSource, connection);
|
||||||
|
|
||||||
return connection.activeConnections;
|
return connection.activeConnections;
|
||||||
|
|
||||||
@@ -201,13 +203,16 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
|
|||||||
* @param {Function} [countActiveConnections]
|
* @param {Function} [countActiveConnections]
|
||||||
* A getter which returns the current number of active connections for
|
* A getter which returns the current number of active connections for
|
||||||
* the given connection. If omitted, the number of active connections
|
* the given connection. If omitted, the number of active connections
|
||||||
* known at the time this function was called is used instead.
|
* known at the time this function was called is used instead. This
|
||||||
|
* function will be passed, in order, the data source identifier and
|
||||||
|
* the connection group in question.
|
||||||
*
|
*
|
||||||
* @param {Function} [countActiveConnectionGroups]
|
* @param {Function} [countActiveConnectionGroups]
|
||||||
* A getter which returns the current number of active connections for
|
* A getter which returns the current number of active connections for
|
||||||
* the given connection group. If omitted, the number of active
|
* the given connection group. If omitted, the number of active
|
||||||
* connections known at the time this function was called is used
|
* connections known at the time this function was called is used
|
||||||
* instead.
|
* instead. This function will be passed, in order, the data source
|
||||||
|
* identifier and the connection group in question.
|
||||||
*
|
*
|
||||||
* @returns {GroupListItem}
|
* @returns {GroupListItem}
|
||||||
* A new GroupListItem which represents the given connection group,
|
* A new GroupListItem which represents the given connection group,
|
||||||
@@ -257,7 +262,7 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
|
|||||||
|
|
||||||
// Use getter, if provided
|
// Use getter, if provided
|
||||||
if (countActiveConnectionGroups)
|
if (countActiveConnectionGroups)
|
||||||
return countActiveConnectionGroups(connectionGroup);
|
return countActiveConnectionGroups(dataSource, connectionGroup);
|
||||||
|
|
||||||
return connectionGroup.activeConnections;
|
return connectionGroup.activeConnections;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user