<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Plato - lib/cmds/nt.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">
  <link href="../../assets/css/vendor/bootstrap.css" rel="stylesheet">
  <link href="../../assets/css/vendor/font-awesome.css" rel="stylesheet">
  <link href="../../assets/css/vendor/codemirror.css" rel="stylesheet">
  <link href="../../assets/css/plato.css" rel="stylesheet">
  <link href="../../assets/css/plato-file.css" rel="stylesheet">

</head>

<body>

<div class="navbar navbar-fixed-top">
  <div class="container">
    <a class="navbar-brand" href="http://github.com/es-analysis/plato">Plato on Github</a>
    <ul class="nav navbar-nav">
      <li>
        <a href="../../index.html">Report Home</a>
      </li>
    </ul>
  </div>
</div>

<div class="jumbotron">
  <div class="container">
    <h1>lib/cmds/nt.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.69</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">179</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">21.07</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.21</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">/*
 * Copyright 2013 Zeno Rocha, All Rights Reserved.
 *
 * Code licensed under the BSD License:
 * https://github.com/eduardolundgren/blob/master/LICENSE.md
 *
 * @author Zeno Rocha &lt;zno.rocha@gmail.com&gt;
 */

// -- Requires -----------------------------------------------------------------
var async = require(&#039;async&#039;),
    base = require(&#039;../base&#039;),
    clc = require(&#039;cli-color&#039;),
    logger = require(&#039;../logger&#039;),
    printed = {};

// -- Constructor --------------------------------------------------------------
function Notifications(options) {
    this.options = options;

    if (!options.repo) {
        logger.error(&#039;You must specify a Git repository to run this command&#039;);
    }
}

// -- Constants ----------------------------------------------------------------
Notifications.DETAILS = {
    options: {
        &#039;latest&#039;: Boolean,
        &#039;repo&#039;  : String,
        &#039;user&#039;  : String,
        &#039;watch&#039; : Boolean
    },
    shorthands: {
        &#039;l&#039;: [ &#039;--latest&#039; ],
        &#039;r&#039;: [ &#039;--repo&#039;   ],
        &#039;u&#039;: [ &#039;--user&#039;   ],
        &#039;w&#039;: [ &#039;--watch&#039;  ]
    },
    description: &#039;Provides a set of util commands to work with Notifications.&#039;
};

// -- Commands -----------------------------------------------------------------
Notifications.prototype.run = function() {
    var instance = this,
        options = instance.options;

    if (options.latest) {
        logger.logTemplate(&#039;{{prefix}} [info] Listing activities on {{greenBright options.user &quot;/&quot; options.repo}}&#039;, {
            options: options
        });

        instance.latest();
    }

    if (options.watch) {
        logger.logTemplate(&#039;{{prefix}} [info] Watching any activity on {{greenBright options.user &quot;/&quot; options.repo}}&#039;, {
            options: options
        });

        instance.watch();
    }
};

Notifications.prototype.latest = function(opt_watch) {
    var instance = this,
        options = instance.options,
        operations,
        payload,
        listEvents,
        filteredListEvents = [];

    operations = [
        function(callback) {
            payload = {
                user: options.user,
                repo: options.repo
            };

            base.github.events.getFromRepo(payload, function(err, data) {
                if (!err) {
                    listEvents = data;
                }
                callback(err);
            });
        },
        function(callback) {
            listEvents.forEach(function(event) {
                event.txt = instance.getMessage_(event);

                if (options.watch) {
                    if (!printed[event.created_at]) {
                        filteredListEvents.push(event);
                    }
                }
                else {
                    filteredListEvents.push(event);
                }

                printed[event.created_at] = true;
            });
            callback();
        }
    ];

    async.series(operations, function(err) {
        if (filteredListEvents.length) {
            logger.logTemplateFile(&#039;nt.handlebars&#039;, {
                user: options.user,
                repo: options.repo,
                latest: options.latest,
                watch: opt_watch,
                events: filteredListEvents
            });
        }

        logger.defaultCallback(err, null, false);
    });
};

Notifications.prototype.watch = function() {
    var instance = this,
        intervalTime = 3000;

    instance.latest();

    setInterval(function() {
        instance.latest(true);
    }, intervalTime);
};

Notifications.prototype.getMessage_ = function(event) {
    var instance = this,
        txt = &#039;&#039;,
        type = event.type,
        payload = event.payload;

    switch (type) {
        case &#039;CommitCommentEvent&#039;:
            txt = &#039;commented on a commit at&#039;;
            break;
        case &#039;CreateEvent&#039;:
            txt = &#039;created a &#039; + payload.ref_type + &#039; at&#039;;
            break;
        case &#039;DeleteEvent&#039;:
            txt = &#039;removed &#039; + payload.ref_type + &#039; at&#039;;
            break;
        case &#039;DownloadEvent&#039;:
            txt = &#039;downloaded&#039;;
            break;
        case &#039;ForkEvent&#039;:
            txt = &#039;forked&#039;;
            break;
        case &#039;ForkApplyEvent&#039;:
            txt = &#039;applied patch &#039; + payload.head + &#039; at&#039;;
            break;
        case &#039;IssueCommentEvent&#039;:
            txt = &#039;commented on an issue at&#039;;
            break;
        case &#039;IssuesEvent&#039;:
            txt = payload.action + &#039; an issue at&#039;;
            break;
        case &#039;MemberEvent&#039;:
            txt = &#039;added &#039; + payload.member + &#039; as a collaborator to&#039;;
            break;
        case &#039;PublicEvent&#039;:
            txt = &#039;open sourced&#039;;
            break;
        case &#039;PullRequestEvent&#039;:
            txt = payload.action + &#039; pull request #&#039; + payload.number + &#039; at&#039;;
            break;
        case &#039;PullRequestReviewCommentEvent&#039;:
            txt = &#039;commented on a pull request at&#039;;
            break;
        case &#039;PushEvent&#039;:
            txt = &#039;pushed &#039; + payload.commits.length + &#039; commit(s) to&#039;;
            break;
        case &#039;WatchEvent&#039;:
            txt = &#039;is now watching&#039;;
            break;
        default:
            logger.error(&#039;event type not found: &#039; + clc.red(type));
            break;
    }

    return txt;
};

exports.Impl = Notifications;</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>
