<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Plato - components/Event/BasicEvent.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/BasicEvent.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">64.97</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">176</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.45</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.12</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 { getOriginalEvent, getEventIcon, getLastCommentContent, getEventCreationDate, getEventHistoryCreationDate, getContent } from &#039;../../helpers/EventHelpers&#039;;
import EventContentDisplayer from &#039;./EventContentDisplayer&#039;;
import { ANNOTATION, NOTIFICATION, EDIT_MODE, DOC_VIEW, BASIC_EVENT_CONTEXT } from &#039;../../constants/EventTypes&#039;;

import { OverlayTrigger, Tooltip, Dropdown, MenuItem } from &#039;react-bootstrap&#039;;
import TagContainer from &#039;../../containers/TagContainer&#039;;

require(&#039;./event.css&#039;);


/**
 * A basic event of the logbook
 */
class BasicEvent extends React.Component {
    render() {

        function showContent() {
            if (event.content &amp;&amp; (getContent(event.content, &#039;plainText&#039;) !== null || getContent(event.content, &#039;html&#039;) !== null)) {
                if (event.type === ANNOTATION) {
                    return (&lt;AnnotationContent event={event} view={view} /&gt;);
                } else if (event.type === NOTIFICATION) {
                    return (&lt;NotificationContent event={event} /&gt;);
                };
            } else {
                return (&lt;div&gt;
                    &lt;div style={{ flexGrow: &#039;1&#039;, marginLeft: &#039;10px&#039;, paddingTop: &#039;4px&#039;, paddingBottom: &#039;4px&#039; }} &gt;
                        &lt;Icon event={event} view={view} /&gt;
                    &lt;/div&gt;

                    &lt;p style={{ margin: &#039;0px&#039;, color: &#039;#777777&#039;, fontStyle: &#039;italic&#039; }}&gt;This event has no content&lt;/p&gt;
                &lt;/div&gt;
                );
            };
        };

        let { event, toggleMode, view, investigationId } = this.props;
        let paddingTopDate = (event.type === ANNOTATION) ? &#039;6px&#039; : &#039;0px&#039;;

        return (
            &lt;div
                id=&#039;contentDocList&#039;
                onDoubleClick={() =&gt; { toggleMode(EDIT_MODE); }}
                style={{ display: &#039;flex&#039; }} &gt;
                &lt;div
                    id={(this.props.isSelected === true) ? &#039;selectedEvent&#039; : &#039;&#039;}
                    style={{ flexGrow: &#039;0&#039;, flexShrink: &#039;0&#039; }}
                &gt;
                    &lt;OverlayTrigger
                        placement=&#039;right&#039;
                        overlay={
                            &lt;Tooltip id=&#039;tooltip&#039;&gt;
                                &lt;p&gt; Event created on {getEventHistoryCreationDate(getOriginalEvent(event))} &lt;/p&gt;
                            &lt;/Tooltip&gt;
                        }&gt;
                        &lt;div&gt;
                            &lt;div style={{ paddingTop: paddingTopDate, paddingLeft: &#039;10px&#039;, color: &#039;#666666&#039;, display: &#039;inline&#039; }}&gt;
                                {getEventCreationDate(getOriginalEvent(event))}
                            &lt;/div&gt;
                            &lt;Dropdown id=&#039;dropdown-custom-1&#039; &gt;
                                &lt;Dropdown.Toggle bsStyle=&#039;link&#039; style={{
                                    paddingRight: &#039;2px&#039;,
                                    paddingLeft: &#039;4px&#039;,
                                    paddingTop: &#039;0px&#039;,
                                    paddingBottom: &#039;0px&#039;,
                                    backgroundColor: &#039;transparent&#039;,
                                    marginRight: &#039;10px&#039;,
                                    color: &#039;#888888&#039;
                                }}&gt;

                                &lt;/Dropdown.Toggle &gt;
                                &lt;Dropdown.Menu className=&#039;super-colors&#039;&gt;
                                    &lt;MenuItem eventKey=&#039;1&#039; onClick={() =&gt; this.props.reverseEventsSortingByCreationDate(this.props.event._id)}    &gt;
                                        Reverse sort and highlight this event.
                                    &lt;/MenuItem&gt;

                                &lt;/Dropdown.Menu&gt;
                            &lt;/Dropdown&gt;
                        &lt;/div&gt;
                    &lt;/OverlayTrigger&gt;
                &lt;/div&gt;
                &lt;div style={{ flexGrow: &#039;1&#039;, marginLeft: &#039;30px&#039; }}&gt;
                    {showContent()}
                &lt;/div&gt;
                &lt;div style={{ flexGrow: &#039;1&#039;, flexShrink: &#039;0&#039;, flexBasis: &#039;100px&#039; }}&gt;
                    &lt;div style={{ textAlign: &#039;right&#039; }}&gt;
                        &lt;TagContainer context={BASIC_EVENT_CONTEXT} investigationId={investigationId} event={event} /&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div &gt;
        );
    };
}

BasicEvent.propTypes = {
    /* the event object as received from the ICAT+ server */
    event: PropTypes.object.isRequired,
    /** whether this event is selected or not */
    isSelected: PropTypes.bool,
    /* callback functon which trigger a change to another mode */
    toggleMode: PropTypes.func.isRequired,
    /** the user who is currently logged in */
    user: PropTypes.object.isRequired,
    /* the current view */
    view: PropTypes.string.isRequired,
};


const AnnotationContent = (props) =&gt; {
    let { event, view } = props;

    return (
        &lt;div style={{ flexGrow: &#039;1&#039;, marginLeft: &#039;10px&#039;, paddingTop: &#039;4px&#039;, paddingBottom: &#039;4px&#039; }} &gt;
            &lt;Icon event={event} view={view} /&gt;

            &lt;EventContentDisplayer
                content={event.content}
                useRichTextEditor={false}
                isEditionMode={false}
            /&gt;
        &lt;/div&gt;
    );
};

const NotificationContent = (props) =&gt; {
    let { event } = props;

    let notificationMessage = getOriginalEvent(event);
    let renderedCommentContent;
    let lastCommentContent = getLastCommentContent(event);
    if (lastCommentContent) {
        renderedCommentContent = () =&gt; (
            &lt;div style={{ clear: &#039;left&#039;, marginLeft: &#039;30px&#039;, paddingTop: &#039;8px&#039;, paddingBottom: &#039;8px&#039; }}&gt;
                {/* &lt;div className=&#039;pull-left&#039; style={{ paddingRight: &#039;8px&#039; }}&gt;
                    {getEventIcon(&#039;comment&#039;, &#039;20&#039;)}
                &lt;/div&gt; */}
                &lt;EventContentDisplayer
                    content={lastCommentContent}
                    useRichTextEditor={false}
                    isEditionMode={false}
                /&gt;
            &lt;/div&gt;);
    } else { renderedCommentContent = () =&gt; null; };

    return (
        &lt;div style={{ flexGrow: &#039;1&#039;, marginLeft: &#039;10px&#039; }} &gt;
            &lt;div className=&#039;pull-left&#039; style={{ paddingRight: &#039;8px&#039; }}&gt;
                {getEventIcon(event.category, &#039;20&#039;)}
            &lt;/div&gt;

            &lt;div id=&#039;divContainingHTMLNotificationInDocView&#039;&gt;
                &lt;EventContentDisplayer
                    content={notificationMessage.content}
                    useRichTextEditor={false}
                    isEditionMode={false}
                /&gt;
            &lt;/div&gt;

            {renderedCommentContent()}
        &lt;/div&gt;);
};

const Icon = (props) =&gt; {
    let { event, view } = props;
    if (view &amp;&amp; view === DOC_VIEW) {
        return null;
    };

    return (&lt;div className=&#039;pull-left&#039; style={{ paddingRight: &#039;8px&#039; }}&gt;
        {getEventIcon(event.category, &#039;20&#039;)}
    &lt;/div&gt;
    );
};

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