<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Plato - components/Event/Tag/TagEditor.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/Event/Tag/TagEditor.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">76.74</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">160</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">19.50</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.87</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 { Grid, Row, Col, FormControl, Popover, OverlayTrigger, Button, Panel, FormGroup, ControlLabel } from &#039;react-bootstrap&#039;;
import { GUI_CONFIG } from &#039;../../../config/gui.config&#039;;
import { GithubPicker } from &#039;react-color&#039;;
import _ from &#039;lodash&#039;;


/**
 * React component used to edit or create a tag
 */
class TagEditor extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            tag: this.props.tag || { name: &#039;&#039;, description: &#039;&#039;, color: GUI_CONFIG().DEFAULT_TAG_COLOR, investigationId: this.props.investigationId },
        };

        this.onChangeComplete = this.onChangeComplete.bind(this);
    }

    render() {
        let tag = this.state.tag;

        return (
            &lt;Grid fluid style={{ marginTop: &#039;20px&#039;, marginBottom: &#039;70px&#039; }}&gt;
                &lt;Row className=&#039;show-grid&#039;&gt;
                    &lt;Col xs={0} md={1}&gt; &lt;/Col&gt;
                    &lt;Col xs={12} md={10}&gt;
                        &lt;h3&gt; Editing Tag &lt;/h3&gt;
                        &lt;Panel bsStyle=&#039;primary&#039;&gt;
                            &lt;Panel.Heading&gt;
                                &lt;strong&gt;Please update tag details &lt;/strong&gt;
                            &lt;/Panel.Heading&gt;
                            &lt;Panel.Body&gt;
                                &lt;FormGroup controlId=&#039;formControlTagLabel&#039;&gt;
                                    &lt;ControlLabel&gt;Label &lt;Mandatory&gt;&lt;/Mandatory&gt;&lt;/ControlLabel&gt;
                                    &lt;FormControl
                                        componentClass=&#039;input&#039;
                                        type=&#039;text&#039;
                                        placeholder=&#039;Tag name&#039;
                                        value={tag.name}
                                        onChange={(e) =&gt; this.onInputChange(&#039;name&#039;, e)} /&gt;
                                &lt;/FormGroup&gt;

                                &lt;FormGroup controlId=&#039;formControlTagDescription&#039;&gt;
                                    &lt;ControlLabel&gt;Description &lt;/ControlLabel&gt;
                                    &lt;FormControl
                                        componentClass=&#039;input&#039;
                                        type=&#039;text&#039;
                                        placeholder=&#039;Tag description&#039;
                                        value={tag.description}
                                        onChange={(e) =&gt; this.onInputChange(&#039;description&#039;, e)} /&gt;
                                &lt;/FormGroup&gt;

                                &lt;FormGroup controlId=&#039;formControlTagScope&#039;&gt;
                                    &lt;ControlLabel&gt;Scope &lt;Mandatory&gt;&lt;/Mandatory&gt; &lt;/ControlLabel&gt;
                                    &lt;FormControl
                                        componentClass=&#039;select&#039;
                                        type=&#039;text&#039;
                                        placeholder=&#039;Tag scope&#039;
                                        value={tag.description}
                                        onChange={(e) =&gt; this.onInputChange(&#039;scope&#039;, e)}
                                    &gt;
                                        &lt;option value=&#039;investigation&#039;&gt;investigation&lt;/option&gt;
                                        {/* &lt;option value=&#039;beamline&#039;&gt;beamline&lt;/option&gt; */}
                                    &lt;/FormControl&gt;
                                &lt;/FormGroup&gt;

                                &lt;FormGroup controlId=&#039;formControlTagColor&#039;&gt;
                                    &lt;ControlLabel&gt; Color &lt;/ControlLabel&gt;
                                    &lt;Row&gt;
                                        &lt;Col xs=&#039;12&#039;&gt;
                                            &lt;OverlayTrigger
                                                trigger=&#039;click&#039;
                                                placement=&#039;top&#039;
                                                rootClose=&#039;true&#039;
                                                overlay={PopoverColorPickerBottom(this.onChangeComplete)}
                                            &gt;
                                                &lt;div
                                                    style={{
                                                        backgroundColor: tag.color || GUI_CONFIG().DEFAULT_TAG_COLOR,
                                                        width: &#039;30px&#039;,
                                                        height: &#039;30px&#039;,
                                                        marginLeft: &#039;50%&#039;,
                                                        marginRight: &#039;50%&#039;
                                                    }}&gt;
                                                &lt;/div&gt;
                                            &lt;/OverlayTrigger&gt;
                                        &lt;/Col &gt;
                                    &lt;/Row&gt;
                                &lt;/FormGroup&gt;
                                &lt;br /&gt;

                                &lt;div style={{ float: &#039;right&#039; }}&gt;
                                    &lt;Button bsStyle=&#039;primary&#039; style={{ marginRight: &#039;10px&#039; }} onClick={() =&gt; this.onSave()}&gt; Save &lt;/Button&gt;
                                    &lt;Button bsStyle=&#039;primary&#039; style={{ marginRight: &#039;10px&#039; }} onClick={() =&gt; this.props.showAvailableTags()} &gt; Cancel &lt;/Button&gt;
                                &lt;/div&gt;
                            &lt;/Panel.Body&gt;
                        &lt;/Panel&gt;
                    &lt;/Col&gt;
                    &lt;Col xs={0} md={1}&gt; &lt;/Col&gt;

                &lt;/Row&gt;
            &lt;/Grid&gt;
        );
    }

    /** 
     * CallBack function triggered when the user changes the tag field
    */
    onInputChange(changedTagProperty, event) {
        let value = event.target.value;

        let tagCopy = this.state.tag;
        tagCopy[changedTagProperty] = value;

        this.setState({
            tag: tagCopy
        });
    }

    /* CallBack function triggered when the user selects a new color */
    onChangeComplete(color) {
        let fakeEvent = {};
        fakeEvent.target = {};
        fakeEvent.target.value = color.hex;
        this.onInputChange(&#039;color&#039;, fakeEvent);
    }

    onSave() {
        if (this.props.tag) {
            this.props.updateTags([this.state.tag]);
        } else {
            this.props.createNewTag(this.state.tag);
        };
    }
}

class Mandatory extends React.Component {
    render() {
        return (            &lt;span style={{ color: &#039;red&#039; }}&gt;*&lt;/span&gt;        );
    }
};

const PopoverColorPickerBottom = (callback) =&gt; {
    return (&lt;Popover id=&#039;popover-positioned-bottom&#039; title=&#039;Select a color&#039;&gt;
        &lt;GithubPicker triangle=&#039;hide&#039; width=&#039;230px&#039; onChangeComplete={callback} /&gt;
    &lt;/Popover&gt;
    );
};

TagEditor.propTypes = {
    /** callback function used to show the tag list */
    showAvailableTags: PropTypes.func,
    /* if present, it corresponds to the tag to edit. If absent, it indcates that a tag is being created*/
    tag: PropTypes.object
};

export default TagEditor;</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>
