<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Plato - components/Menu/Menu.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>components/Menu/Menu.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.52</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">199</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">30.15</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.39</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 from &#039;react&#039;;
import { Link } from &#039;react-router-dom&#039;;
import { LinkContainer } from &#039;react-router-bootstrap&#039;
import { Glyphicon, Nav, NavItem, Navbar, NavDropdown, MenuItem } from &#039;react-bootstrap&#039;;
import logo from &#039;../../images/ebs.gif&#039;;
import &#039;./Menu.css&#039;;
import &#039;./glyhicon-spinner.css&#039;;
import BreadCrumbs from &#039;../Breadcrumbs/BreadCrumbs.js&#039;;
import _ from &#039;lodash&#039;;
import UI from &#039;./../../config/ui/config.js&#039;;


export class Menu extends React.Component {
    constructor(props) {
        super(props);
        this.onLogOutClicked = this.onLogOutClicked.bind(this);        
    }
    
    getNewTag(){
        return &lt;sub style={{ color: &#039;red&#039;, fontSize: &#039;10px&#039;, marginLeft: &#039;5px&#039; }}&gt;NEW&lt;/sub&gt;;
    }

    onLogOutClicked(e) {
        this.props.doLogOut();
    }

    getLoggedOutRender() {
        return &lt;Navbar fluid inverse fixedTop&gt;
            &lt;Navbar.Header&gt;
                &lt;Navbar.Brand&gt;
                    &lt;Link to=&quot;/investigations&quot; &gt;&lt;img alt=&quot;&quot; src={logo} className=&#039;logo&#039; /&gt;&lt;/Link&gt;
                &lt;/Navbar.Brand&gt;
                &lt;Navbar.Toggle /&gt;
            &lt;/Navbar.Header&gt;
        &lt;/Navbar&gt;;
    }

    getOpenDataMenuItem() {
        if (this.props.datacollections.fetching) {
            return &lt;LinkContainer to=&#039;/public&#039;&gt;
                &lt;NavItem eventKey={3} href=&#039;/public&#039;&gt;
                    Open Data&lt;span style={{ marginLeft: &#039;10px&#039; }} className=&quot;glyphicon glyphicon-repeat fast-right-spinner&quot;&gt;&lt;/span&gt;
                &lt;/NavItem&gt;
            &lt;/LinkContainer&gt;;
        }
        return &lt;LinkContainer to=&#039;/public&#039;&gt;
            &lt;NavItem eventKey={3} href=&#039;/public&#039;&gt;
                Open Data&lt;span className=&quot;badge&quot; style={{ marginLeft: &#039;10px&#039; }}&gt;{this.props.datacollections.data.length}&lt;/span&gt;
            &lt;/NavItem&gt;
        &lt;/LinkContainer&gt;;
    }

    getClosedDataMenuItem() {
        if (!this.props.investigations.initialized){
            if (this.props.investigations.fetching) {
                return &lt;LinkContainer to=&#039;/closed&#039;&gt;
                    &lt;NavItem eventKey={4} href=&#039;/closed&#039;&gt;
                        Closed Data&lt;span style={{ marginLeft: &#039;10px&#039; }} class=&quot;glyphicon glyphicon-repeat fast-right-spinner&quot;&gt;&lt;/span&gt;
                    &lt;/NavItem&gt;
                &lt;/LinkContainer&gt;;
            }
        }
        return &lt;LinkContainer to=&#039;/closed&#039;&gt;
            &lt;NavItem eventKey={4} href=&#039;/closed&#039;&gt;
                Closed Data&lt;span className=&quot;badge&quot; style={{ marginLeft: &#039;10px&#039; }}&gt;{this.props.investigations.data.length}&lt;/span&gt;
            &lt;/NavItem&gt;
        &lt;/LinkContainer&gt;;

    }


    render() {

        /** If there is not sessionId it means that we are not already been authenticated **/
        if ((!this.props.user) || (!this.props.user.sessionId)) {
            return this.getLoggedOutRender();
        }

        return (&lt;div&gt;
            &lt;Navbar inverse collapseOnSelect&gt;
                &lt;Navbar.Header&gt;
                    &lt;Navbar.Brand&gt;
                        &lt;a href=&quot;/&quot;&gt;{UI.menu.applicationTittle}&lt;/a&gt;
                    &lt;/Navbar.Brand&gt;
                    &lt;Navbar.Toggle /&gt;
                &lt;/Navbar.Header&gt;
                &lt;Navbar.Collapse&gt;
                    &lt;Nav&gt;
                        { UI.menu.isSearchVisible &amp;&amp;
                            &lt;LinkContainer to=&#039;/search&#039;&gt;
                                &lt;NavItem eventKey={2}&gt;
                                    &lt;span&gt;
                                        &lt;Glyphicon style={{ fontSize: &#039;20px&#039; }} glyph=&quot;glyphicon glyphicon-search&quot; /&gt;                                                                    
                                    &lt;/span&gt;
                                &lt;/NavItem&gt;
                            &lt;/LinkContainer&gt;
                        }
                        &lt;LinkContainer to=&#039;/investigations&#039;&gt;
                            &lt;NavItem eventKey={3} &gt;
                                My Data&lt;span className=&quot;badge&quot; style={{ marginLeft: &#039;10px&#039; }}&gt;{this.props.myInvestigations.data.length}&lt;/span&gt;
                            &lt;/NavItem&gt;
                        &lt;/LinkContainer&gt;
                        { UI.menu.isOpenDataVisible &amp;&amp;
                            this.getOpenDataMenuItem()
                        }
                        { UI.menu.isClosedDataVisible &amp;&amp;
                            this.getClosedDataMenuItem()
                        }
                        { UI.menu.isMySelectionVisible &amp;&amp; this.props.selection.datasetIds.length &gt; 0 &amp;&amp;
                            &lt;LinkContainer to=&#039;/selection&#039;&gt;
                                &lt;NavItem eventKey={3}&gt;
                                    My Selection&lt;span className=&quot;badge&quot; style={{ marginLeft: &#039;10px&#039; }}&gt;{this.props.selection.datasetIds.length}&lt;/span&gt;
                                &lt;/NavItem&gt;
                            &lt;/LinkContainer&gt;
                        }
                        { (this.props.user.isAdministrator || this.props.scientistInstrumentInvestigations.data.length &gt; 0) &amp;&amp;
                            &lt;ManagerMenu user={this.props.user} getNewTag={this.getNewTag}  scientistInstrumentInvestigations={this.props.scientistInstrumentInvestigations}&gt;&lt;/ManagerMenu&gt;
                        }        
                    &lt;/Nav&gt;
                    &lt;Nav pullRight&gt;
                        &lt;NavItem eventKey={2} onClick={this.onLogOutClicked} &gt;
                            &lt;Glyphicon glyph=&quot;glyphicon glyphicon-log-out&quot; /&gt;
                            Log out &lt;strong&gt;{this.props.user.fullName}&lt;/strong&gt;
                        &lt;/NavItem&gt;
                    &lt;/Nav&gt;
                &lt;/Navbar.Collapse&gt;
            &lt;/Navbar&gt;
            &lt;BreadCrumbs breadcrumbsList={this.props.breadcrumbsList}&gt;&lt;/BreadCrumbs&gt;
        &lt;/div&gt;)
    }
}


class ManagerMenu extends React.Component {

    getBeamlineList(instruments){
        if (this.props.scientistInstrumentInvestigations.fetching) {
            return &lt;LinkContainer to=&#039;/usermanagement&#039;&gt;
                        &lt;MenuItem eventKey={3.3}&gt;
                            Fetching beamlines&lt;span style={{ marginLeft: &#039;10px&#039; }} className=&quot;glyphicon glyphicon-repeat fast-right-spinner&quot;&gt;&lt;/span&gt;
                        &lt;/MenuItem&gt;
                    &lt;/LinkContainer&gt;;
        
        }

        if (instruments &amp;&amp; instruments.length &gt; 0){
            var _this = this;
            function getInvestigationCountByBeamlineName(beamlineName){
                return &lt;span className=&quot;badge&quot; style={{ marginLeft: &#039;10px&#039; }}&gt;
                             {_.filter(_this.props.scientistInstrumentInvestigations.data, function(inv){ 
                                 if (inv.investigationInstruments.length === 0) return;
                                 return inv.investigationInstruments[0].instrument.name === beamlineName}).length}
                        &lt;/span&gt;;
            }
            
            var items = instruments.sort().map((value, index) =&gt; {
                if (value)
                    return &lt;LinkContainer to={&quot;/investigations?beamline=&quot;+ value}&gt;&lt;MenuItem eventKey={3 + &quot;.&quot; + index} key={index}&gt;{value} {getInvestigationCountByBeamlineName(value)}&lt;/MenuItem&gt;&lt;/LinkContainer&gt;
            });
            return items;
        }          
        return null;
    }
    render(){
        var instruments = _.uniq(_.map(this.props.scientistInstrumentInvestigations.data, function(inv){ 
            if (inv.investigationInstruments.length &gt; 0){
                return inv.investigationInstruments[0].instrument.name;
            }
        })); 
        const navDropdownTitle = (&lt;span&gt;Manager &lt;span className=&quot;badge&quot; style={{ marginLeft: &#039;10px&#039; }}&gt;
            { this.props.scientistInstrumentInvestigations.fetching &amp;&amp;
                &lt;span style={{ marginLeft: &#039;10px&#039; }} className=&quot;glyphicon glyphicon-repeat fast-right-spinner&quot;&gt;&lt;/span&gt;
            }
            { this.props.scientistInstrumentInvestigations.fetched &amp;&amp;
                instruments.length
            }
            &lt;/span&gt;&lt;/span&gt; );
        return &lt;NavDropdown eventKey={3} title={navDropdownTitle} id=&quot;basic-nav-dropdown&quot;&gt;
                &lt;LinkContainer to=&#039;/usermanagement&#039;&gt;
                    &lt;MenuItem eventKey={3.3}&gt;
                            &lt;Glyphicon glyph=&quot;user&quot; /&gt;
                            &lt;span style={{ marginLeft: &#039;10px&#039; }} &gt;Beamline Managers {this.props.getNewTag()}&lt;/span&gt;
                    &lt;/MenuItem&gt;
                &lt;/LinkContainer&gt;
                { this.props.user.isAdministrator &amp;&amp;
                        &lt;LinkContainer to=&#039;/manager/stats&#039;&gt;
                        &lt;MenuItem eventKey={3.4}&gt;
                                &lt;Glyphicon glyph=&quot;stats&quot; /&gt;
                                &lt;span style={{ marginLeft: &#039;10px&#039; }} &gt;Data Statistics {this.props.getNewTag()}&lt;/span&gt;
                        &lt;/MenuItem&gt;
                    &lt;/LinkContainer&gt; 
                }
            &lt;MenuItem divider /&gt;
             { this.getBeamlineList(instruments)}

        &lt;/NavDropdown&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>
