summaryrefslogtreecommitdiff
path: root/share/www/script
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2009-12-10 13:27:42 +0000
committerChristopher Lenz <cmlenz@apache.org>2009-12-10 13:27:42 +0000
commit5ad12f26e8288a0bc4ae061b9c2f0465d1ada95d (patch)
tree7e5b7ad655b23f2e3e9db82cbcd8203d2c3c7063 /share/www/script
parent10e8a4b9d69e75b705f8e491a3a428fca7139d98 (diff)
Add a "Reduce" checkbox to the database view page in Futon, which controls the `reduce=true|false` query string parameter. I had to add `reduce=false` support for temp views on the server side to make the feature not-confusing.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@889256 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www/script')
-rw-r--r--share/www/script/couch_tests.js1
-rw-r--r--share/www/script/futon.browse.js51
-rw-r--r--share/www/script/test/reduce_false.js7
-rw-r--r--share/www/script/test/reduce_false_temp.js37
4 files changed, 72 insertions, 24 deletions
diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js
index d991c05d..817bfa5e 100644
--- a/share/www/script/couch_tests.js
+++ b/share/www/script/couch_tests.js
@@ -66,6 +66,7 @@ loadTest("recreate_doc.js");
loadTest("reduce.js");
loadTest("reduce_builtin.js");
loadTest("reduce_false.js");
+loadTest("reduce_false_temp.js");
loadTest("replication.js");
loadTest("rev_stemming.js");
loadTest("security_validation.js");
diff --git a/share/www/script/futon.browse.js b/share/www/script/futon.browse.js
index d5b860e2..0c85a909 100644
--- a/share/www/script/futon.browse.js
+++ b/share/www/script/futon.browse.js
@@ -211,6 +211,7 @@
);
$("#grouptruenotice").show();
} else {
+ $("#reduce").hide();
page.updateDocumentListing();
}
page.populateLanguagesMenu();
@@ -329,7 +330,7 @@
page.storedViewLanguage = page.viewLanguage;
if (callback) callback();
}
- },{async:false});
+ }, {async: false});
} else {
page.updateViewEditor(page.storedViewCode.map,
page.storedViewCode.reduce || "");
@@ -349,6 +350,7 @@
mapFun.split("\n").length,
reduceFun.split("\n").length
);
+ $("#reduce").toggle(reduceFun != null);
$("#viewcode textarea").attr("rows", Math.min(15, Math.max(3, lines)));
}
@@ -500,12 +502,12 @@
this.updateDocumentListing = function(options) {
if (options === undefined) options = {};
if (options.limit === undefined) {
- per_page = parseInt($("#perpage").val(), 10)
+ var perPage = parseInt($("#perpage").val(), 10)
// Fetch an extra row so we know when we're on the last page for
// reduce views
- options.limit = per_page + 1;
+ options.limit = perPage + 1;
} else {
- per_page = options.limit - 1;
+ perPage = options.limit - 1;
}
if ($("#documents thead th.key").is(".desc")) {
if (typeof options.descending == 'undefined') options.descending = true;
@@ -524,17 +526,17 @@
resp.offset = 0;
}
var descending_reverse = ((options.descending && !descend) || (descend && (options.descending === false)));
- var has_reduce_prev = resp.total_rows === undefined && (descending_reverse ? resp.rows.length > per_page : options.startkey !== undefined);
+ var has_reduce_prev = resp.total_rows === undefined && (descending_reverse ? resp.rows.length > perPage : options.startkey !== undefined);
if (descending_reverse && resp.rows) {
resp.rows = resp.rows.reverse();
- if (resp.rows.length > per_page) {
+ if (resp.rows.length > perPage) {
resp.rows.push(resp.rows.shift());
}
}
if (resp.rows !== null && (has_reduce_prev || (descending_reverse ?
- (resp.total_rows - resp.offset > per_page) :
+ (resp.total_rows - resp.offset > perPage) :
(resp.offset > 0)))) {
- $("#paging a.prev").attr("href", "#" + (resp.offset - per_page)).click(function() {
+ $("#paging a.prev").attr("href", "#" + (resp.offset - perPage)).click(function() {
var opt = {
descending: !descend,
limit: options.limit
@@ -553,17 +555,17 @@
} else {
$("#paging a.prev").removeAttr("href");
}
- var has_reduce_next = resp.total_rows === undefined && (descending_reverse ? options.startkey !== undefined : resp.rows.length > per_page);
+ var has_reduce_next = resp.total_rows === undefined && (descending_reverse ? options.startkey !== undefined : resp.rows.length > perPage);
if (resp.rows !== null && (has_reduce_next || (descending_reverse ?
- (resp.offset - resp.total_rows < per_page) :
- (resp.total_rows - resp.offset > per_page)))) {
- $("#paging a.next").attr("href", "#" + (resp.offset + per_page)).click(function() {
+ (resp.offset - resp.total_rows < perPage) :
+ (resp.total_rows - resp.offset > perPage)))) {
+ $("#paging a.next").attr("href", "#" + (resp.offset + perPage)).click(function() {
var opt = {
descending: descend,
limit: options.limit
};
if (resp.rows.length > 0) {
- var lastDoc = resp.rows[Math.min(per_page, resp.rows.length) - 1];
+ var lastDoc = resp.rows[Math.min(perPage, resp.rows.length) - 1];
opt.startkey = lastDoc.key !== undefined ? lastDoc.key : null;
if (lastDoc.id !== undefined) {
opt.startkey_docid = lastDoc.id;
@@ -577,7 +579,7 @@
$("#paging a.next").removeAttr("href");
}
- for (var i = 0; i < Math.min(per_page, resp.rows.length); i++) {
+ for (var i = 0; i < Math.min(perPage, resp.rows.length); i++) {
var row = resp.rows[i];
var tr = $("<tr></tr>");
var key = "null";
@@ -601,13 +603,14 @@
html: true, indent: 0, linesep: "", quoteKeys: false
});
}
- $("<td class='value'><div></div></td>").find("div").html(value).end().appendTo(tr).dblclick(function() {
- location.href = this.previousSibling.firstChild.href;
- });
+ $("<td class='value'><div></div></td>").find("div").html(value).end()
+ .appendTo(tr).dblclick(function() {
+ location.href = this.previousSibling.firstChild.href;
+ });
tr.appendTo("#documents tbody.content");
}
var firstNum = 1;
- var lastNum = totalNum = Math.min(per_page, resp.rows.length);
+ var lastNum = totalNum = Math.min(perPage, resp.rows.length);
if (resp.total_rows != null) {
if (descending_reverse) {
lastNum = Math.min(resp.total_rows, resp.total_rows - resp.offset);
@@ -642,7 +645,11 @@
var reduceFun = $.trim($("#viewcode_reduce").val()) || null;
if (reduceFun) {
$.cookies.set(db.name + ".reduce", reduceFun);
- options.group = true;
+ if ($("#reduce :checked").length) {
+ options.group = true;
+ } else {
+ options.reduce = false;
+ }
} else {
$.cookies.remove(db.name + ".reduce");
}
@@ -658,7 +665,11 @@
var currentMapCode = $("#viewcode_map").val();
var currentReduceCode = $.trim($("#viewcode_reduce").val()) || null;
if (currentReduceCode) {
- options.group = true;
+ if ($("#reduce :checked").length) {
+ options.group = true;
+ } else {
+ options.reduce = false;
+ }
}
if (page.isDirty) {
db.query(currentMapCode, currentReduceCode, page.viewLanguage, options);
diff --git a/share/www/script/test/reduce_false.js b/share/www/script/test/reduce_false.js
index 29890ce4..699b258f 100644
--- a/share/www/script/test/reduce_false.js
+++ b/share/www/script/test/reduce_false.js
@@ -25,8 +25,8 @@ couchTests.reduce_false = function(debug) {
_id:"_design/test",
language: "javascript",
views: {
- summate: {map:"function (doc) {emit(doc.integer, doc.integer)};",
- reduce:"function (keys, values) { return sum(values); };"},
+ summate: {map:"function (doc) { emit(doc.integer, doc.integer); }",
+ reduce:"function (keys, values) { return sum(values); }"},
}
};
T(db.save(designDoc).ok);
@@ -38,8 +38,7 @@ couchTests.reduce_false = function(debug) {
//Test that we get our docs back
res = db.view('test/summate', {reduce: false});
T(res.rows.length == 5);
- for(var i=0; i<5; i++)
- {
+ for(var i=0; i<5; i++) {
T(res.rows[i].value == i+1);
}
};
diff --git a/share/www/script/test/reduce_false_temp.js b/share/www/script/test/reduce_false_temp.js
new file mode 100644
index 00000000..d45f05b2
--- /dev/null
+++ b/share/www/script/test/reduce_false_temp.js
@@ -0,0 +1,37 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+couchTests.reduce_false_temp = function(debug) {
+ var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"});
+ db.deleteDb();
+ db.createDb();
+ if (debug) debugger;
+
+ var numDocs = 5;
+ var docs = makeDocs(1,numDocs + 1);
+ db.bulkSave(docs);
+ var summate = function(N) {return (N+1)*N/2;};
+
+ var mapFun = "function (doc) { emit(doc.integer, doc.integer); }";
+ var reduceFun = "function (keys, values) { return sum(values); }";
+
+ // Test that the reduce works
+ var res = db.query(mapFun, reduceFun);
+ T(res.rows.length == 1 && res.rows[0].value == summate(5));
+
+ //Test that we get our docs back
+ res = db.query(mapFun, reduceFun, {reduce: false});
+ T(res.rows.length == 5);
+ for(var i=0; i<5; i++) {
+ T(res.rows[i].value == i+1);
+ }
+};