couchdb-dev mailing list archives

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

    https://github.com/apache/couchdb-fauxton/pull/370#discussion_r28456063
  
    --- Diff: app/addons/databases/components.react.jsx ---
    @@ -0,0 +1,271 @@
    +// 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.
    +
    +define([
    +  'app',
    +  'api',
    +  'react',
    +  'addons/fauxton/components.react',
    +  'addons/databases/stores',
    +  'addons/databases/resources',
    +  'addons/databases/actions',
    +  'helpers'
    +], function (app, FauxtonAPI, React, ComponentsReact, Stores, Resources, Actions, Helpers)
{
    +
    +  var databasesStore = Stores.databasesStore;
    +
    +  var DatabasesController = React.createClass({
    +
    +    getStoreState: function () {
    +      return {
    +        collection: databasesStore.getCollection()
    +      };
    +    },
    +
    +    getInitialState: function () {
    +      return this.getStoreState();
    +    },
    +
    +    render: function () {
    +      return (
    +        <DatabaseTable body={this.state.collection} />
    +      );
    +    }
    +  });
    +
    +  var DatabaseTable = React.createClass({
    +
    +    createRows: function () {
    +      return _.map(this.props.body, function (item, iteration) {
    +        return (
    +          <DatabaseRow row={item} />
    +        );
    +      });
    +    },
    +
    +    render: function () {
    +      var rows = this.createRows();
    +      return (
    +        <div className="view">
    +          <table className="databases table table-striped">
    +            <thead>
    +              <th>Name</th>
    +              <th>Size</th>
    +              <th># of Docs</th>
    +              <th>Update Seq</th>
    +              <th>Actions</th>
    +            </thead>
    +            <tbody>
    +            {rows}
    +            </tbody>
    +          </table>
    +        </div>
    +      );
    +    }
    +  });
    +
    +  var DatabaseRow = React.createClass({
    +
    +    renderGraveyard : function (row) {
    +      if (row.status.isGraveYard()) {
    +        return (
    +          <GraveyardInfo row={row} />
    +        );
    +      } else {
    +        return null;
    +      }
    +    },
    +
    +    render: function () {
    +      var row = this.props.row;
    +      var name = row.get("name");
    +      var encoded = app.utils.safeURLName(name);
    +      var size = Helpers.formatSize(row.status.dataSize());
    +      return (
    +        <tr>
    +          <td>
    +            <a href={"#/database/"+encoded+"/_all_docs"}>{name}</a>
    +          </td>
    +          <td>{size}</td>
    +          <td>{row.status.numDocs()} {this.renderGraveyard(row)}</td>
    +          <td>{row.status.updateSeq()}</td>
    +          <td>
    +            <a className="db-actions btn fonticon-replicate set-replication-start"
title={"Replicate "+name} href={"#/replication/"+encoded}></a>&#160;
    +            <a className="db-actions btn icon-lock set-permissions" title={"Set permissions
for "+name} href={"#/database/"+encoded+"/permissions"}></a>
    +          </td>
    +        </tr>
    +      );
    +    }
    +  });
    +
    +  var GraveyardInfo = React.createClass({
    +
    +    componentDidMount : function () {
    +      $(this.refs.myself.getDOMNode()).tooltip();
    +    },
    +
    +    render : function () {
    +      var row = this.props.row;
    +      return (
    +        <i className="js-db-graveyard icon icon-exclamation-sign" ref="myself" title={"This
database has just " + row.status.numDocs() + " docs and " + row.status.numDeletedDocs() +
" deleted docs"}></i>
    +      );
    +    }
    +  });
    +
    +  var RightDatabasesHeader = React.createClass({
    +
    +    render : function () {
    +      return (
    +        <div className="header-right">
    +          <AddDatabaseWidget />
    +          <JumpToDatabaseWidget />
    +        </div>
    +      );
    +    }
    +  });
    +
    +  var AddDatabaseWidget = React.createClass({
    +
    +    onTrayToggle : function () {
    +      var that = this;
    +      this.refs.newDbTray.toggle(function (shown) {
    +        if (shown) {
    +          that.refs.newDbName.getDOMNode().focus();
    +        }
    +      });
    +    },
    +
    +    onKeyUpInInput : function (e) {
    +      if (e.which === 13) {
    +        this.onAddDatabase();
    +      }
    +    },
    +
    +    onAddDatabase : function () {
    +      var databaseName = $(this.refs.newDbName.getDOMNode()).val();
    +      Actions.createNewDatabase(databaseName, this.refs.newDbTray.hide, FauxtonAPI.addNotification);
    +    },
    +
    +    render : function () {
    +
    +      return (
    +        <div className="button" id="add-db-button">
    +          <a id="add-new-database" className="add-new-database-btn" href="#" onClick={this.onTrayToggle}><i
className="header-icon fonticon-new-database"></i> Add New Database</a>
    +          <ComponentsReact.Tray trayid="new-database-tray" ref="newDbTray" className="new-database-tray">
    +            <span className="add-on">Add New Database</span>
    +            <input id="js-new-database-name" type="text" onKeyUp={this.onKeyUpInInput}
ref="newDbName" className="input-xxlarge" placeholder="Name of database" />
    +            <a className="btn" id="js-create-database" onClick={this.onAddDatabase}>Create</a>
    +          </ComponentsReact.Tray>
    +        </div>
    +      );
    +    }
    +  });
    +
    +  var JumpToDatabaseWidget = React.createClass({
    +
    +    componentDidMount : function () {
    +      var that = this;
    +      $(this.refs.searchDbName.getDOMNode()).typeahead({
    +        source : databasesStore.getDatabaseNames(),
    +        updater: function (item) {
    +          that.jumpToDb(item);
    +        }
    +      });
    +      // turn of browser autocomplete
    +      $(this.refs.searchDbName.getDOMNode()).attr("autocomplete", "off");
    --- End diff --
    
    you can't - React will drop the attribute. And we're doing JQuery here anyway. As long
as we don't tynamically update the input field I think we're very OK and won't break things.
We just have to remember not to bind anything to the input dynamically via react. Otherwise
there would be "data-autocomplete='off'" - but still: we're using JQuery anyway and data-...
does at least have a similar chance of getting in the way...


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