GUAC-1140: Use StableSort to maintain active session sort order.

This commit is contained in:
Michael Jumper
2015-03-23 13:42:11 -07:00
parent 34ad1f2099
commit 6135883643
3 changed files with 98 additions and 34 deletions

View File

@@ -29,6 +29,7 @@ angular.module('manage').controller('manageSessionsController', ['$scope', '$inj
// Required types // Required types
var ActiveConnectionWrapper = $injector.get('ActiveConnectionWrapper'); var ActiveConnectionWrapper = $injector.get('ActiveConnectionWrapper');
var ConnectionGroup = $injector.get('ConnectionGroup'); var ConnectionGroup = $injector.get('ConnectionGroup');
var StableSort = $injector.get('StableSort');
// Required services // Required services
var activeConnectionService = $injector.get('activeConnectionService'); var activeConnectionService = $injector.get('activeConnectionService');
@@ -37,13 +38,6 @@ angular.module('manage').controller('manageSessionsController', ['$scope', '$inj
var guacNotification = $injector.get('guacNotification'); var guacNotification = $injector.get('guacNotification');
var permissionService = $injector.get('permissionService'); 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 * All permissions associated with the current user, or null if the user's
* permissions have not yet been loaded. * permissions have not yet been loaded.
@@ -60,19 +54,41 @@ angular.module('manage').controller('manageSessionsController', ['$scope', '$inj
*/ */
$scope.wrappers = null; $scope.wrappers = null;
// Query the user's permissions /**
permissionService.getPermissions(authenticationService.getCurrentUserID()) * StableSort instance which maintains the sort order of the visible
.success(function permissionsReceived(permissions) { * connection wrappers.
$scope.permissions = permissions; *
}); * @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. * Map of all visible connections by object identifier.
* *
* @type Object.<String, Connection> * @type Object.<String, Connection>
*/ */
$scope.connections = {}; var connections = {};
/** /**
* Map of all currently-selected active connection wrappers by identifier. * 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) { var addConnection = function addConnection(connection) {
// Add given connection to set of visible connections // 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); connectionGroup.childConnectionGroups.forEach(addDescendantConnections);
}; };
// Retrieve all connections /**
connectionGroupService.getConnectionGroupTree(ConnectionGroup.ROOT_IDENTIFIER) * Wraps all loaded active connections, storing the resulting array within
.success(function connectionGroupReceived(rootGroup) { * the scope. If required data has not yet finished loading, this function
$scope.rootGroup = rootGroup; * has no effect.
addDescendantConnections($scope.rootGroup); */
}); var wrapActiveConnections = function wrapActiveConnections() {
// Query active sessions // Abort if not all required data is available
activeConnectionService.getActiveConnections().success(function sessionsRetrieved(activeConnections) { if (!activeConnections || !connections)
return;
// Wrap all active connections for sake of display // Wrap all active connections for sake of display
$scope.wrappers = []; $scope.wrappers = [];
for (var identifier in activeConnections) { 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() { $scope.isLoaded = function isLoaded() {
return $scope.wrappers !== null return $scope.wrappers !== null
&& $scope.permissions !== null && $scope.permissions !== null;
&& $scope.rootGroup !== null;
}; };

View File

@@ -55,7 +55,7 @@ THE SOFTWARE.
<td>{{wrapper.activeConnection.username}}</td> <td>{{wrapper.activeConnection.username}}</td>
<td>{{wrapper.activeConnection.startDate | date:'short'}}</td> <td>{{wrapper.activeConnection.startDate | date:'short'}}</td>
<td>{{wrapper.activeConnection.remoteHost}}</td> <td>{{wrapper.activeConnection.remoteHost}}</td>
<td>{{connections[wrapper.activeConnection.connectionIdentifier].name}}</td> <td>{{wrapper.name}}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@@ -66,7 +66,7 @@ THE SOFTWARE.
</p> </p>
<!-- Pager for session list --> <!-- 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>
</div> </div>

View File

@@ -31,10 +31,20 @@ angular.module('manage').factory('ActiveConnectionWrapper', [
* properties, such as a checked option. * properties, such as a checked option.
* *
* @constructor * @constructor
* @param {String} name
* The display name of the active connection.
*
* @param {ActiveConnection} activeConnection * @param {ActiveConnection} activeConnection
* The ActiveConnection to wrap. * 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. * The wrapped ActiveConnection.