Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

basic by_when view

  • Loading branch information...
commit b0276d8658a6379d2017bd764296180bdeb1a9f1 1 parent da61c21
@alexch authored
View
4 README.markdown
@@ -66,9 +66,13 @@ We could gather all sorts of other events as well, like tab opens and closes. Bu
* Categories a la RescueTime
* Detect idle time
* either stop recording, or record "time since activity" per sample
+ * http://paulirish.com/2009/jquery-idletimer-plugin/
+ * http://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly
+ * http://www.frebsite.nl/werk/scripts/jquery_nap_plugin/index_en.php#voorbeelden
* log per-page info e.g. GMail subject and from
* Geolocation (possibly with GeoCouch)
* https://github.com/couchbase/geocouch
+* Store times in GMT?
# Credits
View
7 Rakefile
@@ -138,3 +138,10 @@ namespace :uninstall do
puts "google chrome > window > extensions > whence > uninstall"
end
end
+
+desc "Tail the Couchbase log"
+task :tail do
+ exec "tail -f /Applications/Couchbase\\ Server.app/Contents/Resources/couchdbx-core/var/log/couchdb/couch.log"
+end
+
+
View
BIN  builds/whence.crx
Binary file not shown
View
1  ext/manifest.json
@@ -7,7 +7,6 @@
"background_page" : "background.html",
"permissions": [
"tabs",
- "http://localhost:*/*",
"http://localhost/*"
]
}
View
58 ext/whence.js
@@ -15,14 +15,14 @@ function couch(method, options) {
data.when = new Date();
}
$.ajax({
- url: urlPrefix + dbName,
- type: method.toUpperCase(), // type = method
- dataType: 'json', // dataType = response
- data: JSON.stringify(data), // data = request // use https://github.com/douglascrockford/JSON-js/blob/master/json2.js to get JSON in non-Chrome environments
- contentType: "application/json",
+ url: url,
+ type: method.toUpperCase(), // type = method
+ data: JSON.stringify(data), // data = request // use https://github.com/douglascrockford/JSON-js/blob/master/json2.js to get JSON in non-Chrome environments
+ dataType: 'json', // dataType = response
+ contentType: "application/json", // contentType = response
success: function(response) {
if (options.success == undefined) {
- console.log("Success during " + method + " " + urlPrefix + dbName)
+ console.log("Success during " + method + " " + url)
console.log(response);
} else {
options.success(response);
@@ -30,7 +30,7 @@ function couch(method, options) {
},
error: function(e) {
if (options.error == undefined) {
- console.log("Error during " + method + " " + urlPrefix + dbName)
+ console.log("Error during " + method + " " + url)
console.log(e);
}
else {
@@ -55,8 +55,52 @@ error:function(error) {
}});
// log db info, for fun
+console.log("db info:")
couch('get');
+// create/update the design documents
+// Permanent views are stored inside special documents called design documents, and can be accessed via an HTTP GET request to the URI /{dbname}/{docid}/{viewname}, where {docid} has the prefix _design/ so that CouchDB recognizes the document as a design document, and {viewname} has the prefix _view/ so that CouchDB recognizes it as a view.
+
+var views = {
+ all: {
+ map: (function(doc) { emit(null, doc); }).toString()
+ },
+ by_when: {
+ map: (function(doc) {
+ var secs = Date.parse(doc.when);
+ emit(secs, doc);
+ }).toString()
+ }
+};
+
+console.log("getting view")
+couch('get', {
+ docId: '_design/sample',
+ success: function(response) {
+ console.log(response);
+ // todo: only put if it's different
+ console.log("setting view")
+ couch('put', {
+ docId: '_design/sample',
+ data: {
+ language: 'javascript',
+ _rev: response._rev,
+ views: views,
+ },
+ success: function(response) {
+ // get 'em all, for laffs
+ couch('get', {
+ docId: '_design/sample/_view/by_when'
+ })
+ }
+ });
+ },
+});
+
+
+//
+
+
function parseUrl(url) {
var parts = url.match(/(.*):\/\/([^\/]*)(\/.*)/);
if (parts == null) {
Please sign in to comment.
Something went wrong with that request. Please try again.