blob: c9532e4f063aec03b267cd840180e60015f94bc8 [file] [log] [blame]
James E. Blair8ae50e32013-01-17 15:32:22 -08001// Copyright 2012 OpenStack Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may
4// not use this file except in compliance with the License. You may obtain
5// a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations
13// under the License.
14
15window.zuul_enable_status_updates = true;
16
17function format_pipeline(data) {
18 var html = '<div class="pipeline"><h3 class="subhead">'+
19 data['name']+'</h3>';
20 if (data['description'] != null) {
21 html += '<p>'+data['description']+'</p>';
22 }
23
24 $.each(data['change_queues'], function(change_queue_i, change_queue) {
25 $.each(change_queue['heads'], function(head_i, head) {
26 if (data['change_queues'].length > 1 && head_i == 0) {
27 html += '<div> Change queue: ';
28
29 var name = change_queue['name'];
30 html += '<a title="' + name + '">';
31 if (name.length > 32) {
32 name = name.substr(0,32) + '...';
33 }
34 html += name + '</a></div>'
35 }
36 $.each(head, function(change_i, change) {
37 if (change_i > 0) {
38 html += '<div class="arrow">&uarr;</div>'
39 }
40 html += format_change(change);
41 });
42 });
43 });
44
45 html += '</div>';
46 return html;
47}
48
49function format_change(change) {
50 var html = '<div class="change"><div class="header">';
51
52 html += '<span class="project">'+change['project']+'</span>';
53 var id = change['id'];
54 var url = change['url'];
55 if (id.length == 40) {
56 id = id.substr(0,7);
57 }
58 html += '<span class="changeid">';
59 if (url != null) {
60 html += '<a href="'+url+'">';
61 }
62 html += id;
63 if (url != null) {
64 html += '</a>';
65 }
66 html += '</span></div><div class="jobs">';
67
68 $.each(change['jobs'], function(i, job) {
69 result = job['result'];
70 var result_class = "result";
71 if (result == null) {
72 if (job['url'] != null) {
73 result = 'in progress';
74 } else {
75 result = 'queued';
76 }
77 } else if (result == 'SUCCESS') {
78 result_class += " result_success";
79 } else if (result == 'FAILURE') {
80 result_class += " result_failure";
81 } else if (result == 'LOST') {
82 result_class += " result_unstable";
83 } else if (result == 'UNSTABLE') {
84 result_class += " result_unstable";
85 }
86 html += '<span class="job">';
87 if (job['url'] != null) {
88 html += '<a href="'+job['url']+'">';
89 }
90 html += job['name'];
91 if (job['url'] != null) {
92 html += '</a>';
93 }
94 html += ': <span class="'+result_class+'">'+result+'</span>';
95 if (job['voting'] == false) {
96 html += ' (non-voting)';
97 }
98 html += '</span>';
99 });
100
101 html += '</div></div>';
102 return html;
103}
104
105function update_timeout() {
106 if (!window.zuul_enable_status_updates) {
107 setTimeout(update_timeout, 5000);
108 return;
109 }
110
111 update();
112
113 setTimeout(update_timeout, 5000);
114}
115
116function update() {
117 var html = '';
118
119 $.getJSON('/status.json', function(data) {
120 if ('message' in data) {
121 $("#message-container").attr('class', 'topMessage');
122 $("#message").html(data['message']);
123 } else {
124 $("#message-container").removeClass('topMessage');
125 $("#message").html('');
126 }
127
128 html += '<br style="clear:both"/>';
129
130 $.each(data['pipelines'], function(i, pipeline) {
131 html = html + format_pipeline(pipeline);
132 });
133
134 html += '<br style="clear:both"/>';
135 $("#pipeline-container").html(html);
136 });
137}
138
139$(function() {
140 update_timeout();
141
142 $(document).on({
143 'show.visibility': function() {
144 window.zuul_enable_status_updates = true;
145 update();
146 },
147 'hide.visibility': function() {
148 window.zuul_enable_status_updates = false;
149 }
150 });
151
152});