From 303230cb554aa07ce7ada5520b4d3dc0bb89ec51 Mon Sep 17 00:00:00 2001 From: Christopher Lenz Date: Mon, 2 Jun 2008 20:37:41 +0000 Subject: Display group reduce results in Futon by default. git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@662554 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/browse.js | 62 ++++++++++++++++++++++------------------- share/www/script/couch_tests.js | 4 +-- 2 files changed, 36 insertions(+), 30 deletions(-) (limited to 'share/www/script') diff --git a/share/www/script/browse.js b/share/www/script/browse.js index ec514f09..d7e3fcee 100644 --- a/share/www/script/browse.js +++ b/share/www/script/browse.js @@ -348,6 +348,9 @@ function CouchDatabasePage() { if (options.count === undefined) { options.count = parseInt($("#perpage").val(), 10); } + if (options.group === undefined) { + options.group = true; + } if ($("#documents thead th.key").is(".desc")) { options.descending = true; $.cookies.set(dbName + ".desc", "1"); @@ -363,7 +366,7 @@ function CouchDatabasePage() { if (resp.offset === undefined) { resp.offset = 0; } - if (resp.total_rows !== null && resp.offset > 0) { + if (resp.rows !== null && resp.offset > 0) { $("#paging a.prev").attr("href", "#" + (resp.offset - options.count)).click(function() { var firstDoc = resp.rows[0]; page.updateDocumentListing({ @@ -377,7 +380,7 @@ function CouchDatabasePage() { } else { $("#paging a.prev").removeAttr("href"); } - if (resp.total_rows !== null && resp.total_rows - resp.offset > options.count) { + if (resp.rows !== null && resp.total_rows - resp.offset > options.count) { $("#paging a.next").attr("href", "#" + (resp.offset + options.count)).click(function() { var lastDoc = resp.rows[resp.rows.length - 1]; page.updateDocumentListing({ @@ -392,39 +395,42 @@ function CouchDatabasePage() { $("#paging a.next").removeAttr("href"); } - if (resp.total_rows != null) { - for (var i = 0; i < resp.rows.length; i++) { - var row = resp.rows[i]; - var tr = $(""); - var key = row.key; + for (var i = 0; i < resp.rows.length; i++) { + var row = resp.rows[i]; + var tr = $(""); + var key = row.key; + if (row.id) { $("
" + + "/" + encodeURIComponent(row.id) + "'>
" + "ID: " + row.id + "
") - .find("em").text(key !== null ? prettyPrintJSON(key, 0, "") : "null").end() + .find("strong").text(key !== null ? prettyPrintJSON(key, 0, "") : "null").end() + .appendTo(tr); + } else { + $("") + .find("strong").text(key !== null ? prettyPrintJSON(key, 0, "") : "null").end() .appendTo(tr); - var value = row.value; - $("").text( - value !== null ? prettyPrintJSON(value, 0, "") : "null" - ).appendTo(tr).dblclick(function() { - location.href = this.previousSibling.firstChild.href; - }); - tr.appendTo("#documents tbody.content"); } - $("#documents tbody.footer td span").text( - "Showing " + Math.min(resp.total_rows, resp.offset + 1) + "-" + - (resp.offset + resp.rows.length) + " of " + resp.total_rows + - " document" + (resp.total_rows != 1 ? "s" : "")); - $("#documents").removeClass("reduced"); - } else { - var tr = $(""); - $("").appendTo(tr); + var value = row.value; $("").text( - resp.result !== null ? prettyPrintJSON(resp.result) : "null" - ).appendTo(tr); + value !== null ? prettyPrintJSON(value, 0, "") : "null" + ).appendTo(tr).dblclick(function() { + location.href = this.previousSibling.firstChild.href; + }); tr.appendTo("#documents tbody.content"); - $("#documents tbody.footer td span").text("Showing reduce result"); - $("#documents").addClass("reduced"); } + var firstNum = 1; + var lastNum = totalNum = resp.rows.length; + if (resp.total_rows != null) { + firstNum = Math.min(resp.total_rows, resp.offset + 1); + lastNum = firstNum + resp.rows.length - 1; + totalNum = resp.total_rows; + $("#paging").show(); + } else { + $("#paging").hide(); + } + $("#documents tbody.footer td span").text( + "Showing " + firstNum + "-" + lastNum + " of " + totalNum + + " row" + (firstNum != lastNum ? "s" : "")); $("#documents tbody tr:odd").addClass("odd"); $(document.body).removeClass("loading"); } diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 4d626ca0..523d7d54 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -93,14 +93,14 @@ var tests = { T(db.info().doc_count == 6); var reduceFunction = function(keys, values){ - return sum(values); + return sum(values); }; results = db.query(mapFunction, reduceFunction); T(results.rows[0].value == 33); - // delete a document + // delete a document T(db.deleteDoc(existingDoc).ok); // make sure we can't open the doc -- cgit v1.2.3