couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r889256 - in /couchdb/trunk: share/ share/www/ share/www/script/ share/www/script/test/ share/www/style/ src/couchdb/
Date Thu, 10 Dec 2009 13:27:43 GMT
Author: cmlenz
Date: Thu Dec 10 13:27:42 2009
New Revision: 889256

URL: http://svn.apache.org/viewvc?rev=889256&view=rev
Log:
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.

Added:
    couchdb/trunk/share/www/script/test/reduce_false_temp.js
Modified:
    couchdb/trunk/share/Makefile.am
    couchdb/trunk/share/www/database.html
    couchdb/trunk/share/www/script/couch_tests.js
    couchdb/trunk/share/www/script/futon.browse.js
    couchdb/trunk/share/www/script/test/reduce_false.js
    couchdb/trunk/share/www/style/layout.css
    couchdb/trunk/src/couchdb/couch_httpd_view.erl

Modified: couchdb/trunk/share/Makefile.am
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/Makefile.am?rev=889256&r1=889255&r2=889256&view=diff
==============================================================================
--- couchdb/trunk/share/Makefile.am (original)
+++ couchdb/trunk/share/Makefile.am Thu Dec 10 13:27:42 2009
@@ -134,6 +134,7 @@
     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 \

Modified: couchdb/trunk/share/www/database.html
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/database.html?rev=889256&r1=889255&r2=889256&view=diff
==============================================================================
--- couchdb/trunk/share/www/database.html [utf-8] (original)
+++ couchdb/trunk/share/www/database.html [utf-8] Thu Dec 10 13:27:42 2009
@@ -73,6 +73,8 @@
         // 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 @@
           $(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 @@
         <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">

Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=889256&r1=889255&r2=889256&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Thu Dec 10 13:27:42 2009
@@ -66,6 +66,7 @@
 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");

Modified: couchdb/trunk/share/www/script/futon.browse.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/futon.browse.js?rev=889256&r1=889255&r2=889256&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/futon.browse.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/futon.browse.js [utf-8] Thu Dec 10 13:27:42 2009
@@ -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);

Modified: couchdb/trunk/share/www/script/test/reduce_false.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/reduce_false.js?rev=889256&r1=889255&r2=889256&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/reduce_false.js (original)
+++ couchdb/trunk/share/www/script/test/reduce_false.js Thu Dec 10 13:27:42 2009
@@ -25,8 +25,8 @@
     _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 @@
   //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);
   }
 };

Added: couchdb/trunk/share/www/script/test/reduce_false_temp.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/reduce_false_temp.js?rev=889256&view=auto
==============================================================================
--- couchdb/trunk/share/www/script/test/reduce_false_temp.js (added)
+++ couchdb/trunk/share/www/script/test/reduce_false_temp.js Thu Dec 10 13:27:42 2009
@@ -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);
+  }
+};

Modified: couchdb/trunk/share/www/style/layout.css
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/style/layout.css?rev=889256&r1=889255&r2=889256&view=diff
==============================================================================
--- couchdb/trunk/share/www/style/layout.css (original)
+++ couchdb/trunk/share/www/style/layout.css Thu Dec 10 13:27:42 2009
@@ -376,6 +376,9 @@
 /* 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;
 }

Modified: couchdb/trunk/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_view.erl?rev=889256&r1=889255&r2=889256&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_view.erl Thu Dec 10 13:27:42 2009
@@ -124,12 +124,18 @@
     {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,



Mime
View raw message