Browse files

Add helper views/lists to the couchapp.

  • Loading branch information...
1 parent 27b3ffa commit a1ec1e5c2e3f6dfff68d65da123a5f54c0e15d73 @mertonium mertonium committed Jun 22, 2011
Showing with 30 additions and 0 deletions.
  1. +22 −0 couchapp/lists/sum.js
  2. +5 −0 couchapp/views/attach-count/map.js
  3. +3 −0 couchapp/views/sfonly/map.js
View
22 couchapp/lists/sum.js
@@ -0,0 +1,22 @@
+function(head, req) {
+ var row, out, sum = 0, sep = '\n';
+
+ // Send the same Content-Type as CouchDB would
+ if (req.headers.Accept.indexOf('application/json')!=-1)
+ start({"headers":{"Content-Type" : "application/json"}});
+ else
+ start({"headers":{"Content-Type" : "text/plain"}});
+
+ if ('callback' in req.query) send(req.query['callback'] + "(");
+
+
+ while (row = getRow()) {
+ sum += parseFloat(row.value);
+ }
+
+ out = JSON.stringify(sum);
+ send(out);
+
+ if ('callback' in req.query) send(")");
+
+};
View
5 couchapp/views/attach-count/map.js
@@ -0,0 +1,5 @@
+function(doc) {
+ if(doc.source =='San Francisco Arts Commission') {
+ if(doc._attachments) emit(null, Object.keys(Object(doc._attachments)).length);
+ }
+}
View
3 couchapp/views/sfonly/map.js
@@ -0,0 +1,3 @@
+function(doc) {
+ if(doc.source =='San Francisco Arts Commission') emit(doc.accession_id, doc);
+}

0 comments on commit a1ec1e5

Please sign in to comment.