From 668822052222dfe2e9968a467b3f5f8525d57584 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Mon, 12 Aug 2013 01:45:36 -0700 Subject: [PATCH] Implement GuacamoleService.ConnectionGroup. Migrate GuacamoleService.Connections.list to new XML format. --- guacamole/src/main/webapp/scripts/service.js | 296 +++++++++++++------ 1 file changed, 211 insertions(+), 85 deletions(-) diff --git a/guacamole/src/main/webapp/scripts/service.js b/guacamole/src/main/webapp/scripts/service.js index ffcfcb4bc..1bd9c7258 100644 --- a/guacamole/src/main/webapp/scripts/service.js +++ b/guacamole/src/main/webapp/scripts/service.js @@ -22,6 +22,74 @@ */ var GuacamoleService = GuacamoleService || {}; +/** + * An arbitary Guacamole connection group, having the given type, ID and name. + * + * @constructor + * @param {Number} type The type of this connection group - either ORGANIZATIONAL + * or BALANCING. + * @param {String} id An arbitrary ID, likely assigned by the auth provider. + * @param {String} name The human-readable name of this group. + */ +GuacamoleService.ConnectionGroup = function(type, id, name) { + + /** + * The type of this connection group. + * @type Number + */ + this.type = type; + + /** + * The unique ID of this connection group. + * @type String + */ + this.id = id; + + /** + * The human-readable name associated with this connection group. + * @type String + */ + this.name = name; + + /** + * All connection groups contained within this group. + * @type GuacamoleService.ConnectionGroup[] + */ + this.groups = []; + + /** + * All connections contained within this group. + * @type GuacamoleService.Connection[] + */ + this.connections = []; + +}; + +/** + * Set of all possible types for ConnectionGroups. + */ +GuacamoleService.ConnectionGroup.Type = { + + /** + * Organizational groups exist solely to hold connections or other groups, + * and provide no other semantics. + * + * @type Number + */ + "ORGANIZATIONAL" : 0, + + /** + * Balancing groups act as connections. Users that have READ permission on + * balancing groups can use the group as if it were a connection, and that + * group will choose an appropriate connection within itself for that user + * to use. + * + * @type Number + */ + "BALANCING" : 1 + +}; + /** * An arbitrary Guacamole connection, consisting of an ID/protocol pair. * @@ -52,23 +120,13 @@ GuacamoleService.Connection = function(protocol, id, name) { */ this.parameters = {}; - /** - * The hierarchy of groups containing this connection. The first element - * in this array is the highest-level group. If the connection is within - * the root group, this array will be empty. - * - * @type String[] - */ - this.path = name.split("/"); - /** * The name of this connection. This name is arbitrary and local to the - * group containing the connection. If the connection is in the root - * group, this name will be effectively equal to the ID. + * group containing the connection. * * @type String */ - this.name = guac_connection.path.pop(); + this.name = name; /** * An array of GuacamoleService.Connection.Record listing the usage @@ -249,24 +307,153 @@ GuacamoleService.handleResponse = function(xhr) { GuacamoleService.Connections = { /** - * Comparator which compares two GuacamoleService.Connection objects. + * Comparator which compares two arbitrary objects by their name property. */ "comparator" : function(a, b) { return a.name.localeCompare(b.name); }, - /** - * Returns an array of Connections for which the current user has access. - * - * @param {String} parameters Any parameters which should be passed to the - * server for the sake of authentication - * (optional). - * @return {GuacamoleService.Connection[]} An array of Connections for - * which the current user has - * access. - */ + /** + * Returns the root connection group, containing a hierarchy of all other + * groups and connections for which the current user has access. + * + * @param {String} parameters Any parameters which should be passed to the + * server for the sake of authentication + * (optional). + * @return {GuacamoleService.ConnectionGroup} The root group, containing + * a hierarchy of all other + * groups and connections to + * which the current user has + * access. + */ "list" : function(parameters) { + /** + * Parse the contents of the given connection element within XML, + * returning a corresponding GuacamoleService.Connection. + * + * @param {Element} element + * @return {GuacamoleService.Connection} The connection represented by + * the element just parsed. + */ + function parseConnection(element) { + + var i; + + var connection = new GuacamoleService.Connection( + element.getAttribute("protocol"), + element.getAttribute("id"), + element.getAttribute("name") + ); + + // Add parameter values for each parmeter received + var paramElements = element.getElementsByTagName("param"); + for (i=0; i