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/10/29 12:16:25 UTC

fauxton commit: updated refs/heads/master to fcdedc7

Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master 30fadf1ac -> fcdedc7cf


Fix rendering on view-list after creating a view

AllDocsList is lazily adding subviews in the `beforeRender` method,
which causes that it will throw an error for all methods that
access these subviews from outside before explicitly rendering
the view.

As the beforeRender is adding paging, subviews, and the establish
takes care of our collection, we are fine with just rendering.

After we got this working, we can navigate without a
`trigger: false` and are getting a view on the indexed doc after
creating the view.


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

Branch: refs/heads/master
Commit: fcdedc7cf675047a38df9720362037cb4e97c4e8
Parents: 30fadf1
Author: Robert Kowalski <ro...@apache.org>
Authored: Tue Oct 28 15:54:02 2014 +0100
Committer: Robert Kowalski <ro...@apache.org>
Committed: Wed Oct 29 12:15:47 2014 +0100

----------------------------------------------------------------------
 app/addons/documents/routes-documents.js | 14 ++++++--------
 app/addons/documents/tests/routeSpec.js  | 12 ++++++++++++
 app/addons/documents/views-index.js      |  2 +-
 3 files changed, 19 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/fcdedc7c/app/addons/documents/routes-documents.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/routes-documents.js b/app/addons/documents/routes-documents.js
index 49e9c22..b885f33 100644
--- a/app/addons/documents/routes-documents.js
+++ b/app/addons/documents/routes-documents.js
@@ -357,10 +357,13 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
           urlParams = params.urlParams,
           docParams = params.docParams,
           ddoc = event.ddoc,
+          defaultPageSize,
+          isLazyInit,
           pageSize,
           collection;
 
-      var defaultPageSize = _.isUndefined(this.documentsView) ? 20 : this.documentsView.perPage();
+      isLazyInit = _.isUndefined(this.documentsView) || _.isUndefined(this.documentsView.allDocsNumber);
+      defaultPageSize = isLazyInit ? 20 : this.documentsView.perPage();
       docParams.limit = pageSize = this.getDocPerPageLimit(urlParams, defaultPageSize);
 
       if (event.allDocs) {
@@ -392,15 +395,10 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
         }
       }
 
-      this.documentsView.setCollection(collection);
       this.documentsView.setParams(docParams, urlParams);
-      this.documentsView.forceRender();
 
-      // this has been commented out because it causes the header bar to disappear after a search (i.e the "Query
-      // Options" link disappears). This issue is being addressed in a separate ticket (not sure about the Jira ID)
-//      this.apiUrl = function() {
-//        return [this.indexedDocs.urlRef("apiurl", urlParams), "docs"];
-//      };
+      // this will lazily initialize all sub-views and render them
+      this.documentsView.forceRender();
     },
 
     perPageChange: function (perPage) {

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/fcdedc7c/app/addons/documents/tests/routeSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/tests/routeSpec.js b/app/addons/documents/tests/routeSpec.js
index 9b6458f..c59003a 100644
--- a/app/addons/documents/tests/routeSpec.js
+++ b/app/addons/documents/tests/routeSpec.js
@@ -32,5 +32,17 @@ define([
       routeObj.viewFn('newdatabase', 'ads', 'newView');
       assert.equal(typeof routeObj.rightHeader, 'object');
     });
+
+    // after saving a new CouchDB-View we are calling the updateAllDocsFromView function.
+    // The backbone-view AllDocsList is lazily initializing other views, in particular the
+    // view AllDocsNumber and the pagination in the beforeRender method.
+    // That means the we can not access .setCollection and .perPage from outside
+    // before we render the view.
+    it('does not fail because of lazy initializing race conditions', function () {
+      var routeObj = new DocumentRoute(null, null, ['test']);
+      routeObj.updateAllDocsFromView({ddoc: "_design/asdfsadf", view: "newView"});
+
+      assert.equal(typeof routeObj.documentsView, 'object');
+    });
   });
 });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/fcdedc7c/app/addons/documents/views-index.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/views-index.js b/app/addons/documents/views-index.js
index cbc76ad..128be04 100644
--- a/app/addons/documents/views-index.js
+++ b/app/addons/documents/views-index.js
@@ -189,7 +189,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, QueryOption
           if (that.newView || viewNameChange) {
             var fragment = '/database/' + that.database.safeID() +'/' + ddoc.safeID() + '/_views/' + app.utils.safeURLName(viewName);
 
-            FauxtonAPI.navigate(fragment, { trigger: false });
+            FauxtonAPI.navigate(fragment);
             that.newView = false;
             that.ddocID = ddoc.safeID();
             that.viewName = viewName;