couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From garrensmith <...@git.apache.org>
Subject [GitHub] couchdb-fauxton pull request: Active tasks in react
Date Mon, 16 Mar 2015 10:07:35 GMT
Github user garrensmith commented on a diff in the pull request:

    https://github.com/apache/couchdb-fauxton/pull/317#discussion_r26471989
  
    --- Diff: app/addons/activetasks/components.react.jsx ---
    @@ -0,0 +1,387 @@
    +// 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/helpers",
    +  "api",
    +  "react",
    +  "addons/activetasks/stores",
    +  "addons/activetasks/resources",
    +  "addons/activetasks/actions"
    +
    +], function (Helpers, FauxtonAPI, React, Stores, Resources, Actions) {
    +  var activeTasksStore = Stores.activeTasksStore;
    +
    +  var ActiveTasksController = React.createClass({
    +
    +    getStoreState: function () {
    +      return {  
    +        selectedTab: activeTasksStore.getSelectedTab(),
    +        collection: activeTasksStore.getCollection(),
    +        searchTerm: activeTasksStore.getSearchTerm(),
    +        setPolling: activeTasksStore.setPolling(),
    +        clearPolling: activeTasksStore.clearPolling
    +      };
    +    },
    +
    +    getInitialState: function () {
    +      return this.getStoreState();
    +    },
    +
    +    componentDidMount: function () {
    +      this.state.setPolling;
    +      activeTasksStore.on('change', this.onChange, this);      
    +    },
    +
    +    componentWillUnmount: function() {
    +      this.state.clearPolling();
    +      activeTasksStore.off('change', this.onChange, this); 
    +    },
    +    onChange: function () {
    +      this.setState(this.getStoreState());
    +    },
    +    render: function () {
    +      var collection = this.state.collection; 
    +      var searchTerm = this.state.searchTerm;
    +      var selectedTab = this.state.selectedTab;
    +
    +      if (collection.length === 0 ) {
    +        return ( <div className="active-tasks"><tr><td><p>  No
tasks. </p></td></tr></div> );
    +      } else {
    +        return (
    +          <div className="scrollable">
    +            <div className="inner">
    +              <ActiveTasksFilterHeader/>
    +              <ActiveTaskTable collection={collection} searchTerm={searchTerm} tab={selectedTab}/>
    +            </div>
    +          </div>
    +        );
    +      }
    +    }
    +  });
    +
    +  var ActiveTasksFilterHeader = React.createClass({ //This is for the little '+ Filter'
Tab 
    +    getStoreState: function () {
    +      return {  
    +        searchTerm: activeTasksStore.getSearchTerm()
    +      };
    +    },
    +
    +    getInitialState: function () {
    +      return this.getStoreState();
    +    },
    +
    +    toggleFilter: function () {
    +      $('#dashboard-content').scrollTop(0);
    +      $('#query').toggle('slow');
    +    },
    +    setNewSearchTerm: function (e) {
    +      this.setState({searchTerm: e.target.value});
    +      Actions.setSearchTerm(e.target.value);
    +    },
    +    render: function () {
    +      var searchTerm = this.state.searchTerm;
    +      return (
    +        <div id="dashboard-upper-content">
    +          <div className="dashboard-upper-menu">
    +            <ul className="nav nav-tabs" id="db-views-tabs-nav">
    +              <li>
    +                <a className="js-toggle-filter" href="#filter" data-bypass="true"
data-toggle="tab" onClick={this.toggleFilter}>
    +                  <i className="fonticon fonticon-plus"></i>Filter
    +                </a>
    +              </li>
    +            </ul>
    +          </div>
    +
    +          <div className="tab-content">
    +            <div className="tab-pane" id="query">
    +              <div className="activetasks-header">
    +                <div className="pull-right">
    +                  <input  
    +                    className="task-search-database" 
    +                    type="text" name="search" 
    +                    placeholder="Search for databases..." 
    +                    value={searchTerm}
    +                    onChange={this.setNewSearchTerm}
    +                  />
    +                </div>
    +              </div>
    +            </div>
    +          </div>
    +        </div>
    +      );
    +    }
    +  });
    +
    +  var ActiveTaskTable = React.createClass({
    +    getInfo: function (item) {
    +      return {
    +        type : item.get('type'),
    +        objectField : this.getDatabaseFieldMessage(item) ,
    +        started_on : this.getTimeInfo(item.get('started_on')), 
    +        updated_on : this.getTimeInfo(item.get('updated_on')),
    +        pid : item.get('pid').replace(/[<>]/g, ''),
    +        progress : this.getProgressMessage(item),
    +      };
    +    },
    +    getTimeInfo: function (timeStamp) {
    +      var timeMessage = [Helpers.formatDate(timeStamp)];
    +      timeMessage.push(Helpers.getDateFromNow(timeStamp));
    +      return timeMessage;
    +    },
    +    getDatabaseFieldMessage: function (model) {
    +      var type = model.get('type');
    +      var databaseFieldMessage = [];
    +
    +      if (type === 'replication') {
    +        databaseFieldMessage.push('From: ' + model.get('source'));
    +        databaseFieldMessage.push('To: ' + model.get('target'));
    +      } else if (type === 'indexer') {
    +        databaseFieldMessage.push(model.get('database'));
    +        databaseFieldMessage.push('(View: ' + model.get('design_document') + ')');
    +      } else {
    +        databaseFieldMessage.push(model.get('database'));
    +      }
    +
    +      return databaseFieldMessage;
    +    },
    +    getProgressMessage: function (model) {
    +      var progressMessage = [];
    +      var type = model.get('type');
    +      if (!_.isUndefined(model.get('progress'))) {
    +        progressMessage.push('Progress: ' + model.get('progress') + '%');
    +      }
    +
    +      if (type === 'indexer') {
    +        progressMessage.push('Processed ' + model.get('changes_done') + ' of ' + model.get('total_changes')
+ ' changes.');
    +      } else if (type === 'replication') {
    +        progressMessage.push(model.get('docs_written')+ ' docs written.');
    +        if (!_.isUndefined(model.get('changes_pending'))) {
    +          progressMessage.push(model.get('changes_pending') + ' pending changes.');
    +        }
    +      }
    +      if (!_.isUndefined(model.get('source_seq'))) {
    +        progressMessage.push('Current source sequence: ' + model.get('source_seq') +
'. ');
    +      }
    +      if (!_.isUndefined(model.get('changes_done'))) {
    +        progressMessage.push(model.get('changes_done') + ' Changes done.');
    +      }
    +      
    +      return progressMessage;
    +    },
    +    passesFilter: function (item) {
    +      var searchTerm = this.props.searchTerm;
    +      var regex = new RegExp(searchTerm, 'g');
    +      
    +      var itemDatabasesTerm = '';
    +      if (item.has('database')) {
    +        itemDatabasesTerm += item.get('database'); 
    +      }
    +      if (item.has('source')) {
    +        itemDatabasesTerm += item.get('source'); 
    +      }
    +      if (item.has('target')) {
    +        itemDatabasesTerm += item.get('target'); 
    +      }
    +
    +      if (regex.test(itemDatabasesTerm)) {
    +        return this.passesTabFilter(item.get('type'));
    +      }
    +      return false;
    +    },
    +    passesTabFilter: function (type) {
    +      if (this.props.tab.toLowerCase() === type.replace('_', ' ') || this.props.tab ==='All
Tasks') {
    +        return true;
    +      }
    +      return false;
    +    },
    +    sortByHeader: function (e) {
    +      var headerField = $(e.currentTarget),
    +      columnName = headerField.attr('data-type');
    +      Actions.sortByColumnHeader(columnName);
    +    },
    +    render: function () {
    +      var collection = this.props.collection;
    +      var resultsCount = 0;
    +
    +      return (
    +        <div id="dashboard-lower-content">
    +          <table className="table table-bordered table-striped active-tasks">
    +            <thead>
    +              <tr>
    +                <th className="type"      data-type="type"        onClick={this.sortByHeader}>
Type</th>
    +                <th className="database"  data-type="database"    onClick={this.sortByHeader}>
Database</th>
    +                <th className="started"   data-type="started_on"  onClick={this.sortByHeader}>
Started on</th>
    +                <th className="updated"   data-type="updated_on"  onClick={this.sortByHeader}>
Last updated on</th>
    +                <th className="pid"       data-type="pid"         onClick={this.sortByHeader}>
PID</th>
    +                <th className="status"    data-type="progress"    onClick={this.sortByHeader}>
Status</th>
    +              </tr>
    +            </thead>
    +            <tbody className="js-tasks-go-here">
    +              { collection.map(function (item, iteration) {
    +    
    +                  //'+ Filter' Tab , shows rows that match the search term, no search
term shows all rows
    +                  if (this.passesFilter(item)) {
    +                    resultsCount++;
    +                    return <ActiveTaskTableBody key={item.cid} itemInfo={this.getInfo(item)}
/>;
    +                  }
    +
    +                  //Show a message if nothing is returned
    +                  if ((iteration === collection.length - 1) && resultsCount ===
0) {  //if we looped through everything AND there is nothing
    +                    if (this.props.searchTerm ==="") {      //no search filter
    +                      return (
    +                        <tr className="no-matching-database-on-search" key={item.cid}>
    +                          <td  colSpan="6">No active {this.props.tab} tasks.</td>
    +                        </tr>
    +                      );
    +                    } else {  // with search filter
    +                      return (  
    +                        <tr className="no-matching-database-on-search" key={item.cid}>
    +                          <td  colSpan="6">No active {this.props.tab} tasks match
with filter: "{this.props.searchTerm}".</td>
    +                        </tr>
    +                      );
    +                    }
    +                  }
    +
    +                }.bind(this))
    +              }
    +            </tbody>
    +          </table>
    +        </div>
    +      );
    +    }
    +  });
    +
    +  var ActiveTaskTableBody = React.createClass({
    +    render: function () {
    +      var data =  this.props.itemInfo;
    +      return (
    +        <tr>
    +          <td>{data.type}            </td>
    +          <td>
    +            { data.objectField.map(function (msgLine, iterator) {
    +                return (
    +                  <p key={iterator} className="multiline-active-tasks-message">{msgLine}</p>

    +                );
    +              })
    +            }
    +          </td>
    +          <td>
    +            <p className="multiline-active-tasks-message">{data.started_on[0]}</p>
    +            <p className="multiline-active-tasks-message gray">{data.started_on[1]}</p>
    +          </td>
    +          <td>
    +            <p className="multiline-active-tasks-message">{data.updated_on[0]}</p>
    +            <p className="multiline-active-tasks-message gray">{data.updated_on[1]}</p>
    +          </td>
    +          <td>{data.pid}             </td>
    +          <td>
    +            { data.progress.map(function (msgLine, iterator) {
    +                return (
    +                  <p key={iterator} className="multiline-active-tasks-message">{msgLine}</p>

    +                );
    +              })
    +            }
    +          </td>
    +        </tr>
    +      );
    +    }
    +  });
    +
    +  var ActiveTasksSidebar = React.createClass({
    +    tabs : function () {
    +      return ['All Tasks', 
    +              'Replication',
    +              'Database Compaction', 
    +              'Indexer', 
    +              'View Compaction'
    +             ];
    +    },
    +    getStoreState: function () {
    +      return {  
    +        selectedTab: activeTasksStore.getSelectedTab(),
    +        pollingInterval:  activeTasksStore.getPollingInterval()
    +      };
    +    },
    +    getInitialState: function () {
    +      return this.getStoreState();
    +    },
    +    componentDidMount: function () {
    +       activeTasksStore.on('change', this.onChange, this);      
    +    },
    +    switchTab: function (goToTab) {
    +      Actions.switchTab(goToTab);
    +    },
    +    onChange: function () {  
    +      if (this.isMounted()) {
    +        this.setState(this.getStoreState());
    +      }
    +    },
    +    isSelected: function (tabName) {
    +      if (tabName === activeTasksStore.getSelectedTab()) {
    +       return true;
    +      }
    +      return false;
    +    },
    +    pollingIntervalChange: function (event) {
    +      Actions.changePollingInterval(event.target.value);
    +    },
    +
    +    render: function () {
    +      var pollingInterval = this.state.pollingInterval;
    +
    +      return (
    +        <div>
    +        <ul className="task-tabs nav nav-list">
    +          { this.tabs().map(function (tabName) {
    +            return (
    +              <li key = {tabName} 
    +                  onClick = {this.switchTab.bind(this, tabName)} 
    +                  className = {this.isSelected(tabName) ? 'active': ''}
    +              >
    +                <a>{tabName}</a>
    +              </li>
    +            );
    +          }.bind(this))}
    +        </ul>
    +        <ul className="nav nav-list views polling-interval">
    +          <li className="nav-header">Polling interval</li>
    +          <li>
    +            <input id="pollingRange" type="range" min="1" max="30" step="1" value={pollingInterval}
onChange={this.pollingIntervalChange}/>
    +            <label htmlFor="pollingRange"><span>{pollingInterval}</span>
{pollingInterval === "1" ? 'second' : 'seconds'}</label>
    --- End diff --
    
    For neatness move the `pollingInterval` if statement into a function.


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