mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
GUAC-1126: Use active connection service to retrieve active connection counts within group list.
This commit is contained in:
@@ -88,11 +88,58 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList()
|
|||||||
},
|
},
|
||||||
|
|
||||||
templateUrl: 'app/groupList/templates/guacGroupList.html',
|
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');
|
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
|
* Returns whether the given item represents a connection that can
|
||||||
* be displayed. If there is no connection template, then no
|
* be displayed. If there is no connection template, then no
|
||||||
@@ -131,7 +178,8 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList()
|
|||||||
if (connectionGroup) {
|
if (connectionGroup) {
|
||||||
|
|
||||||
// Create item hierarchy, including connections only if they will be visible
|
// 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 root group is to be shown, wrap that group as the child of a fake root group
|
||||||
if ($scope.showRootGroup)
|
if ($scope.showRootGroup)
|
||||||
@@ -161,7 +209,7 @@ angular.module('groupList').directive('guacGroupList', [function guacGroupList()
|
|||||||
$scope.toggleExpanded = function toggleExpanded(groupListItem) {
|
$scope.toggleExpanded = function toggleExpanded(groupListItem) {
|
||||||
groupListItem.isExpanded = !groupListItem.isExpanded;
|
groupListItem.isExpanded = !groupListItem.isExpanded;
|
||||||
};
|
};
|
||||||
|
|
||||||
}]
|
}]
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@@ -102,12 +102,14 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
|
|||||||
this.isExpanded = template.isExpanded;
|
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.
|
* connection group, if known.
|
||||||
*
|
*
|
||||||
* @type Number
|
* @type Number
|
||||||
*/
|
*/
|
||||||
this.activeConnections = template.activeConnections;
|
this.getActiveConnections = template.getActiveConnections || (function getActiveConnections() {
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The connection or connection group whose data is exposed within
|
* 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
|
* The connection whose contents should be represented by the new
|
||||||
* GroupListItem.
|
* 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}
|
* @returns {GroupListItem}
|
||||||
* A new GroupListItem which represents the given connection.
|
* 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 item representing the given connection
|
||||||
return new GroupListItem({
|
return new GroupListItem({
|
||||||
@@ -144,7 +151,15 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
|
|||||||
isConnectionGroup : false,
|
isConnectionGroup : false,
|
||||||
|
|
||||||
// Count of currently active connections using this connection
|
// 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
|
// Wrapped item
|
||||||
wrappedItem : connection
|
wrappedItem : connection
|
||||||
@@ -165,26 +180,37 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
|
|||||||
* Whether connections should be included in the contents of the
|
* Whether connections should be included in the contents of the
|
||||||
* resulting GroupListItem. By default, connections are included.
|
* 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}
|
* @returns {GroupListItem}
|
||||||
* 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(connectionGroup,
|
||||||
includeConnections) {
|
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));
|
children.push(GroupListItem.fromConnection(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));
|
children.push(GroupListItem.fromConnectionGroup(child, includeConnections, countActiveConnections, countActiveConnectionGroups));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +230,16 @@ angular.module('groupList').factory('GroupListItem', ['ConnectionGroup', functio
|
|||||||
children : children,
|
children : children,
|
||||||
|
|
||||||
// Count of currently active connection groups using this connection
|
// 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
|
// Wrapped item
|
||||||
wrappedItem : connectionGroup
|
wrappedItem : connectionGroup
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<div class="caption" ng-class="{active: item.activeConnections}">
|
<div class="caption" ng-class="{active: item.getActiveConnections()}">
|
||||||
|
|
||||||
<!-- Connection icon -->
|
<!-- Connection icon -->
|
||||||
<div class="protocol">
|
<div class="protocol">
|
||||||
@@ -32,8 +32,8 @@
|
|||||||
<span class="name">{{item.name}}</span>
|
<span class="name">{{item.name}}</span>
|
||||||
|
|
||||||
<!-- Active user count -->
|
<!-- Active user count -->
|
||||||
<span class="activeUserCount" ng-show="item.activeConnections">
|
<span class="activeUserCount" ng-show="item.getActiveConnections()">
|
||||||
{{'HOME.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.activeConnections}'}}
|
{{'HOME.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.getActiveConnections()}'}}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@@ -21,7 +21,7 @@
|
|||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<div class="caption" ng-class="{active: item.activeConnections}">
|
<div class="caption" ng-class="{active: item.getActiveConnections()}">
|
||||||
|
|
||||||
<!-- Connection icon -->
|
<!-- Connection icon -->
|
||||||
<div class="protocol">
|
<div class="protocol">
|
||||||
@@ -32,8 +32,8 @@
|
|||||||
<span class="name">{{item.name}}</span>
|
<span class="name">{{item.name}}</span>
|
||||||
|
|
||||||
<!-- Active user count -->
|
<!-- Active user count -->
|
||||||
<span class="activeUserCount" ng-show="item.activeConnections">
|
<span class="activeUserCount" ng-show="item.getActiveConnections()">
|
||||||
{{'MANAGE_CONNECTION.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.activeConnections}'}}
|
{{'MANAGE_CONNECTION.INFO_ACTIVE_USER_COUNT' | translate:'{USERS: item.getActiveConnections()}'}}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user