github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/public/static/js/scheduler_events.js (about)

     1  mciModule.controller('SchedulerEventCtrl', function($scope, $window, $http) {
     2    $scope.events = [];
     3    $scope.stats = [];
     4    $scope.userTz = $window.userTz;
     5    $scope.distro = $window.distro;
     6  
     7  
     8    $scope.consts = {
     9      logs : "logs",
    10      stats: "stats"
    11    };
    12  
    13    // granularitySeconds represents the amount of seconds in a given bucket
    14    $scope.granularitySeconds = [
    15    {display: "day", value: 24 * 60 * 60, format:"MM/DD"},
    16    {display: "hour", value: 60 * 60, format:"H:mm"},
    17    {display: "minute", value: 60, format:"H:mm"},
    18    ];
    19    $scope.currentGranularity = $scope.granularitySeconds[1];
    20  
    21    $scope.numberDays = [
    22    {display: "1 day", value: "1"},
    23    {display: "1 week", value: 7},
    24    {display: "2 weeks", value: 14},
    25    {display: "1 month",value: 30}, 
    26    {display: "2 Months", value: 60}, 
    27    {display: "3 months", value: 90}
    28    ];
    29  
    30    $scope.currentNumberDays = $scope.numberDays[0];
    31  
    32    // disableDays sets the buttons to be disabled if the the granularity is a minute and 
    33    // there are too many days to load. 
    34    $scope.disableDays = function(numberDays){
    35      if ($scope.currentGranularity.display== "minute") {
    36        if (numberDays.value >= 30) {
    37          return true;
    38        }
    39      }
    40      return false;
    41    }
    42  
    43  
    44    $scope.setNumberDays = function(numberDays){
    45      $scope.currentNumberDays = numberDays;
    46      $scope.stats = [];
    47      $scope.loadData();
    48    }
    49    $scope.setGranularity = function(granularity){
    50      $scope.currentGranularity = granularity;
    51      $scope.stats = [];
    52      $scope.loadData();
    53    }
    54  
    55    $scope.loadData = function(){
    56      switch($scope.tab){
    57        case $scope.consts.logs: 
    58          if ($scope.events.length == 0){
    59            $http.get("/scheduler/distro/" + $scope.distro + "/logs")
    60            .success(function(data){
    61              $scope.events = data;
    62              $scope.fullEvents = _.filter($scope.events, function(event){
    63                return event.data.task_queue_info.task_queue_length > 0;
    64              });
    65              return
    66            })
    67            .error(function(data, status){
    68              console.log(status);
    69            });
    70          }
    71          break;
    72        case $scope.consts.stats: 
    73          if ($scope.stats.length == 0) {
    74            var query = "granularity=" + encodeURIComponent($scope.currentGranularity.value) + 
    75            "&numberDays=" + encodeURIComponent($scope.currentNumberDays.value);
    76            $http.get("/scheduler/distro/"+ $scope.distro + "/stats?" + query)
    77            .success(function(data){
    78              $scope.stats = data;
    79  
    80            })
    81            .error(function(data, status){
    82              console.log(status);
    83            });
    84          }
    85          break;
    86        } 
    87    }
    88  
    89    $scope.tab = $scope.consts.logs;
    90    $scope.loadData();
    91  
    92    $scope.setTab = function(tabName){
    93      $scope.tab = tabName;
    94      $scope.loadData();
    95    }
    96  
    97  })