Author: jchris
Date: Mon Feb  9 01:00:33 2009
New Revision: 742220

URL: http://svn.apache.org/viewvc?rev=742220&view=rev
Log:
row_info object for _list pagination. Thanks benoitc.

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=742220&r1=742219&r2=742220&view=diff
==============================================================================
--- couchdb/trunk/share/server/main.js [utf-8] (original)
+++ couchdb/trunk/share/server/main.js [utf-8] Mon Feb  9 01:00:33 2009
@@ -354,25 +354,32 @@
         var listFun = funs[0];
         var head = cmd[1];
         var req = cmd[2];
-        row_line[listFun] = 0;
+        row_line[listFun] = { first_key: null, row_number: 0, prev_key: null };
         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, row_line[listFun]]);
-        row_line[listFun]++;
+        var row_info = row_line[listFun];
+        runRenderFunction(listFun, [null, row, req, row_info]);
+        if (row_info.first_key == null) {
+            row_info.first_key = row.key;
+        } else {
+            row_info.prev_key = row.key;
+        }
+        row_info.row_number++;
+        row_line[listFun] = row_info;
         break;
       case "list_tail":
         var listFun = funs[0];
         var req = cmd[1];
-        var row_number = null;
+        var row_info = null;
         try {
-            row_number = row_line[listFun];
+            row_info = row_line[listFun];
             delete row_line[listFun];
         } catch (e) {}
-        runRenderFunction(listFun, [null, null, req, row_number]);
+        runRenderFunction(listFun, [null, null, req, row_info]);
         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=742220&r1=742219&r2=742220&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  9 01:00:33 
2009
@@ -2677,13 +2677,13 @@
         }
       },
       lists: {
-        simpleForm: stringFun(function(head, row, req, row_number) {
+        simpleForm: stringFun(function(head, row, req, row_info) {
           if (row) {
             // we ignore headers on rows and tail
             return {
                     body : '\n<li>Key: '+row.key
                     +' Value: '+row.value
-                    +' LineNo: '+row_number+'</li>'
+                    +' LineNo: '+row_info.row_number+'</li>'
             };
           } else if (head) {
             // we return an object (like those used by external and show)
@@ -2696,10 +2696,12 @@
             };
           } else {
             // tail
-            return {body : '</ul>'};
+            return {body : '</ul>'+
+                '<p>FirstKey: '+row_info.first_key+ 
+                ' LastKey: '+row_info.prev_key+'</p>'};
           }
         }),
-        acceptSwitch: stringFun(function(head, row, req, row_number) {
+        acceptSwitch: stringFun(function(head, row, req, row_info) {
           return respondWith(req, {
             html : function() {
               // If you're outputting text and you're not setting
@@ -2709,9 +2711,10 @@
               } else if (row) {
                 return '\n<li>Key: '
                   +row.key+' Value: '+row.value
-                  +' LineNo: '+row_number+'</li>';
+                  +' LineNo: '+row_info.row_number+'</li>';
               } else { // tail
-                return "</ul>";
+                return '</ul>';
+
               }
             },
             xml : function() {
@@ -2754,6 +2757,9 @@
     T(/Key: 1/.test(xhr.responseText));
     T(/LineNo: 0/.test(xhr.responseText));
     T(/LineNo: 5/.test(xhr.responseText));
+    T(/FirstKey: 0/.test(xhr.responseText));
+    T(/LastKey: 9/.test(xhr.responseText));
+
 
     var lines = xhr.responseText.split('\n');
     T(/LineNo: 5/.test(lines[6]));
@@ -2763,6 +2769,9 @@
     T(xhr.status == 200);
     T(/Total Rows/.test(xhr.responseText));
     T(!(/Key: 1/.test(xhr.responseText)));
+    T(/FirstKey: 3/.test(xhr.responseText));
+    T(/LastKey: 9/.test(xhr.responseText));
+
     
     // with 0 rows
     var xhr = CouchDB.request("GET", 
"/test_suite_db/_list/lists/simpleForm/basicView?startkey=30");


Reply via email to