You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ro...@apache.org on 2014/07/17 19:14:16 UTC

[04/10] fauxton commit: updated refs/heads/2158-changes-filter to b1121db

Fauxton: Implement a filter for changes

As code is duplicated, mode the filter to the component. Tthe filter
then can be overwritten if there anything special is needed.


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

Branch: refs/heads/2158-changes-filter
Commit: 8ff72f889bf9a07fd7a49568dd426978ab2769aa
Parents: 99665a1
Author: Robert Kowalski <ro...@kowalski.gd>
Authored: Thu May 8 21:26:36 2014 +0200
Committer: Robert Kowalski <ro...@kowalski.gd>
Committed: Thu Jul 17 19:13:37 2014 +0200

----------------------------------------------------------------------
 app/addons/documents/routes.js                  |  4 ++-
 .../documents/templates/changes_sidebar.html    | 18 +++++++++++
 app/addons/documents/views.js                   | 26 +++++++++++++--
 app/addons/fauxton/templates/filter.html        |  2 +-
 app/core/base.js                                | 34 ++++++++++++++++++++
 5 files changed, 79 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/8ff72f88/app/addons/documents/routes.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/routes.js b/app/addons/documents/routes.js
index a21bdaa..a4a0baa 100644
--- a/app/addons/documents/routes.js
+++ b/app/addons/documents/routes.js
@@ -452,7 +452,7 @@ function(app, FauxtonAPI, Documents, Databases) {
   });
 
   var ChangesRouteObject = FauxtonAPI.RouteObject.extend({
-    layout: "with_tabs",
+    layout: "with_sidebar",
     selectedHeader: "Databases",
     crumbs: function () {
       return [
@@ -478,6 +478,8 @@ function(app, FauxtonAPI, Documents, Databases) {
       this.setView("#dashboard-content", new Documents.Views.Changes({
         model: this.database
       }));
+
+      this.setView("#sidebar-content", new Documents.Views.ChangesSidebar());
     },
 
     apiUrl: function() {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/8ff72f88/app/addons/documents/templates/changes_sidebar.html
----------------------------------------------------------------------
diff --git a/app/addons/documents/templates/changes_sidebar.html b/app/addons/documents/templates/changes_sidebar.html
new file mode 100644
index 0000000..9f3d369
--- /dev/null
+++ b/app/addons/documents/templates/changes_sidebar.html
@@ -0,0 +1,18 @@
+<!--
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this file except in compliance with the License. You may obtain a copy of
+the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations under
+the License.
+-->
+
+<div class="sidebar-content" id="changes-sidebar">
+  <header>Changes Filter</header>
+  <div class="js-filter"></div>
+</div>

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/8ff72f88/app/addons/documents/views.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/views.js b/app/addons/documents/views.js
index 6ccb733..e035449 100644
--- a/app/addons/documents/views.js
+++ b/app/addons/documents/views.js
@@ -1920,12 +1920,18 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
 
   Views.Indexed = FauxtonAPI.View.extend({});
 
+  Views.ChangesEvents = {};
+  _.extend(Views.ChangesEvents, Backbone.Events);
+
   Views.Changes = FauxtonAPI.View.extend({
     template: "addons/documents/templates/changes",
 
     initialize: function () {
-      this.listenTo( this.model.changes, 'sync', this.render);
-      this.listenTo( this.model.changes, 'cachesync', this.render);
+      this.listenTo(this.model.changes, 'sync', this.render);
+      this.listenTo(this.model.changes, 'cachesync', this.render);
+
+      this.listenTo(Views.ChangesEvents, "changes:filter", this.filter);
+      this.listenTo(Views.ChangesEvents, "changes:remove", this.removeFilter);
     },
 
     events: {
@@ -1957,8 +1963,10 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
     },
 
     serialize: function () {
+      var json = this.model.changes.toJSON(),
+          filteredData = this.createFilteredData(json);
       return {
-        changes: this.model.changes.toJSON(),
+        changes: filteredData,
         database: this.model
       };
     },
@@ -1970,6 +1978,18 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb,
     }
   });
 
+  Views.ChangesSidebar = FauxtonAPI.View.extend({
+    template: "addons/documents/templates/changes_sidebar",
+
+    initialize: function (options) {
+
+      this.setView(".js-filter", new Components.FilterView({
+        eventListener: Views.ChangesEvents,
+        eventNamespace: "changes"
+      }));
+    }
+  });
+
   Views.DdocInfo = FauxtonAPI.View.extend({
     template: "addons/documents/templates/ddoc_info",
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/8ff72f88/app/addons/fauxton/templates/filter.html
----------------------------------------------------------------------
diff --git a/app/addons/fauxton/templates/filter.html b/app/addons/fauxton/templates/filter.html
index d7930fc..7c3a33c 100644
--- a/app/addons/fauxton/templates/filter.html
+++ b/app/addons/fauxton/templates/filter.html
@@ -14,7 +14,7 @@ the License.
 
 <form class="form-inline js-log-filter-form">
   <fieldset>
-    <input type="text" name="filter" placeholder="Type a filter to sort the logs by">
+    <input type="text" name="filter" placeholder="Type a filter">
     <button type="submit" class="btn">Filter</button>
     <span class="help-block"> <h6> Eg. debug or <1.4.1> or any regex </h6> </span>
   </fieldset>

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/8ff72f88/app/core/base.js
----------------------------------------------------------------------
diff --git a/app/core/base.js b/app/core/base.js
index 15499b3..3425ca1 100644
--- a/app/core/base.js
+++ b/app/core/base.js
@@ -62,9 +62,43 @@ function(Backbone, LayoutManager) {
     manage: true,
     disableLoader: false,
 
+    filters: [],
+
     forceRender: function () {
       this.hasRendered = false;
+    },
+
+    filter: function (filter) {
+      this.filters.push(filter);
+      this.render();
+    },
+
+    createFilteredData: function (json) {
+      var that = this;
+
+      return _.reduce(this.filters, function (elements, filter) {
+
+        return _.filter(elements, function (element) {
+          var match = false;
+
+          _.each(element, function (value) {
+            if (new RegExp(filter).test(value.toString())) {
+              match = true;
+            }
+          });
+          return match;
+        });
+
+
+      }, json, this);
+
+    },
+
+    removeFilter: function (filter) {
+      this.filters.splice(this.filters.indexOf(filter), 1);
+      this.render();
     }
+
   });
 
   var caching = {