diff --git a/guacamole/src/main/webapp/client.xhtml b/guacamole/src/main/webapp/client.xhtml index fc3f178a6..0f817a0e4 100644 --- a/guacamole/src/main/webapp/client.xhtml +++ b/guacamole/src/main/webapp/client.xhtml @@ -63,6 +63,7 @@ + diff --git a/guacamole/src/main/webapp/index.xhtml b/guacamole/src/main/webapp/index.xhtml index 902012bbd..5fdd2bfa9 100644 --- a/guacamole/src/main/webapp/index.xhtml +++ b/guacamole/src/main/webapp/index.xhtml @@ -138,6 +138,7 @@ + diff --git a/guacamole/src/main/webapp/scripts/history.js b/guacamole/src/main/webapp/scripts/history.js new file mode 100644 index 000000000..ba6eb0d5f --- /dev/null +++ b/guacamole/src/main/webapp/scripts/history.js @@ -0,0 +1,69 @@ +/** + * Set of thumbnails for each connection, indexed by ID. + */ +GuacamoleHistory = new (function() { + + var history = + JSON.parse(localStorage.getItem("GUAC_HISTORY") || "{}"); + + /** + * Returns the URL for the thumbnail of the connection with the given ID, + * or undefined if no thumbnail is associated with that connection. + */ + this.get = function(id) { + return history[id] || new GuacamoleHistory.Entry(); + }; + + /** + * Updates the thumbnail and access time of the history entry for the + * connection with the given ID. + */ + this.update = function(id, thumbnail) { + + // Create updated entry + var entry = new GuacamoleHistory.Entry( + id, + thumbnail, + new Date().getTime() + ); + + // Store entry in history + history[id] = entry; + + // Save updated history + localStorage.setItem("GUAC_HISTORY", JSON.stringify(history)); + + }; + +})(); + +/** + * A single entry in the indexed connection usage history. + * + * @constructor + * @param {String} id The ID of this connection. + * @param {String} thumbnail The URL of the thumbnail to use to represent this + * connection. + * @param {Number} last_access The time this connection was last accessed, in + * seconds. + */ +GuacamoleHistory.Entry = function(id, thumbnail, last_access) { + + /** + * The ID of the connection associated with this history entry. + */ + this.id = id; + + /** + * The thumbnail associated with the connection associated with this history + * entry. + */ + this.thumbnail = thumbnail; + + /** + * The time the connection associated with this entry was last accessed. + */ + this.accessed = last_access; + +}; + \ No newline at end of file diff --git a/guacamole/src/main/webapp/scripts/interface.js b/guacamole/src/main/webapp/scripts/interface.js index 76933073c..ad5bd11a8 100644 --- a/guacamole/src/main/webapp/scripts/interface.js +++ b/guacamole/src/main/webapp/scripts/interface.js @@ -348,19 +348,9 @@ GuacamoleUI.attach = function(guac) { 0, 0, thumbnail.width, thumbnail.height ); - // Get thumbnail set from local storage - var thumbnails = {}; - try { - var thumbnail_json = localStorage.getItem("GUAC_THUMBNAILS"); - if (thumbnail_json) - thumbnails = JSON.parse(thumbnail_json); - } - catch (e) {} - - // Save thumbnail to local storage + // Save thumbnail to history var id = decodeURIComponent(window.location.search.substring(4)); - thumbnails[id] = thumbnail.toDataURL(); - localStorage.setItem("GUAC_THUMBNAILS", JSON.stringify(thumbnails)); + GuacamoleHistory.update(id, thumbnail.toDataURL()); } @@ -474,10 +464,8 @@ GuacamoleUI.attach = function(guac) { // Disconnect and update thumbnail on close window.onunload = function() { - - if (localStorage) - updateThumbnail(); + updateThumbnail(); guac.disconnect(); }; diff --git a/guacamole/src/main/webapp/scripts/root-ui.js b/guacamole/src/main/webapp/scripts/root-ui.js index 60546e510..20945767e 100644 --- a/guacamole/src/main/webapp/scripts/root-ui.js +++ b/guacamole/src/main/webapp/scripts/root-ui.js @@ -92,28 +92,61 @@ GuacamoleRootUI.login = function(username, password) { }; /** - * Set of thumbnails for each connection, indexed by ID. + * An arbitrary Guacamole configuration, consisting of an ID/protocol pair. + * + * @constructor + * @param {String} protocol The protocol used by this configuration. + * @param {String} id The ID associated with this configuration. */ -GuacamoleRootUI.Thumbnails = new (function() { - - var thumbnails = - JSON.parse(localStorage.getItem("GUAC_THUMBNAILS") || "{}"); +GuacamoleRootUI.Configuration = function(protocol, id) { /** - * Returns the URL for the thumbnail of the connection with the given ID, - * or undefined if no thumbnail is associated with that connection. + * The protocol associated with this configuration. */ - this.getURL = function(id) { - return thumbnails[id]; - }; + this.protocol = protocol; -}); + /** + * The ID associated with this configuration. + */ + this.id = id; + +}; + +GuacamoleRootUI.getConfigurations = function(parameters) { + + // Construct request URL + var configs_url = "configs"; + if (parameters) configs_url += "?" + parameters; + + // Get config list + var xhr = new XMLHttpRequest(); + xhr.open("GET", configs_url, false); + xhr.send(null); + + // If fail, throw error + if (xhr.status != 200) + throw new Error(xhr.statusText); + + // Otherwise, get list + var configs = new Array(); + + var configElements = xhr.responseXML.getElementsByTagName("config"); + for (var i=0; i