Home | History | Annotate | Download | only in sheriffing
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 /** Information about a particular status page. */
      6 function StatusPageInfo(statusPageName, statusPageUrl) {
      7   this.date = '';
      8   this.inFlight = 0;
      9   this.jsonUrl = statusPageUrl + 'current?format=json';
     10   this.message = '';
     11   this.name = statusPageName;
     12   this.state = '';
     13   this.url = statusPageUrl;
     14 }
     15 
     16 /** Send and parse an asynchronous request to get a repo status JSON. */
     17 StatusPageInfo.prototype.requestJson = function() {
     18   if (this.inFlight) return;
     19 
     20   this.inFlight++;
     21   gNumRequestsInFlight++;
     22 
     23   var statusPageInfo = this;
     24   var request = new XMLHttpRequest();
     25   request.open('GET', this.jsonUrl, true);
     26   request.onreadystatechange = function() {
     27     if (request.readyState == 4 && request.status == 200) {
     28       statusPageInfo.inFlight--;
     29       gNumRequestsInFlight--;
     30 
     31       var statusPageJson = JSON.parse(request.responseText);
     32       statusPageInfo.date = statusPageJson.date;
     33       statusPageInfo.message = statusPageJson.message;
     34       statusPageInfo.state = statusPageJson.general_state;
     35     }
     36   };
     37   request.send(null);
     38 };
     39 
     40 /** Creates HTML displaying the status. */
     41 StatusPageInfo.prototype.createHtml = function() {
     42   var linkElement = document.createElement('a');
     43   linkElement.href = this.url;
     44   linkElement.innerHTML = this.name;
     45 
     46   var statusElement = document.createElement('li');
     47   statusElement.appendChild(linkElement);
     48 
     49   var dateElement = document.createElement('li');
     50   dateElement.innerHTML = this.date;
     51 
     52   var messageElement = document.createElement('li');
     53   messageElement.innerHTML = this.message;
     54 
     55   var boxElement = document.createElement('ul');
     56   boxElement.className = 'box ' + this.state;
     57   boxElement.appendChild(statusElement);
     58   boxElement.appendChild(dateElement);
     59   boxElement.appendChild(messageElement);
     60   return boxElement;
     61 };
     62