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/09/18 17:35:38 UTC
git commit: updated refs/heads/typeahead-jump-doc to fbbaaff
Updated Branches:
refs/heads/typeahead-jump-doc [created] fbbaaffaa
Fauxton: Add typeahead support to jump to doc
Simple type ahead support to check for start of id. It also checks if
document exists if not return back to _all_docs list
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/fbbaaffa
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/fbbaaffa
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/fbbaaffa
Branch: refs/heads/typeahead-jump-doc
Commit: fbbaaffaac347368aff7bc480071fc6ef7399d59
Parents: bdc14be
Author: Garren Smith <ga...@gmail.com>
Authored: Wed Sep 18 17:34:33 2013 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Wed Sep 18 17:34:33 2013 +0200
----------------------------------------------------------------------
src/fauxton/app/api.js | 14 +++++---
src/fauxton/app/modules/documents/resources.js | 4 ---
src/fauxton/app/modules/documents/routes.js | 5 ++-
src/fauxton/app/modules/documents/views.js | 27 +++++++++++++--
src/fauxton/app/modules/fauxton/components.js | 35 ++++++++++++++++++++
.../app/templates/documents/jumpdoc.html | 2 +-
src/fauxton/assets/less/fauxton.less | 14 ++++++++
7 files changed, 88 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/fbbaaffa/src/fauxton/app/api.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js
index 5cf59a2..6f47bd8 100644
--- a/src/fauxton/app/api.js
+++ b/src/fauxton/app/api.js
@@ -335,10 +335,13 @@ function(app, Fauxton) {
reason: resp
};
- FauxtonAPI.addNotification({
- msg: 'An Error occurred ' + resp.responseText,
- type: 'error'
- });
+ if (resp) {
+ FauxtonAPI.addNotification({
+ msg: 'An Error occurred' + resp.responseText,
+ type: 'error'
+ });
+ }
+
masterLayout.renderView(selector);
});
@@ -352,8 +355,9 @@ function(app, Fauxton) {
});
});
}.bind(this), function (resp) {
+ if (!resp) { return; }
FauxtonAPI.addNotification({
- msg: 'An Error occurred ' + resp.responseText,
+ msg: 'An Error occurred' + resp.responseText,
type: 'error'
});
});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/fbbaaffa/src/fauxton/app/modules/documents/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js
index 70be81c..395d171 100644
--- a/src/fauxton/app/modules/documents/resources.js
+++ b/src/fauxton/app/modules/documents/resources.js
@@ -22,10 +22,6 @@ function(app, FauxtonAPI) {
Documents.Doc = Backbone.Model.extend({
idAttribute: "_id",
- defaults: {
- views: {}
- },
-
url: function(context) {
if (context === "app") {
return this.getDatabase().url("app") + "/" + this.safeID();
http://git-wip-us.apache.org/repos/asf/couchdb/blob/fbbaaffa/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 0edf18d..7a75740 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -205,7 +205,10 @@ function(app, FauxtonAPI, Documents, Databases) {
if (this.viewEditor) { this.viewEditor.remove(); }
- this.toolsView = this.setView("#dashboard-upper-menu", new Documents.Views.JumpToDoc({database: this.data.database}));
+ this.toolsView = this.setView("#dashboard-upper-menu", new Documents.Views.JumpToDoc({
+ database: this.data.database,
+ collection: this.data.database.allDocs
+ }));
this.documentsView = this.setView("#dashboard-lower-content", new Documents.Views.AllDocsList({
collection: this.data.database.allDocs
http://git-wip-us.apache.org/repos/asf/couchdb/blob/fbbaaffa/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 576e14e..3296a0d 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -646,7 +646,24 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
},
establish: function() {
- return [this.model.fetch()];
+ var promise = this.model.fetch(),
+ databaseId = this.database.id,
+ deferred = $.Deferred();
+
+ promise.then(function () {
+ deferred.resolve()
+ }, function (xhr, reason, msg) {
+ if (xhr.status === 404) {
+ FauxtonAPI.addNotification({
+ msg: 'The document does not exist',
+ type: 'error'
+ });
+ FauxtonAPI.navigate('/database/' + databaseId + '/_all_docs?limit=20');
+ }
+ deferred.reject();
+ });
+
+ return deferred;
},
saveDoc: function(event) {
@@ -1345,13 +1362,19 @@ function(app, FauxtonAPI, Components, Documents, pouchdb, Codemirror, JSHint, re
events: {
"submit #jump-to-doc": "jumpToDoc",
- "click #jump-to-doc-label": "jumpToDoc"
},
jumpToDoc: function (event) {
event.preventDefault();
+
var docId = this.$('#jump-to-doc-id').val();
+
FauxtonAPI.navigate('/database/' + this.database.id +'/' + docId, {trigger: true});
+ },
+
+ afterRender: function () {
+ this.typeAhead = new Components.DocSearchTypeahead({el: '#jump-to-doc-id', database: this.database});
+ this.typeAhead.render();
}
});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/fbbaaffa/src/fauxton/app/modules/fauxton/components.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/fauxton/components.js b/src/fauxton/app/modules/fauxton/components.js
index 10e08dc..09dcc51 100644
--- a/src/fauxton/app/modules/fauxton/components.js
+++ b/src/fauxton/app/modules/fauxton/components.js
@@ -105,6 +105,7 @@ function(app, FauxtonAPI) {
});
+
Components.DbSearchTypeahead = Components.Typeahead.extend({
initialize: function (options) {
this.dbLimit = options.dbLimit || 30;
@@ -133,6 +134,40 @@ function(app, FauxtonAPI) {
}
});
+ Components.DocSearchTypeahead = Components.Typeahead.extend({
+ initialize: function (options) {
+ this.docLimit = options.docLimit || 30;
+ this.database = options.database;
+ _.bindAll(this);
+ },
+ source: function(query, process) {
+ var url = [
+ app.host,
+ "/",
+ this.database.id,
+ "/_all_docs?startkey=%22",
+ query,
+ "%22&endkey=%22",
+ query,
+ "\u9999%22&limit=",
+ this.docLimit
+ ].join('');
+
+ if (this.ajaxReq) { this.ajaxReq.abort(); }
+
+ this.ajaxReq = $.ajax({
+ url: url,
+ dataType: 'json',
+ success: function(data) {
+ var ids = _.map(data.rows, function (row) {
+ return row.id;
+ });
+ process(ids);
+ }
+ });
+ }
+ });
+
return Components;
});
http://git-wip-us.apache.org/repos/asf/couchdb/blob/fbbaaffa/src/fauxton/app/templates/documents/jumpdoc.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/jumpdoc.html b/src/fauxton/app/templates/documents/jumpdoc.html
index 546134b..2e83c52 100644
--- a/src/fauxton/app/templates/documents/jumpdoc.html
+++ b/src/fauxton/app/templates/documents/jumpdoc.html
@@ -15,6 +15,6 @@ the License.
<form id="jump-to-doc" class="form-inline">
<label id="jump-to-doc-label" class="fonticon-search">
- <input type="text" id="jump-to-doc-id" class="input-large" placeholder="Document ID"></input>
+ <input type="text" id="jump-to-doc-id" class="i1nput-large" placeholder="Document ID"></input>
</label>
</form>
http://git-wip-us.apache.org/repos/asf/couchdb/blob/fbbaaffa/src/fauxton/assets/less/fauxton.less
----------------------------------------------------------------------
diff --git a/src/fauxton/assets/less/fauxton.less b/src/fauxton/assets/less/fauxton.less
index e5f5142..82e0a14 100644
--- a/src/fauxton/assets/less/fauxton.less
+++ b/src/fauxton/assets/less/fauxton.less
@@ -914,3 +914,17 @@ div.spinner {
}
}
}
+
+#jump-to-doc {
+ width: 88%;
+ max-width: 600px;
+
+ #jump-to-doc-label {
+ width: 100%;
+ }
+
+ #jump-to-doc-id {
+ width: 100%;
+ margin-top: -4px;
+ }
+}