couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gar...@apache.org
Subject fauxton commit: updated refs/heads/master to e3ec1ac
Date Tue, 24 Jan 2017 13:47:22 GMT
Repository: couchdb-fauxton
Updated Branches:
  refs/heads/master 434e8f9ab -> e3ec1acb5


some fixes for jest to work with react-bootstrap


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

Branch: refs/heads/master
Commit: e3ec1acb5a1733dd15843ef147f071d105e589d9
Parents: 434e8f9
Author: Garren Smith <garren.smith@gmail.com>
Authored: Tue Jan 24 15:05:49 2017 +0200
Committer: Garren Smith <garren.smith@gmail.com>
Committed: Tue Jan 24 15:05:49 2017 +0200

----------------------------------------------------------------------
 assets/js/plugins/cloudant.pagingcollection.js | 335 +++++++++-----------
 jest-config.json                               |   1 -
 jest-setup.js                                  |   3 +
 package.json                                   |   1 +
 4 files changed, 161 insertions(+), 179 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e3ec1acb/assets/js/plugins/cloudant.pagingcollection.js
----------------------------------------------------------------------
diff --git a/assets/js/plugins/cloudant.pagingcollection.js b/assets/js/plugins/cloudant.pagingcollection.js
index e383489..f18d78f 100644
--- a/assets/js/plugins/cloudant.pagingcollection.js
+++ b/assets/js/plugins/cloudant.pagingcollection.js
@@ -10,214 +10,193 @@
 // License for the specific language governing permissions and limitations under
 // the License.
 
-(function(root, factory) {
-  "use strict";
-  // start with AMD, so paginate could then be used by ``var paginate = require('paginate');``
-  if (typeof define === 'function' && define.amd) {
-    define(['underscore', 'backbone', 'jquery'], function(_, Backbone, $) {
-      // Export global even in AMD case in case this script is loaded with
-      // others that may still expect a global paginate.
-      return factory(root, null, _, Backbone, $.param);
+import _ from 'lodash';
+import $ from 'jquery';
+import Backbone from "backbone";
+
+const $param = $.param;
+
+//PagingCollection
+//----------------
+
+// A PagingCollection knows how to build appropriate requests to the
+// CouchDB-like server and how to fetch. The Collection will always contain a
+// single page of documents.
+
+export const PagingCollection = Backbone.Collection.extend({
+
+  // initialize parameters and page size
+  constructor: function() {
+    Backbone.Collection.apply(this, arguments);
+    this.configure.apply(this, arguments);
+  },
+
+  configure: function(collections, options) {
+    var querystring = _.result(this, "url").split("?")[1] || "";
+    this.paging = _.defaults((options.paging || {}), {
+      defaultParams: _.defaults({}, options.params, this._parseQueryString(querystring)),
+      hasNext: false,
+      hasPrevious: false,
+      params: {},
+      pageSize: 20,
+      direction: undefined
     });
 
-  // Next check for Node.js or CommonJS. Also look to see if either
-  // underscore or lodash are the modules being used
-  } else if (typeof exports !== 'undefined') {
-    var Backbone = require('Backbone'),
-        $param = require('querystring').stringify,
-        _;
-    try {
-      _ = require('underscore');
-    } catch(e) {
-      _ = require('lodash');
-    }
-    factory(root, exports, _, Backbone, $param);
+    this.paging.params = _.clone(this.paging.defaultParams);
+    this.updateUrlQuery(this.paging.defaultParams);
+  },
 
-  // Finally, register as a browser global.
-  } else {
-    root.PagingCollection = factory(root, {}, root._, root.Backbone, root.$.param);
-  }
+  calculateParams: function(currentParams, skipIncrement, limitIncrement) {
 
-}(this, function(root, exports, _, Backbone, $param) {
-  "use strict";
+    var params = _.clone(currentParams);
+    params.skip = (parseInt(currentParams.skip, 10) || 0) + skipIncrement;
 
-  //PagingCollection
-  //----------------
+    // guard against hard limits
+    if(this.paging.defaultParams.limit) {
+      params.limit = Math.min(this.paging.defaultParams.limit, params.limit);
+    }
+    // request an extra row so we know that there are more results
+    params.limit = limitIncrement + 1;
+    // prevent illegal skip values
+    params.skip = Math.max(params.skip, 0);
+
+    return params;
+  },
+
+  pageSizeReset: function(pageSize, opts) {
+    var options = _.defaults((opts || {}), {fetch: true});
+    this.paging.direction = undefined;
+    this.paging.pageSize = pageSize;
+    this.paging.params = this.paging.defaultParams;
+    this.paging.params.limit = pageSize;
+    this.updateUrlQuery(this.paging.params);
+    if (options.fetch) {
+      return this.fetch();
+    }
+  },
 
-  // A PagingCollection knows how to build appropriate requests to the
-  // CouchDB-like server and how to fetch. The Collection will always contain a
-  // single page of documents.
+  _parseQueryString: function(uri) {
+    var queryString = decodeURI(uri).split(/&/);
 
-  var PagingCollection = Backbone.Collection.extend({
+    return _.reduce(queryString, function (parsedQuery, item) {
+        var nameValue = item.split(/=/);
+        if (nameValue.length === 2) {
+          parsedQuery[nameValue[0]] = nameValue[1];
+        }
 
-    // initialize parameters and page size
-    constructor: function() {
-      Backbone.Collection.apply(this, arguments);
-      this.configure.apply(this, arguments);
-    },
+        return parsedQuery;
+    }, {});
+  },
 
-    configure: function(collections, options) {
-      var querystring = _.result(this, "url").split("?")[1] || "";
-      this.paging = _.defaults((options.paging || {}), {
-        defaultParams: _.defaults({}, options.params, this._parseQueryString(querystring)),
-        hasNext: false,
-        hasPrevious: false,
-        params: {},
-        pageSize: 20,
-        direction: undefined
-      });
+  _iterate: function(offset, opts) {
+    var options = _.defaults((opts || {}), {fetch: true});
 
-      this.paging.params = _.clone(this.paging.defaultParams);
-      this.updateUrlQuery(this.paging.defaultParams);
-    },
+    this.paging.params = this.calculateParams(this.paging.params, offset, this.paging.pageSize);
 
-    calculateParams: function(currentParams, skipIncrement, limitIncrement) {
+    // Fetch the next page of documents
+    this.updateUrlQuery(this.paging.params);
+    if (options.fetch) {
+      return this.fetch({reset: true});
+    }
+  },
+
+  // `next` is called with the number of items for the next page.
+  // It returns the fetch promise.
+  next: function(options){
+    this.paging.direction = "next";
+    return this._iterate(this.paging.pageSize, options);
+  },
+
+  // `previous` is called with the number of items for the previous page.
+  // It returns the fetch promise.
+  previous: function(options){
+    this.paging.direction = "previous";
+    return this._iterate(0 - this.paging.pageSize, options);
+  },
+
+  shouldStringify: function (val) {
+    try {
+      JSON.parse(val);
+      return false;
+    } catch(e) {
+      return true;
+    }
+  },
 
-      var params = _.clone(currentParams);
-      params.skip = (parseInt(currentParams.skip, 10) || 0) + skipIncrement;
+  // Encodes the parameters so that couchdb will understand them
+  // and then sets the url with the new url.
+  updateUrlQuery: function (params) {
+    var url = _.result(this, "url").split("?")[0];
 
-      // guard against hard limits
-      if(this.paging.defaultParams.limit) {
-        params.limit = Math.min(this.paging.defaultParams.limit, params.limit);
-      }
-      // request an extra row so we know that there are more results
-      params.limit = limitIncrement + 1;
-      // prevent illegal skip values
-      params.skip = Math.max(params.skip, 0);
-
-      return params;
-    },
-
-    pageSizeReset: function(pageSize, opts) {
-      var options = _.defaults((opts || {}), {fetch: true});
-      this.paging.direction = undefined;
-      this.paging.pageSize = pageSize;
-      this.paging.params = this.paging.defaultParams;
-      this.paging.params.limit = pageSize;
-      this.updateUrlQuery(this.paging.params);
-      if (options.fetch) {
-        return this.fetch();
+    _.each(['startkey', 'endkey', 'key'], function (key) {
+      if (_.has(params, key) && this.shouldStringify(params[key])) {
+        params[key] = JSON.stringify(params[key]);
       }
-    },
-
-    _parseQueryString: function(uri) {
-      var queryString = decodeURI(uri).split(/&/);
-
-      return _.reduce(queryString, function (parsedQuery, item) {
-          var nameValue = item.split(/=/);
-          if (nameValue.length === 2) {
-            parsedQuery[nameValue[0]] = nameValue[1];
-          }
-
-          return parsedQuery;
-      }, {});
-    },
+    }, this);
 
-    _iterate: function(offset, opts) {
-      var options = _.defaults((opts || {}), {fetch: true});
+    this.url = url + '?' + $param(params);
+  },
 
-      this.paging.params = this.calculateParams(this.paging.params, offset, this.paging.pageSize);
-
-      // Fetch the next page of documents
+  fetch: function () {
+    // if this is a fetch for the first time, fetch one extra to see if there is a next
+    if (!this.paging.direction && this.paging.params.limit > 0) {
+      this.paging.direction = 'fetch';
+      this.paging.params.limit = this.paging.params.limit + 1;
       this.updateUrlQuery(this.paging.params);
-      if (options.fetch) {
-        return this.fetch({reset: true});
-      }
-    },
-
-    // `next` is called with the number of items for the next page.
-    // It returns the fetch promise.
-    next: function(options){
-      this.paging.direction = "next";
-      return this._iterate(this.paging.pageSize, options);
-    },
-
-    // `previous` is called with the number of items for the previous page.
-    // It returns the fetch promise.
-    previous: function(options){
-      this.paging.direction = "previous";
-      return this._iterate(0 - this.paging.pageSize, options);
-    },
-
-    shouldStringify: function (val) {
-      try {
-        JSON.parse(val);
-        return false;
-      } catch(e) {
-        return true;
-      }
-    },
-
-    // Encodes the parameters so that couchdb will understand them
-    // and then sets the url with the new url.
-    updateUrlQuery: function (params) {
-      var url = _.result(this, "url").split("?")[0];
+    }
 
-      _.each(['startkey', 'endkey', 'key'], function (key) {
-        if (_.has(params, key) && this.shouldStringify(params[key])) {
-          params[key] = JSON.stringify(params[key]);
-        }
-      }, this);
+    return Backbone.Collection.prototype.fetch.apply(this, arguments);
+  },
 
-      this.url = url + '?' + $param(params);
-    },
+  parse: function (resp) {
+    var rows = resp.rows;
 
-    fetch: function () {
-      // if this is a fetch for the first time, fetch one extra to see if there is a next
-      if (!this.paging.direction && this.paging.params.limit > 0) {
-        this.paging.direction = 'fetch';
-        this.paging.params.limit = this.paging.params.limit + 1;
-        this.updateUrlQuery(this.paging.params);
-      }
+    this.paging.hasNext = this.paging.hasPrevious = false;
 
-      return Backbone.Collection.prototype.fetch.apply(this, arguments);
-    },
+    this.viewMeta = {
+      total_rows: resp.total_rows,
+      offset: resp.offset,
+      update_seq: resp.update_seq
+    };
 
-    parse: function (resp) {
-      var rows = resp.rows;
+    var skipLimit = this.paging.defaultParams.skip || 0;
+    if(this.paging.params.skip > skipLimit) {
+      this.paging.hasPrevious = true;
+    }
 
-      this.paging.hasNext = this.paging.hasPrevious = false;
+    if(rows.length === this.paging.pageSize + 1) {
+      this.paging.hasNext = true;
 
-      this.viewMeta = {
-        total_rows: resp.total_rows,
-        offset: resp.offset,
-        update_seq: resp.update_seq
-      };
+      // remove the next page marker result
+      rows.pop();
+      this.viewMeta.total_rows = this.viewMeta.total_rows - 1;
+    }
+    return rows;
+  },
 
-      var skipLimit = this.paging.defaultParams.skip || 0;
-      if(this.paging.params.skip > skipLimit) {
-        this.paging.hasPrevious = true;
-      }
+  hasNext: function() {
+    return this.paging.hasNext;
+  },
 
-      if(rows.length === this.paging.pageSize + 1) {
-        this.paging.hasNext = true;
+  hasPrevious: function() {
+    return this.paging.hasPrevious;
+  }
+});
 
-        // remove the next page marker result
-        rows.pop();
-        this.viewMeta.total_rows = this.viewMeta.total_rows - 1;
-      }
-      return rows;
-    },
+export default PagingCollection;
 
-    hasNext: function() {
-      return this.paging.hasNext;
-    },
 
-    hasPrevious: function() {
-      return this.paging.hasPrevious;
-    }
-  });
+//   if (exports) {
+//     // Overload the Backbone.ajax method, this allows PagingCollection to be able to
+//     // work in node.js
+//     exports.setAjax = function (ajax) {
+//       Backbone.ajax = ajax;
+//     };
 
+//     exports.PagingCollection = PagingCollection;
+//   }
 
-  if (exports) {
-    // Overload the Backbone.ajax method, this allows PagingCollection to be able to
-    // work in node.js
-    exports.setAjax = function (ajax) {
-      Backbone.ajax = ajax;
-    };
+//   return PagingCollection;
+// }));
 
-    exports.PagingCollection = PagingCollection;
-  }
 
-  return PagingCollection;
-}));

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e3ec1acb/jest-config.json
----------------------------------------------------------------------
diff --git a/jest-config.json b/jest-config.json
index 7f817ce..e818216 100644
--- a/jest-config.json
+++ b/jest-config.json
@@ -4,7 +4,6 @@
   "setupTestFrameworkScriptFile": "jest-setup.js",
 
   "moduleNameMapper": {
-    "bootstrap": "<rootDir>/assets/js/libs/bootstrap",
     "underscore": "lodash",
 
     "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|swf|wav|mp3|m4a|aac|oga)$":
"<rootDir>/__mocks__/fileMock.js",

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e3ec1acb/jest-setup.js
----------------------------------------------------------------------
diff --git a/jest-setup.js b/jest-setup.js
index 6d567f6..69906b1 100644
--- a/jest-setup.js
+++ b/jest-setup.js
@@ -13,5 +13,8 @@
 require('jest');
 
 window.$ = window.jQuery = require('jquery');
+window._ = require('lodash');
+window.Backbone = require('backbone');
 
 global.fetch = require('jest-fetch-mock');
+

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/e3ec1acb/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 4be5550..9557031 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,7 @@
     ]
   },
   "devDependencies": {
+    "babel-jest": "^18.0.0",
     "bootstrap": "^3.3.7",
     "enzyme": "^2.4.1",
     "es5-shim": "4.5.4",


Mime
View raw message