couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowalski <...@git.apache.org>
Subject [GitHub] couchdb-fauxton pull request: Databases view in react
Date Thu, 16 Apr 2015 20:36:47 GMT
Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/370#discussion_r28547303
  
    --- Diff: app/addons/fauxton/components.react.jsx ---
    @@ -84,9 +84,131 @@ function (app, FauxtonAPI, React, ZeroClipboard) {
       });
     
     
    +  var Tray = React.createClass({
    +
    +    getInitialState : function () {
    +      return {
    +        show: false
    +      };
    +    },
    +
    +    toggle : function (done) {
    +      if (this.state.show) {
    +        this.hide(done);
    +      } else {
    +        this.show(done);
    +      }
    +    },
    +
    +    componentDidMount : function () {
    +      var that = this;
    +      $('body').on('click.Tray-' + this.props.trayid + "-" + this._rootNodeID, function
(e) {
    +        var tgt = $(e.target);
    +        if (that.state.show && tgt.closest('.tray').length === 0) {
    +          that.hide();
    +        }
    +      });
    +    },
    +
    +    componentWillUnmount : function () {
    +      $('body').off('click.Tray-' + this.props.trayid + "-" + this._rootNodeID);
    +    },
    +
    +    show : function (done) {
    +      this.setState({show: true});
    +      $(this.refs.myself.getDOMNode()).velocity('transition.slideDownIn', FauxtonAPI.constants.MISC.TRAY_TOGGLE_SPEED,
function () {
    +        if (done) {
    +          done(true);
    +        }
    +      });
    +    },
    +
    +    hide : function (done) {
    +      var that = this;
    +      $(this.refs.myself.getDOMNode()).velocity('reverse', FauxtonAPI.constants.MISC.TRAY_TOGGLE_SPEED,
function () {
    +        that.setState({show: false});
    +        if (done) {
    +          done(false);
    +        }
    +      });
    +    },
    +
    +    render : function () {
    +      var styleSpec = this.state.show ? {"display": "block", "opacity": 1} :  {"display":
"none", "opacity": 0};
    +      var classSpec = this.props.className || "";
    +      classSpec += " tray";
    +      return (
    +        <div ref="myself" style={styleSpec} className={classSpec}>{this.props.children}</div>
    +      );
    +    }
    +  });
    +
    +  var Pagination = React.createClass({
    +
    +    getInitialState: function () {
    +      return {};
    +    },
    +
    +    getDefaultProps : function () {
    +      return {
    +        perPage: FauxtonAPI.constants.MISC.DEFAULT_PAGE_SIZE,
    +        page: 1,
    +        total: 0
    +      };
    +    },
    +
    +    render : function () {
    +      function getVisiblePages (page, totalPages) {
    +        var from, to;
    +        if (totalPages < 10) {
    +          from = 1;
    +          to = totalPages + 1;
    +        } else {
    +          from = page - 5;
    +          to = page + 5;
    +          if (from <= 1) {
    +            from = 1;
    +            to = 11;
    +          }
    +          if (to > totalPages + 1) {
    +            from =  totalPages - 9;
    +            to = totalPages + 1;
    +          }
    +        }
    +        return {
    +          from: from,
    +          to: to
    +        };
    +      }
    +      var page = this.state.page || this.props.page;
    +      var total = this.state.total || this.props.total;
    +      var perPage = this.props.perPage;
    +      var prefix = this.props.urlPrefix || "";
    +      var suffix = this.props.urlSuffix || "";
    +      var totalPages = total === 0 ? 1 : Math.ceil(total / perPage);
    +      var visiblePages = getVisiblePages(page, totalPages);
    +      var rangeItems = [];
    +      for (var i = visiblePages.from; i < visiblePages.to; i++) {
    +        rangeItems.push(
    +          <li className={(page === i ? "active" : null)}><a href={prefix + i
+ suffix}>{i}</a></li>
    +        );
    +      }
    +      return (
    +        <ul className="pagination">
    +          <li className={(page === 1 ? "disabled" : null)}><a href={prefix +
Math.max(page - 1, 1) + suffix}>&laquo;</a></li>
    +          {rangeItems}
    +          <li className={(page < totalPages ? null : "disabled")}><a href={prefix
+ Math.min(page + 1, totalPages) + suffix}>&raquo;</a></li>
    +        </ul>
    +      );
    +    }
    +  });
    +
    +
    --- End diff --
    
    it was related to the previous formatting of the code, take a look at the whitespace around
the `:`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message