couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject [8/50] [abbrv] git commit: context specific search box for database
Date Mon, 11 Feb 2013 11:12:15 GMT
context specific search box for database

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

Branch: refs/heads/fauxton
Commit: 48752ff3bae1d70be21e3d1a64bf751ea3f26abb
Parents: 67d81a4
Author: Simon Metson <simon+github@cloudant.com>
Authored: Thu Jan 3 00:07:32 2013 +0000
Committer: Simon Metson <simon+github@cloudant.com>
Committed: Fri Jan 18 16:55:25 2013 -0500

----------------------------------------------------------------------
 .../app/addons/stats/templates/by_code.html        |    2 +-
 src/fauxton/app/modules/documents/routes.js        |   10 ++-
 src/fauxton/app/modules/documents/views.js         |   62 ++++++++++++++-
 src/fauxton/app/templates/documents/search.html    |    1 +
 src/fauxton/app/templates/documents/tabs.html      |    4 +-
 5 files changed, 72 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/48752ff3/src/fauxton/app/addons/stats/templates/by_code.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/stats/templates/by_code.html b/src/fauxton/app/addons/stats/templates/by_code.html
index cc3672a..4414b07 100644
--- a/src/fauxton/app/addons/stats/templates/by_code.html
+++ b/src/fauxton/app/addons/stats/templates/by_code.html
@@ -1,3 +1,3 @@
 <h2>By Code <small>200, 201, 404, 409</small></h2>
 <div id="httpd_status_codes"></div>
-<b>Total requests:</b> <%= statistics.reduce(function(memo, d){ return memo
+ d.y; }, 0) %>
\ No newline at end of file
+<b>Total requests:</b> <%= statistics.reduce(function(memo, d){return memo
+ d.get("sum"); }, 0) %>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/couchdb/blob/48752ff3/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 233308d..efaa374 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -249,7 +249,10 @@ function(app, FauxtonAPI, Documents, Databases) {
             collection: data.designDocs
           }),
 
-          "#tabs": new Documents.Views.Tabs({})
+          "#tabs": new Documents.Views.Tabs({
+            collection: data.designDocs,
+            database: data.database.id
+          })
         },
 
         apiUrl: data.database.allDocs.url()
@@ -307,7 +310,10 @@ function(app, FauxtonAPI, Documents, Databases) {
             collection: data.designDocs
           }),
 
-          "#tabs": new Documents.Views.Tabs({})
+          "#tabs": new Documents.Views.Tabs({
+            collection: data.designDocs,
+            database: data.database.id
+          })
         },
 
         crumbs: [

http://git-wip-us.apache.org/repos/asf/couchdb/blob/48752ff3/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 d942887..31db461 100644
--- a/src/fauxton/app/modules/documents/views.js
+++ b/src/fauxton/app/modules/documents/views.js
@@ -16,7 +16,67 @@ function(app, FauxtonAPI, Codemirror, JSHint) {
   var Views = {};
 
   Views.Tabs = FauxtonAPI.View.extend({
-    template: "templates/documents/tabs"
+    template: "templates/documents/tabs",
+    initialize: function(options){
+      this.collection = options.collection;
+      this.database = options.database;
+    },
+    beforeRender: function(manage) {
+      this.insertView("#search", new Views.SearchBox({
+        collection: this.collection,
+        database: this.database
+      }));
+    }
+  });
+
+  Views.SearchBox = FauxtonAPI.View.extend({
+    template: "templates/documents/search",
+    tagName: "form",
+    initialize: function(options){
+      this.collection = options.collection;
+      this.database = options.database;
+    },
+    afterRender: function(){
+      var collection = this.collection;
+      var form = this.$el;
+      var searchbox = form.find("input#searchbox");
+      var database = this.database;
+
+      form.submit(function(evt){
+        evt.preventDefault();
+        var viewname = form.find("input#view").val().split('/');
+        var url = "#database/" + database + "/_design/";
+        url += viewname[0] + "/_view/" + viewname[1];
+        if (searchbox.val() !== ""){
+          // TODO: this'll need to work when val() is a number etc.
+          url += '?start_key="' + searchbox.val() + '"';
+        }
+        FauxtonAPI.navigate(url);
+      });
+
+      searchbox.typeahead({
+        source: function(query, process) {
+          // TODO: include _all_docs and view keys somehow
+          var views = _.map(collection.pluck('doc'), function(d){
+            return _.map(_.keys(d.views), function(view){
+              return d._id.split('/')[1] + "/" + view;
+            });
+          });
+          return _.flatten(views);
+        },
+        minLength: 3,
+        updater: function(item){
+          // TODO: some way to return the original search box
+          this.$element.removeClass('span12');
+          this.$element.addClass('span6');
+          this.$element.attr('placeholder', 'Search by view key');
+          $('<span class="add-on span6">' + item +'</span>').insertBefore(this.$element);
+          $('<input type="hidden" id="view" value="' + item +'"/>').insertBefore(this.$element);
+          // Remove the type ahead for now
+          $('.typehead').unbind();
+        }
+      });
+    }
   });
 
   Views.FieldEditorTabs = FauxtonAPI.View.extend({

http://git-wip-us.apache.org/repos/asf/couchdb/blob/48752ff3/src/fauxton/app/templates/documents/search.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/search.html b/src/fauxton/app/templates/documents/search.html
new file mode 100644
index 0000000..ee67e7d
--- /dev/null
+++ b/src/fauxton/app/templates/documents/search.html
@@ -0,0 +1 @@
+<input id="searchbox" type="text" class="span12" placeholder="Search by doc id, view key
or search index">
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/couchdb/blob/48752ff3/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 7befec2..8cca6c3 100644
--- a/src/fauxton/app/templates/documents/tabs.html
+++ b/src/fauxton/app/templates/documents/tabs.html
@@ -2,9 +2,7 @@
   <li class="active"><a href="#">Docs</a></li>
   <li><a href="#">Permissions</a></li>
   <li><a href="#">Stats</a></li>
-  <form class="navbar-search nav pull-right">
-    <input type="text" class="search-query" placeholder="Search by doc id">
-  </form>
+  <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;">
     <li>


Mime
View raw message