From e8aedccd2996e5bd0e93bbfa346ad52a934ac096 Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sat, 16 Feb 2013 16:22:42 -0800 Subject: [PATCH] Ticket #270: Display history in connection popup. --- guacamole/src/main/webapp/scripts/admin-ui.js | 101 +++++++++++++++++- guacamole/src/main/webapp/styles/ui.css | 6 ++ 2 files changed, 106 insertions(+), 1 deletion(-) diff --git a/guacamole/src/main/webapp/scripts/admin-ui.js b/guacamole/src/main/webapp/scripts/admin-ui.js index f14863ddb..03e092a93 100644 --- a/guacamole/src/main/webapp/scripts/admin-ui.js +++ b/guacamole/src/main/webapp/scripts/admin-ui.js @@ -280,6 +280,51 @@ GuacAdmin.hasEntry = function(object) { return false; }; +/** + * Given a Date, returns a formatted String. + * + * @param {Date} date The date tor format. + * @return {String} A formatted String. + */ +GuacAdmin.formatDate = function(date) { + + var month = date.getMonth() + 1; + var day = date.getDate(); + var year = date.getFullYear(); + + var hour = date.getHours(); + var minute = date.getMinutes(); + var second = date.getSeconds(); + + return ("00" + month).slice(-2) + + "/" + ("00" + day).slice(-2) + + "/" + year + + " " + ("00" + hour).slice(-2) + + ":" + ("00" + minute).slice(-2) + + ":" + ("00" + second).slice(-2); + +}; + +/** + * Given a number of seconds, returns a String representing that length + * of time in a human-readable format. + * + * @param {Number} seconds The number of seconds. + * @return {String} A human-readable description of the duration specified. + */ +GuacAdmin.formatSeconds = function(seconds) { + + function round(value) { + return Math.round(value * 10) / 10; + } + + if (seconds < 60) return round(seconds) + " seconds"; + if (seconds < 3600) return round(seconds / 60) + " minutes"; + if (seconds < 86400) return round(seconds / 3600) + " hours"; + return round(seconds / 86400) + " days"; + +}; + /** * Adds the user with the given name to the displayed user list. */ @@ -487,6 +532,8 @@ GuacAdmin.addConnection = function(connection) { if (GuacAdmin.selected_connection) return; else GuacAdmin.selected_connection = connection.id; + var i; + // Create form base elements var form_element = GuacUI.createElement("div", "form"); var connection_header = GuacUI.createChildElement(form_element, "h2"); @@ -509,7 +556,7 @@ GuacAdmin.addConnection = function(connection) { var fields = {}; // Add protocols - for (var i=0; i 0) { + + // History section + var history_table = GuacUI.createChildElement( + GuacUI.createChildElement(sections, "dd"), + "table", "history section"); + + var history_table_header = GuacUI.createChildElement( + history_table, "tr"); + + GuacUI.createChildElement(history_table_header, "th").textContent = + "Username"; + + GuacUI.createChildElement(history_table_header, "th").textContent = + "Start Time"; + + GuacUI.createChildElement(history_table_header, "th").textContent = + "Duration"; + + // Add history + for (i=0; i