summaryrefslogtreecommitdiff
path: root/src/fauxton
diff options
context:
space:
mode:
authorSimon Metson <simon+github@cloudant.com>2012-11-28 14:26:16 +0000
committerSimon Metson <simon+github@cloudant.com>2012-11-28 21:07:15 +0000
commit008746a0678de98d7da064c221727091d00aa01a (patch)
treef94ffaa1c6b053e9896b506b8810ed63e8148759 /src/fauxton
parent9458cd263ddc475479d91910926ada0eaca69958 (diff)
downloadcouchdb-008746a0678de98d7da064c221727091d00aa01a.tar.gz
refactor routers into their own file
filter by view
Diffstat (limited to 'src/fauxton')
-rw-r--r--src/fauxton/app/modules/databases.js2
-rw-r--r--src/fauxton/app/modules/documents/models_collections.js (renamed from src/fauxton/app/modules/documents.js)44
-rw-r--r--src/fauxton/app/modules/documents/routes.js51
-rw-r--r--src/fauxton/app/modules/documents/views.js39
-rw-r--r--src/fauxton/app/router.js3
-rw-r--r--src/fauxton/app/templates/documents/all_docs_item.html2
-rw-r--r--src/fauxton/app/templates/documents/index_menu_item.html (renamed from src/fauxton/app/templates/documents/index_item.html)0
-rw-r--r--src/fauxton/app/templates/documents/index_row.html11
8 files changed, 134 insertions, 18 deletions
diff --git a/src/fauxton/app/modules/databases.js b/src/fauxton/app/modules/databases.js
index 0fc486581..2879f5131 100644
--- a/src/fauxton/app/modules/databases.js
+++ b/src/fauxton/app/modules/databases.js
@@ -4,7 +4,7 @@ define([
"fauxton_api",
// Modules
- "modules/documents",
+ "modules/documents/models_collections",
// Views
"modules/databases/views"
diff --git a/src/fauxton/app/modules/documents.js b/src/fauxton/app/modules/documents/models_collections.js
index 74b13b5cd..9d8feafb7 100644
--- a/src/fauxton/app/modules/documents.js
+++ b/src/fauxton/app/modules/documents/models_collections.js
@@ -105,6 +105,50 @@ function(app, Backbone, Views) {
}
});
+ Documents.IndexCollection = Backbone.Collection.extend({
+ model: Backbone.Model,
+
+ initialize: function(_models, options) {
+ this.database = options.database;
+ this.view = options.view;
+ this.design = options.design;
+ this.params = _.extend({group: true, limit: 10}, options.params);
+ this.idxType = "_view";
+ },
+
+ url: function() {
+ var query = "";
+ if (this.params) {
+ query = "?" + $.param(this.params);
+ }
+ var url = [app.host, this.database.id, "_design", this.design, this.idxType, this.view];
+ return url.join("/") + query;
+ },
+
+ parse: function(resp) {
+ that = this;
+ return _.map(resp.rows, function(row) {
+ return {
+ value: row.value,
+ key: row.key,
+ doc: row.doc || undefined
+ };
+ });
+ },
+
+ pageUrl: function() {
+ console.log("Documents.Index.pageUrl");
+ },
+
+ buildAllDocs: function(){
+ this.fetch();
+ },
+
+ allDocs: function(){
+ return this.models;
+ }
+ });
+
Documents.Views = Views;
return Documents;
diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js
index c6787cb8f..64e1c098e 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -4,7 +4,7 @@ define([
"fauxton_api",
// Modules
- "modules/documents",
+ "modules/documents/models_collections",
"modules/databases"
],
@@ -97,7 +97,7 @@ function(app, FauxtonAPI, Documents, Databases) {
views: {
"#dashboard-content": new Documents.Views.AllDocsList({
- model: data.database
+ collection: data.database.allDocs
}),
"#sidebar-content": new Documents.Views.Sidebar({
@@ -112,7 +112,52 @@ function(app, FauxtonAPI, Documents, Databases) {
},
"database/:database/_design/:ddoc/_view/:view": function(databaseName, ddoc, view) {
- console.log(databaseName, ddoc, view);
+ // alert("This will filter your data by the " + ddoc + "/" + view + "view.");
+ var data = {
+ database: new Databases.Model({id:databaseName})
+ };
+
+ data.indexedDocs = new Documents.IndexCollection(null, {
+ database: data.database,
+ design: ddoc,
+ view: view,
+ params: {}
+ });
+
+ data.designDocs = new Documents.AllDocs(null, {
+ database: data.database,
+ params: {startkey: '"_design"',
+ endkey: '"_design1"',
+ include_docs: true}
+ });
+
+ return {
+ layout: "with_tabs_sidebar",
+
+ data: data,
+ // TODO: change dashboard-content
+ views: {
+ "#dashboard-content": new Documents.Views.AllDocsList({
+ collection: data.indexedDocs,
+ nestedView: Documents.Views.Row
+ }),
+
+ "#sidebar-content": new Documents.Views.Sidebar({
+ collection: data.designDocs
+ }),
+
+ "#tabs": new Documents.Views.Tabs({})
+ },
+
+ crumbs: [
+ {"name": "Dashboard", "link": app.root},
+ {"name": "Databases", "link": app.root},
+ {"name": data.database.id, "link": Databases.databaseUrl(data.database)},
+ {"name": ddoc + "/" + view, "link": data.indexedDocs.url()}
+ ],
+ // TODO: change to view URL
+ apiUrl: data.indexedDocs.url()
+ };
}
};
diff --git a/src/fauxton/app/modules/documents/views.js b/src/fauxton/app/modules/documents/views.js
index 36c0adff3..918266d29 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -19,7 +19,7 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
template: "documents/tabs"
});
- Views.AllDocsItem = FauxtonAPI.View.extend({
+ Views.Document = FauxtonAPI.View.extend({
template: "documents/all_docs_item",
tagName: "tr",
@@ -57,8 +57,19 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
}
});
+ Views.Row = FauxtonAPI.View.extend({
+ template: "documents/index_row",
+ tagName: "tr",
+
+ serialize: function() {
+ return {
+ doc: this.model
+ };
+ }
+ });
+
Views.IndexItem = FauxtonAPI.View.extend({
- template: "documents/index_item",
+ template: "documents/index_menu_item",
tagName: "li",
initialize: function(options){
this.index = options.index;
@@ -75,15 +86,19 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
}
});
+ // TODO: Rename to reflect that this is a list of rows or documents
Views.AllDocsList = FauxtonAPI.View.extend({
template: "documents/all_docs_list",
-
events: {
- "click button.all": "selectAll"
- },
+ "click button.all": "selectAll"
+ },
+
+ initialize: function(options){
+ this.nestedView = options.nestedView || Views.Document;
+ },
establish: function() {
- return [this.model.allDocs.fetch()];
+ return [this.collection.fetch()];
},
selectAll: function(evt){
@@ -92,13 +107,13 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
serialize: function() {
return {
- database: this.model
+ database: this.collection
};
},
beforeRender: function() {
- this.model.allDocs.each(function(doc) {
- this.insertView("table.all-docs tbody", new Views.AllDocsItem({
+ this.collection.each(function(doc) {
+ this.insertView("table.all-docs tbody", new this.nestedView({
model: doc
}));
}, this);
@@ -208,7 +223,7 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
"click a.new#doc": "newDocument",
"click a.new#index": "newIndex",
"click .nav-list.views a.new": "showNew",
- "click .nav-list.views a.toggle-view": "toggleView",
+ // "click .nav-list.views a.toggle-view": "toggleView",
"click .nav-list a.toggle-view#all-docs": "toggleView",
"click .nav-list a.toggle-view#design-docs": "toggleView",
"click .nav-list.search a.new": "showNew",
@@ -249,11 +264,11 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
alert('filter data by search/view/type');
event.preventDefault();
url = event.currentTarget.href.split('#')[1];
- console.log(url);
app.router.navigate(url);
},
buildIndexList: function(collection, selector, design){
+
_.each(_.keys(collection), function(key){
this.insertView("ul.nav." + selector, new Views.IndexItem({
ddoc: design,
@@ -279,5 +294,7 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
});
+ Views.Indexed = FauxtonAPI.View.extend({});
+
return Views;
});
diff --git a/src/fauxton/app/router.js b/src/fauxton/app/router.js
index 6de20ace5..8e61698f1 100644
--- a/src/fauxton/app/router.js
+++ b/src/fauxton/app/router.js
@@ -71,8 +71,7 @@ function(app, Initialize, FauxtonAPI, Fauxton, Dashboard, Databases, Documents,
// need access to the Router instance which is not created in this
// module
addModuleRoute: function(generator, route) {
- //var name = settings.name || route;
- this.route(route, route.toString(), generateRoute(generator));
+ this.route(route, route.toString(), generateRoute(generator));
},
setModuleRoutes: function() {
diff --git a/src/fauxton/app/templates/documents/all_docs_item.html b/src/fauxton/app/templates/documents/all_docs_item.html
index 379e49246..69540a565 100644
--- a/src/fauxton/app/templates/documents/all_docs_item.html
+++ b/src/fauxton/app/templates/documents/all_docs_item.html
@@ -1,4 +1,4 @@
- <td class="select"><input type="checkbox"></td>
+<td class="select"><input type="checkbox"></td>
<td>
<div>
<pre class="prettyprint"><%= doc.prettyJSON() %></pre>
diff --git a/src/fauxton/app/templates/documents/index_item.html b/src/fauxton/app/templates/documents/index_menu_item.html
index 63f28df40..63f28df40 100644
--- a/src/fauxton/app/templates/documents/index_item.html
+++ b/src/fauxton/app/templates/documents/index_menu_item.html
diff --git a/src/fauxton/app/templates/documents/index_row.html b/src/fauxton/app/templates/documents/index_row.html
new file mode 100644
index 000000000..7eed46d74
--- /dev/null
+++ b/src/fauxton/app/templates/documents/index_row.html
@@ -0,0 +1,11 @@
+<td class="select"><input type="checkbox"></td>
+<td>
+ <div>
+ <pre class="prettyprint"><%= JSON.stringify(doc.get("key")) %></pre>
+ </div>
+</td>
+<td>
+ <div>
+ <pre class="prettyprint"><%= JSON.stringify(doc.get("value"), null, " ") %></pre>
+ </div>
+</td> \ No newline at end of file