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/03/04 10:14:55 UTC

couchdb commit: updated refs/heads/paginate-api-options to 7381193

Repository: couchdb
Updated Branches:
  refs/heads/paginate-api-options b63c79130 -> 738119364


Improvements from code review


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

Branch: refs/heads/paginate-api-options
Commit: 7381193640ddc55fa67b6054312ad3c68ea9f21d
Parents: b63c791
Author: Garren Smith <ga...@gmail.com>
Authored: Tue Mar 4 11:15:29 2014 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Tue Mar 4 11:15:29 2014 +0200

----------------------------------------------------------------------
 src/fauxton/app/addons/documents/resources.js   | 25 ++++++++++-
 src/fauxton/app/addons/documents/routes.js      | 23 +++-------
 .../documents/templates/advanced_options.html   |  2 +-
 .../templates/advanced_options_menu.html        | 46 --------------------
 src/fauxton/app/addons/documents/views.js       | 12 ++---
 5 files changed, 36 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/73811936/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 73d9a0a..c0b736f 100644
--- a/src/fauxton/app/addons/documents/resources.js
+++ b/src/fauxton/app/addons/documents/resources.js
@@ -18,6 +18,28 @@ define([
 function(app, FauxtonAPI) {
   var Documents = FauxtonAPI.addon();
 
+  Documents.QueryParams = (function () {
+    var _eachParams = function (params, action) {
+      _.each(['startkey', 'endkey', 'key'], function (key) {
+        if (_.has(params, key)) {
+          params[key] = action(params[key]);
+        }
+      });
+
+      return params;
+    };
+
+    return {
+      parse: function (params) {
+        return _eachParams(params, JSON.parse);
+      },
+
+      stringify: function (params) {
+        return _eachParams(params, JSON.stringify);
+      }
+    };
+  })();
+
   Documents.paginate = {
     history: [],
     calculate: function (doc, defaultParams, currentParams, _isAllDocs) {
@@ -79,7 +101,7 @@ function(app, FauxtonAPI) {
 
     reset: function () {
       this.history = [];
-    }
+    } 
   };
 
   Documents.Doc = FauxtonAPI.Model.extend({
@@ -595,6 +617,7 @@ function(app, FauxtonAPI) {
 
       return timeString;
     }
+
   });
 
   

http://git-wip-us.apache.org/repos/asf/couchdb/blob/73811936/src/fauxton/app/addons/documents/routes.js
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/routes.js b/src/fauxton/app/addons/documents/routes.js
index 21e76e0..f340195 100644
--- a/src/fauxton/app/addons/documents/routes.js
+++ b/src/fauxton/app/addons/documents/routes.js
@@ -392,28 +392,20 @@ function(app, FauxtonAPI, Documents, Databases) {
           collection = this.documentsView.collection;
 
       this.documentsView.forceRender();
-      var rawCollection = collection.map(function (item) { return item.toJSON(); });
 
       // this is really ugly. But we basically need to make sure that
       // all parameters are in the correct state and have been parsed before we
       // calculate how to paginate the collection
-      _.each(['startkey', 'endkey', 'key'], function (key) {
-        if (_.has(collection.params, key)) {
-          collection.params[key] = JSON.parse(collection.params[key]);
-        }
-
-        if (_.has(urlParams, key)) {
-          urlParams[key] = JSON.parse(urlParams[key]);
-        }
-      });
+      collection.params = Documents.QueryParams.parse(collection.params);
+      urlParams = Documents.QueryParams.parse(urlParams);
 
       if (options.direction === 'next') {
-          params = Documents.paginate.next(rawCollection, 
+          params = Documents.paginate.next(collection.toJSON(), 
                                            collection.params,
                                            options.perPage, 
                                            !!collection.isAllDocs);
       } else {
-          params = Documents.paginate.previous(rawCollection, 
+          params = Documents.paginate.previous(collection.toJSON(), 
                                                collection.params, 
                                                options.perPage, 
                                                !!collection.isAllDocs);
@@ -425,12 +417,7 @@ function(app, FauxtonAPI, Documents, Databases) {
 
       // again not pretty but need to make sure all the parameters can be correctly
       // built into a query
-      _.each(['startkey', 'endkey', 'key'], function (key) {
-        if (_.has(params, key)) {
-          params[key] = JSON.stringify(params[key]);
-        }
-      });
-
+      params = Documents.QueryParams.stringify(params);
       collection.updateParams(params);
     },
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/73811936/src/fauxton/app/addons/documents/templates/advanced_options.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/templates/advanced_options.html b/src/fauxton/app/addons/documents/templates/advanced_options.html
index fbf958e..e282c62 100644
--- a/src/fauxton/app/addons/documents/templates/advanced_options.html
+++ b/src/fauxton/app/addons/documents/templates/advanced_options.html
@@ -12,7 +12,7 @@ License for the specific language governing permissions and limitations under
 the License.
 -->
 <div class="errors-container"></div>
-<form class="view-query-update custom-inputs">
+<form class="js-view-query-update custom-inputs">
   <div class="controls-group">
     <div class="row-fluid">
       <div class="controls controls-row">

http://git-wip-us.apache.org/repos/asf/couchdb/blob/73811936/src/fauxton/app/addons/documents/templates/advanced_options_menu.html
----------------------------------------------------------------------
diff --git a/src/fauxton/app/addons/documents/templates/advanced_options_menu.html b/src/fauxton/app/addons/documents/templates/advanced_options_menu.html
deleted file mode 100644
index abc08bd..0000000
--- a/src/fauxton/app/addons/documents/templates/advanced_options_menu.html
+++ /dev/null
@@ -1,46 +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.
--->
-<div class="row-fluid custom-inputs">
-  <div class="controls controls-row">
-    <div class="checkbox inline">  
-      <input id="include-docs-views" type="checkbox" name="include-docs" value="true">  
-      <label for="include-docs-views">
-        Include Docs</label>  
-    </div> 
-    <% if (hasReduce) { %>
-    <div class="checkbox inline">  
-      <input id="reduce" name="reduce" type="checkbox" value="true">
-      <label for="reduce">Reduce</label>  
-      <label id="group-level-label" style="display:none" class="drop-down inline">
-        Group Level:
-        <select id="group-level"  name="group_level" class="input-small">
-          <option value="0">None</option>
-          <option value="1">1</option>
-          <option value="2">2</option>
-          <option value="3">3</option>
-          <option value="4">4</option>
-          <option value="5">5</option>
-          <option value="6">6</option>
-          <option value="7">7</option>
-          <option value="8">8</option>
-          <option value="9">9</option>
-          <option value="999" selected="selected">exact</option>
-        </select>
-      </label>
-    </div> 
-    <% } %>
-    <a data-bypass="true" id="query-nav" class="" href="#query" data-toggle="tab">More query options</a></li>
-  </div> 
-</div> 
-

http://git-wip-us.apache.org/repos/asf/couchdb/blob/73811936/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 f828d71..5b18982 100644
--- a/src/fauxton/app/addons/documents/views.js
+++ b/src/fauxton/app/addons/documents/views.js
@@ -1065,9 +1065,9 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
     },
 
     events: {
-      "change form.view-query-update input": "updateFilters",
-      "change form.view-query-update select": "updateFilters",
-      "submit form.view-query-update": "updateView",
+      "change form.js-view-query-update input": "updateFilters",
+      "change form.js-view-query-update select": "updateFilters",
+      "submit form.js-view-query-update": "updateView",
       "click button.preview": "previewView"
     },
 
@@ -1087,7 +1087,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
     },
 
     queryParams: function () {
-      var $form = this.$(".view-query-update");
+      var $form = this.$(".js-view-query-update");
       // Ignore params without a value
       var params = _.reduce($form.serializeArray(), function(params, param) {
         if (!param.value) { return params; }
@@ -1123,7 +1123,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
     },
 
     updateFiltersFor: function(name, $ele) {
-      var $form = $ele.parents("form.view-query-update:first");
+      var $form = $ele.parents("form.js-view-query-update:first");
       switch (name) {
         // Reduce constraints
         //   - Can't include_docs for reduce=true
@@ -1151,7 +1151,7 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
     },
 
     updateFromParams: function (params) {
-      var $form = this.$el.find("form.view-query-update");
+      var $form = this.$el.find("form.js-view-query-update");
       _.each(params, function(val, key) {
         var $ele;
         switch (key) {