mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-31 09:03:21 +00:00 
			
		
		
		
	GUAC-1140: Use StableSort to maintain active session sort order.
This commit is contained in:
		| @@ -29,6 +29,7 @@ angular.module('manage').controller('manageSessionsController', ['$scope', '$inj | ||||
|     // Required types | ||||
|     var ActiveConnectionWrapper = $injector.get('ActiveConnectionWrapper'); | ||||
|     var ConnectionGroup         = $injector.get('ConnectionGroup'); | ||||
|     var StableSort              = $injector.get('StableSort'); | ||||
|  | ||||
|     // Required services | ||||
|     var activeConnectionService = $injector.get('activeConnectionService'); | ||||
| @@ -37,13 +38,6 @@ angular.module('manage').controller('manageSessionsController', ['$scope', '$inj | ||||
|     var guacNotification        = $injector.get('guacNotification'); | ||||
|     var permissionService       = $injector.get('permissionService'); | ||||
|  | ||||
|     /** | ||||
|      * The root connection group of the connection group hierarchy. | ||||
|      * | ||||
|      * @type ConnectionGroup | ||||
|      */ | ||||
|     $scope.rootGroup = null; | ||||
|  | ||||
|     /** | ||||
|      * All permissions associated with the current user, or null if the user's | ||||
|      * permissions have not yet been loaded. | ||||
| @@ -60,19 +54,41 @@ angular.module('manage').controller('manageSessionsController', ['$scope', '$inj | ||||
|      */ | ||||
|     $scope.wrappers = null; | ||||
|  | ||||
|     // Query the user's permissions | ||||
|     permissionService.getPermissions(authenticationService.getCurrentUserID()) | ||||
|             .success(function permissionsReceived(permissions) { | ||||
|         $scope.permissions = permissions; | ||||
|     }); | ||||
|     /** | ||||
|      * StableSort instance which maintains the sort order of the visible | ||||
|      * connection wrappers. | ||||
|      * | ||||
|      * @type StableSort | ||||
|      */ | ||||
|     $scope.wrapperOrder = new StableSort([ | ||||
|         'activeConnection.username', | ||||
|         'activeConnection.startDate', | ||||
|         'activeConnection.remoteHost', | ||||
|         'name' | ||||
|     ]); | ||||
|  | ||||
|     /** | ||||
|      * The root connection group of the connection group hierarchy. | ||||
|      * | ||||
|      * @type ConnectionGroup | ||||
|      */ | ||||
|     var rootGroup = null; | ||||
|  | ||||
|     /** | ||||
|      * All active connections, if known, or null if active connections have not | ||||
|      * yet been loaded. | ||||
|      * | ||||
|      * @type ActiveConnection | ||||
|      */ | ||||
|     var activeConnections = null; | ||||
|  | ||||
|     /** | ||||
|      * Map of all visible connections by object identifier. | ||||
|      * | ||||
|      * @type Object.<String, Connection> | ||||
|      */ | ||||
|     $scope.connections = {}; | ||||
|      | ||||
|     var connections = {}; | ||||
|  | ||||
|     /** | ||||
|      * Map of all currently-selected active connection wrappers by identifier. | ||||
|      *  | ||||
| @@ -90,7 +106,7 @@ angular.module('manage').controller('manageSessionsController', ['$scope', '$inj | ||||
|     var addConnection = function addConnection(connection) { | ||||
|  | ||||
|         // Add given connection to set of visible connections | ||||
|         $scope.connections[connection.identifier] = connection; | ||||
|         connections[connection.identifier] = connection; | ||||
|  | ||||
|     }; | ||||
|  | ||||
| @@ -113,23 +129,62 @@ angular.module('manage').controller('manageSessionsController', ['$scope', '$inj | ||||
|             connectionGroup.childConnectionGroups.forEach(addDescendantConnections); | ||||
|  | ||||
|     }; | ||||
|      | ||||
|     // Retrieve all connections  | ||||
|     connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER) | ||||
|     .success(function connectionGroupReceived(rootGroup) { | ||||
|         $scope.rootGroup = rootGroup; | ||||
|         addDescendantConnections($scope.rootGroup); | ||||
|     }); | ||||
|      | ||||
|     // Query active sessions | ||||
|     activeConnectionService.getActiveConnections().success(function sessionsRetrieved(activeConnections) { | ||||
|          | ||||
|  | ||||
|     /** | ||||
|      * Wraps all loaded active connections, storing the resulting array within | ||||
|      * the scope. If required data has not yet finished loading, this function | ||||
|      * has no effect. | ||||
|      */ | ||||
|     var wrapActiveConnections = function wrapActiveConnections() { | ||||
|  | ||||
|         // Abort if not all required data is available | ||||
|         if (!activeConnections || !connections) | ||||
|             return; | ||||
|  | ||||
|         // Wrap all active connections for sake of display | ||||
|         $scope.wrappers = []; | ||||
|         for (var identifier in activeConnections) { | ||||
|             $scope.wrappers.push(new ActiveConnectionWrapper(activeConnections[identifier]));  | ||||
|  | ||||
|             var activeConnection = activeConnections[identifier]; | ||||
|             var connection = connections[activeConnection.connectionIdentifier]; | ||||
|  | ||||
|             $scope.wrappers.push(new ActiveConnectionWrapper( | ||||
|                 connection.name, | ||||
|                 activeConnection | ||||
|             ));  | ||||
|  | ||||
|         } | ||||
|          | ||||
|  | ||||
|     }; | ||||
|  | ||||
|     // Query the user's permissions | ||||
|     permissionService.getPermissions(authenticationService.getCurrentUserID()) | ||||
|             .success(function permissionsReceived(retrievedPermissions) { | ||||
|         $scope.permissions = retrievedPermissions; | ||||
|     }); | ||||
|  | ||||
|     // Retrieve all connections  | ||||
|     connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER) | ||||
|     .success(function connectionGroupReceived(retrievedRootGroup) { | ||||
|  | ||||
|         // Load connections from retrieved group tree | ||||
|         rootGroup = retrievedRootGroup; | ||||
|         addDescendantConnections(rootGroup); | ||||
|  | ||||
|         // Attempt to produce wrapped list of active connections | ||||
|         wrapActiveConnections(); | ||||
|  | ||||
|     }); | ||||
|      | ||||
|     // Query active sessions | ||||
|     activeConnectionService.getActiveConnections().success(function sessionsRetrieved(retrievedActiveConnections) { | ||||
|  | ||||
|         // Store received list | ||||
|         activeConnections = retrievedActiveConnections; | ||||
|  | ||||
|         // Attempt to produce wrapped list of active connections | ||||
|         wrapActiveConnections(); | ||||
|  | ||||
|     }); | ||||
|  | ||||
|     /** | ||||
| @@ -141,9 +196,8 @@ angular.module('manage').controller('manageSessionsController', ['$scope', '$inj | ||||
|      */ | ||||
|     $scope.isLoaded = function isLoaded() { | ||||
|  | ||||
|         return $scope.wrappers             !== null | ||||
|             && $scope.permissions          !== null | ||||
|             && $scope.rootGroup            !== null; | ||||
|         return $scope.wrappers    !== null | ||||
|             && $scope.permissions !== null; | ||||
|  | ||||
|     }; | ||||
|  | ||||
|   | ||||
| @@ -55,7 +55,7 @@ THE SOFTWARE. | ||||
|                     <td>{{wrapper.activeConnection.username}}</td> | ||||
|                     <td>{{wrapper.activeConnection.startDate | date:'short'}}</td> | ||||
|                     <td>{{wrapper.activeConnection.remoteHost}}</td> | ||||
|                     <td>{{connections[wrapper.activeConnection.connectionIdentifier].name}}</td> | ||||
|                     <td>{{wrapper.name}}</td> | ||||
|                 </tr> | ||||
|             </tbody> | ||||
|         </table> | ||||
| @@ -66,7 +66,7 @@ THE SOFTWARE. | ||||
|         </p> | ||||
|  | ||||
|         <!-- Pager for session list --> | ||||
|         <guac-pager page="wrapperPage" page-size="25" items="wrappers | orderBy : 'username'"></guac-pager> | ||||
|         <guac-pager page="wrapperPage" page-size="25" items="wrappers | orderBy : wrapperOrder.predicate"></guac-pager> | ||||
|     </div> | ||||
|  | ||||
| </div> | ||||
| @@ -31,10 +31,20 @@ angular.module('manage').factory('ActiveConnectionWrapper', [ | ||||
|      * properties, such as a checked option. | ||||
|      *  | ||||
|      * @constructor | ||||
|      * @param {String} name | ||||
|      *     The display name of the active connection. | ||||
|      * | ||||
|      * @param {ActiveConnection} activeConnection | ||||
|      *     The ActiveConnection to wrap. | ||||
|      */ | ||||
|     var ActiveConnectionWrapper = function ActiveConnectionWrapper(activeConnection) { | ||||
|     var ActiveConnectionWrapper = function ActiveConnectionWrapper(name, activeConnection) { | ||||
|  | ||||
|         /** | ||||
|          * The display name of this connection. | ||||
|          * | ||||
|          * @type String | ||||
|          */ | ||||
|         this.name = name; | ||||
|  | ||||
|         /** | ||||
|          * The wrapped ActiveConnection. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user