couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r805201 - in /couchdb/trunk: share/www/script/test/list_views.js src/couchdb/couch_httpd_show.erl src/couchdb/couch_httpd_view.erl
Date Mon, 17 Aug 2009 23:04:28 GMT
Author: jan
Date: Mon Aug 17 23:04:28 2009
New Revision: 805201

URL: http://svn.apache.org/viewvc?rev=805201&view=rev
Log:
allow list function and view function to be in different design docs, patch by Mark Hammond,
closes COUCHDB-446

Modified:
    couchdb/trunk/share/www/script/test/list_views.js
    couchdb/trunk/src/couchdb/couch_httpd_show.erl
    couchdb/trunk/src/couchdb/couch_httpd_view.erl

Modified: couchdb/trunk/share/www/script/test/list_views.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/list_views.js?rev=805201&r1=805200&r2=805201&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/list_views.js (original)
+++ couchdb/trunk/share/www/script/test/list_views.js Mon Aug 17 23:04:28 2009
@@ -166,6 +166,17 @@
       })
     }
   };
+  var viewOnlyDesignDoc = {
+    _id:"_design/views",
+    language: "javascript",
+    views : {
+      basicView : {
+        map : stringFun(function(doc) {
+          emit(-doc.integer, doc.string);
+        })
+      }
+    }
+  };
 
   T(db.save(designDoc).ok);
 
@@ -359,4 +370,13 @@
   T(xhr.getResponseHeader("Content-Type") == "application/xml");
   T(xhr.responseText.match(/XML/));
   T(xhr.responseText.match(/entry/));
+
+  // Test we can run lists and views from separate docs.
+  T(db.save(viewOnlyDesignDoc).ok);
+  xhr = CouchDB.request("GET", "/test_suite_db/_design/lists/_list/simpleForm/views/basicView?startkey=-3");
+  T(xhr.status == 200, "with query params");
+  T(/Total Rows/.test(xhr.responseText));
+  T(!(/Key: -4/.test(xhr.responseText)));
+  T(/FirstKey: -3/.test(xhr.responseText));
+  T(/LastKey: 0/.test(xhr.responseText));
 };

Modified: couchdb/trunk/src/couchdb/couch_httpd_show.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_show.erl?rev=805201&r1=805200&r2=805201&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_show.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_show.erl Mon Aug 17 23:04:28 2009
@@ -13,7 +13,7 @@
 -module(couch_httpd_show).
 
 -export([handle_doc_show_req/2, handle_doc_update_req/2, handle_view_list_req/2,
-        handle_doc_show/5, handle_view_list/6]).
+        handle_doc_show/5, handle_view_list/7]).
 
 -include("couch_db.hrl").
 
@@ -96,9 +96,15 @@
     end,
     send_doc_show_response(Lang, ShowSrc, DocId, Doc, Req, Db).
 
+% view-list request with view and list from same design doc.
 handle_view_list_req(#httpd{method='GET',
         path_parts=[_DbName, _Design, DesignName, _List, ListName, ViewName]}=Req, Db) ->
-    handle_view_list(Req, DesignName, ListName, ViewName, Db, nil);
+    handle_view_list(Req, DesignName, ListName, DesignName, ViewName, Db, nil);
+
+% view-list request with view and list from different design docs.
+handle_view_list_req(#httpd{method='GET',
+        path_parts=[_DbName, _Design, DesignName, _List, ListName, ViewDesignName, ViewName]}=Req,
Db) ->
+    handle_view_list(Req, DesignName, ListName, ViewDesignName, ViewName, Db, nil);
 
 handle_view_list_req(#httpd{method='GET'}=Req, _Db) ->
     send_error(Req, 404, <<"list_error">>, <<"Invalid path.">>);
@@ -108,18 +114,26 @@
     ReqBody = couch_httpd:body(Req),
     {Props2} = ?JSON_DECODE(ReqBody),
     Keys = proplists:get_value(<<"keys">>, Props2, nil),
-    handle_view_list(Req#httpd{req_body=ReqBody}, DesignName, ListName, ViewName, Db, Keys);
+    handle_view_list(Req#httpd{req_body=ReqBody}, DesignName, ListName, DesignName, ViewName,
Db, Keys);
 
 handle_view_list_req(Req, _Db) ->
     send_method_not_allowed(Req, "GET,POST,HEAD").
 
-handle_view_list(Req, DesignName, ListName, ViewName, Db, Keys) ->
-    DesignId = <<"_design/", DesignName/binary>>,
-    #doc{body={Props}} = couch_httpd_db:couch_doc_open(Db, DesignId, nil, []),
-    Lang = proplists:get_value(<<"language">>, Props, <<"javascript">>),
-    ListSrc = couch_util:get_nested_json_value({Props}, [<<"lists">>, ListName]),
-    send_view_list_response(Lang, ListSrc, ViewName, DesignId, Req, Db, Keys).
+handle_view_list(Req, ListDesignName, ListName, ViewDesignName, ViewName, Db, Keys) ->
+    ListDesignId = <<"_design/", ListDesignName/binary>>,
+    #doc{body={ListProps}} = couch_httpd_db:couch_doc_open(Db, ListDesignId, nil, []),
+    if
+    ViewDesignName == ListDesignName ->
+        ViewProps = ListProps,
+        ViewDesignId = ListDesignId;
+    true ->
+        ViewDesignId = <<"_design/", ViewDesignName/binary>>,
+        #doc{body={ViewProps}} = couch_httpd_db:couch_doc_open(Db, ViewDesignId, nil, [])
+    end,
 
+    ViewLang = proplists:get_value(<<"language">>, ViewProps, <<"javascript">>),
+    ListSrc = couch_util:get_nested_json_value({ListProps}, [<<"lists">>, ListName]),
+    send_view_list_response(ViewLang, ListSrc, ViewName, ViewDesignId, Req, Db, Keys).
 
 
 send_view_list_response(Lang, ListSrc, ViewName, DesignId, Req, Db, Keys) ->

Modified: couchdb/trunk/src/couchdb/couch_httpd_view.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_view.erl?rev=805201&r1=805200&r2=805201&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_view.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_view.erl Mon Aug 17 23:04:28 2009
@@ -83,7 +83,7 @@
     case ListName of
         nil -> couch_httpd_view:design_doc_view(Req, Db, DName, ViewName, nil);
         _ ->
-            couch_httpd_show:handle_view_list(Req, DName, ListName, ViewName, Db, nil)
+            couch_httpd_show:handle_view_list(Req, DName, ListName, DName, ViewName, Db,
nil)
     end;
 
 handle_db_view_req(#httpd{method='POST',
@@ -110,7 +110,7 @@
         {Props2} = ?JSON_DECODE(ReqBody),
         Keys = proplists:get_value(<<"keys">>, Props2, nil),
         couch_httpd_show:handle_view_list(Req#httpd{req_body=ReqBody},
-            DName, ListName, ViewName, Db, Keys)
+            DName, ListName, DName, ViewName, Db, Keys)
     end;
 
 handle_db_view_req(Req, _Db) ->



Mime
View raw message