couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [39/50] [abbrv] git commit: add changes feed to database
Date Mon, 11 Feb 2013 11:12:14 GMT
add changes feed to database


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/6001be11
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/6001be11
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/6001be11

Branch: refs/heads/fauxton
Commit: 6001be116437a65e0c39c3bae0dd302816ddabf5
Parents: 2c48183
Author: Garren Smith <garren.smith@gmail.com>
Authored: Tue Feb 5 14:56:58 2013 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Tue Feb 5 14:56:58 2013 +0200

----------------------------------------------------------------------
 src/fauxton/TODO.md                                |    2 +-
 src/fauxton/app/modules/databases/resources.js     |   31 +++++++
 src/fauxton/app/modules/documents/routes.js        |   69 +++++++++++----
 src/fauxton/app/modules/documents/views.js         |   34 +++++++
 src/fauxton/app/templates/documents/changes.html   |   16 ++++
 src/fauxton/app/templates/documents/tabs.html      |    3 +-
 src/fauxton/app/templates/layouts/with_tabs.html   |   13 +++
 .../app/templates/layouts/with_tabs_sidebar.html   |    2 +-
 8 files changed, 150 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/6001be11/src/fauxton/TODO.md
----------------------------------------------------------------------
diff --git a/src/fauxton/TODO.md b/src/fauxton/TODO.md
index 31127e0..b929e05 100644
--- a/src/fauxton/TODO.md
+++ b/src/fauxton/TODO.md
@@ -11,7 +11,7 @@ In no particular order
 - [ ] show design docs only
 - [ ] fix delete doc button UI bug
 - [ ] delete multiple docs via _bulk_docs
-- [ ] show change events in database view
+- [x] show change events in database view
 - [ ] pouchdb addon
 - [ ] bespoke bootstrap style
 - [ ] responsive interface

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6001be11/src/fauxton/app/modules/databases/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/databases/resources.js b/src/fauxton/app/modules/databases/resources.js
index 76f8c6e..73af4f7 100644
--- a/src/fauxton/app/modules/databases/resources.js
+++ b/src/fauxton/app/modules/databases/resources.js
@@ -39,6 +39,37 @@ function(app, FauxtonAPI, Documents) {
       } else {
         return app.host + "/" + this.id;
       }
+    },
+
+    buildChanges: function (params) {
+      this.changes = new Databases.Changes({
+        database: this,
+        params: params
+      });
+
+      return this.changes;
+    }
+  });
+
+  Databases.Changes = Backbone.Collection.extend({
+
+    initialize: function(options) {
+      this.database = options.database;
+      this.params = options.params;
+    },
+
+    url: function () {
+      var query = "";
+      if (this.params) {
+        query = "?" + $.param(this.params);
+      }
+
+      return app.host + '/' + this.database.id + '/_changes' + query;
+    },
+
+    parse: function (resp) {
+      this.last_seq = resp.last_seq;
+      return resp.results;
     }
   });
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6001be11/src/fauxton/app/modules/documents/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js
index d851caf..dfa208f 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -1,11 +1,11 @@
 define([
-  "app",
+       "app",
 
-  "api",
+       "api",
 
-  // Modules
-  "modules/documents/resources",
-  "modules/databases/base"
+       // Modules
+       "modules/documents/resources",
+       "modules/databases/base"
 ],
 
 function(app, FauxtonAPI, Documents, Databases) {
@@ -25,8 +25,8 @@ function(app, FauxtonAPI, Documents, Databases) {
     data.designDocs = new Documents.AllDocs(null, {
       database: data.database,
       params: {startkey: '"_design"',
-               endkey: '"_design1"',
-               include_docs: true}
+        endkey: '"_design1"',
+        include_docs: true}
     });
 
     var options = app.getParams();
@@ -73,8 +73,8 @@ function(app, FauxtonAPI, Documents, Databases) {
     data.designDocs = new Documents.AllDocs(null, {
       database: data.database,
       params: {startkey: '"_design"',
-               endkey: '"_design1"',
-               include_docs: true}
+        endkey: '"_design1"',
+        include_docs: true}
     });
 
     var options = app.getParams();
@@ -120,8 +120,8 @@ function(app, FauxtonAPI, Documents, Databases) {
       data.designDocs = new Documents.AllDocs(null, {
         database: data.database,
         params: {startkey: '"_design"',
-                 endkey: '"_design1"',
-                 include_docs: true}
+          endkey: '"_design1"',
+          include_docs: true}
       });
 
       var options = app.getParams();
@@ -182,8 +182,8 @@ function(app, FauxtonAPI, Documents, Databases) {
       data.designDocs = new Documents.AllDocs(null, {
         database: data.database,
         params: {startkey: '"_design"',
-                 endkey: '"_design1"',
-                 include_docs: true}
+          endkey: '"_design1"',
+          include_docs: true}
       });
 
       var options = app.getParams();
@@ -222,8 +222,8 @@ function(app, FauxtonAPI, Documents, Databases) {
       data.designDocs = new Documents.AllDocs(null, {
         database: data.database,
         params: {startkey: '"_design"',
-                 endkey: '"_design1"',
-                 include_docs: true}
+          endkey: '"_design1"',
+          include_docs: true}
       });
 
       var options = app.getParams();
@@ -259,6 +259,41 @@ function(app, FauxtonAPI, Documents, Databases) {
       };
     },
 
+    "database/:database/_changes(:params)": function(databaseName, params) {
+      var data = {
+        database: new Databases.Model({id:databaseName})
+      };
+
+      var options = app.getParams();
+      data.database.buildChanges(options);
+
+      return {
+        layout: "with_tabs",
+
+        data: data,
+
+        crumbs: [
+          {"name": "Databases", "link": "/_all_dbs"},
+          {"name": data.database.id, "link": Databases.databaseUrl(data.database)},
+          {"name": "_changes", "link": "/_changes"}
+        ],
+
+        views: {
+          "#dashboard-content": new Documents.Views.Changes({
+            collection: data.database.changes
+          }),
+
+          "#tabs": new Documents.Views.Tabs({
+            collection: data.designDocs,
+            database: data.database,
+            active_id: 'changes'
+          })
+        },
+
+        apiUrl: data.database.changes.url()
+      };
+    },
+
     "database/:database/new": newDocCodeEditorCallback,
 
     // TODO: fix optional search params
@@ -283,8 +318,8 @@ function(app, FauxtonAPI, Documents, Databases) {
       data.designDocs = new Documents.AllDocs(null, {
         database: data.database,
         params: {startkey: '"_design"',
-                 endkey: '"_design1"',
-                 include_docs: true}
+          endkey: '"_design1"',
+          include_docs: true}
       });
 
       var ddocInfo = {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6001be11/src/fauxton/app/modules/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js
index 556a5cf..0d6eb7e 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -20,12 +20,21 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
     initialize: function(options){
       this.collection = options.collection;
       this.database = options.database;
+      this.active_id = options.active_id;
     },
 
     events: {
       "click #delete-database": "delete_database"
     },
 
+    serialize: function () {
+      return {
+        // TODO make this not hard coded here
+        changes_url: '#database/'+ this.database.id + '/_changes?descending=true&limit=100',
+        db_url: '#database/'+ this.database.id + '/_all_docs?limit=100'
+      };
+    },
+
     beforeRender: function(manage) {
       this.insertView("#search", new Views.SearchBox({
         collection: this.collection,
@@ -33,6 +42,13 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
       }));
     },
 
+    afterRender: function () {
+      if (this.active_id) {
+        this.$('.active').removeClass('active');
+        this.$('#'+this.active_id).addClass('active');
+      }
+    },
+
     delete_database: function (event) {
       event.preventDefault();
 
@@ -662,5 +678,23 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
 
   Views.Indexed = FauxtonAPI.View.extend({});
 
+  Views.Changes = FauxtonAPI.View.extend({
+    template: "templates/documents/changes",
+
+    establish: function() {
+      return [
+        this.collection.fetch()
+      ];
+    },
+
+    serialize: function () {
+      return {
+        changes: this.collection.toJSON()
+      };
+    }
+
+  });
+
+
   return Views;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6001be11/src/fauxton/app/templates/documents/changes.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/changes.html b/src/fauxton/app/templates/documents/changes.html
new file mode 100644
index 0000000..9cdb30a
--- /dev/null
+++ b/src/fauxton/app/templates/documents/changes.html
@@ -0,0 +1,16 @@
+<table class="table">
+  <thead>
+    <th> seq </th>
+    <th> id </th>
+    <th changes </th>
+  </thead>
+  <tbody>
+  <% _.each(changes, function (change) { %>
+  <tr>
+    <td> <%= change.seq %> </td>
+    <td> <%= change.id %> </td>
+    <td> <%= JSON.stringify(change.changes) %> </td>
+  </tr>
+  <% }); %>
+  </tbody>
+</table>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6001be11/src/fauxton/app/templates/documents/tabs.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/tabs.html b/src/fauxton/app/templates/documents/tabs.html
index d0231e0..f302019 100644
--- a/src/fauxton/app/templates/documents/tabs.html
+++ b/src/fauxton/app/templates/documents/tabs.html
@@ -1,7 +1,8 @@
 <ul class="nav nav-tabs">
-  <li class="active"><a href="#">Docs</a></li>
+  <li class="active"><a href="<%= db_url %>">Docs</a></li>
   <li><a href="#">Permissions</a></li>
   <li><a href="#">Stats</a></li>
+  <li id="changes"><a  href="<%= changes_url %>">Changes</a></li>
   <div id="search" class="navbar-search span4 nav pull-right input-prepend" style="height:20px;"></div>
   <!-- TODO: put this styling into less -->
   <ul class="nav pull-right" style="margin:5px 10px 0px 10px;">

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6001be11/src/fauxton/app/templates/layouts/with_tabs.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/layouts/with_tabs.html b/src/fauxton/app/templates/layouts/with_tabs.html
new file mode 100644
index 0000000..f9c289a
--- /dev/null
+++ b/src/fauxton/app/templates/layouts/with_tabs.html
@@ -0,0 +1,13 @@
+<div id="primary-navbar"></div>
+<div id="dashboard" class="container">
+
+<div class="row-fluid">
+  <div id="breadcrumbs" class="row-fluid"></div>
+  <div id="tabs" class="row-fluid"></div>
+
+  <div class="row-fluid">
+    <div id="dashboard-content" class="list span12"></div>
+  </div>
+</div>
+
+<div id="api-navbar"></div>

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6001be11/src/fauxton/app/templates/layouts/with_tabs_sidebar.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/layouts/with_tabs_sidebar.html b/src/fauxton/app/templates/layouts/with_tabs_sidebar.html
index 7e90427..e6ba655 100644
--- a/src/fauxton/app/templates/layouts/with_tabs_sidebar.html
+++ b/src/fauxton/app/templates/layouts/with_tabs_sidebar.html
@@ -11,4 +11,4 @@
   </div>
 </div>
 
-<div id="api-navbar"></div>
\ No newline at end of file
+<div id="api-navbar"></div>


Mime
View raw message