You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2013/03/15 22:50:09 UTC
[2/50] git commit: add changes feed to database
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/206fd49a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/206fd49a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/206fd49a
Branch: refs/heads/fauxton-rebase
Commit: 206fd49ab6f733f4a7f3b5397ccef7e6f4b6f5fa
Parents: e1d5737
Author: Garren Smith <ga...@gmail.com>
Authored: Tue Feb 5 14:56:58 2013 +0200
Committer: Russell Branca <ch...@gmail.com>
Committed: Fri Mar 15 14:35:12 2013 -0700
----------------------------------------------------------------------
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/206fd49a/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/206fd49a/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/206fd49a/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/206fd49a/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/206fd49a/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/206fd49a/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/206fd49a/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/206fd49a/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>