diff options
Diffstat (limited to 'share')
-rw-r--r-- | share/server/main.js | 19 | ||||
-rw-r--r-- | share/www/script/couch_tests.js | 21 |
2 files changed, 28 insertions, 12 deletions
diff --git a/share/server/main.js b/share/server/main.js index 13e85ed8..34b0a353 100644 --- a/share/server/main.js +++ b/share/server/main.js @@ -354,25 +354,32 @@ while (cmd = eval(readline())) { 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", diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index dd070958..2df262d7 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -2677,13 +2677,13 @@ db.createDb(); } }, 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 @@ db.createDb(); }; } 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 @@ db.createDb(); } 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 @@ db.createDb(); 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 @@ db.createDb(); 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"); |