Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 12E581163A for ; Thu, 17 Jul 2014 17:14:14 +0000 (UTC) Received: (qmail 16776 invoked by uid 500); 17 Jul 2014 17:14:14 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 16567 invoked by uid 500); 17 Jul 2014 17:14:13 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 16428 invoked by uid 99); 17 Jul 2014 17:14:13 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Jul 2014 17:14:13 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 9F2EF8C0B91; Thu, 17 Jul 2014 17:14:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: robertkowalski@apache.org To: commits@couchdb.apache.org Date: Thu, 17 Jul 2014 17:14:17 -0000 Message-Id: <85471f904ea641a89e4cd3fecc8a307c@git.apache.org> In-Reply-To: <040a73fad9184f96ade72fe81f85269e@git.apache.org> References: <040a73fad9184f96ade72fe81f85269e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [05/10] fauxton commit: updated refs/heads/2158-changes-filter to b1121db review Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/263d328d Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/263d328d Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/263d328d Branch: refs/heads/2158-changes-filter Commit: 263d328dace3756a5bec0eb59a241ba6e8187898 Parents: 8ff72f8 Author: Robert Kowalski Authored: Fri May 16 20:44:15 2014 +0200 Committer: Robert Kowalski Committed: Thu Jul 17 19:13:37 2014 +0200 ---------------------------------------------------------------------- app/addons/documents/routes.js | 30 +++++++++++++++++++--- app/addons/documents/views.js | 14 ++-------- app/addons/fauxton/components.js | 33 +++++++++++++++++++----- app/addons/fauxton/tests/filterViewSpec.js | 28 ++++---------------- app/core/base.js | 34 ------------------------- 5 files changed, 59 insertions(+), 80 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/263d328d/app/addons/documents/routes.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/routes.js b/app/addons/documents/routes.js index a4a0baa..bf62f0a 100644 --- a/app/addons/documents/routes.js +++ b/app/addons/documents/routes.js @@ -17,10 +17,11 @@ define([ // Modules "addons/documents/views", - "addons/databases/base" + "addons/databases/base", + "addons/fauxton/components" ], -function(app, FauxtonAPI, Documents, Databases) { +function(app, FauxtonAPI, Documents, Databases, Components) { var DocEditorRouteObject = FauxtonAPI.RouteObject.extend({ layout: "one_pane", @@ -465,6 +466,11 @@ function(app, FauxtonAPI, Documents, Databases) { "database/:database/_changes(:params)": "changes" }, + events: { + "route:changesFilterAdd": "addFilter", + "route:changesFilterRemove": "removeFilter" + }, + initialize: function (route, masterLayout, options) { this.databaseName = options[0]; this.database = new Databases.Model({id: this.databaseName}); @@ -475,11 +481,27 @@ function(app, FauxtonAPI, Documents, Databases) { }, changes: function (event) { - this.setView("#dashboard-content", new Documents.Views.Changes({ + this.dashboardView = this.setView("#dashboard-content", new Documents.Views.Changes({ model: this.database })); - this.setView("#sidebar-content", new Documents.Views.ChangesSidebar()); + this.filterView = new Components.FilterView({ + eventNamespace: "changes" + }); + + this.sideBarView = this.setView("#sidebar-content", new Documents.Views.ChangesSidebar({ + filterView: this.filterView + })); + }, + + addFilter: function (filter) { + this.dashboardView.filters.push(filter); + this.dashboardView.render(); + }, + + removeFilter: function (filter) { + this.dashboardView.filters.splice(this.dashboardView.filters.indexOf(filter), 1); + this.dashboardView.render(); }, apiUrl: function() { http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/263d328d/app/addons/documents/views.js ---------------------------------------------------------------------- diff --git a/app/addons/documents/views.js b/app/addons/documents/views.js index e035449..eb129f2 100644 --- a/app/addons/documents/views.js +++ b/app/addons/documents/views.js @@ -1920,18 +1920,12 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, Views.Indexed = FauxtonAPI.View.extend({}); - Views.ChangesEvents = {}; - _.extend(Views.ChangesEvents, Backbone.Events); - - Views.Changes = FauxtonAPI.View.extend({ + Views.Changes = Components.FilteredView.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(Views.ChangesEvents, "changes:filter", this.filter); - this.listenTo(Views.ChangesEvents, "changes:remove", this.removeFilter); }, events: { @@ -1982,11 +1976,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, template: "addons/documents/templates/changes_sidebar", initialize: function (options) { - - this.setView(".js-filter", new Components.FilterView({ - eventListener: Views.ChangesEvents, - eventNamespace: "changes" - })); + this.setView(".js-filter", options.filterView); } }); http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/263d328d/app/addons/fauxton/components.js ---------------------------------------------------------------------- diff --git a/app/addons/fauxton/components.js b/app/addons/fauxton/components.js index 79a9320..de633f3 100644 --- a/app/addons/fauxton/components.js +++ b/app/addons/fauxton/components.js @@ -339,11 +339,34 @@ function(app, FauxtonAPI, ace, spin) { } }); + Components.FilteredView = FauxtonAPI.View.extend({ + filters: [], + + 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); + } + }); + Components.FilterView = FauxtonAPI.View.extend({ template: "addons/fauxton/templates/filter", initialize: function (options) { - this.eventListener = options.eventListener; this.eventNamespace = options.eventNamespace; }, @@ -360,17 +383,15 @@ function(app, FauxtonAPI, ace, spin) { return; } - this.eventListener.trigger(this.eventNamespace + ":filter", filter); + FauxtonAPI.triggerRouteEvent(this.eventNamespace + "FilterAdd", filter); this.insertView(".filter-list", new Components.FilterItemView({ filter: filter, - eventListener: this.eventListener, eventNamespace: this.eventNamespace })).render(); $filter.val(''); } - }); Components.FilterItemView = FauxtonAPI.View.extend({ @@ -379,7 +400,6 @@ function(app, FauxtonAPI, ace, spin) { initialize: function (options) { this.filter = options.filter; - this.eventListener = options.eventListener; this.eventNamespace = options.eventNamespace; }, @@ -395,8 +415,7 @@ function(app, FauxtonAPI, ace, spin) { removeFilter: function (event) { event.preventDefault(); - - this.eventListener.trigger(this.eventNamespace + ":remove", this.filter); + FauxtonAPI.triggerRouteEvent(this.eventNamespace + "FilterRemove", this.filter); this.remove(); } http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/263d328d/app/addons/fauxton/tests/filterViewSpec.js ---------------------------------------------------------------------- diff --git a/app/addons/fauxton/tests/filterViewSpec.js b/app/addons/fauxton/tests/filterViewSpec.js index fec970d..7bfd0a6 100644 --- a/app/addons/fauxton/tests/filterViewSpec.js +++ b/app/addons/fauxton/tests/filterViewSpec.js @@ -17,18 +17,18 @@ define([ 'api' ], function (app, Components, testUtils, FauxtonAPI) { var assert = testUtils.assert, - ViewSandbox = testUtils.ViewSandbox, - myEvents = {}; - - _.extend(myEvents, Backbone.Events); + ViewSandbox = testUtils.ViewSandbox; describe('FilterView', function () { var viewSandbox, filterView; + if (!FauxtonAPI.router.triggerRouteEvent) { + FauxtonAPI.router.triggerRouteEvent = function () {}; + } + beforeEach(function () { filterView = new Components.FilterView({ - eventListener: myEvents, eventNamespace: 'mynamespace' }); @@ -40,24 +40,6 @@ define([ viewSandbox.remove(); }); - it('should trigger an event on add', function () { - filterView.$('[name="filter"]').val('i am a lonely filter'); - myEvents.listenToOnce(myEvents, 'ente:filter', function (msg) { - assert.equal('i am a lonely filter', msg); - }); - filterView.$('.js-log-filter-form').submit(); - }); - - it('should trigger an event on remove', function () { - myEvents.listenToOnce(myEvents, 'mynamespace:filter', function (msg) { - assert.equal('i am a lonely filter', msg); - }); - - filterView.$('[name="filter"]').val('i am a lonely filter'); - filterView.$('.js-log-filter-form').submit(); - filterView.$('.js-remove-filter').click(); - }); - it('should add filter markup', function () { filterView.$('[name="filter"]').val('i was a lonely filter'); filterView.$('.js-log-filter-form').submit(); http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/263d328d/app/core/base.js ---------------------------------------------------------------------- diff --git a/app/core/base.js b/app/core/base.js index 3425ca1..15499b3 100644 --- a/app/core/base.js +++ b/app/core/base.js @@ -62,43 +62,9 @@ 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 = {