couchdb-dev mailing list archives

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

    https://github.com/apache/couchdb-fauxton/pull/370#discussion_r28735951
  
    --- Diff: app/addons/fauxton/components.react.jsx ---
    @@ -83,10 +83,132 @@ function (app, FauxtonAPI, React, ZeroClipboard) {
         }
       });
     
    +  var _NextTrayInternalId = 0;
    +  var Tray = React.createClass({
    +
    +    getInitialState: function () {
    +      return {
    +        show: false,
    +        internalid: (_NextTrayInternalId++)
    +      };
    +    },
    +
    +    toggle: function (done) {
    +      if (this.state.show) {
    +        this.hide(done);
    +      } else {
    +        this.show(done);
    +      }
    +    },
    +
    +    componentDidMount: function () {
    +      $('body').on('click.Tray-' + this.state.internalid, function (e) {
    +        var tgt = $(e.target);
    +        if (this.state.show && tgt.closest('.tray').length === 0) {
    +          this.hide();
    +        }
    +      }.bind(this));
    +    },
    +
    +    componentWillUnmount: function () {
    +      $('body').off('click.Tray-' + this.state.internalid);
    +    },
    +
    +    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) {
    +      $(this.refs.myself.getDOMNode()).velocity('reverse', FauxtonAPI.constants.MISC.TRAY_TOGGLE_SPEED,
function () {
    +        this.setState({show: false});
    +        if (done) {
    +          done(false);
    +        }
    +      }.bind(this));
    +    },
    +
    +    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
    +      };
    +    },
    +
    +    getVisiblePages: function (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
    +      };
    +    },
    +
    +    render: function () {
    +      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 = this.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>
    +        );
    --- End diff --
    
    ```
    <li key={i} className={(page === i ? "active" : null)} >
       <a href={prefix + i + suffix} >{i}</a>
    </li>
    ```
    
    to get rid of console error


---
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