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

     1  mciModule.controller('HostCtrl', function($scope, $window) {
     2    $scope.userTz = $window.userTz;
     3    $scope.host = $window.host;
     4    $scope.running_task = $window.runningTask;
     5    $scope.events = $window.events.reverse();
     6  
     7    $scope.host.uptime = "N/A";
     8    if ($scope.host.host_type !== "static") {
     9        var uptime;
    10        if($scope.host.status == "terminated"){
    11          uptime = moment($scope.host.termination_time).diff($scope.host.creation_time, 'seconds');
    12        }else{
    13          uptime = moment().diff($scope.host.creation_time, 'seconds');
    14        }
    15        $scope.host.uptime = moment.duration(uptime, 'seconds').humanize();
    16    }
    17  
    18    var epochTime = moment("Jan 1, 1970");
    19  
    20    var last_reachability = moment($scope.host.last_reachability_check);
    21    if (last_reachability <= epochTime) { 
    22  	  $scope.host.last_reachability_check = "N/A";
    23    } else {
    24  	  var last_reachability_seconds = moment().diff($scope.host.last_reachability_check, 'seconds');
    25        $scope.host.last_reachability_check = moment.duration(last_reachability_seconds, 'seconds').humanize() + ' ago';
    26    }
    27  
    28    // Determining the start and elapsed time should be done the same way as in hosts.js
    29    if ($scope.running_task && $scope.running_task.id) {
    30        var dispatchTimeDiffedPrefix = "";
    31  
    32        // In case the task is dispatched but not yet marked as
    33        // started, use the task's 'dispatch_time' in lieu of 'start_time'
    34        var startTime = moment($scope.running_task.start_time);
    35  
    36        // 'start_time' is set to epochTime by default. We use
    37        // the <= comparison to allow for conversion imprecision
    38        if (startTime <= epochTime) {
    39          startTime = $scope.running_task.dispatch_time;
    40          dispatchTimeDiffedPrefix = "*";
    41        }
    42  
    43  
    44        var elapsedTime = moment().diff(startTime, 'seconds');
    45        $scope.host.start_time = startTime;
    46        $scope.host.elapsed = dispatchTimeDiffedPrefix + moment.duration(elapsedTime, 'seconds').humanize();
    47    } else {
    48        $scope.host.start_time = "N/A";
    49        $scope.host.elapsed = "N/A";
    50    }
    51  
    52    $scope.getStatusLabel = function(host) {
    53        if (host) {
    54          switch (host.status) {
    55          case 'running':
    56            return 'host-running';
    57          case 'provisioning':
    58          case 'starting':
    59            return 'host-starting';
    60          case 'decommissioned':
    61          case 'unreachable':
    62          case 'quarantined':
    63          case 'provision failed':
    64            return 'host-unreachable';
    65          case 'terminated':
    66            return 'host-terminated';
    67          default:
    68            return 'host-unreachable';
    69          }
    70        }
    71      }
    72  });