{"size": 1858, "ext": "js", "max_stars_repo_path": "public/plugins/raintank/panels/raintankEventsPanel/module.js", "max_stars_repo_name": "splaspood/raintank-grafana", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/plugins/raintank/panels/raintankEventsPanel/module.js", "max_issues_repo_name": "splaspood/raintank-grafana", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "public/plugins/raintank/panels/raintankEventsPanel/module.js", "max_forks_repo_name": "splaspood/raintank-grafana", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.9275362319, "max_line_length": 108, "alphanum_fraction": 0.6162540366}
define([
  'angular',
  'app',
  'lodash',
  'kbn',
  'components/panelmeta',
],
function (angular, app, _, kbn, PanelMeta) {
  'use strict';

  var module = angular.module('grafana.panels.raintankEventsPanel', []);
  app.useModule(module);

  app.useModule(module);
  module.directive('grafanaPanelRaintankeventspanel', function() {
    return {
      controller: 'raintankEventsPanel',
      templateUrl: 'plugins/raintank/panels/raintankEventsPanel/module.html',
    };
  });

  module.controller('raintankEventsPanel', function($scope, panelSrv, timeSrv, backendSrv, templateSrv) {
    $scope.panelMeta = new PanelMeta({
      panelName: 'Raintank Events',
      description : "Events",
      fullscreen: true
    });
    $scope.panelMeta.addEditorTab('Filter', 'plugins/raintank/panels/raintankEventsPanel/editor.html');

    // Set and populate defaults
    var _d = {
      filter: null,
      title: "Events",
      size: 10
    };

    _.defaults($scope.panel, _d);

    $scope.init = function() {
      panelSrv.init(this);
    };

    $scope.refreshData = function() {
      $scope.range = timeSrv.timeRange();
      if (!$scope.panel.filter) {
        return;
      }
      if ($scope.panel.filter.indexOf(":", $scope.panel.filter.length - 1) !== -1) {
        //filter ends with a colon. elasticsearch will send a 500error for this.
        return;
      }

      var params = {
        query: templateSrv.replace($scope.panel.filter, $scope.panel.scopedVars),
        start: $scope.range.from.getTime(),
        end:  $scope.range.to.getTime(),
        size: $scope.panel.size,
      };

      backendSrv.get('/api/events', params).then(function(events) {
        $scope.events = events;
        $scope.panel.scopedVars['eventCount'] = {selected: true, text: events.length, value: events.length};
      });
    };

    $scope.init();
  });
});
