<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Plato - containers/Selection/SelectionContainer.js</title>

  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="">

  <!--[if lt IE 9]>
  <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
  <![endif]-->

  <link href="../../assets/css/vendor/morris.css" rel="stylesheet" type="text/css">
  <link href="../../assets/css/vendor/bootstrap.css" rel="stylesheet" type="text/css">
  <link href="../../assets/css/vendor/font-awesome.css" rel="stylesheet" type="text/css">
  <link href="../../assets/css/vendor/codemirror.css" rel="stylesheet" type="text/css">
  <link href="../../assets/css/plato.css" rel="stylesheet" type="text/css">
  <link href="../../assets/css/plato-file.css" rel="stylesheet" type="text/css">

</head>

<body>

<div class="navbar navbar-fixed-top">
  <div class="container">
    <a class="navbar-brand" href="https://github.com/the-simian/es6-plato">ES6 Plato on Github</a>
    <ul class="nav navbar-nav">
      <li>
        <a href="../../index.html">Report Home</a>
      </li>
      <li class="active">
        <a href="display.html">Summary Display</a>
      </li>
    </ul>
  </div>
</div>

<div class="jumbotron">
  <div class="container">
    <h1>containers/Selection/SelectionContainer.js</h1>
  </div>
</div>

<div class="container aggregate-stats">
  <div class="row">
    <div class="col-md-6">
      <h2 class="header">Maintainability <a href="http://blogs.msdn.com/b/codeanalysis/archive/2007/11/20/maintainability-index-range-and-meaning.aspx"><i class="icon icon-info-sign" rel="popover" data-placement="top" data-trigger="hover" data-content="A value between 0 and 100 that represents the relative ease of maintaining the code. A high value means better maintainability." data-original-title="Maintainability Index"  data-container="body"></i></a></h2>
      <p class="stat">72.32</p>
    </div>
    <div class="col-md-6">
      <h2 class="header">Lines of code <i class="icon icon-info-sign" rel="popover" data-placement="top" data-trigger="hover" data-content="Source Lines of Code / Logical Lines of Code" data-original-title="SLOC/LSLOC" data-container="body"></i></h2>
      <p class="stat">150</p>
    </div>
  </div>
  <div class="row historical">
    <div class="col-md-6">
      <p id="chart_historical_maint" class="chart"></p>
    </div>
    <div class="col-md-6">
      <p id="chart_historical_sloc" class="chart"></p>
    </div>
  </div>
  <div class="row">
    <div class="col-md-6">
      <h2 class="header">Difficulty  <a href="http://en.wikipedia.org/wiki/Halstead_complexity_measures"><i class="icon icon-info-sign" rel="popover" data-placement="top" data-trigger="hover" data-content="The difficulty measure is related to the difficulty of the program to write or understand." data-original-title="Difficulty" data-container="body"></i></a></h2>
      <p class="stat">23.09</p>
    </div>
    <div class="col-md-6">
      <h2 class="header">Estimated Errors  <a href="http://en.wikipedia.org/wiki/Halstead_complexity_measures"><i class="icon icon-info-sign" rel="popover" data-placement="top" data-trigger="hover" data-content="Halstead's delivered bugs is an estimate for the number of errors in the implementation." data-original-title="Delivered Bugs" data-container="body"></i></a></h2>
      <p class="stat">1.09</p>
    </div>
  </div>
</div>

<div class="container charts">
  <div class="row">
    <h2 class="header">Function weight</h2>
  </div>
  <div class="row">
    <div class="col-md-6">
      <h3 class="chart-header">By Complexity <a href="http://en.wikipedia.org/wiki/Cyclomatic_complexity"><i class="icon icon-info-sign" rel="popover" data-placement="top" data-trigger="hover" data-content="This metric counts the number of distinct paths through a block of code. Lower values are better." data-original-title="Cyclomatic Complexity" data-container="body"></i></a></h3>
      <div id="fn-by-complexity" class="stat"></div>
    </div>
    <div class="col-md-6">
      <h3 class="chart-header">By SLOC  <i class="icon icon-info-sign" rel="popover" data-placement="top" data-trigger="hover" data-content="Source Lines of Code / Logical Lines of Code" data-original-title="SLOC/LSLOC" data-container="body"></i></h3>
      <div id="fn-by-sloc" class="stat"></div>
    </div>
  </div>
</div>

<div class="container">
  <div class="row">
    <textarea id="file-source" class="col-md-12">import React, { Component } from &#039;react&#039;;
import axios from &quot;axios&quot;;
import PropTypes from &#039;prop-types&#039;;
import { connect } from &#039;react-redux&#039;;
import DatasetTable from &quot;../../components/Dataset/DatasetTable.js&quot;;
import { bindActionCreators } from &#039;redux&#039;;
import { getDatasetsById } from &#039;../../api/icat/icatPlus.js&#039;;
import { doSignIn } from &#039;../../actions/login.js&#039;;
import { PERSPECTIVE } from &#039;../../constants/Perspectives.js&#039;;
import { Glyphicon, Button, ButtonToolbar, Tooltip, OverlayTrigger } from &#039;react-bootstrap&#039;;
import { addDatasetById, removeDatasetById } from &#039;../../actions/selection.js&#039;;
import { setBreadCrumbs } from &#039;../../actions/breadcrumbs.js&#039;;


class SelectionContainer extends Component {
  constructor(props) {
    super(props);

    this.state = {
      investigationId: this.props.investigationId,
      username: this.props.user.username,
      sessionId: this.props.user.sessionId,
      datasets: [],
      filtered: [],
      fetching: true,
      datasetIds: this.props.selection.datasetIds
    }
  }


  componentDidMount() {
    this.retrieveSelectedDatasetsFromDatabase();
    this.props.setBreadCrumbs([{ name: &#039;Selection&#039;, link: &#039;/selection&#039; }, { name: &#039;Datasets&#039;}]);
  }

  retrieveSelectedDatasetsFromDatabase() {
    if (this.props.selection.datasetIds.length &gt; 0) {
      axios.get(getDatasetsById(this.state.sessionId, this.props.selection.datasetIds))
        .then(res =&gt; {                    
          this.setState({
            datasets: res.data,
            filtered: res.data,
            fetching: false

          });
        })
        .catch((error) =&gt; {
          if (error.response) {
            if (error.response.status === 401) {
              //this.props.doSignIn();
            }
          }
        });
    }
    else {
      this.setState({
        datasets: [],
        filtered: [],
        fetching: false

      });
    }
  }
  render() {
     if (this.props.user.sessionId == null){
       return null;
     }
    /** This means that datasets has not been loaded yet. It could be done with FETCHING (?) **/    
    /*if (this.props.selection.datasetIds.length !== this.state.datasets.length) {
      this.retrieveSelectedDatasetsFromDatabase();
    }*/

    return &lt;div&gt;
      &lt;SelectionContainerMenu&gt;&lt;/SelectionContainerMenu&gt;
      &lt;div style={{ marginTop: &quot;60px&quot; }}&gt;
        &lt;DatasetTable
          selection={this.props.selection}
          removeDatasetById={this.props.removeDatasetById}
          addDatasetById={this.props.addDatasetById}
          sessionId={this.props.user.sessionId}
          datasets={this.state.filtered}
          fetching={this.state.fetching}&gt;
        &lt;/DatasetTable&gt;
      &lt;/div&gt;
    &lt;/div&gt;;
  }
}

function mapStateToProps(state) {
  return {
    user: state.user,
    events: state.events,
    selection: state.selection
  };
}

function mapDispatchToProps(dispatch) {
  return {
    removeDatasetById: bindActionCreators(removeDatasetById, dispatch),
    addDatasetById: bindActionCreators(addDatasetById, dispatch),
    doSignIn: bindActionCreators(doSignIn, dispatch),
    doLogOut: bindActionCreators(doSignIn, dispatch),
    setBreadCrumbs: bindActionCreators(setBreadCrumbs, dispatch)
  };
}

SelectionContainer.propTypes = {
  perspective: PropTypes.oneOf([PERSPECTIVE.DATASETS, PERSPECTIVE.FILES, PERSPECTIVE.EVENTS])
}

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(SelectionContainer);

class SelectionContainerMenu extends React.Component {
  handleKeyPress(event) {
    if (event.key === &#039;Enter&#039;) {
      this.onSearch(event.target.value);
    }
  }

  render() {
    const tooltip = (text) =&gt; (
      &lt;Tooltip id=&quot;tooltip&quot;&gt;
        {text}
      &lt;/Tooltip&gt;
    );

    return &lt;div &gt;
      &lt;ButtonToolbar fluid className=&quot;navbar-fixed-top&quot; style={{ backgroundColor: &#039;white&#039;, marginBottom: &quot;10px&quot;, marginTop: &quot;100px&quot; }}&gt;
        &lt;div style={{ marginLeft: &#039;40px&#039;, marginTop: &#039;10px&#039; }}&gt;
          &lt;OverlayTrigger placement=&quot;bottom&quot; overlay={tooltip(&quot;Mint a DOI for all selected datasets&quot;)} &gt;
            &lt;Button bsSize=&quot;small&quot; bsStyle=&quot;primary&quot; href=&#039;selection/mint&#039;&gt;
              &lt;Glyphicon glyph=&quot;plus&quot; /&gt; Mint a DOI
                          &lt;/Button&gt;
          &lt;/OverlayTrigger&gt;
          &lt;OverlayTrigger placement=&quot;bottom&quot; overlay={tooltip(&quot;Download all selected datasets&quot;)}&gt;
            &lt;Button style={{ marginLeft: &#039;5px&#039; }} bsSize=&quot;small&quot; bsStyle=&quot;primary&quot; target=&quot;_blank&quot;&gt;
              &lt;Glyphicon glyph=&quot;download&quot; style={{ marginRight: &quot;3px&quot; }} /&gt; Download all
                          &lt;/Button&gt;
          &lt;/OverlayTrigger&gt;
        &lt;/div&gt;
      &lt;/ButtonToolbar&gt;
    &lt;/div&gt;
  }

}

</textarea>
  </div>
</div>

<footer class="footer">
  <div class="container">
    <p>.</p>
  </div>
</footer>

<script type="text/html" id="complexity-popover-template">
  <div class="complexity-notice">
    Complexity : {{ complexity.cyclomatic }} <br>
    Length : {{ complexity.halstead.length }} <br>
    Difficulty : {{ complexity.halstead.difficulty.toFixed(2) }} <br>
    Est # bugs : {{ complexity.halstead.bugs.toFixed(2) }}<br>
  </div>
</script>

<script type="text/javascript" src="../../assets/scripts/bundles/core-bundle.js"></script>
<script type="text/javascript" src="../../assets/scripts/bundles/codemirror.js"></script>
<script type="text/javascript" src="../../assets/scripts/codemirror.markpopovertext.js"></script>
<script type="text/javascript" src="report.js"></script>
<script type="text/javascript" src="report.history.js"></script>
<script type="text/javascript" src="../../assets/scripts/plato-file.js"></script>
</body>
</html>
