[all][s]: (refs #1) refactor layout to be like standard js library rather than couch app.
120
app.js
@ -1,120 +0,0 @@
|
||||
var couchapp = require('couchapp')
|
||||
, path = require('path')
|
||||
;
|
||||
|
||||
ddoc =
|
||||
{ _id:'_design/recline'
|
||||
, rewrites :
|
||||
[ {from:"/", to:'pages/index.html'}
|
||||
, {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/rows", to:'_view/all'}
|
||||
, {from:"/api", to:'../../'}
|
||||
, {from:"/api/*", to:'../../*'}
|
||||
, {from:"/*", to:'*'}
|
||||
]
|
||||
}
|
||||
;
|
||||
|
||||
ddoc.views = {
|
||||
/**
|
||||
* A simple map function mocking _all, but allows usage with lists etc.
|
||||
*/
|
||||
all: {
|
||||
map: function(doc) {
|
||||
emit(doc._id, doc);
|
||||
}
|
||||
},
|
||||
headers: {
|
||||
map: function(doc) {
|
||||
var keys = [];
|
||||
for (var key in doc) {
|
||||
emit(key, 1);
|
||||
}
|
||||
},
|
||||
reduce: "_sum"
|
||||
}
|
||||
};
|
||||
|
||||
ddoc.lists = {
|
||||
/**
|
||||
* Generates a CSV from all the rows in the view.
|
||||
*
|
||||
* Takes in a url encoded array of headers as an argument. You can
|
||||
* generate this by querying /_list/urlencode/headers. Pass it in
|
||||
* as the headers get parameter, e.g.: ?headers=%5B%22_id%22%2C%22_rev%5D
|
||||
*
|
||||
* @author Max Ogden
|
||||
*/
|
||||
csv: function(head, req) {
|
||||
if ('headers' in req.query) {
|
||||
var headers = JSON.parse(unescape(req.query.headers));
|
||||
|
||||
var row, sep = '\n', headerSent = false, startedOutput = false;
|
||||
|
||||
start({"headers":{"Content-Type" : "text/csv; charset=utf-8"}});
|
||||
send('"' + headers.join('","') + '"\n');
|
||||
while (row = getRow()) {
|
||||
for (var header in headers) {
|
||||
if (row.value[headers[header]]) {
|
||||
if (startedOutput) send(",");
|
||||
var value = row.value[headers[header]];
|
||||
if (typeof(value) == "object") value = JSON.stringify(value);
|
||||
if (typeof(value) == "string") value = value.replace(/\"/g, '""');
|
||||
send("\"" + value + "\"");
|
||||
} else {
|
||||
if (startedOutput) send(",");
|
||||
}
|
||||
startedOutput = true;
|
||||
}
|
||||
startedOutput = false;
|
||||
send('\n');
|
||||
}
|
||||
} else {
|
||||
send("You must pass in the urlencoded headers you wish to build the CSV from. Query /_list/urlencode/headers?group=true");
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Returns an array of the view keys
|
||||
*
|
||||
* @author Max Ogden
|
||||
*/
|
||||
array: function(head, req) {
|
||||
start({"headers":{"Content-Type" : "application/json; charset=utf-8"}});
|
||||
if ('callback' in req.query) send(req.query['callback'] + "(");
|
||||
|
||||
var headers = [];
|
||||
while (row = getRow()) {
|
||||
headers.push(row.key);
|
||||
}
|
||||
send(JSON.stringify(headers));
|
||||
|
||||
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(")");
|
||||
}
|
||||
}
|
||||
|
||||
couchapp.loadAttachments(ddoc, path.join(__dirname, 'attachments'));
|
||||
|
||||
module.exports = ddoc;
|
||||
|
Before Width: | Height: | Size: 87 B After Width: | Height: | Size: 87 B |
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@ -7,11 +7,11 @@
|
||||
<link rel="stylesheet" href="style/data-table.css" media="screen">
|
||||
<link rel="stylesheet" href="style/style.css" media="screen">
|
||||
<!-- only using jqueryui for draggable -- a lighter solution would be nice -->
|
||||
<script type="text/javascript" src="script/deps-min.js"></script>
|
||||
<script type="text/javascript" src="script/util.js"></script>
|
||||
<script type="text/javascript" src="script/costco.js"></script>
|
||||
<script type="text/javascript" src="script/recline.js"></script>
|
||||
<script type="text/javascript" src="script/site.js"></script>
|
||||
<script type="text/javascript" src="../src/deps-min.js"></script>
|
||||
<script type="text/javascript" src="../src/util.js"></script>
|
||||
<script type="text/javascript" src="../src/costco.js"></script>
|
||||
<script type="text/javascript" src="../src/recline.js"></script>
|
||||
<script type="text/javascript" src="../src/site.js"></script>
|
||||
</head>
|
||||
<body class="bod">
|
||||
<div class="container">
|
||||
@ -435,4 +435,4 @@
|
||||
</div>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 971 B After Width: | Height: | Size: 971 B |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |