Home | History | Annotate | Download | only in model
      1 <!--
      2 Copyright 2014 The Chromium Authors. All rights reserved.
      3 Use of this source code is governed by a BSD-style license that can be
      4 found in the LICENSE file.
      5 -->
      6 
      7 <link rel="import" href="../lib/net.html">
      8 
      9 <script>
     10 function TreeStatus(project) {
     11   this.project = project;
     12   this.message = '';
     13   this.status = 'unknown';
     14 
     15   this.url = "https://{1}-status.appspot.com/".assign(project);
     16 }
     17 
     18 TreeStatus.prototype.update = function() {
     19   var url = this.url + 'current?format=json';
     20   return net.json(url).then(function(response) {
     21     this.updateStatus(response);
     22   }.bind(this));
     23 };
     24 
     25 TreeStatus.prototype.updateStatus = function(status) {
     26   if (status.can_commit_freely) {
     27     this.message = null;
     28     this.status = 'open';
     29     return;
     30   }
     31 
     32   this.message = status.message + ' by ' + status.username;
     33   var responseLowerCase = status.message.toLowerCase();
     34   if (responseLowerCase.indexOf('throttled') != -1) {
     35     this.status = 'throttled';
     36   } else if (responseLowerCase.indexOf("closed") != -1) {
     37     this.status = 'closed';
     38   } else {
     39     this.status = 'unknown';
     40   }
     41 };
     42 </script>
     43