couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [14/16] couchdb commit: updated refs/heads/fauxton-file-reorder to 8f67a9f
Date Wed, 29 Jan 2014 13:54:41 GMT
Fixes from reviews


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

Branch: refs/heads/fauxton-file-reorder
Commit: 652f8890212bc4c74446a5e3d2820c87ac6037a4
Parents: 864e0d1
Author: Garren Smith <garren.smith@gmail.com>
Authored: Mon Jan 27 10:17:33 2014 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Wed Jan 29 15:48:54 2014 +0200

----------------------------------------------------------------------
 src/fauxton/app/addons/documents/resources.js   |  17 +--
 src/fauxton/app/addons/documents/views.js       |   2 +-
 src/fauxton/app/addons/fauxton/base.js          |  28 +++-
 src/fauxton/app/addons/fauxton/layout.js        |  89 ------------
 .../app/addons/fauxton/tests/baseSpec.js        |  11 +-
 src/fauxton/app/app.js                          |   2 +-
 src/fauxton/app/core/api.js                     |   3 +-
 src/fauxton/app/core/layout.js                  |  43 +++---
 src/fauxton/app/router.js                       | 142 -------------------
 src/fauxton/test/mocha/testUtils.js             |   2 +-
 10 files changed, 56 insertions(+), 283 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/652f8890/src/fauxton/app/addons/documents/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/resources.js b/src/fauxton/app/addons/documents/resources.js
index 75cd541..831d5e3 100644
--- a/src/fauxton/app/addons/documents/resources.js
+++ b/src/fauxton/app/addons/documents/resources.js
@@ -18,21 +18,6 @@ define([
 function(app, FauxtonAPI) {
   var Documents = FauxtonAPI.addon();
 
-  Documents.UUID = FauxtonAPI.Model.extend({
-    initialize: function(options) {
-      options = _.extend({count: 1}, options);
-      this.count = options.count;
-    },
-
-    url: function() {
-      return "/_uuids?count=" + this.count;
-    },
-
-    next: function() {
-      return this.get("uuids").pop();
-    }
-  });
-
   Documents.Doc = Backbone.Model.extend({
     idAttribute: "_id",
     documentation: function(){
@@ -273,7 +258,7 @@ function(app, FauxtonAPI) {
 
   Documents.NewDoc = Documents.Doc.extend({
     fetch: function() {
-      var uuid = new Documents.UUID();
+      var uuid = new FauxtonAPI.UUID();
       var deferred = this.deferred = $.Deferred();
       var that = this;
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/652f8890/src/fauxton/app/addons/documents/views.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/views.js b/src/fauxton/app/addons/documents/views.js
index 6cdd1db..aeb5983 100644
--- a/src/fauxton/app/addons/documents/views.js
+++ b/src/fauxton/app/addons/documents/views.js
@@ -264,7 +264,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
     showModal: function () {
       var showModal = this._showModal,
           setDefaultIdValue = this.setDefaultIdValue,
-          uuid = new Documents.UUID();
+          uuid = new FauxtonAPI.UUID();
 
       uuid.fetch().then(function () {
         setDefaultIdValue(uuid.next());

http://git-wip-us.apache.org/repos/asf/couchdb/blob/652f8890/src/fauxton/app/addons/fauxton/base.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/fauxton/base.js b/src/fauxton/app/addons/fauxton/base.js
index b42188e..35babb5 100644
--- a/src/fauxton/app/addons/fauxton/base.js
+++ b/src/fauxton/app/addons/fauxton/base.js
@@ -30,14 +30,30 @@ function(app, FauxtonAPI, resizeColumns) {
     return view.renderNotification();
   };
 
+  FauxtonAPI.UUID = FauxtonAPI.Model.extend({
+    initialize: function(options) {
+      options = _.extend({count: 1}, options);
+      this.count = options.count;
+    },
+
+    url: function() {
+      return app.host + "/_uuids?count=" + this.count;
+    },
+
+    next: function() {
+      return this.get("uuids").pop();
+    }
+  });
+
+
   Fauxton.initialize = function () {
     app.footer = new Fauxton.Footer({el: "#footer-content"}),
     app.navBar = new Fauxton.NavBar();
     app.apiBar = new Fauxton.ApiBar();
 
     FauxtonAPI.when.apply(null, app.footer.establish()).done(function() {
-      FauxtonAPI.masterLayout.layout.setView("#primary-navbar", app.navBar);
-      FauxtonAPI.masterLayout.layout.setView("#api-navbar", app.apiBar);
+      FauxtonAPI.masterLayout.setView("#primary-navbar", app.navBar, true);
+      FauxtonAPI.masterLayout.setView("#api-navbar", app.apiBar, true);
       app.navBar.render();
       app.apiBar.render();
 
@@ -57,13 +73,13 @@ function(app, FauxtonAPI, resizeColumns) {
     });
 
     FauxtonAPI.RouteObject.on('beforeEstablish', function (routeObject) {
-      FauxtonAPI.masterLayout.clearBreadcrumbs();
+      FauxtonAPI.masterLayout.removeView('#breadcrumbs');
       var crumbs = routeObject.get('crumbs');
 
       if (crumbs.length) {
-        FauxtonAPI.masterLayout.setBreadcrumbs(new Fauxton.Breadcrumbs({
+        FauxtonAPI.masterLayout.setView('#breadcrumbs', new Fauxton.Breadcrumbs({
           crumbs: crumbs
-        }));
+        }), true).render();
       }
     });
 
@@ -163,8 +179,6 @@ function(app, FauxtonAPI, resizeColumns) {
       } else {
         this.navLinks.push(link);
       }
-
-      //this.render();
     },
 
     removeLink: function (removeLink) {

http://git-wip-us.apache.org/repos/asf/couchdb/blob/652f8890/src/fauxton/app/addons/fauxton/layout.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/fauxton/layout.js b/src/fauxton/app/addons/fauxton/layout.js
deleted file mode 100644
index baac864..0000000
--- a/src/fauxton/app/addons/fauxton/layout.js
+++ /dev/null
@@ -1,89 +0,0 @@
-// 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(["backbone"],
-
-function(Backbone) {
-
-  // A wrapper of the main Backbone.layoutmanager
-  // Allows the main layout of the page to be changed by any plugin.
-  // Exposes the different views:
-  //    navBar -> the top navigation bar
-  //    dashboardContent -> Main display view
-  //    breadcrumbs -> Breadcrumbs navigation section
-  var Layout = function () {
-    this.layout = new Backbone.Layout({
-      template: "templates/layouts/with_sidebar",
-    });
-
-    this.layoutViews = {};
-    this.el = this.layout.el;
-  };
-
-  Layout.configure = function (options) {
-    Backbone.Layout.configure(options);
-  };
-
-  // creatings the dashboard object same way backbone does
-  _.extend(Layout.prototype, {
-    render: function () {
-      return this.layout.render();
-    },
-
-    setTemplate: function(template) {
-      if (template.prefix){
-        this.layout.template = template.prefix + template.name;
-      } else{
-        this.layout.template = "templates/layouts/" + template;
-      }
-      // If we're changing layouts all bets are off, so kill off all the
-      // existing views in the layout.
-      _.each(this.layoutViews, function(view){view.remove();});
-      this.layoutViews = {};
-      this.render();
-    },
-
-    setTabs: function(view){
-      // TODO: Not sure I like this - seems fragile/repetitive
-      this.tabs = this.layout.setView("#tabs", view);
-      this.tabs.render();
-    },
-
-    setBreadcrumbs: function(view) {
-      this.breadcrumbs = this.layout.setView("#breadcrumbs", view);
-      this.breadcrumbs.render();
-    },
-
-    clearBreadcrumbs: function () {
-      if (!this.breadcrumbs) {return ;}
-
-      this.breadcrumbs.remove();
-    },
-
-    setView: function(selector, view) {
-      this.layoutViews[selector] = this.layout.setView(selector, view, false);
-    },
-
-    renderView: function(selector) {
-      var view = this.layoutViews[selector];
-      if (!view) {
-        return false;
-      } else {
-        return view.render();
-      }
-    }
-
-  });
-
-  return Layout;
-
-});

http://git-wip-us.apache.org/repos/asf/couchdb/blob/652f8890/src/fauxton/app/addons/fauxton/tests/baseSpec.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/fauxton/tests/baseSpec.js b/src/fauxton/app/addons/fauxton/tests/baseSpec.js
index 644002c..7df4dfc 100644
--- a/src/fauxton/app/addons/fauxton/tests/baseSpec.js
+++ b/src/fauxton/app/addons/fauxton/tests/baseSpec.js
@@ -34,13 +34,18 @@ define([
       testRouteObject = new TestRouteObject();
       var apiBar = {};
       apiBar.hide = sinon.spy();
+      var setViewSpy = sinon.stub();
+      setViewSpy.returns({
+        render: function () {}
+      });
 
       // Need to find a better way of doing this
       mockLayout = {
         setTemplate: sinon.spy(),
         clearBreadcrumbs: sinon.spy(),
-        setView: sinon.spy(),
+        setView: setViewSpy,
         renderView: sinon.spy(),
+        removeView: sinon.spy(),
         hooks: [],
         setBreadcrumbs: sinon.spy(),
         apiBar: apiBar,
@@ -59,13 +64,13 @@ define([
     it('Should clear breadcrumbs', function () {
       FauxtonAPI.masterLayout = mockLayout;
       testRouteObject.renderWith('the-route', mockLayout, 'args');
-      assert.ok(mockLayout.clearBreadcrumbs.calledOnce, 'Clear Breadcrumbs called');
+      assert.ok(mockLayout.removeView.calledWith('#breadcrumbs'), 'Clear Breadcrumbs called');
     });
 
     it('Should set breadcrumbs when breadcrumbs exist', function () {
       FauxtonAPI.masterLayout = mockLayout;
       testRouteObject.renderWith('the-route', mockLayout, 'args');
-      assert.ok(mockLayout.setBreadcrumbs.calledOnce, 'Set Breadcrumbs was called');
+      assert.ok(mockLayout.setView.calledOnce, 'Set Breadcrumbs was called');
     });
 
   });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/652f8890/src/fauxton/app/app.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/app.js b/src/fauxton/app/app.js
index 3ec2c99..521ad6c 100644
--- a/src/fauxton/app/app.js
+++ b/src/fauxton/app/app.js
@@ -24,7 +24,7 @@ define([
   "core/utils",
   // Modules
   "core/api",
-  "core/couchdbSession",
+  "core/couchdbsession",
   // Plugins.
   "plugins/backbone.layoutmanager",
   "plugins/jquery.form"

http://git-wip-us.apache.org/repos/asf/couchdb/blob/652f8890/src/fauxton/app/core/api.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/core/api.js b/src/fauxton/app/core/api.js
index 5483f44..1b21dca 100644
--- a/src/fauxton/app/core/api.js
+++ b/src/fauxton/app/core/api.js
@@ -15,11 +15,10 @@ define([
        "core/layout",
        "core/router",
        "core/routeObject",
-       "core/couchdbSession",
        "core/utils"
 ],
 
-function(FauxtonAPI, Layout, Router, RouteObject, CouchdbSession, utils) {
+function(FauxtonAPI, Layout, Router, RouteObject, utils) {
   FauxtonAPI = _.extend(FauxtonAPI, {
     Layout: Layout,
     Router: Router,

http://git-wip-us.apache.org/repos/asf/couchdb/blob/652f8890/src/fauxton/app/core/layout.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/core/layout.js b/src/fauxton/app/core/layout.js
index a5ed88c..ff339c7 100644
--- a/src/fauxton/app/core/layout.js
+++ b/src/fauxton/app/core/layout.js
@@ -17,10 +17,6 @@ define([
 
   // A wrapper of the main Backbone.layoutmanager
   // Allows the main layout of the page to be changed by any plugin.
-  // Exposes the different views:
-  //    navBar -> the top navigation bar
-  //    dashboardContent -> Main display view
-  //    breadcrumbs -> Breadcrumbs navigation section
   var Layout = function () {
     this.layout = new Backbone.Layout({
       template: "templates/layouts/with_sidebar",
@@ -53,25 +49,14 @@ define([
       this.render();
     },
 
-    setTabs: function(view){
-      // TODO: Not sure I like this - seems fragile/repetitive
-      this.tabs = this.layout.setView("#tabs", view);
-      this.tabs.render();
-    },
-
-    setBreadcrumbs: function(view) {
-      this.breadcrumbs = this.layout.setView("#breadcrumbs", view);
-      this.breadcrumbs.render();
-    },
-
-    clearBreadcrumbs: function () {
-      if (!this.breadcrumbs) {return ;}
+    setView: function(selector, view, keep) {
+      this.layout.setView(selector, view, false);
 
-      this.breadcrumbs.remove();
-    },
+      if (!keep) {
+        this.layoutViews[selector] = view;
+      }
 
-    setView: function(selector, view) {
-      this.layoutViews[selector] = this.layout.setView(selector, view, false);
+      return view;
     },
 
     renderView: function(selector) {
@@ -81,6 +66,22 @@ define([
       } else {
         return view.render();
       }
+    },
+
+    removeView: function (selector) {
+      var view = this.layout.getView(selector);
+
+      if (!view) {
+        return false;
+      }
+
+      view.remove();
+      
+      if (this.layoutViews[selector]) {
+        delete this.layoutViews[selector];
+      }
+
+      return true;
     }
 
   });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/652f8890/src/fauxton/app/router.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/router.js b/src/fauxton/app/router.js
deleted file mode 100644
index 1e0caac..0000000
--- a/src/fauxton/app/router.js
+++ /dev/null
@@ -1,142 +0,0 @@
-// 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([
-       // Load require for use in nested requiring
-       // as per the note in: http://requirejs.org/docs/api.html#multiversion
-       "require",
-
-       // Application.
-       "app",
-
-       // Initialize application
-       "initialize",
-
-       // Load Fauxton API
-       "core/api",
-
-       // Modules
-       //"addons/fauxton/base",
-       // Layout
-       //"addons/fauxton/layout",
-
-       "load_addons"
-],
-
-function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, LoadAddons) {
-
-  var beforeUnloads = {};
-
-  var Router = app.router = Backbone.Router.extend({
-    routes: {},
-
-    beforeUnload: function (name, fn) {
-      beforeUnloads[name] = fn;
-    },
-
-    removeBeforeUnload: function (name) {
-      delete beforeUnloads[name];
-    },
-
-    navigate: function (fragment, trigger) {
-      var continueNav  = true,
-          msg = _.find(_.map(beforeUnloads, function (fn) { return fn(); }), function (beforeReturn)
{
-            if (beforeReturn) { return true; }
-          });
-
-      if (msg) {
-        continueNav = window.confirm(msg);
-      }
-
-      if (continueNav) {
-        Backbone.Router.prototype.navigate(fragment, trigger);
-      }
-    },
-
-    addModuleRouteObject: function(RouteObject) {
-      var that = this;
-      var masterLayout = this.masterLayout,
-      routeUrls = RouteObject.prototype.getRouteUrls();
-
-      _.each(routeUrls, function(route) {
-        this.route(route, route.toString(), function() {
-          var args = Array.prototype.slice.call(arguments),
-          roles = RouteObject.prototype.getRouteRoles(route),
-          authPromise = app.auth.checkAccess(roles);
-
-          authPromise.then(function () {
-            if (!that.activeRouteObject || !that.activeRouteObject.hasRoute(route)) {
-              if (that.activeRouteObject) {
-                that.activeRouteObject.cleanup();
-              }
-              that.activeRouteObject = new RouteObject(route, masterLayout, args);
-            }
-
-            var routeObject = that.activeRouteObject;
-            routeObject.routeCallback(route, args);
-            routeObject.renderWith(route, masterLayout, args);
-          }, function () {
-            FauxtonAPI.auth.authDeniedCb();
-          });
-
-        }); 
-      }, this);
-    },
-
-    setModuleRoutes: function() {
-      _.each(LoadAddons.addons, function(module) {
-        console.log('aa', module);
-        if (module){
-          module.initialize();
-          // This is pure routes the addon provides
-          if (module.RouteObjects) {
-            _.each(module.RouteObjects, this.addModuleRouteObject, this);
-          }
-        }
-      }, this);
-    },
-
-    initialize: function() {
-      //TODO: It would be nice to handle this with a router
-      this.navBar = app.navBar = new Fauxton.NavBar();
-      this.apiBar = app.apiBar = new Fauxton.ApiBar();
-      this.auth = app.auth = FauxtonAPI.auth;
-      app.session = FauxtonAPI.session;
-
-      app.masterLayout = this.masterLayout = new Layout(this.navBar, this.apiBar);
-      app.footer = new Fauxton.Footer({el: "#footer-content"});
-
-      // NOTE: This must be below creation of the layout
-      // FauxtonAPI header links and others depend on existence of the layout
-      this.setModuleRoutes();
-
-      $("#app-container").html(this.masterLayout.el);
-      this.masterLayout.render();
-
-      // TODO: move this to a proper Fauxton.View
-      $.when.apply(null, app.footer.establish()).done(function() {
-        app.footer.render();
-      });
-    },
-
-    triggerRouteEvent: function(event, args) {
-      if (this.activeRouteObject) {
-        var eventArgs = [event].concat(args);
-        this.activeRouteObject.trigger.apply(this.activeRouteObject, eventArgs );
-        this.activeRouteObject.renderWith(eventArgs, this.masterLayout, args);
-      }
-    }
-  });
-
-  return Router;
-
-});

http://git-wip-us.apache.org/repos/asf/couchdb/blob/652f8890/src/fauxton/test/mocha/testUtils.js
----------------------------------------------------------------------
diff --git a/src/fauxton/test/mocha/testUtils.js b/src/fauxton/test/mocha/testUtils.js
index 08b80c7..2c418f9 100644
--- a/src/fauxton/test/mocha/testUtils.js
+++ b/src/fauxton/test/mocha/testUtils.js
@@ -25,7 +25,7 @@ function(FauxtonAPI,chai, sinonChai) {
    
    _.extend(ViewSandbox.prototype, {
     initialize: function () {
-      this.$el = $('<div style="display:no1ne"></div>').appendTo('body');
+      this.$el = $('<div style="display:none"></div>').appendTo('body');
       this.$ = this.$el.find;
     },
     views: [],


Mime
View raw message