You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2013/10/28 17:14:05 UTC
[48/50] git commit: updated refs/heads/1853-fauxton-route-events to
b70b7ae
Fauxton: Hide new view when no docs in database
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/faf215fb
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/faf215fb
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/faf215fb
Branch: refs/heads/1853-fauxton-route-events
Commit: faf215fbed40f881a9362a97998cd2664e0d2389
Parents: 9e5e3a5
Author: Garren Smith <ga...@gmail.com>
Authored: Mon Oct 28 14:57:07 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Mon Oct 28 14:57:07 2013 +0200
----------------------------------------------------------------------
src/fauxton/app/modules/documents/routes.js | 15 ++++++--
src/fauxton/app/modules/documents/views.js | 38 ++++++--------------
.../app/templates/documents/sidebar.html | 12 ++++---
3 files changed, 31 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/faf215fb/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 df8c07d..fae5c5c 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -21,9 +21,6 @@ define([
],
function(app, FauxtonAPI, Documents, Databases) {
- // TODO: look at using:
- // var Documents = require("modules/documents/models_collections");
- // var Databases = require("modules/databases/module");
var DocEditorRouteObject = FauxtonAPI.RouteObject.extend({
layout: "one_pane",
@@ -203,6 +200,9 @@ function(app, FauxtonAPI, Documents, Databases) {
}
if (this.viewEditor) { this.viewEditor.remove(); }
+
+ this.listenTo(this.data.database.allDocs, 'reset', this.checkExistingDocs);
+ this.listenTo(this.data.database.allDocs, 'remove', this.checkExistingDocs);
this.toolsView = this.setView("#dashboard-upper-menu", new Documents.Views.JumpToDoc({
database: this.data.database,
@@ -360,7 +360,16 @@ function(app, FauxtonAPI, Documents, Databases) {
if (event && event.selectedTab) {
this.sidebar.setSelectedTab(event.selectedTab);
}
+ },
+
+ checkExistingDocs: function () {
+ if (this.data.database.allDocs.length > 0) {
+ this.sidebar.toggleNewView(true);
+ } else {
+ this.sidebar.toggleNewView(false);
+ }
}
+
});
var ChangesRouteObject = FauxtonAPI.RouteObject.extend({
http://git-wip-us.apache.org/repos/asf/couchdb/blob/faf215fb/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 55ca405..f822544 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -683,7 +683,6 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
this.insertView('#documents-pagination', this.pagination);
var docs = this.expandDocs ? this.collection : this.collection.simple();
- console.log('docs', docs);
docs.each(function(doc) {
this.rows[doc.id] = this.insertView("table.all-docs tbody", new this.nestedView({
@@ -1633,18 +1632,16 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
Views.Sidebar = FauxtonAPI.View.extend({
template: "templates/documents/sidebar",
events: {
- "click a.new#index": "newIndex",
"click button#delete-database": "deleteDatabase"
},
initialize: function(options) {
this.database = options.database;
+ this.showNewView = true;
if (options.ddocInfo) {
this.ddocID = options.ddocInfo.id;
this.currView = options.ddocInfo.currView;
}
- // this.listenTo(this.collection, "add", this.render);
- // this.listenTo(this.collection, "remove", this.render);
},
deleteDatabase: function (event) {
@@ -1674,34 +1671,14 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
changes_url: '#' + this.database.url('changes'),
permissions_url: '#' + this.database.url('app') + '/permissions',
db_url: '#' + this.database.url('index') + '?limit=100',
- index: [1,2,3],
- view: [1,2],
database: this.collection.database,
database_url: '#' + this.database.url('app'),
- docLinks: docLinks
+ docLinks: docLinks,
+ showNewView: this.showNewView
};
},
- newIndex: function(event){
- event.preventDefault();
- $.contribute(
- 'Create a new view.',
- 'app/addons/documents/views.js'
- );
- },
-
- toggleView: function(event){
- event.preventDefault();
- $.contribute(
- 'Filter data by type or view',
- 'app/addons/databases/views.js'
- );
- url = event.currentTarget.href.split('#')[1];
- app.router.navigate(url);
- },
-
buildIndexList: function(collection, selector, design){
-
_.each(_.keys(collection), function(key){
var selected = this.ddocID == "_design/"+design;
this.insertView("ul.nav." + selector, new Views.IndexItem({
@@ -1734,8 +1711,15 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
this.selectedTab = selectedTab;
this.$('li').removeClass('active');
this.$('#' + selectedTab).parent().addClass('active');
- }
+ },
+ toggleNewView: function (show) {
+ // only render if there is a change
+ if (show !== this.showNewView) {
+ this.showNewView = show;
+ this.render();
+ }
+ },
});
Views.Indexed = FauxtonAPI.View.extend({});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/faf215fb/src/fauxton/app/templates/documents/sidebar.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/sidebar.html b/src/fauxton/app/templates/documents/sidebar.html
index 881309f..93bddc9 100644
--- a/src/fauxton/app/templates/documents/sidebar.html
+++ b/src/fauxton/app/templates/documents/sidebar.html
@@ -43,9 +43,11 @@ the License.
<li>
<a id="doc" href="#<%= database.url('app') %>/new">New doc</a>
</li>
- <li>
- <a href="#<%= database.url('app') %>/new_view">New view</a>
- </li>
+ <% if (showNewView) { %>
+ <li>
+ <a href="#<%= database.url('app') %>/new_view">New view</a>
+ </li>
+ <% } %>
</ul>
</div>
</div>
@@ -62,7 +64,9 @@ the License.
</ul>
<ul class="nav nav-list views">
<li class="nav-header">Secondary Indices</li>
- <li><a id="new-view" href="#<%= database.url('app') %>/new_view" class="new"><i class="icon-plus"></i> New</a></li>
+ <% if (showNewView) { %>
+ <li><a id="new-view" href="#<%= database.url('app') %>/new_view" class="new"><i class="icon-plus"></i> New</a></li>
+ <% } %>
</ul>
</nav>
</div>