adding json export

This commit is contained in:
Max Ogden 2011-07-02 16:15:55 -07:00
parent fafc1f77bd
commit a9d4117b24
3 changed files with 28 additions and 1 deletions

24
app.js
View File

@ -7,6 +7,7 @@ ddoc =
, rewrites : , rewrites :
[ {from:"/", to:'pages/index.html'} [ {from:"/", to:'pages/index.html'}
, {from:"/api/csv", to:'_list/csv/all'} , {from:"/api/csv", to:'_list/csv/all'}
, {from:"/api/json", to:'_list/bulkDocs/all'}
, {from:"/api/headers", to:'_list/array/headers', query: {group: "true"}} , {from:"/api/headers", to:'_list/array/headers', query: {group: "true"}}
, {from:"/api/rows", to:'_view/all'} , {from:"/api/rows", to:'_view/all'}
, {from:"/api", to:'../../'} , {from:"/api", to:'../../'}
@ -80,7 +81,7 @@ ddoc.lists = {
* @author Max Ogden * @author Max Ogden
*/ */
array: function(head, req) { array: function(head, req) {
start({"headers":{"Content-Type" : "application/json"}}); start({"headers":{"Content-Type" : "application/json; charset=utf-8"}});
if ('callback' in req.query) send(req.query['callback'] + "("); if ('callback' in req.query) send(req.query['callback'] + "(");
var headers = []; var headers = [];
@ -90,6 +91,27 @@ ddoc.lists = {
send(JSON.stringify(headers)); send(JSON.stringify(headers));
if ('callback' in req.query) send(")"); if ('callback' in req.query) send(")");
},
/**
* A list function that outputs the same format that you use to post into the _bulk_docs API
*
* @author Max Ogden
*/
bulkDocs: function(head, req) {
var row, out, sep = '\n';
start({"headers":{"Content-Type" : "application/json"}});
if ('callback' in req.query) send(req.query['callback'] + "(");
send('{"docs":[');
while (row = getRow()) {
out = JSON.stringify(row.value);
send(sep + out);
sep = ',\n';
}
send("\n]}");
if ('callback' in req.query) send(")");
} }
} }

View File

@ -76,6 +76,7 @@
<script type='text/mustache' id="exportActionsTemplate"> <script type='text/mustache' id="exportActionsTemplate">
<li><a class="csv" href="JavaScript:void(0);">CSV</a></li> <li><a class="csv" href="JavaScript:void(0);">CSV</a></li>
<li><a class="csv" href="JavaScript:void(0);">JSON</a></li>
</script> </script>
<script type='text/mustache' id="columnActionsTemplate"> <script type='text/mustache' id="columnActionsTemplate">

View File

@ -22,6 +22,10 @@ var removalist = function() {
window.location.href = app.csvUrl; window.location.href = app.csvUrl;
} }
if ($(e.target).hasClass('json')) {
window.location.href = app.csvUrl;
}
e.preventDefault(); e.preventDefault();
$('.menu').hide(); $('.menu').hide();