summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/Makefile.am1
-rw-r--r--share/www/database.html15
-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
-rw-r--r--share/www/style/layout.css3
-rw-r--r--src/couchdb/couch_httpd_view.erl6
8 files changed, 96 insertions, 25 deletions
diff --git a/share/Makefile.am b/share/Makefile.am
index 34711b11..0d5e585e 100644
--- a/share/Makefile.am
+++ b/share/Makefile.am
@@ -134,6 +134,7 @@ nobase_dist_localdata_DATA = \
www/script/test/reduce.js \
www/script/test/reduce_builtin.js \
www/script/test/reduce_false.js \
+ www/script/test/reduce_false_temp.js \
www/script/test/replication.js \
www/script/test/rev_stemming.js \
www/script/test/security_validation.js \
diff --git a/share/www/database.html b/share/www/database.html
index 400081b0..3609cc7b 100644
--- a/share/www/database.html
+++ b/share/www/database.html
@@ -73,6 +73,8 @@ specific language governing permissions and limitations under the License.
// Restore preferences/state from cookies
var desc = $.cookies.get(page.db.name + ".desc");
if (desc) $("#documents thead th.key").addClass("desc");
+ var reduce = $.cookies.get(page.db.name + ".doreduce");
+ $("#reduce :checkbox")[0].checked = reduce;
var rowsPerPage = $.cookies.get(page.db.name + ".perpage");
if (rowsPerPage) $("#perpage").val(rowsPerPage);
@@ -93,6 +95,14 @@ specific language governing permissions and limitations under the License.
$(this).toggleClass("desc");
page.updateDocumentListing();
});
+ $("#documents thead th.value #reduce :checkbox").click(function() {
+ page.updateDocumentListing();
+ if (this.checked) {
+ $.cookies.set(page.db.name + ".doreduce", "1");
+ } else {
+ $.cookies.remove(page.db.name + ".doreduce");
+ }
+ });
$("#perpage").change(function() {
page.updateDocumentListing();
$.cookies.set(page.db.name + ".perpage", this.value);
@@ -187,7 +197,10 @@ specific language governing permissions and limitations under the License.
<thead>
<tr>
<th class="key"><div>Key</div></th>
- <th class="value">Value</th>
+ <th class="value">
+ <label id="reduce"><input type="checkbox" autocomplete="off" checked> Reduce</label>
+ Value
+ </th>
</tr>
</thead>
<tbody class="content">
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);
+ }
+};
diff --git a/share/www/style/layout.css b/share/www/style/layout.css
index 4a8e6d67..222bdc82 100644
--- a/share/www/style/layout.css
+++ b/share/www/style/layout.css
@@ -376,6 +376,9 @@ body.fullwidth #wrap { margin-right: 0; }
/* Documents table */
#documents thead th { width: 50%; }
+#documents thead th.value label { float: right; font-size: 90%;
+ text-shadow: none;
+}
#documents tbody.content td { color: #999;
font: normal 11px "DejaVu Sans Mono",Menlo,Courier,monospace;
}
diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl
index af91b654..af31ac9c 100644
--- a/src/couchdb/couch_httpd_view.erl
+++ b/src/couchdb/couch_httpd_view.erl
@@ -124,12 +124,18 @@ handle_temp_view_req(#httpd{method='POST'}=Req, Db) ->
{DesignOptions} = proplists:get_value(<<"options">>, Props, {[]}),
MapSrc = proplists:get_value(<<"map">>, Props),
Keys = proplists:get_value(<<"keys">>, Props, nil),
+ Reduce = get_reduce_type(Req),
case proplists:get_value(<<"reduce">>, Props, null) of
null ->
QueryArgs = parse_view_params(Req, Keys, map),
{ok, View, Group} = couch_view:get_temp_map_view(Db, Language,
DesignOptions, MapSrc),
output_map_view(Req, View, Group, Db, QueryArgs, Keys);
+ _ when Reduce =:= false ->
+ QueryArgs = parse_view_params(Req, Keys, red_map),
+ {ok, View, Group} = couch_view:get_temp_map_view(Db, Language,
+ DesignOptions, MapSrc),
+ output_map_view(Req, View, Group, Db, QueryArgs, Keys);
RedSrc ->
QueryArgs = parse_view_params(Req, Keys, reduce),
{ok, View, Group} = couch_view:get_temp_reduce_view(Db, Language,