<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Plato - components/Logbook/EventVersions.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/EventVersions.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">70.19</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">123</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">29.65</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.71</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 { Row, Col, Popover, Button, Well } from &#039;react-bootstrap&#039;;
import { getPreviousVersionNumber, } from &#039;../../helpers/EventHelpers&#039;;
import Popup from &#039;reactjs-popup&#039;;
import Moment from &#039;moment&#039;;
import EventVersionPanel from &#039;./EventVersionPanel&#039;;
import { LATEST_EVENT_VERSION, ORIGINAL_EVENT_VERSION, MIDDLE_EVENT_VERSION } from &#039;../../constants/EventTypes&#039;;

/**
* Render the popup which displays all event versions of the event
* @param {*} event the event under investigation
        */
export default function EventVersions(event) {
    let e = event;

    /* build the different lines representing the previous versions */
    let lines = [];
    while (e.previousVersionEvent != null) {
        if (lines.length === 0) {
            lines.push(&lt;EventVersionItem event={e} type=&#039;edition&#039; mostRecent={true} /&gt;);
        } else {
            lines.push(&lt;EventVersionItem event={e} type=&#039;edition&#039; mostRecent={false} /&gt;);
        };
        e = e.previousVersionEvent;
    }
    lines.push(&lt;EventVersionItem event={e} type=&#039;creation&#039; /&gt;);


    /* build the popover */
    return (&lt;Popover id=&#039;mypopover&#039;&gt;
        &lt;div&gt;
            &lt;p style={{ marginBottom: &#039;5px&#039; }}&gt; This log has {getPreviousVersionNumber(event) + 1} versions. &lt;/p&gt;
            &lt;hr style={{ marginTop: &#039;5px&#039; }} /&gt;
            {lines.map((item, index) =&gt; &lt;Popup
                key={index}
                trigger={&lt;div&gt; {item} &lt;/div&gt;}
                modal
                closeOnDocumentClick={false}
                contentStyle={{ width: &#039;90%&#039;, height: &#039;90%&#039; }}
            &gt;
                {close =&gt; (
                    &lt;div className=&#039;fullPage&#039;&gt;
                        &lt;a className=&#039;close&#039; onClick={close}&gt; &amp;times; &lt;/a&gt;
                        &lt;div className=&#039;content&#039;&gt;
                            &lt;EventVersionPanel
                                event={item.props.event}
                                version={index === 0 ? LATEST_EVENT_VERSION : index === lines.length - 1 ? ORIGINAL_EVENT_VERSION : MIDDLE_EVENT_VERSION} /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                )}
            &lt;/Popup&gt;
            )}
            &lt;hr style={{ marginBottom: &#039;5px&#039; }} /&gt;

            &lt;Popup
                trigger={&lt;div style={{ display: &#039;inline&#039; }}&gt; &lt;Button bsStyle=&#039;link&#039;&gt; See all versions  &lt;/Button&gt; &lt;/div&gt;}
                modal
                closeOnDocumentClick={false}
                contentStyle={{ width: &#039;90%&#039;, height: &#039;90%&#039; }}
            &gt;
                {close =&gt; {
                    return &lt;div className=&#039;fullPage&#039;&gt;
                        &lt;a className=&#039;close&#039; onClick={close}&gt; &amp;times; &lt;/a&gt;
                        &lt;div className=&#039;content&#039;&gt;
                            &lt;CompleteEventHistory event={event} /&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;

                }}
            &lt;/Popup&gt;

        &lt;/div&gt;
    &lt;/Popover&gt;);
}

/**
 * React component which represents on item of the event history
* @param {*} props  the props passed to this component
                */
class EventVersionItem extends React.Component {
    render() {
        function buildTheDisplay(event, type, mostRecent) {
            return (
                &lt;Well bsSize=&#039;small&#039; style={{ marginBottom: &#039;5px&#039;, cursor: &#039;pointer&#039; }}&gt;
                    &lt;b&gt; {event.username} &lt;/b&gt;
                    {type === &#039;creation&#039; ? &#039;created on &#039; : &#039;&#039;}
                    {type === &#039;edition&#039; ? &#039;edited on &#039; : &#039;&#039;}
                    {Moment(event.creationDate).format(&#039;MMMM DD HH:mm&#039;)}
                    {mostRecent === true ? &#039; (most recent)&#039; : &#039;&#039;}
                    {event.machine ? &lt;span style={{ color: &#039;#777777&#039;, fontStyle: &#039;italic&#039; }}&gt; from {event.machine} &lt;/span&gt; : &#039;&#039;}
                &lt;/Well&gt;
            );
        };

        return (
            buildTheDisplay(this.props.event, this.props.type, this.props.mostRecent)
        );
    };
};

/**
 * React component which displays the complete event history
 */
const CompleteEventHistory = (props) =&gt; {
    let { event } = props;
    let eventVersions = [];
    /* first push the current event which is the latest version of the event */
    eventVersions.push(&lt;EventVersionPanel event={event} version={LATEST_EVENT_VERSION} /&gt;);
    /* then display the previous version of this event */
    while (event.previousVersionEvent != null) {
        event = event.previousVersionEvent;
        eventVersions.push(&lt;div className=&#039;margin-bottom-10&#039;&gt;
            &lt;Row&gt;
                &lt;Col xs={1}&gt; &lt;/Col&gt;
                &lt;Col xs={11}&gt;
                    &lt;EventVersionPanel event={event} version={event.previousVersionEvent === null ? ORIGINAL_EVENT_VERSION : MIDDLE_EVENT_VERSION} /&gt;
                &lt;/Col&gt;
            &lt;/Row&gt;
        &lt;/div&gt;);
    };

    return eventVersions;
};</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>
