diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2011-11-05 14:55:55 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2011-11-05 15:06:47 +0000 |
commit | 2d2c7d1ef49e3e051daf9ee0ea60896a493073fb (patch) | |
tree | 2cb0f12a9402da0228e757da42bbfcaf7f61db72 | |
parent | 2190ff008c3c701e603c128f7effa9cae4897107 (diff) | |
download | couchdb-2d2c7d1ef49e3e051daf9ee0ea60896a493073fb.tar.gz |
Add view request duration to Futon
Closes COUCHDB-509
-rw-r--r-- | share/www/database.html | 3 | ||||
-rw-r--r-- | share/www/script/futon.browse.js | 39 | ||||
-rw-r--r-- | share/www/script/jquery.couch.js | 11 | ||||
-rw-r--r-- | share/www/style/layout.css | 2 |
4 files changed, 50 insertions, 5 deletions
diff --git a/share/www/database.html b/share/www/database.html index 213159be1..7a3294fc1 100644 --- a/share/www/database.html +++ b/share/www/database.html @@ -262,6 +262,9 @@ specific language governing permissions and limitations under the License. </tr> </tbody> </table> + <p id="viewrequestduration"> + View request duration: <span class="timestamp"></span> + </p> </div> </div></body> </html> diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js index b24840e68..d33623774 100644 --- a/share/www/script/futon.browse.js +++ b/share/www/script/futon.browse.js @@ -11,6 +11,38 @@ // the License. (function($) { + + $.toTimeString = function(milliseconds) { + var ms, sec, min, h, timeString; + + sec = Math.floor(milliseconds / 1000.0); + min = Math.floor(sec / 60.0); + sec = (sec % 60.0).toString(); + if (sec.length < 2) { + sec = "0" + sec; + } + + h = (Math.floor(min / 60.0)).toString(); + if (h.length < 2) { + h = "0" + h; + } + + min = (min % 60.0).toString(); + if (min.length < 2) { + min = "0" + min; + } + + timeString = h + ":" + min + ":" + sec; + + ms = (milliseconds % 1000.0).toString(); + while (ms.length < 3) { + ms = "0" + ms; + } + timeString += "." + ms; + + return timeString; + }; + $.futon = $.futon || {}; $.extend($.futon, { @@ -624,7 +656,7 @@ $("#documents").find("tbody.content").empty().end().show(); page.updateDesignDocLink(); - options.success = function(resp) { + options.success = function(resp, requestDuration) { if (resp.offset === undefined) { resp.offset = 0; } @@ -734,6 +766,11 @@ "Showing " + firstNum + "-" + lastNum + " of " + totalNum + " row" + (firstNum != lastNum || totalNum == "unknown" ? "s" : "")); $("#documents tbody tr:odd").addClass("odd"); + + if (viewName && viewName !== "_all_docs" && viewName !== "_design_docs") { + $("#viewrequestduration").show(); + $("#viewrequestduration .timestamp").text($.toTimeString(requestDuration)); + } } options.error = function(status, error, reason) { alert("Error: " + error + "\n\n" + reason); diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js index 2c4c89e4a..4ae3d40b6 100644 --- a/share/www/script/jquery.couch.js +++ b/share/www/script/jquery.couch.js @@ -1005,7 +1005,7 @@ * @private */ function ajax(obj, options, errorMessage, ajaxOptions) { - + var timeStart; var defaultAjaxOpts = { contentType: "application/json", headers:{"Accept": "application/json"} @@ -1014,6 +1014,7 @@ options = $.extend({successStatus: 200}, options); ajaxOptions = $.extend(defaultAjaxOpts, ajaxOptions); errorMessage = errorMessage || "Unknown error"; + timeStart = (new Date()).getTime(); $.ajax($.extend($.extend({ type: "GET", dataType: "json", cache : !$.browser.msie, beforeSend: function(xhr){ @@ -1024,6 +1025,7 @@ } }, complete: function(req) { + var reqDuration = (new Date()).getTime() - timeStart; try { var resp = $.parseJSON(req.responseText); } catch(e) { @@ -1038,11 +1040,12 @@ options.ajaxStart(resp); } if (req.status == options.successStatus) { - if (options.beforeSuccess) options.beforeSuccess(req, resp); - if (options.success) options.success(resp); + if (options.beforeSuccess) options.beforeSuccess(req, resp, reqDuration); + if (options.success) options.success(resp, reqDuration); } else if (options.error) { options.error(req.status, resp && resp.error || - errorMessage, resp && resp.reason || "no response"); + errorMessage, resp && resp.reason || "no response", + reqDuration); } else { alert(errorMessage + ": " + resp.reason); } diff --git a/share/www/style/layout.css b/share/www/style/layout.css index ea8b11720..814eecd77 100644 --- a/share/www/style/layout.css +++ b/share/www/style/layout.css @@ -387,6 +387,8 @@ body.loading #dialog h2 { #tempwarn { display: none; font-size: 90%; margin: 0 2em 1.5em; } #grouptruenotice { display: none; font-size: 90%; margin: 1ex 2em 1.5em; } +#viewrequestduration { display: none; font-size: 90%; margin: 1ex 2em 1.5em; } +#viewrequestduration .timestamp { margin-left: 0.25em; } /* Database table */ |