summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2014-03-04 11:15:29 +0200
committerGarren Smith <garren.smith@gmail.com>2014-03-04 11:15:29 +0200
commit7381193640ddc55fa67b6054312ad3c68ea9f21d (patch)
tree956211ec492577d34f49ce2129fb1989dcda397d
parentb63c79130e15c08810b1288495e0c0ba89358c3d (diff)
downloadcouchdb-7381193640ddc55fa67b6054312ad3c68ea9f21d.tar.gz
Improvements from code reviewpaginate-api-options
-rw-r--r--src/fauxton/app/addons/documents/resources.js25
-rw-r--r--src/fauxton/app/addons/documents/routes.js23
-rw-r--r--src/fauxton/app/addons/documents/templates/advanced_options.html2
-rw-r--r--src/fauxton/app/addons/documents/templates/advanced_options_menu.html46
-rw-r--r--src/fauxton/app/addons/documents/views.js12
5 files changed, 36 insertions, 72 deletions
diff --git a/src/fauxton/app/addons/documents/resources.js b/src/fauxton/app/addons/documents/resources.js
index 73d9a0a8f..c0b736f35 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;
}
+
});
diff --git a/src/fauxton/app/addons/documents/routes.js b/src/fauxton/app/addons/documents/routes.js
index 21e76e022..f34019578 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);
},
diff --git a/src/fauxton/app/addons/documents/templates/advanced_options.html b/src/fauxton/app/addons/documents/templates/advanced_options.html
index fbf958e1f..e282c6254 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">
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 abc08bdbc..000000000
--- 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>
-
diff --git a/src/fauxton/app/addons/documents/views.js b/src/fauxton/app/addons/documents/views.js
index f828d7114..5b18982de 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) {