couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject [38/50] git commit: updated refs/heads/route-events to c33e390
Date Thu, 09 May 2013 14:01:35 GMT
Port editors to route objects


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

Branch: refs/heads/route-events
Commit: 64d7eed3014c9cc4398c71675edeb63e2cff4cf4
Parents: d17f8c8
Author: Russell Branca <chewbranca@gmail.com>
Authored: Tue Apr 9 16:20:26 2013 -0400
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Thu May 9 09:59:58 2013 +0200

----------------------------------------------------------------------
 src/fauxton/app/api.js                             |    2 +-
 src/fauxton/app/modules/documents/resources.js     |    4 +-
 src/fauxton/app/modules/documents/routes.js        |  202 +++++----------
 src/fauxton/app/router.js                          |    4 +-
 .../templates/documents/doc_field_editor_tabs.html |    2 +-
 5 files changed, 66 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/64d7eed3/src/fauxton/app/api.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/api.js b/src/fauxton/app/api.js
index 085291d..2c68086 100644
--- a/src/fauxton/app/api.js
+++ b/src/fauxton/app/api.js
@@ -134,7 +134,7 @@ function(app, Fauxton) {
     // immediately if its already done, but this way the RouteObject.route
     // function can rebuild the deferred as needed
     render: function(route, masterLayout, args) {
-      this.route.apply(this, args);
+      this.route.call(this, route, args);
 
       if (this.renderedState === true) {
         this.rerender.apply(this, arguments);

http://git-wip-us.apache.org/repos/asf/couchdb/blob/64d7eed3/src/fauxton/app/modules/documents/resources.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/resources.js b/src/fauxton/app/modules/documents/resources.js
index 3f07238..f1a07c3 100644
--- a/src/fauxton/app/modules/documents/resources.js
+++ b/src/fauxton/app/modules/documents/resources.js
@@ -35,9 +35,11 @@ function(app, FauxtonAPI, Views) {
       }
     },
 
-    initialize: function() {
+    initialize: function(_attrs, options) {
       if (this.collection && this.collection.database) {
         this.database = this.collection.database;
+      } else if (options.database) {
+        this.database = options.database;
       }
     },
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/64d7eed3/src/fauxton/app/modules/documents/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/modules/documents/routes.js b/src/fauxton/app/modules/documents/routes.js
index 34b00d8..ffed186 100644
--- a/src/fauxton/app/modules/documents/routes.js
+++ b/src/fauxton/app/modules/documents/routes.js
@@ -25,51 +25,69 @@ function(app, FauxtonAPI, Documents, Databases) {
   // var Documents = require("modules/documents/models_collections");
   // var Databases = require("modules/databases/module");
 
-  var codeEditorCallback = function(databaseName, docID) {
-    var data = {
-      database: new Databases.Model({id:databaseName}),
-      doc: new Documents.Doc({
-        "_id": docID
-      }),
-      selected: "code_editor"
-    };
-    data.doc.database = data.database;
-    data.designDocs = new Documents.AllDocs(null, {
-      database: data.database,
-      params: {startkey: '"_design"',
-        endkey: '"_design1"',
-        include_docs: true}
-    });
+  // TODO:: expand this for new docs and design docs
+  var DocEditorRouteObject = FauxtonAPI.RouteObject.extend({
+    layout: "one_pane",
 
-    var options = app.getParams();
-    options.include_docs = true;
-    data.database.buildAllDocs(options);
+    initialize: function() {
+      this.selected = false;
+    },
 
-    return {
-      layout: "one_pane",
+    routes: function() {
+      return _.keys(this.selectedRoutes);
+    },
 
-      data: data,
+    selectedRoutes: {
+      "database/:database/:doc/field_editor": "field_editor",
+      "database/:database/:doc/code_editor": "code_editor",
+      "database/:database/:doc": "code_editor"
+    },
 
-      crumbs: [
+    crumbs: function() {
+      return [
         {"name": "Databases", "link": "/_all_dbs"},
-        {"name": data.database.id, "link": Databases.databaseUrl(data.database)},
-        {"name": docID, "link": "#"}
-      ],
+        {"name": this.database.id, "link": Databases.databaseUrl(this.database)},
+        {"name": this.docID, "link": "#"}
+      ];
+    },
 
-      views: {
-        "#dashboard-content": new Documents.Views.Doc({
-          model: data.doc
-        }),
+    setEditorView: function() {
+      if (this.selected === "field_editor") {
+        this.docView = this.setView("#dashboard-content", new Documents.Views.DocFieldEditor({
+          model: this.doc
+        }));
+      } else {
+        this.docView = this.setView("#dashboard-content", new Documents.Views.Doc({
+          model: this.doc
+        }));
+      }
+    },
 
-        "#tabs": new Documents.Views.FieldEditorTabs({
-          selected: data.selected,
-          model: data.doc
-        })
-      },
+    route: function(route, args) {
+      var databaseName = args[0], docID = args[1];
 
-      apiUrl: data.doc.url()
-    };
-  };
+      this.database = this.database || new Databases.Model({id: databaseName});
+      this.doc = this.doc || new Documents.Doc({
+        _id: docID
+      }, {
+        database: this.database
+      });
+
+      if (this.selected !== this.selectedRoutes[route]) {
+        this.selected = this.selectedRoutes[route];
+        this.setEditorView();
+      }
+
+      this.tabsView = this.setView("#tabs", new Documents.Views.FieldEditorTabs({
+        selected: this.selected,
+        model: this.doc
+      }));
+    },
+
+    apiUrl: function() {
+      return this.doc.url();
+    }
+  });
 
   var newViewEditorCallback = function(databaseName) {
     var data = {
@@ -161,117 +179,13 @@ function(app, FauxtonAPI, Documents, Databases) {
   };
 
   Documents.Routes = {
-    "database/:database/:doc/field_editor": function(databaseName, docID) {
-      var data = {
-        database: new Databases.Model({id:databaseName}),
-        doc: new Documents.Doc({
-          "_id": docID
-        }),
-        selected: "field_editor"
-      };
-      data.doc.database = data.database;
-      data.designDocs = new Documents.AllDocs(null, {
-        database: data.database,
-        params: {startkey: '"_design"',
-          endkey: '"_design1"',
-          include_docs: true}
-      });
-
-      var options = app.getParams();
-      options.include_docs = true;
-      data.database.buildAllDocs(options);
-
-      return {
-        layout: "one_pane",
-
-        data: data,
-
-        crumbs: [
-          {"name": "Databases", "link": "/_all_dbs"},
-          {"name": data.database.id, "link": Databases.databaseUrl(data.database)},
-          {"name": docID, "link": "#"}
-        ],
-
-        views: {
-          "#dashboard-content": new Documents.Views.DocFieldEditor({
-            model: data.doc
-          }),
-
-          "#tabs": new Documents.Views.FieldEditorTabs({
-            selected: data.selected,
-            model: data.doc
-          })
-        },
-
-        apiUrl: data.doc.url()
-      };
-    },
-
-    "database/:database/:doc/code_editor": codeEditorCallback,
-    "database/:database/:doc": codeEditorCallback,
+    //"database/:database/:doc/code_editor": codeEditorCallback,
+    //"database/:database/:doc": codeEditorCallback,
     "database/:database/_design%2F:doc": function(database, doc) {
       var docID = "_design/"+doc;
       return codeEditorCallback(database, docID);
     },
 
-    // HACK
-    // The ordering of routes is different in this object that the
-    // routes object in the Backbone.Router. As a result, the
-    // declaration order of show doc and _handler methods has been
-    // switched. This is a brittle solution that needs to be fixed.
-    // Conflicts with route: "database/:database/_:handler"
-    //
-    // TODO: add support for regex based rotues
-    // Javascript does not handle a regex as an object key very well,
-    // and it turns it into its string representation when you use in
-    // non object literal form, which does get recast back as a regex
-    // when we need it.
-    // The inability to use regex based routes here is a design flaw
-    // and should be rectified.
-    "old_database/:database/:doc": function(databaseName, docID) {
-      var data = {
-        database: new Databases.Model({id:databaseName}),
-        doc: new Documents.Doc({
-          "_id": docID
-        })
-      };
-      data.doc.database = data.database;
-      data.designDocs = new Documents.AllDocs(null, {
-        database: data.database,
-        params: {startkey: '"_design"',
-          endkey: '"_design1"',
-          include_docs: true}
-      });
-
-      var options = app.getParams();
-      options.include_docs = true;
-      data.database.buildAllDocs(options);
-
-      return {
-        layout: "with_sidebar",
-
-        data: data,
-
-        crumbs: [
-          {"name": "Databases", "link": "/_all_dbs"},
-          {"name": data.database.id, "link": Databases.databaseUrl(data.database)},
-          {"name": docID, "link": "#"}
-        ],
-
-        views: {
-          "#dashboard-content": new Documents.Views.Doc({
-            model: data.doc
-          }),
-
-          "#sidebar-content": new Documents.Views.Sidebar({
-            collection: data.designDocs
-          })
-        },
-
-        apiUrl: data.doc.url()
-      };
-    },
-
     "database/:database/_all_docs(:extra)": function(databaseName, page) {
       var data = {
         database: new Databases.Model({id:databaseName})
@@ -422,5 +336,7 @@ function(app, FauxtonAPI, Documents, Databases) {
     }
   };
 
+  Documents.RouteObjects = [new DocEditorRouteObject()];
+
   return Documents;
 });

http://git-wip-us.apache.org/repos/asf/couchdb/blob/64d7eed3/src/fauxton/app/router.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/router.js b/src/fauxton/app/router.js
index d75fe5a..45fd282 100644
--- a/src/fauxton/app/router.js
+++ b/src/fauxton/app/router.js
@@ -109,10 +109,10 @@ function(req, app, Initialize, FauxtonAPI, Fauxton, Layout, Databases,
Documents
 
     addModuleRouteObject: function(routeObject) {
       var masterLayout = this.masterLayout;
-      _.each(routeObject.routes, function(route) {
+      _.each(routeObject.get('routes'), function(route) {
         //this.route(route, route.toString(), _.partial(routeObject.renderWith, route, this.masterLayout));
         this.route(route, route.toString(), function() {
-          routeObject.render(route, masterLayout, arguments);
+          routeObject.render(route, masterLayout, Array.prototype.slice.call(arguments));
         });
       }, this);
     },

http://git-wip-us.apache.org/repos/asf/couchdb/blob/64d7eed3/src/fauxton/app/templates/documents/doc_field_editor_tabs.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/templates/documents/doc_field_editor_tabs.html b/src/fauxton/app/templates/documents/doc_field_editor_tabs.html
index ecb0e48..bb16d73 100644
--- a/src/fauxton/app/templates/documents/doc_field_editor_tabs.html
+++ b/src/fauxton/app/templates/documents/doc_field_editor_tabs.html
@@ -13,7 +13,7 @@ the License.
 -->
 
 <ul class="nav nav-tabs">
-  <!--<li class="<%= isSelectedClass('field_editor') %>"><a href="#<%=
doc.url('app') %>/field_editor">Doc fields</a></li>-->
+  <li class="<%= isSelectedClass('field_editor') %>"><a href="#<%= doc.url('app')
%>/field_editor">Doc fields</a></li>
   <li class="<%= isSelectedClass('code_editor') %>"><a href="#<%= doc.url('app')
%>/code_editor"><i class="icon-pencil"></i> Code editor</a></li>
   <ul class="nav pull-right" style="margin:5px 10px 0px 10px;">
     <li>


Mime
View raw message