<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Plato - components/Logbook/LabeledElement.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/Logbook/LabeledElement.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">67.79</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">88</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">24.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">0.53</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 Proptypes from &#039;prop-types&#039;;
import { InputGroup, Label, FormControl, OverlayTrigger, Tooltip } from &#039;react-bootstrap&#039;;

/**
 * A React component which renders a labeled elemtn (input or simple text)
 */
class LabeledElement extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            inputValue: props.data || &#039;&#039;
        };
    }

    render() {
        let { data, hasNoData, labelText, setTitleInput, tooltip, type } = this.props;

        if (type === &#039;input&#039;) {
            return &lt;OverlayTrigger placement=&#039;top&#039; overlay={&lt;Tooltip id=&#039;tooltip&#039;&gt; {tooltip} &lt;/Tooltip&gt;}&gt;
                &lt;InputGroup&gt;
                    &lt;InputGroup.Addon style={{ backgroundColor: &#039;transparent&#039;, border: &#039;none&#039; }}&gt;
                        &lt;Label&gt; {labelText} &lt;/Label&gt;
                    &lt;/InputGroup.Addon&gt;
                    &lt;FormControl
                        type=&#039;text&#039;
                        value={this.state.inputValue}
                        onChange={this.onChangeInputValue}
                        placeholder={&#039;Optional &#039; + labelText + &#039; here&#039;}
                        ref={setTitleInput}
                    /&gt;
                &lt;/InputGroup&gt;
            &lt;/ OverlayTrigger&gt;
        }

        if (type === &#039;text&#039;) {
            return (&lt;Overlay {...this.props}&gt;
                &lt;div&gt;
                    &lt;Label&gt; {labelText} &lt;/Label&gt;
                    {(hasNoData === true || (hasNoData === false &amp;&amp; data)) ?
                        &lt;div style={{ paddingTop: &#039;5px&#039;, paddingLeft: &#039;10px&#039;, color: &#039;#666666&#039;, display: &#039;inline-block&#039; }}&gt; {data} &lt;/div&gt;
                        :
                        &lt;div style={{ paddingTop: &#039;5px&#039;, paddingLeft: &#039;10px&#039;, color: &#039;#888888&#039;, display: &#039;inline-block&#039;, fontStyle: &#039;italic&#039; }}&gt; Not available &lt;/div&gt;
                    }
                &lt;/div&gt;
            &lt;/Overlay&gt;);
        }
    }

    componentDidUpdate() {
        if (this.props.type === &#039;input&#039;) { this.props.onEventModified(); };
    }

    onChangeInputValue(e) {
        this.setState({ inputValue: e.target.value });
    }
};

export default LabeledElement;

LabeledElement.proptypes = {
    /** data to render */
    data: Proptypes.string,
    /** whehther data are provided or not */
    hasNoData: Proptypes.bool.isRequired,
    /** Text of the label */
    labelText: Proptypes.string,
    /** callback function triggered when user changed the data of the event */
    onEventModified: Proptypes.func,
    /** Callback function used to get data from this input from the parent compoenent */
    setTitleInput: Proptypes.func,
    /** When defined, this component has an overlay to display the provided tooltip. No overlay when this prop is not set. */
    tooltip: Proptypes.object,
    /** type of the element to render : &#039;input&#039; or  */
    type: Proptypes.string.isRequired,
}

/** Simple react component which render an overlay or not */
const Overlay = (props) =&gt; {
    if (props.tooltip) {
        return (&lt;OverlayTrigger
            placement=&#039;top&#039;
            overlay={&lt;Tooltip id=&#039;tooltip&#039;&gt; {props.tooltip} &lt;/Tooltip&gt;}&gt;
            {props.children}
        &lt;/OverlayTrigger&gt;);
    };
    return props.children // no tooltic by default
}</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>
