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 2014/09/30 15:24:10 UTC

fauxton commit: updated refs/heads/master to c0af4a2

Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master fcb7116c5 -> c0af4a2ef


Override breadcrumbs

In documents module the routeObject manages the breadcrumbs via the
leftheader and does not need the fauxton module's event handlers to
automatically manage the breadcrumbs. This adds an override flag so that
the breadcrumbs won't be automatically added.


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

Branch: refs/heads/master
Commit: c0af4a2ef93789263856065a1cc4d1e04593a837
Parents: fcb7116
Author: Garren Smith <ga...@gmail.com>
Authored: Mon Sep 29 11:01:28 2014 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Tue Sep 30 15:23:30 2014 +0200

----------------------------------------------------------------------
 app/addons/documents/routes-documents.js    | 12 +---
 app/addons/fauxton/base.js                  |  2 +
 app/addons/fauxton/tests/breadcrumbsSpec.js | 91 ++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/c0af4a2e/app/addons/documents/routes-documents.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/routes-documents.js b/app/addons/documents/routes-documents.js
index 72478c8..36bf4ed 100644
--- a/app/addons/documents/routes-documents.js
+++ b/app/addons/documents/routes-documents.js
@@ -88,6 +88,8 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
       "route:changesFilterRemove": "removeFilter"
     },
 
+    overrideBreadcrumbs: true,
+
     initialize: function (route, masterLayout, options) {
       this.databaseName = options[0];
 
@@ -184,7 +186,6 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
 
 
       this.leftheader.updateCrumbs(crumbs.allDocs(this.database)); 
-      this.leftheader.forceRender();
 
       this.apiUrl = [designDocInfo.url('apiurl'), designDocInfo.documentation() ];
 
@@ -229,7 +230,6 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
       }
 
       this.leftheader.updateCrumbs(crumbs.allDocs(this.database)); 
-      this.leftheader.forceRender();
       this.database.buildAllDocs(docParams);
 
       if (docParams.startkey && docParams.startkey.indexOf('_design') > -1) {
@@ -303,7 +303,6 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
       this.sidebar.setSelectedTab(app.utils.removeSpecialCharacters(ddoc) + '_' + app.utils.removeSpecialCharacters(view));
 
       this.rightHeader.updateApiUrl([this.indexedDocs.urlRef("apiurl", urlParams), "docs"]);
-      this.leftheader.forceRender();
     },
 
     ddocInfo: function (designDoc, designDocs, view) {
@@ -344,7 +343,6 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
       this.sidebar.setSelectedTab('new-view');
 
       //this.rightHeader.updateApiUrl([this.indexedDocs.urlRef("apiurl", urlParams), "docs"]);
-      this.leftheader.forceRender();
     },
 
     updateAllDocsFromView: function (event) {
@@ -403,21 +401,18 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
       this.documentsView.forceRender();
       this.documentsView.collection.pageSizeReset(perPage, {fetch: false});
       this.setDocPerPageLimit(perPage);
-      this.leftheader.forceRender();
     },
 
     paginate: function (options) {
       var collection = this.documentsView.collection;
 
       this.documentsView.forceRender();
-      this.leftheader.forceRender();
       collection.paging.pageSize = options.perPage;
       var promise = collection[options.direction]({fetch: false});
     },
 
     reloadDesignDocs: function (event) {
       this.sidebar.forceRender();
-      this.leftheader.forceRender();
 
       if (event && event.selectedTab) {
         this.sidebar.setSelectedTab(event.selectedTab);
@@ -472,20 +467,17 @@ function(app, FauxtonAPI, Documents, Changes, Index, DocEditor, Databases, Resou
       this.sidebar.setSelectedTab('changes');
 
       this.leftheader.updateCrumbs(crumbs.changes(this.database));
-      this.leftheader.forceRender();
       this.rightHeader.updateApiUrl([this.database.url("changes-apiurl"), this.database.documentation()]);
     },
 
     addFilter: function (filter) {
       this.changesView.filters.push(filter);
       this.changesView.render();
-      this.leftheader.forceRender();
     },
 
     removeFilter: function (filter) {
       this.changesView.filters.splice(this.changesView.filters.indexOf(filter), 1);
       this.changesView.render();
-      this.leftheader.forceRender();
     }
 
   });

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/c0af4a2e/app/addons/fauxton/base.js
----------------------------------------------------------------------
diff --git a/app/addons/fauxton/base.js b/app/addons/fauxton/base.js
index 42ad996..1114c50 100644
--- a/app/addons/fauxton/base.js
+++ b/app/addons/fauxton/base.js
@@ -72,6 +72,8 @@ function(app, FauxtonAPI, resizeColumns, Components, ZeroClipboard) {
     });
 
     FauxtonAPI.RouteObject.on('beforeEstablish', function (routeObject) {
+      if (routeObject.overrideBreadcrumbs) { return; }
+
       FauxtonAPI.masterLayout.removeView('#breadcrumbs');
       var crumbs = routeObject.get('crumbs');
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/c0af4a2e/app/addons/fauxton/tests/breadcrumbsSpec.js
----------------------------------------------------------------------
diff --git a/app/addons/fauxton/tests/breadcrumbsSpec.js b/app/addons/fauxton/tests/breadcrumbsSpec.js
new file mode 100644
index 0000000..c209de0
--- /dev/null
+++ b/app/addons/fauxton/tests/breadcrumbsSpec.js
@@ -0,0 +1,91 @@
+// 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.
+define([
+  'api',
+  'addons/fauxton/base',
+  'testUtils'
+], function (FauxtonAPI, Fauxton, testUtils) {
+  var assert = testUtils.assert;
+
+  describe('Breadcrumbs', function () {
+
+    describe('can be overriden in routeObject', function () {
+      var routeObj;
+
+      beforeEach(function () {
+        var RouteObj = FauxtonAPI.RouteObject.extend({
+          overrideBreadcrumbs: true,
+          crumbs: ["crumb"]
+        });
+        routeObj = new RouteObj({});
+      });
+
+      it('should not remove old breadcrumbs', function () {
+        var removeViewSpy = sinon.spy(FauxtonAPI.masterLayout, 'removeView');
+
+        routeObj.triggerBroadcast('beforeEstablish');
+        assert.notOk(removeViewSpy.called);
+        FauxtonAPI.masterLayout.removeView.restore();
+      });
+    });
+
+    //Breadcrumbs are create and managed in Fauxton/base.js
+    //If the route object has a crumbs function a breadcrumbs view is created
+    //and rendered on the page in #breadcrumbs
+    describe('Auto creation of breadcrumbs', function () {
+      var routeObj;
+
+      beforeEach(function () {
+        var RouteObj = FauxtonAPI.RouteObject.extend({
+          crumbs: ["crumb1", "crumb2"]
+        });
+        routeObj = new RouteObj({});
+      });
+
+      afterEach(function () {
+        if (FauxtonAPI.masterLayout.removeView.restore) {
+          FauxtonAPI.masterLayout.removeView.restore();
+        }
+
+        if (FauxtonAPI.masterLayout.setView.restore) {
+          FauxtonAPI.masterLayout.setView.restore();
+        }
+      });
+
+      it('should remove old breadcrumbs', function () {
+        var removeViewSpy = sinon.spy(FauxtonAPI.masterLayout, 'removeView');
+
+        routeObj.triggerBroadcast('beforeEstablish');
+        assert.ok(removeViewSpy.called);
+      });
+
+      it('should create new breadcrumbs', function () {
+        var setViewSpy = sinon.spy(FauxtonAPI.masterLayout, 'setView');
+
+        routeObj.triggerBroadcast('beforeEstablish');
+        assert.equal(setViewSpy.getCall(0).args[0], '#breadcrumbs');
+      });
+
+      it('should not create new breadcrumbs when no crumbs are on routeObject', function () {
+        var removeViewSpy = sinon.spy(FauxtonAPI.masterLayout, 'setView');
+        routeObj.crumbs = [];
+        routeObj.triggerBroadcast('beforeEstablish');
+
+        assert.notOk(removeViewSpy.called);
+      });
+
+    });
+  });
+
+
+});
+