mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-06 13:17:41 +00:00
Merge pull request #143 from glyptodon/readable-active-connections
GUAC-1126: Calculate active connections using the active connection service
This commit is contained in:
@@ -106,14 +106,14 @@ public class ActiveConnectionRESTService {
|
||||
if (permissions != null && permissions.isEmpty())
|
||||
permissions = null;
|
||||
|
||||
// An admin user has access to any user
|
||||
// An admin user has access to any connection
|
||||
SystemPermissionSet systemPermissions = self.getSystemPermissions();
|
||||
boolean isAdmin = systemPermissions.hasPermission(SystemPermission.Type.ADMINISTER);
|
||||
|
||||
// Get the directory
|
||||
Directory<ActiveConnection> activeConnectionDirectory = userContext.getActiveConnectionDirectory();
|
||||
|
||||
// Filter users, if requested
|
||||
// Filter connections, if requested
|
||||
Collection<String> activeConnectionIdentifiers = activeConnectionDirectory.getIdentifiers();
|
||||
if (!isAdmin && permissions != null) {
|
||||
ObjectPermissionSet activeConnectionPermissions = self.getActiveConnectionPermissions();
|
||||
|
@@ -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.<String, Number>
|
||||
*/
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
}]
|
||||
|
||||
};
|
||||
|
@@ -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
|
||||
|
@@ -21,7 +21,7 @@
|
||||
THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<div class="caption" ng-class="{active: item.activeConnections}">
|
||||
<div class="caption" ng-class="{active: item.getActiveConnections()}">
|
||||
|
||||
<!-- Connection icon -->
|
||||
<div class="protocol">
|
||||
@@ -32,8 +32,8 @@
|
||||
<span class="name">{{item.name}}</span>
|
||||
|
||||
<!-- Active user count -->
|
||||
<span class="activeUserCount" ng-show="item.activeConnections">
|
||||
{{'HOME.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.activeConnections}'}}
|
||||
<span class="activeUserCount" ng-show="item.getActiveConnections()">
|
||||
{{'HOME.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.getActiveConnections()}'}}
|
||||
</span>
|
||||
|
||||
</div>
|
||||
|
@@ -21,7 +21,7 @@
|
||||
THE SOFTWARE.
|
||||
-->
|
||||
|
||||
<div class="caption" ng-class="{active: item.activeConnections}">
|
||||
<div class="caption" ng-class="{active: item.getActiveConnections()}">
|
||||
|
||||
<!-- Connection icon -->
|
||||
<div class="protocol">
|
||||
@@ -32,8 +32,8 @@
|
||||
<span class="name">{{item.name}}</span>
|
||||
|
||||
<!-- Active user count -->
|
||||
<span class="activeUserCount" ng-show="item.activeConnections">
|
||||
{{'MANAGE_CONNECTION.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.activeConnections}'}}
|
||||
<span class="activeUserCount" ng-show="item.getActiveConnections()">
|
||||
{{'MANAGE_CONNECTION.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.getActiveConnections()}'}}
|
||||
</span>
|
||||
|
||||
</div>
|
||||
|
@@ -59,7 +59,7 @@ angular.module('rest').factory('ActiveConnection', [function defineActiveConnect
|
||||
|
||||
/**
|
||||
* The time that the connection began, in seconds since
|
||||
* 1970-01-01 00:00:00 UTC.
|
||||
* 1970-01-01 00:00:00 UTC, if known.
|
||||
*
|
||||
* @type Number
|
||||
*/
|
||||
@@ -73,7 +73,7 @@ angular.module('rest').factory('ActiveConnection', [function defineActiveConnect
|
||||
this.remoteHost = template.remoteHost;
|
||||
|
||||
/**
|
||||
* The username of the user associated with the connection.
|
||||
* The username of the user associated with the connection, if known.
|
||||
*
|
||||
* @type String
|
||||
*/
|
||||
|
Reference in New Issue
Block a user