aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/webstatusserver/static/index.js
blob: 4ef967111cd281939714fca9e901d6a0d6e9444d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var icons = {
  running: '\u25B6',
  finished: '\u2611'
};

function showData() {
  renderTestList(getTestsData());
}

function getTestsData() {
  // TODO(bazel-team): change it to async callback retrieving data in background
  // (for simplicity this is synchronous now)
  return $.ajax({
      type: 'GET',
      url: document.URL + 'tests/list',
      async: false
  }).responseJSON;
}

function renderTestList(tests) {
  var rows = d3.select('#testsList')
    .selectAll()
    .data(tests)
    .enter().append('div')
    .classed('info-cell', true);

  // status
  rows.append('div').classed('info-detail', true).text(function(j) {
    return j.finished ? icons.finished : icons.running;
  });

  // target(s) name(s)
  rows.append('div').classed('info-detail', true).text(function(j) {
    if (j.targets.length == 1) {
      return j.targets[0];
    }
    if (j.targets.length == 0) {
      return 'Unknown target.';
    }
    return j.targets;
  });

  // start time
  rows.append('div').classed('info-detail', true).text(function(j) {
    // Pad value with 2 zeroes
    function pad(value) {
      return value < 10 ? '0' + value : value;
    }

    var
      date = new Date(j.startTime),
      today = new Date(Date.now()),
      h = pad(date.getHours()),
      m = pad(date.getMinutes()),
      dd = pad(date.getDay()),
      mm = pad(date.getMonth()),
      yy = date.getYear(),
      day;

    // don't show date if ran today
    if (dd != today.getDay() && mm != today.getMonth() &&
        yy != today.getYear()) {
      day = ' on ' + yy + '-' + mm + '-' + dd;
    } else {
      day = '';
    }
    return h + ':' + m;
  });

  // link
  rows.append('div').classed('info-detail', true).classed('button', true)
      .append('a').attr('href', function(datum, index) {
        return '/tests/' + datum.uuid;
      })
      .text('link');
}