Migrate to root group rather than connection list.

This commit is contained in:
Michael Jumper
2013-08-12 01:45:51 -07:00
parent 6688220522
commit 03ff6edbf4

View File

@@ -140,10 +140,10 @@ GuacamoleRootUI.reset = function() {
return false; return false;
} }
// Read connections // Read root group
var connections; var root_group;
try { try {
connections = GuacamoleService.Connections.list(parameters); root_group = GuacamoleService.Connections.list(parameters);
// Show admin elements if admin permissions available // Show admin elements if admin permissions available
var permissions = GuacamoleService.Permissions.list(null, parameters); var permissions = GuacamoleService.Permissions.list(null, parameters);
@@ -171,68 +171,65 @@ GuacamoleRootUI.reset = function() {
} }
// Associative array of all existing groups
var groups = {};
// Create pager for connections // Create pager for connections
var connection_pager = new GuacUI.Pager(GuacamoleRootUI.sections.all_connections); var connection_pager = new GuacUI.Pager(GuacamoleRootUI.sections.all_connections);
connection_pager.page_capacity = 20; connection_pager.page_capacity = 20;
// Add connection icons /**
for (var i=0; i<connections.length; i++) { * Adds the given group to the given display parent object. This object
* must have an addElement() function, which will be used for adding all
* child elements representing child connections and groups.
*
* @param {GuacamoleService.ConnectionGroup} group The group to add.
* @param {Function} appendChild A function which, given an element, will add that
* element the the display as desired.
*/
function addGroup(group, appendChild) {
// Add connection to set var i;
var connection = connections[i];
GuacamoleRootUI.connections[connection.id] = connection;
// Get connection element // Add all contained connections
var recent_connection = new GuacUI.Connection(connection); for (i=0; i<group.connections.length; i++) {
// If screenshot present, add to recent connections // Add connection to set
if (recent_connection.hasThumbnail()) var connection = group.connections[i];
GuacamoleRootUI.addRecentConnection(recent_connection); GuacamoleRootUI.connections[connection.id] = connection;
// Construct group hierarchy, creating new group components as // Get connection element
// necessary var recent_connection = new GuacUI.Connection(connection);
var parent_group = null;
var path = "";
for (var j=0; j<connection.path.length; j++) {
// Pull name, update current path // If screenshot present, add to recent connections
var name = connection.path[j]; if (recent_connection.hasThumbnail())
path += "/" + name; GuacamoleRootUI.addRecentConnection(recent_connection);
// Pull group from path // Add connection to connection list or parent group
var group = groups[path]; var guacui_connection = new GuacUI.Connection(connection);
appendChild(guacui_connection.getElement());
// If path not yet defined, create it } // end for each connection
if (!group) {
groups[path] = group = new GuacUI.ListGroup(name);
// Add new group to parent group, or to the list directly if // Add all contained groups
// no parent for (i=0; i<group.groups.length; i++) {
if (parent_group)
parent_group.addElement(group.getElement());
else
connection_pager.addElement(group.getElement());
} // Add connection to set
var child_group = group.groups[i];
// Save current group as the parent of the next group/connection // Create display element for group
parent_group = group; var list_group = new GuacUI.ListGroup(group.name);
} // Recursively add all children to the new element
addGroup(child_group, list_group.addElement);
// Add connection to connection list or parent group // Add element to display
var guacui_connection = new GuacUI.Connection(connection); appendChild(list_group.getElement());
if (parent_group)
parent_group.addElement(guacui_connection.getElement()); } // end for each gorup
else
connection_pager.addElement(guacui_connection.getElement());
} }
// Add root group directly to pager
addGroup(root_group, connection_pager.addElement);
// Add buttons if more than one page // Add buttons if more than one page
if (connection_pager.last_page != 0) if (connection_pager.last_page != 0)
GuacamoleRootUI.sections.all_connections_buttons.appendChild( GuacamoleRootUI.sections.all_connections_buttons.appendChild(