blob: ac8a302817869d73e31a80f6591ea3d4169ac8f0 [file] [log] [blame]
Joshua Hesketh4db99cb2014-05-23 11:28:08 +10001// jquery plugin for Zuul status page
Timo Tijhof51516cd2013-04-09 01:32:29 +02002//
Tristan Cacqueray48ddd9e2017-05-21 10:19:02 +00003// @licstart The following is the entire license notice for the
4// JavaScript code in this page.
5//
Timo Tijhof51516cd2013-04-09 01:32:29 +02006// Copyright 2012 OpenStack Foundation
7// Copyright 2013 Timo Tijhof
8// Copyright 2013 Wikimedia Foundation
Joshua Hesketh6b1a2182014-03-21 14:40:04 +11009// Copyright 2014 Rackspace Australia
Timo Tijhof51516cd2013-04-09 01:32:29 +020010//
11// Licensed under the Apache License, Version 2.0 (the "License"); you may
12// not use this file except in compliance with the License. You may obtain
13// a copy of the License at
14//
15// http://www.apache.org/licenses/LICENSE-2.0
16//
17// Unless required by applicable law or agreed to in writing, software
18// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
19// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
20// License for the specific language governing permissions and limitations
21// under the License.
Tristan Cacqueray48ddd9e2017-05-21 10:19:02 +000022//
23// @licend The above is the entire license notice
24// for the JavaScript code in this page.
Timo Tijhof51516cd2013-04-09 01:32:29 +020025
26(function ($) {
Timo Tijhof4be9f742015-04-02 01:13:19 +010027 'use strict';
28
Joshua Heskethace48892014-03-22 17:18:31 +110029 function set_cookie(name, value) {
Monty Taylor860bb0a2014-03-22 09:41:25 -070030 document.cookie = name + '=' + value + '; path=/';
Joshua Heskethace48892014-03-22 17:18:31 +110031 }
32
33 function read_cookie(name, default_value) {
Monty Taylor860bb0a2014-03-22 09:41:25 -070034 var nameEQ = name + '=';
Joshua Heskethace48892014-03-22 17:18:31 +110035 var ca = document.cookie.split(';');
36 for(var i=0;i < ca.length;i++) {
37 var c = ca[i];
Monty Taylor860bb0a2014-03-22 09:41:25 -070038 while (c.charAt(0) === ' ') {
39 c = c.substring(1, c.length);
40 }
41 if (c.indexOf(nameEQ) === 0) {
Joshua Heskethace48892014-03-22 17:18:31 +110042 return c.substring(nameEQ.length, c.length);
43 }
44 }
45 return default_value;
46 }
47
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100048 $.zuul = function(options) {
Timo Tijhof4be9f742015-04-02 01:13:19 +010049 options = $.extend({
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100050 'enabled': true,
51 'graphite_url': '',
Monty Taylor9010dc52018-02-17 13:29:28 -060052 'source': 'status',
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100053 'msg_id': '#zuul_msg',
54 'pipelines_id': '#zuul_pipelines',
55 'queue_events_num': '#zuul_queue_events_num',
Tobias Henkel02ec07f2017-10-19 07:10:37 +020056 'queue_management_events_num': '#zuul_queue_management_events_num',
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100057 'queue_results_num': '#zuul_queue_results_num',
58 }, options);
Joshua Heskethace48892014-03-22 17:18:31 +110059
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100060 var collapsed_exceptions = [];
Joshua Hesketh6f94dd12014-08-20 16:14:53 +100061 var current_filter = read_cookie('zuul_filter_string', '');
Jan Hrubanddeb95a2017-01-03 15:12:41 +010062 var change_set_in_url = window.location.href.split('#')[1];
63 if (change_set_in_url) {
64 current_filter = change_set_in_url;
65 }
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100066 var $jq;
Timo Tijhof51516cd2013-04-09 01:32:29 +020067
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100068 var xhr,
69 zuul_graph_update_count = 0,
70 zuul_sparkline_urls = {};
Joshua Hesketh9d013542014-04-03 13:08:04 +110071
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100072 function get_sparkline_url(pipeline_name) {
73 if (options.graphite_url !== '') {
74 if (!(pipeline_name in zuul_sparkline_urls)) {
75 zuul_sparkline_urls[pipeline_name] = $.fn.graphite
76 .geturl({
77 url: options.graphite_url,
78 from: "-8hours",
79 width: 100,
80 height: 26,
81 margin: 0,
82 hideLegend: true,
83 hideAxes: true,
84 hideGrid: true,
85 target: [
86 "color(stats.gauges.zuul.pipeline." + pipeline_name
Timo Tijhof4be9f742015-04-02 01:13:19 +010087 + ".current_changes, '6b8182')"
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100088 ]
Joshua Hesketh298c4912014-03-20 16:06:25 +110089 });
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100090 }
91 return zuul_sparkline_urls[pipeline_name];
92 }
93 return false;
94 }
Joshua Hesketh298c4912014-03-20 16:06:25 +110095
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100096 var format = {
Joshua Hesketh6b1a2182014-03-21 14:40:04 +110097 job: function(job) {
Joshua Hesketh9e6ce532014-04-01 13:11:53 +110098 var $job_line = $('<span />');
99
Monty Taylore78211d2017-07-21 09:48:41 +0900100 if (job.result !== null) {
101 $job_line.append(
102 $('<a />')
103 .addClass('zuul-job-name')
104 .attr('href', job.report_url)
105 .text(job.name)
106 );
107 }
108 else if (job.url !== null) {
Joshua Hesketh9e6ce532014-04-01 13:11:53 +1100109 $job_line.append(
110 $('<a />')
111 .addClass('zuul-job-name')
112 .attr('href', job.url)
113 .text(job.name)
114 );
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100115 }
Joshua Hesketh9e6ce532014-04-01 13:11:53 +1100116 else {
117 $job_line.append(
118 $('<span />')
119 .addClass('zuul-job-name')
120 .text(job.name)
121 );
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100122 }
Joshua Hesketh9e6ce532014-04-01 13:11:53 +1100123
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000124 $job_line.append(this.job_status(job));
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100125
126 if (job.voting === false) {
127 $job_line.append(
Joshua Hesketh9e6ce532014-04-01 13:11:53 +1100128 $(' <small />')
129 .addClass('zuul-non-voting-desc')
130 .text(' (non-voting)')
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100131 );
132 }
Joshua Hesketh9e6ce532014-04-01 13:11:53 +1100133
Joshua Hesketha95fd552014-08-21 11:21:05 +1000134 $job_line.append($('<div style="clear: both"></div>'));
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100135 return $job_line;
136 },
137
138 job_status: function(job) {
139 var result = job.result ? job.result.toLowerCase() : null;
140 if (result === null) {
141 result = job.url ? 'in progress' : 'queued';
142 }
143
Monty Taylor860bb0a2014-03-22 09:41:25 -0700144 if (result === 'in progress') {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000145 return this.job_progress_bar(job.elapsed_time,
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100146 job.remaining_time);
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100147 }
148 else {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000149 return this.status_label(result);
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100150 }
151 },
152
153 status_label: function(result) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700154 var $status = $('<span />');
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100155 $status.addClass('zuul-job-result label');
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100156
157 switch (result) {
158 case 'success':
159 $status.addClass('label-success');
160 break;
161 case 'failure':
162 $status.addClass('label-danger');
163 break;
164 case 'unstable':
165 $status.addClass('label-warning');
166 break;
Alexander Evseev3103a842015-11-17 10:12:45 +0300167 case 'skipped':
168 $status.addClass('label-info');
169 break;
Antoine Musso4c2053d2016-02-04 23:35:23 +0100170 // 'in progress' 'queued' 'lost' 'aborted' ...
171 default:
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100172 $status.addClass('label-default');
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100173 }
174 $status.text(result);
175 return $status;
176 },
177
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100178 job_progress_bar: function(elapsed_time, remaining_time) {
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100179 var progress_percent = 100 * (elapsed_time / (elapsed_time +
180 remaining_time));
181 var $bar_inner = $('<div />')
182 .addClass('progress-bar')
183 .attr('role', 'progressbar')
184 .attr('aria-valuenow', 'progressbar')
185 .attr('aria-valuemin', progress_percent)
186 .attr('aria-valuemin', '0')
187 .attr('aria-valuemax', '100')
188 .css('width', progress_percent + '%');
189
190 var $bar_outter = $('<div />')
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100191 .addClass('progress zuul-job-result')
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100192 .append($bar_inner);
193
194 return $bar_outter;
195 },
196
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100197 enqueue_time: function(ms) {
198 // Special format case for enqueue time to add style
199 var hours = 60 * 60 * 1000;
200 var now = Date.now();
201 var delta = now - ms;
Monty Taylor860bb0a2014-03-22 09:41:25 -0700202 var status = 'text-success';
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000203 var text = this.time(delta, true);
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100204 if (delta > (4 * hours)) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700205 status = 'text-danger';
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100206 } else if (delta > (2 * hours)) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700207 status = 'text-warning';
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100208 }
209 return '<span class="' + status + '">' + text + '</span>';
210 },
211
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100212 time: function(ms, words) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700213 if (typeof(words) === 'undefined') {
214 words = false;
215 }
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100216 var seconds = (+ms)/1000;
217 var minutes = Math.floor(seconds/60);
218 var hours = Math.floor(minutes/60);
219 seconds = Math.floor(seconds % 60);
220 minutes = Math.floor(minutes % 60);
Monty Taylor860bb0a2014-03-22 09:41:25 -0700221 var r = '';
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100222 if (words) {
223 if (hours) {
224 r += hours;
225 r += ' hr ';
226 }
227 r += minutes + ' min';
228 } else {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700229 if (hours < 10) {
230 r += '0';
231 }
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100232 r += hours + ':';
Monty Taylor860bb0a2014-03-22 09:41:25 -0700233 if (minutes < 10) {
234 r += '0';
235 }
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100236 r += minutes + ':';
Monty Taylor860bb0a2014-03-22 09:41:25 -0700237 if (seconds < 10) {
238 r += '0';
239 }
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100240 r += seconds;
241 }
242 return r;
243 },
244
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100245 change_total_progress_bar: function(change) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700246 var job_percent = Math.floor(100 / change.jobs.length);
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100247 var $bar_outter = $('<div />')
248 .addClass('progress zuul-change-total-result');
249
250 $.each(change.jobs, function (i, job) {
251 var result = job.result ? job.result.toLowerCase() : null;
252 if (result === null) {
253 result = job.url ? 'in progress' : 'queued';
254 }
255
Monty Taylor860bb0a2014-03-22 09:41:25 -0700256 if (result !== 'queued') {
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100257 var $bar_inner = $('<div />')
258 .addClass('progress-bar');
259
260 switch (result) {
261 case 'success':
262 $bar_inner.addClass('progress-bar-success');
263 break;
264 case 'lost':
265 case 'failure':
266 $bar_inner.addClass('progress-bar-danger');
267 break;
268 case 'unstable':
269 $bar_inner.addClass('progress-bar-warning');
270 break;
271 case 'in progress':
272 case 'queued':
273 break;
274 }
275 $bar_inner.attr('title', job.name)
276 .css('width', job_percent + '%');
277 $bar_outter.append($bar_inner);
278 }
279 });
280 return $bar_outter;
281 },
282
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100283 change_header: function(change) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700284 var change_id = change.id || 'NA';
Timo Tijhof51516cd2013-04-09 01:32:29 +0200285
Monty Taylor860bb0a2014-03-22 09:41:25 -0700286 var $change_link = $('<small />');
Joshua Hesketh298c4912014-03-20 16:06:25 +1100287 if (change.url !== null) {
Jens Harbott898a8bf2017-10-04 13:12:04 +0000288 var github_id = change_id.match(/^([0-9]+),([0-9a-f]{40})$/);
Jamie Lennoxa6b33ba2017-02-10 11:33:44 +1100289 if (github_id) {
290 $change_link.append(
291 $('<a />').attr('href', change.url).append(
292 $('<abbr />')
Jens Harbott898a8bf2017-10-04 13:12:04 +0000293 .attr('title', change_id)
Jamie Lennoxa6b33ba2017-02-10 11:33:44 +1100294 .text('#' + github_id[1])
295 )
296 );
Jens Harbott898a8bf2017-10-04 13:12:04 +0000297 } else if (/^[0-9a-f]{40}$/.test(change_id)) {
298 var change_id_short = change_id.slice(0, 7);
Joshua Heskethcd7a0772014-08-21 11:32:44 +1000299 $change_link.append(
300 $('<a />').attr('href', change.url).append(
301 $('<abbr />')
Jens Harbott898a8bf2017-10-04 13:12:04 +0000302 .attr('title', change_id)
Joshua Heskethcd7a0772014-08-21 11:32:44 +1000303 .text(change_id_short)
304 )
305 );
306 }
307 else {
308 $change_link.append(
Jens Harbott898a8bf2017-10-04 13:12:04 +0000309 $('<a />').attr('href', change.url).text(change_id)
Joshua Heskethcd7a0772014-08-21 11:32:44 +1000310 );
311 }
Timo Tijhof51516cd2013-04-09 01:32:29 +0200312 }
Joshua Hesketh298c4912014-03-20 16:06:25 +1100313 else {
Jens Harbott898a8bf2017-10-04 13:12:04 +0000314 if (change_id.length === 40) {
315 change_id = change_id.substr(0, 7);
316 }
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100317 $change_link.text(change_id);
Timo Tijhof51516cd2013-04-09 01:32:29 +0200318 }
Timo Tijhof51516cd2013-04-09 01:32:29 +0200319
Monty Taylor860bb0a2014-03-22 09:41:25 -0700320 var $change_progress_row_left = $('<div />')
Timo Tijhofa62e8492015-04-02 03:05:04 +0100321 .addClass('col-xs-4')
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100322 .append($change_link);
Monty Taylor860bb0a2014-03-22 09:41:25 -0700323 var $change_progress_row_right = $('<div />')
Timo Tijhofa62e8492015-04-02 03:05:04 +0100324 .addClass('col-xs-8')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000325 .append(this.change_total_progress_bar(change));
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100326
Monty Taylor860bb0a2014-03-22 09:41:25 -0700327 var $change_progress_row = $('<div />')
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100328 .addClass('row')
329 .append($change_progress_row_left)
Monty Taylor860bb0a2014-03-22 09:41:25 -0700330 .append($change_progress_row_right);
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100331
Monty Taylor860bb0a2014-03-22 09:41:25 -0700332 var $project_span = $('<span />')
Joshua Heskethace48892014-03-22 17:18:31 +1100333 .addClass('change_project')
334 .text(change.project);
335
Monty Taylor860bb0a2014-03-22 09:41:25 -0700336 var $left = $('<div />')
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100337 .addClass('col-xs-8')
Joshua Hesketh1751e4f2014-04-01 13:24:51 +1100338 .append($project_span, $change_progress_row);
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100339
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000340 var remaining_time = this.time(
Monty Taylor860bb0a2014-03-22 09:41:25 -0700341 change.remaining_time, true);
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000342 var enqueue_time = this.enqueue_time(
Monty Taylor860bb0a2014-03-22 09:41:25 -0700343 change.enqueue_time);
344 var $remaining_time = $('<small />').addClass('time')
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100345 .attr('title', 'Remaining Time').html(remaining_time);
Monty Taylor860bb0a2014-03-22 09:41:25 -0700346 var $enqueue_time = $('<small />').addClass('time')
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100347 .attr('title', 'Elapsed Time').html(enqueue_time);
348
James E. Blair6dc954b2015-02-11 18:32:19 -0800349 var $right = $('<div />');
350 if (change.live === true) {
351 $right.addClass('col-xs-4 text-right')
352 .append($remaining_time, $('<br />'), $enqueue_time);
353 }
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100354
Monty Taylor860bb0a2014-03-22 09:41:25 -0700355 var $header = $('<div />')
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100356 .addClass('row')
357 .append($left, $right);
358 return $header;
359 },
360
361 change_list: function(jobs) {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000362 var format = this;
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100363 var $list = $('<ul />')
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100364 .addClass('list-group zuul-patchset-body');
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100365
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100366 $.each(jobs, function (i, job) {
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100367 var $item = $('<li />')
368 .addClass('list-group-item')
369 .addClass('zuul-change-job')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000370 .append(format.job(job));
Joshua Hesketh298c4912014-03-20 16:06:25 +1100371 $list.append($item);
Timo Tijhof51516cd2013-04-09 01:32:29 +0200372 });
373
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100374 return $list;
375 },
376
377 change_panel: function (change) {
378 var $header = $('<div />')
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100379 .addClass('panel-heading zuul-patchset-header')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000380 .append(this.change_header(change));
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100381
Joshua Heskethdb8046e2014-03-21 18:42:25 +1100382 var panel_id = change.id ? change.id.replace(',', '_')
383 : change.project.replace('/', '_') +
Monty Taylor860bb0a2014-03-22 09:41:25 -0700384 '-' + change.enqueue_time;
Joshua Heskethdb8046e2014-03-21 18:42:25 +1100385 var $panel = $('<div />')
Monty Taylor860bb0a2014-03-22 09:41:25 -0700386 .attr('id', panel_id)
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100387 .addClass('panel panel-default zuul-change')
388 .append($header)
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000389 .append(this.change_list(change.jobs));
Joshua Heskethdb8046e2014-03-21 18:42:25 +1100390
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000391 $header.click(this.toggle_patchset);
Joshua Heskethdb8046e2014-03-21 18:42:25 +1100392 return $panel;
Timo Tijhof51516cd2013-04-09 01:32:29 +0200393 },
394
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100395 change_status_icon: function(change) {
396 var icon_name = 'green.png';
397 var icon_title = 'Succeeding';
398
399 if (change.active !== true) {
400 // Grey icon
401 icon_name = 'grey.png';
402 icon_title = 'Waiting until closer to head of queue to' +
403 ' start jobs';
404 }
James E. Blair107c3852015-02-07 08:23:10 -0800405 else if (change.live !== true) {
406 // Grey icon
407 icon_name = 'grey.png';
Joshua Hesketh6bc619d2015-02-11 09:30:21 +1100408 icon_title = 'Dependent change required for testing';
James E. Blair107c3852015-02-07 08:23:10 -0800409 }
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100410 else if (change.failing_reasons &&
411 change.failing_reasons.length > 0) {
412 var reason = change.failing_reasons.join(', ');
413 icon_title = 'Failing because ' + reason;
414 if (reason.match(/merge conflict/)) {
415 // Black icon
416 icon_name = 'black.png';
417 }
418 else {
419 // Red icon
420 icon_name = 'red.png';
421 }
422 }
423
424 var $icon = $('<img />')
425 .attr('src', 'images/' + icon_name)
426 .attr('title', icon_title)
427 .css('margin-top', '-6px');
428
429 return $icon;
430 },
431
432 change_with_status_tree: function(change, change_queue) {
433 var $change_row = $('<tr />');
434
435 for (var i = 0; i < change_queue._tree_columns; i++) {
436 var $tree_cell = $('<td />')
437 .css('height', '100%')
438 .css('padding', '0 0 10px 0')
439 .css('margin', '0')
440 .css('width', '16px')
441 .css('min-width', '16px')
442 .css('overflow', 'hidden')
443 .css('vertical-align', 'top');
444
445 if (i < change._tree.length && change._tree[i] !== null) {
446 $tree_cell.css('background-image',
447 'url(\'images/line.png\')')
448 .css('background-repeat', 'repeat-y');
449 }
450
451 if (i === change._tree_index) {
452 $tree_cell.append(
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000453 this.change_status_icon(change));
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100454 }
455 if (change._tree_branches.indexOf(i) !== -1) {
456 var $image = $('<img />')
457 .css('vertical-align', 'baseline');
458 if (change._tree_branches.indexOf(i) ===
459 change._tree_branches.length - 1) {
460 // Angle line
461 $image.attr('src', 'images/line-angle.png');
462 }
463 else {
464 // T line
465 $image.attr('src', 'images/line-t.png');
466 }
467 $tree_cell.append($image);
468 }
469 $change_row.append($tree_cell);
470 }
471
472 var change_width = 360 - 16*change_queue._tree_columns;
473 var $change_column = $('<td />')
474 .css('width', change_width + 'px')
475 .addClass('zuul-change-cell')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000476 .append(this.change_panel(change));
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100477
478 $change_row.append($change_column);
479
480 var $change_table = $('<table />')
481 .addClass('zuul-change-box')
482 .css('-moz-box-sizing', 'content-box')
483 .css('box-sizing', 'content-box')
484 .append($change_row);
485
486 return $change_table;
487 },
488
Joshua Hesketh9d013542014-04-03 13:08:04 +1100489 pipeline_sparkline: function(pipeline_name) {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000490 if (options.graphite_url !== '') {
Joshua Hesketh9d013542014-04-03 13:08:04 +1100491 var $sparkline = $('<img />')
492 .addClass('pull-right')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000493 .attr('src', get_sparkline_url(pipeline_name));
Joshua Hesketh9d013542014-04-03 13:08:04 +1100494 return $sparkline;
495 }
496 return false;
497 },
498
499 pipeline_header: function(pipeline, count) {
500 // Format the pipeline name, sparkline and description
501 var $header_div = $('<div />')
502 .addClass('zuul-pipeline-header');
503
504 var $heading = $('<h3 />')
505 .css('vertical-align', 'middle')
506 .text(pipeline.name)
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100507 .append(
Joshua Hesketh9d013542014-04-03 13:08:04 +1100508 $('<span />')
509 .addClass('badge pull-right')
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100510 .css('vertical-align', 'middle')
Joshua Hesketh9d013542014-04-03 13:08:04 +1100511 .css('margin-top', '0.5em')
512 .text(count)
513 )
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000514 .append(this.pipeline_sparkline(pipeline.name));
Joshua Hesketh9d013542014-04-03 13:08:04 +1100515
516 $header_div.append($heading);
Joshua Hesketh298c4912014-03-20 16:06:25 +1100517
Timo Tijhof51516cd2013-04-09 01:32:29 +0200518 if (typeof pipeline.description === 'string') {
Alexander Evseev057aed12015-10-28 17:17:04 +0300519 var descr = $('<small />')
520 $.each( pipeline.description.split(/\r?\n\r?\n/), function(index, descr_part){
521 descr.append($('<p />').text(descr_part));
522 });
Joshua Hesketh9d013542014-04-03 13:08:04 +1100523 $header_div.append(
Alexander Evseev057aed12015-10-28 17:17:04 +0300524 $('<p />').append(descr)
Joshua Hesketh298c4912014-03-20 16:06:25 +1100525 );
Timo Tijhof51516cd2013-04-09 01:32:29 +0200526 }
Joshua Hesketh9d013542014-04-03 13:08:04 +1100527 return $header_div;
528 },
529
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000530 pipeline: function (pipeline, count) {
531 var format = this;
Joshua Hesketh9d013542014-04-03 13:08:04 +1100532 var $html = $('<div />')
533 .addClass('zuul-pipeline col-md-4')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000534 .append(this.pipeline_header(pipeline, count));
Timo Tijhof51516cd2013-04-09 01:32:29 +0200535
Joshua Heskethcbdcca12014-03-20 16:06:25 +1100536 $.each(pipeline.change_queues,
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100537 function (queue_i, change_queue) {
538 $.each(change_queue.heads, function (head_i, changes) {
Joshua Heskethcbdcca12014-03-20 16:06:25 +1100539 if (pipeline.change_queues.length > 1 &&
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100540 head_i === 0) {
541 var name = change_queue.name;
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100542 var short_name = name;
543 if (short_name.length > 32) {
544 short_name = short_name.substr(0, 32) + '...';
Timo Tijhof51516cd2013-04-09 01:32:29 +0200545 }
Joshua Hesketh298c4912014-03-20 16:06:25 +1100546 $html.append(
547 $('<p />')
548 .text('Queue: ')
549 .append(
550 $('<abbr />')
551 .attr('title', name)
552 .text(short_name)
553 )
554 );
Timo Tijhof51516cd2013-04-09 01:32:29 +0200555 }
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100556
557 $.each(changes, function (change_i, change) {
James E. Blair13c5ffc2017-09-05 07:59:13 -0700558 var $change_box =
559 format.change_with_status_tree(
560 change, change_queue);
561 $html.append($change_box);
562 format.display_patchset($change_box);
Timo Tijhof51516cd2013-04-09 01:32:29 +0200563 });
564 });
565 });
Joshua Hesketh298c4912014-03-20 16:06:25 +1100566 return $html;
Joshua Heskethace48892014-03-22 17:18:31 +1100567 },
568
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000569 toggle_patchset: function(e) {
570 // Toggle showing/hiding the patchset when the header is
571 // clicked.
572
Timo Tijhof0445c272017-09-19 19:46:09 +0100573 if (e.target.nodeName.toLowerCase() === 'a') {
574 // Ignore clicks from gerrit patch set link
575 return;
576 }
577
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000578 // Grab the patchset panel
579 var $panel = $(e.target).parents('.zuul-change');
580 var $body = $panel.children('.zuul-patchset-body');
581 $body.toggle(200);
582 var collapsed_index = collapsed_exceptions.indexOf(
583 $panel.attr('id'));
584 if (collapsed_index === -1 ) {
585 // Currently not an exception, add it to list
586 collapsed_exceptions.push($panel.attr('id'));
587 }
588 else {
589 // Currently an except, remove from exceptions
590 collapsed_exceptions.splice(collapsed_index, 1);
591 }
592 },
593
594 display_patchset: function($change_box, animate) {
595 // Determine if to show or hide the patchset and/or the results
596 // when loaded
597
598 // See if we should hide the body/results
599 var $panel = $change_box.find('.zuul-change');
600 var panel_change = $panel.attr('id');
601 var $body = $panel.children('.zuul-patchset-body');
602 var expand_by_default = $('#expand_by_default')
603 .prop('checked');
604
605 var collapsed_index = collapsed_exceptions
606 .indexOf(panel_change);
607
608 if (expand_by_default && collapsed_index === -1 ||
609 !expand_by_default && collapsed_index !== -1) {
610 // Expand by default, or is an exception
611 $body.show(animate);
612 }
613 else {
614 $body.hide(animate);
615 }
616
617 // Check if we should hide the whole panel
618 var panel_project = $panel.find('.change_project').text()
619 .toLowerCase();
620
621
622 var panel_pipeline = $change_box
623 .parents('.zuul-pipeline')
624 .find('.zuul-pipeline-header > h3')
625 .html()
626 .toLowerCase();
627
628 if (current_filter !== '') {
629 var show_panel = false;
630 var filter = current_filter.trim().split(/[\s,]+/);
631 $.each(filter, function(index, f_val) {
632 if (f_val !== '') {
633 f_val = f_val.toLowerCase();
634 if (panel_project.indexOf(f_val) !== -1 ||
635 panel_pipeline.indexOf(f_val) !== -1 ||
636 panel_change.indexOf(f_val) !== -1) {
637 show_panel = true;
638 }
639 }
640 });
641 if (show_panel === true) {
642 $change_box.show(animate);
643 }
644 else {
645 $change_box.hide(animate);
646 }
647 }
648 else {
649 $change_box.show(animate);
650 }
651 },
652 };
653
654 var app = {
655 schedule: function (app) {
Timo Tijhof4be9f742015-04-02 01:13:19 +0100656 app = app || this;
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000657 if (!options.enabled) {
658 setTimeout(function() {app.schedule(app);}, 5000);
659 return;
660 }
Timo Tijhof9a2362d2017-08-24 12:55:00 -0600661 app.update().always(function () {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000662 setTimeout(function() {app.schedule(app);}, 5000);
663 });
664
665 /* Only update graphs every minute */
666 if (zuul_graph_update_count > 11) {
667 zuul_graph_update_count = 0;
668 zuul.update_sparklines();
669 }
670 },
671
672 /** @return {jQuery.Promise} */
673 update: function () {
674 // Cancel the previous update if it hasn't completed yet.
675 if (xhr) {
676 xhr.abort();
677 }
678
679 this.emit('update-start');
680 var app = this;
681
Timo Tijhof4be9f742015-04-02 01:13:19 +0100682 var $msg = $(options.msg_id);
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000683 xhr = $.getJSON(options.source)
684 .done(function (data) {
685 if ('message' in data) {
686 $msg.removeClass('alert-danger')
687 .addClass('alert-info')
688 .text(data.message)
689 .show();
690 } else {
691 $msg.empty()
692 .hide();
693 }
694
695 if ('zuul_version' in data) {
696 $('#zuul-version-span').text(data.zuul_version);
697 }
698 if ('last_reconfigured' in data) {
699 var last_reconfigured =
700 new Date(data.last_reconfigured);
701 $('#last-reconfigured-span').text(
702 last_reconfigured.toString());
703 }
704
705 var $pipelines = $(options.pipelines_id);
706 $pipelines.html('');
707 $.each(data.pipelines, function (i, pipeline) {
708 var count = app.create_tree(pipeline);
709 $pipelines.append(
710 format.pipeline(pipeline, count));
711 });
712
713 $(options.queue_events_num).text(
714 data.trigger_event_queue ?
715 data.trigger_event_queue.length : '0'
716 );
Tobias Henkel02ec07f2017-10-19 07:10:37 +0200717 $(options.queue_management_events_num).text(
718 data.management_event_queue ?
719 data.management_event_queue.length : '0'
720 );
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000721 $(options.queue_results_num).text(
722 data.result_event_queue ?
723 data.result_event_queue.length : '0'
724 );
725 })
Timo Tijhof67f4ac12015-04-10 00:33:50 +0100726 .fail(function (jqXHR, statusText, errMsg) {
727 if (statusText === 'abort') {
728 return;
729 }
Joshua Heskethd50eb582014-04-30 19:51:22 +1000730 $msg.text(options.source + ': ' + errMsg)
731 .addClass('alert-danger')
732 .removeClass('zuul-msg-wrap-off')
733 .show();
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000734 })
Timo Tijhof9a2362d2017-08-24 12:55:00 -0600735 .always(function () {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000736 xhr = undefined;
737 app.emit('update-end');
738 });
739
740 return xhr;
741 },
742
743 update_sparklines: function() {
744 $.each(zuul_sparkline_urls, function(name, url) {
745 var newimg = new Image();
746 var parts = url.split('#');
747 newimg.src = parts[0] + '#' + new Date().getTime();
Timo Tijhof4be9f742015-04-02 01:13:19 +0100748 $(newimg).load(function () {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000749 zuul_sparkline_urls[name] = newimg.src;
750 });
751 });
752 },
753
754 emit: function () {
755 $jq.trigger.apply($jq, arguments);
756 return this;
757 },
758 on: function () {
759 $jq.on.apply($jq, arguments);
760 return this;
761 },
762 one: function () {
763 $jq.one.apply($jq, arguments);
764 return this;
765 },
766
767 control_form: function() {
768 // Build the filter form filling anything from cookies
769
770 var $control_form = $('<form />')
771 .attr('role', 'form')
772 .addClass('form-inline')
773 .submit(this.handle_filter_change);
774
775 $control_form
776 .append(this.filter_form_group())
777 .append(this.expand_form_group());
778
779 return $control_form;
780 },
781
Joshua Hesketh1ed6f9d2014-03-31 22:53:06 +1100782 filter_form_group: function() {
Joshua Heskethace48892014-03-22 17:18:31 +1100783 // Update the filter form with a clear button if required
784
785 var $label = $('<label />')
786 .addClass('control-label')
787 .attr('for', 'filter_string')
788 .text('Filters')
789 .css('padding-right', '0.5em');
790
791 var $input = $('<input />')
792 .attr('type', 'text')
793 .attr('id', 'filter_string')
794 .addClass('form-control')
795 .attr('title',
796 'project(s), pipeline(s) or review(s) comma ' +
797 'separated')
Joshua Hesketh1ed6f9d2014-03-31 22:53:06 +1100798 .attr('value', current_filter);
Joshua Heskethace48892014-03-22 17:18:31 +1100799
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000800 $input.change(this.handle_filter_change);
Joshua Heskethace48892014-03-22 17:18:31 +1100801
802 var $clear_icon = $('<span />')
803 .addClass('form-control-feedback')
804 .addClass('glyphicon glyphicon-remove-circle')
805 .attr('id', 'filter_form_clear_box')
806 .attr('title', 'clear filter')
807 .css('cursor', 'pointer');
808
809 $clear_icon.click(function() {
810 $('#filter_string').val('').change();
811 });
812
Joshua Hesketh1ed6f9d2014-03-31 22:53:06 +1100813 if (current_filter === '') {
Joshua Heskethace48892014-03-22 17:18:31 +1100814 $clear_icon.hide();
815 }
816
817 var $form_group = $('<div />')
818 .addClass('form-group has-feedback')
819 .append($label, $input, $clear_icon);
820 return $form_group;
821 },
822
Joshua Heskethae230f62014-03-22 22:14:44 +1100823 expand_form_group: function() {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700824 var expand_by_default = (
Joshua Heskethae230f62014-03-22 22:14:44 +1100825 read_cookie('zuul_expand_by_default', false) === 'true');
826
Monty Taylor860bb0a2014-03-22 09:41:25 -0700827 var $checkbox = $('<input />')
Joshua Heskethae230f62014-03-22 22:14:44 +1100828 .attr('type', 'checkbox')
829 .attr('id', 'expand_by_default')
830 .prop('checked', expand_by_default)
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000831 .change(this.handle_expand_by_default);
Joshua Heskethae230f62014-03-22 22:14:44 +1100832
Monty Taylor860bb0a2014-03-22 09:41:25 -0700833 var $label = $('<label />')
Joshua Heskethae230f62014-03-22 22:14:44 +1100834 .css('padding-left', '1em')
835 .html('Expand by default: ')
836 .append($checkbox);
837
838 var $form_group = $('<div />')
839 .addClass('checkbox')
840 .append($label);
841 return $form_group;
842 },
843
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000844 handle_filter_change: function() {
845 // Update the filter and save it to a cookie
846 current_filter = $('#filter_string').val();
847 set_cookie('zuul_filter_string', current_filter);
848 if (current_filter === '') {
849 $('#filter_form_clear_box').hide();
Joshua Heskethace48892014-03-22 17:18:31 +1100850 }
851 else {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000852 $('#filter_form_clear_box').show();
Joshua Heskethace48892014-03-22 17:18:31 +1100853 }
Joshua Heskethace48892014-03-22 17:18:31 +1100854
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000855 $('.zuul-change-box').each(function(index, obj) {
856 var $change_box = $(obj);
857 format.display_patchset($change_box, 200);
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100858 });
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000859 return false;
Timo Tijhof51516cd2013-04-09 01:32:29 +0200860 },
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000861
862 handle_expand_by_default: function(e) {
863 // Handle toggling expand by default
864 set_cookie('zuul_expand_by_default', e.target.checked);
865 collapsed_exceptions = [];
866 $('.zuul-change-box').each(function(index, obj) {
867 var $change_box = $(obj);
868 format.display_patchset($change_box, 200);
869 });
870 },
871
872 create_tree: function(pipeline) {
873 var count = 0;
874 var pipeline_max_tree_columns = 1;
875 $.each(pipeline.change_queues, function(change_queue_i,
876 change_queue) {
877 var tree = [];
878 var max_tree_columns = 1;
879 var changes = [];
880 var last_tree_length = 0;
881 $.each(change_queue.heads, function(head_i, head) {
882 $.each(head, function(change_i, change) {
883 changes[change.id] = change;
884 change._tree_position = change_i;
885 });
886 });
887 $.each(change_queue.heads, function(head_i, head) {
888 $.each(head, function(change_i, change) {
James E. Blaird1d3ce32015-02-11 17:56:45 -0800889 if (change.live === true) {
890 count += 1;
891 }
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000892 var idx = tree.indexOf(change.id);
893 if (idx > -1) {
894 change._tree_index = idx;
895 // remove...
896 tree[idx] = null;
897 while (tree[tree.length - 1] === null) {
898 tree.pop();
899 }
900 } else {
901 change._tree_index = 0;
902 }
903 change._tree_branches = [];
904 change._tree = [];
905 if (typeof(change.items_behind) === 'undefined') {
906 change.items_behind = [];
907 }
908 change.items_behind.sort(function(a, b) {
909 return (changes[b]._tree_position -
910 changes[a]._tree_position);
911 });
912 $.each(change.items_behind, function(i, id) {
913 tree.push(id);
914 if (tree.length>last_tree_length &&
915 last_tree_length > 0) {
916 change._tree_branches.push(
917 tree.length - 1);
918 }
919 });
920 if (tree.length > max_tree_columns) {
921 max_tree_columns = tree.length;
922 }
923 if (tree.length > pipeline_max_tree_columns) {
924 pipeline_max_tree_columns = tree.length;
925 }
926 change._tree = tree.slice(0); // make a copy
927 last_tree_length = tree.length;
928 });
929 });
930 change_queue._tree_columns = max_tree_columns;
931 });
932 pipeline._tree_columns = pipeline_max_tree_columns;
933 return count;
934 },
935 };
936
937 $jq = $(app);
938 return {
939 options: options,
940 format: format,
941 app: app,
942 jq: $jq
943 };
Timo Tijhof4be9f742015-04-02 01:13:19 +0100944 };
Timo Tijhof51516cd2013-04-09 01:32:29 +0200945}(jQuery));