couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jch...@apache.org
Subject svn commit: r740094 - in /couchdb/trunk/share: server/main.js www/script/couch_tests.js
Date Mon, 02 Feb 2009 20:27:03 GMT
Author: jchris
Date: Mon Feb  2 20:27:03 2009
New Revision: 740094

URL: http://svn.apache.org/viewvc?rev=740094&view=rev
Log:
add iteration numbers to list row functions. closes COUCHDB-233. thanks Benoit Chesneau.

Modified:
    couchdb/trunk/share/server/main.js
    couchdb/trunk/share/www/script/couch_tests.js

Modified: couchdb/trunk/share/server/main.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/server/main.js?rev=740094&r1=740093&r2=740094&view=diff
==============================================================================
--- couchdb/trunk/share/server/main.js [utf-8] (original)
+++ couchdb/trunk/share/server/main.js [utf-8] Mon Feb  2 20:27:03 2009
@@ -13,6 +13,7 @@
 var cmd;
 var funs = [];        // holds functions used for computation
 var map_results = []; // holds temporary emitted values during doc map
+var row_line = {}; // holds row number in list per func
 
 var sandbox = null;
 
@@ -350,18 +351,25 @@
         var listFun = funs[0];
         var head = cmd[1];
         var req = cmd[2];
-        runRenderFunction(listFun, [head, null, req]);
+        row_line[listFun] = 0;
+        runRenderFunction(listFun, [head, null, req, null]);
         break;
       case "list_row":
         var listFun = funs[0];
         var row = cmd[1];
         var req = cmd[2];
-        runRenderFunction(listFun, [null, row, req]);
+        runRenderFunction(listFun, [null, row, req, row_line[listFun]]);
+        row_line[listFun]++;
         break;
       case "list_tail":
         var listFun = funs[0];
         var req = cmd[1];
-        runRenderFunction(listFun, [null, null, req]);
+        var row_number = null;
+        try {
+            row_number = row_line[listFun];
+            delete row_line[listFun];
+        } catch (e) {}
+        runRenderFunction(listFun, [null, null, req, row_number]);
         break;
       default:
         print(toJSON({error: "query_server_error",

Modified: couchdb/trunk/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/couch_tests.js?rev=740094&r1=740093&r2=740094&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/trunk/share/www/script/couch_tests.js [utf-8] Mon Feb  2 20:27:03 2009
@@ -2677,10 +2677,14 @@
         }
       },
       lists: {
-        simpleForm: stringFun(function(head, row, req) {
+        simpleForm: stringFun(function(head, row, req, row_number) {
           if (row) {
             // we ignore headers on rows and tail
-            return {body : '\n<li>Key: '+row.key+' Value: '+row.value+'</li>'};
+            return {
+                    body : '\n<li>Key: '+row.key
+                    +' Value: '+row.value
+                    +' LineNo: '+row_number+'</li>'
+            };
           } else if (head) {
             // we return an object (like those used by external and show)
             // so that we can specify headers
@@ -2695,7 +2699,7 @@
             return {body : '</ul>'};
           }
         }),
-        acceptSwitch: stringFun(function(head, row, req) {
+        acceptSwitch: stringFun(function(head, row, req, row_number) {
           return respondWith(req, {
             html : function() {
               // If you're outputting text and you're not setting
@@ -2704,7 +2708,8 @@
                 return "HTML <ul>";
               } else if (row) {
                 return '\n<li>Key: '
-                  +row.key+' Value: '+row.value+'</li>';
+                  +row.key+' Value: '+row.value
+                  +' LineNo: '+row_number+'</li>';
               } else { // tail
                 return "</ul>";
               }
@@ -2747,7 +2752,12 @@
     T(xhr.status == 200);
     T(/Total Rows/.test(xhr.responseText));
     T(/Key: 1/.test(xhr.responseText));
-    
+    T(/LineNo: 0/.test(xhr.responseText));
+    T(/LineNo: 5/.test(xhr.responseText));
+
+    var lines = xhr.responseText.split('\n');
+    T(/LineNo: 5/.test(lines[6]));
+
     // get with query params
     var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/basicView?startkey=3");
     T(xhr.status == 200);



Mime
View raw message