diff options
author | Damien F. Katz <damien@apache.org> | 2008-05-19 19:20:19 +0000 |
---|---|---|
committer | Damien F. Katz <damien@apache.org> | 2008-05-19 19:20:19 +0000 |
commit | 55ee8c7f9188443900c52a69ae408bcf457be62a (patch) | |
tree | e98a332b9b43208f4d7494ac357c51df81866b29 | |
parent | 4e47fa72aedc6533bd669599e325c911b2c8c68e (diff) |
Changed temp view definition to always be jsonobjects with map/reduce source as members of the object. Everywhere we used 'text/javascript' or 'application/javascript', we now just use 'javascript'
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@657926 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | etc/couchdb/couch.ini.tpl.in | 2 | ||||
-rw-r--r-- | share/www/script/browse.js | 2 | ||||
-rw-r--r-- | share/www/script/couch.js | 8 | ||||
-rw-r--r-- | share/www/script/couch_tests.js | 2 | ||||
-rw-r--r-- | share/www/script/jquery.couch.js | 2 | ||||
-rw-r--r-- | src/couchdb/couch_doc.erl | 2 | ||||
-rw-r--r-- | src/couchdb/couch_httpd.erl | 34 | ||||
-rw-r--r-- | src/couchdb/couch_view.erl | 2 |
8 files changed, 27 insertions, 27 deletions
diff --git a/etc/couchdb/couch.ini.tpl.in b/etc/couchdb/couch.ini.tpl.in index 8b3b6ec9..555ea3da 100644 --- a/etc/couchdb/couch.ini.tpl.in +++ b/etc/couchdb/couch.ini.tpl.in @@ -20,4 +20,4 @@ LogLevel=info [Couch Query Servers] -text/javascript=%bindir%/%couchjs_command_name% %pkgdatadir%/server/main.js +javascript=%bindir%/%couchjs_command_name% %pkgdatadir%/server/main.js diff --git a/share/www/script/browse.js b/share/www/script/browse.js index b08cbae6..9d821d09 100644 --- a/share/www/script/browse.js +++ b/share/www/script/browse.js @@ -277,7 +277,7 @@ function CouchDatabasePage() { var viewCode = $("#viewcode textarea").val(); var docId = ["_design", data.docid].join("/"); function save(doc) { - if (!doc) doc = {_id: docId, language: "text/javascript"}; + if (!doc) doc = {_id: docId, language: "javascript"}; if (doc.views === undefined) doc.views = {}; doc.views[data.name] = viewCode; db.saveDoc(doc, { diff --git a/share/www/script/couch.js b/share/www/script/couch.js index f72fb712..d63f1eae 100644 --- a/share/www/script/couch.js +++ b/share/www/script/couch.js @@ -98,8 +98,8 @@ function CouchDB(name) { if (typeof(mapFun) != "string") mapFun = mapFun.toSource ? mapFun.toSource() : "(" + mapFun.toString() + ")"; var req = request("POST", this.uri + "_temp_view" + encodeOptions(options), { - headers: {"Content-Type": "text/javascript"}, - body: JSON.stringify(mapFun) + headers: {"Content-Type": "application/json"}, + body: JSON.stringify({language:"javascript",map:mapFun}) }); var result = JSON.parse(req.responseText); if (req.status != 200) @@ -114,8 +114,8 @@ function CouchDB(name) { if (typeof(reduceFun) != "string") reduceFun = reduceFun.toSource ? reduceFun.toSource() : "(" + reduceFun.toString() + ")"; var req = request("POST", this.uri + "_temp_view" + encodeOptions(options), { - headers: {"Content-Type": "text/javascript"}, - body: JSON.stringify({map:mapFun, reduce:reduceFun}) + headers: {"Content-Type": "application/json"}, + body: JSON.stringify({language:"javascript",map:mapFun,reduce:reduceFun}) }); var result = JSON.parse(req.responseText); if (req.status != 200) diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 72ed9f58..7b35cf87 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -436,7 +436,7 @@ var tests = { var designDoc = { _id:"_design/test", - language: "text/javascript", + language: "javascript", views: { all_docs: "function(doc) { map(doc.integer, null) }", no_docs: "function(doc) {}", diff --git a/share/www/script/jquery.couch.js b/share/www/script/jquery.couch.js index de1cddc9..00090619 100644 --- a/share/www/script/jquery.couch.js +++ b/share/www/script/jquery.couch.js @@ -179,7 +179,7 @@ fun = fun.toSource ? fun.toSource() : "(" + fun.toString() + ")"; $.ajax({ type: "POST", url: this.uri + "_temp_view" + encodeOptions(options), - contentType: "text/javascript", data: fun, dataType: "json", + contentType: "javascript", data: fun, dataType: "json", complete: function(req) { var resp = $.httpData(req, "json"); if (req.status == 200 && options.success) { diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl index 1ced93b3..cb70a576 100644 --- a/src/couchdb/couch_doc.erl +++ b/src/couchdb/couch_doc.erl @@ -172,7 +172,7 @@ bin_to_binary({Fd, Sp, Len}) -> Bin. get_view_functions(#doc{body={obj, Fields}}) -> - Lang = proplists:get_value("language", Fields, "text/javascript"), + Lang = proplists:get_value("language", Fields, "javascript"), {obj, Views} = proplists:get_value("views", Fields, {obj, []}), {Lang, [{ViewName, Value} || {ViewName, Value} <- Views, is_list(Value)]}; get_view_functions(_Doc) -> diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index 67a7f13c..915889ff 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -397,30 +397,30 @@ handle_db_request(Req, 'POST', {DbName, _Db, ["_temp_view"]}) -> end_docid = EndDocId } = QueryArgs = parse_view_query(Req), - ContentType = case Req:get_primary_header_value("content-type") of - undefined -> - "text/javascript"; - Else -> - Else + case Req:get_primary_header_value("content-type") of + undefined -> ok; + "application/json" -> ok; + Else -> throw({incorrect_mime_type, Else}) end, - case cjson:decode(Req:recv_body()) of - {obj, Props} -> - MapSrc = proplists:get_value("map",Props), - RedSrc = proplists:get_value("reduce",Props), - {ok, View} = couch_view:get_reduce_view( - {temp, DbName, ContentType, MapSrc, RedSrc}), - {ok, Value} = couch_view:reduce(View, {StartKey, StartDocId}, {EndKey, EndDocId}), - send_json(Req, {obj, [{ok,true}, {result, Value}]}); - Src when is_list(Src) -> - - {ok, View} = couch_view:get_map_view({temp, DbName, ContentType, Src}), + {obj, Props} = cjson:decode(Req:recv_body()), + Language = proplists:get_value("language", Props, "javascript"), + MapSrc = proplists:get_value("map", Props), + case proplists:get_value("reduce", Props, null) of + null -> + {ok, View} = couch_view:get_map_view({temp, DbName, Language, MapSrc}), Start = {StartKey, StartDocId}, {ok, TotalRows} = couch_view:get_row_count(View), FoldlFun = make_view_fold_fun(Req, QueryArgs, TotalRows, fun couch_view:reduce_to_count/1), FoldAccInit = {Count, SkipCount, undefined, []}, FoldResult = couch_view:fold(View, Start, Dir, FoldlFun, FoldAccInit), - finish_view_fold(Req, TotalRows, FoldResult) + finish_view_fold(Req, TotalRows, FoldResult); + + RedSrc -> + {ok, View} = couch_view:get_reduce_view( + {temp, DbName, Language, MapSrc, RedSrc}), + {ok, Value} = couch_view:reduce(View, {StartKey, StartDocId}, {EndKey, EndDocId}), + send_json(Req, {obj, [{ok,true}, {result, Value}]}) end; handle_db_request(_Req, _Method, {_DbName, _Db, ["_temp_view"]}) -> diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl index 5a1ff2e4..4f6a2f47 100644 --- a/src/couchdb/couch_view.erl +++ b/src/couchdb/couch_view.erl @@ -153,7 +153,7 @@ reduce_to_count(Reductions) -> design_doc_to_view_group(#doc{id=Id,body={obj, Fields}}) -> - Language = proplists:get_value("language", Fields, "text/javascript"), + Language = proplists:get_value("language", Fields, "javascript"), {obj, RawViews} = proplists:get_value("views", Fields, {obj, []}), % extract the map/reduce views from the json fields and into lists |