blob: c2cf279cfc3ce3f4fcaef1b669fc2758e3bf57f0 [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': '',
52 'source': 'status.json',
53 'msg_id': '#zuul_msg',
54 'pipelines_id': '#zuul_pipelines',
55 'queue_events_num': '#zuul_queue_events_num',
56 'queue_results_num': '#zuul_queue_results_num',
57 }, options);
Joshua Heskethace48892014-03-22 17:18:31 +110058
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100059 var collapsed_exceptions = [];
Joshua Hesketh6f94dd12014-08-20 16:14:53 +100060 var current_filter = read_cookie('zuul_filter_string', '');
Jan Hrubanddeb95a2017-01-03 15:12:41 +010061 var change_set_in_url = window.location.href.split('#')[1];
62 if (change_set_in_url) {
63 current_filter = change_set_in_url;
64 }
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100065 var $jq;
Timo Tijhof51516cd2013-04-09 01:32:29 +020066
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100067 var xhr,
68 zuul_graph_update_count = 0,
69 zuul_sparkline_urls = {};
Joshua Hesketh9d013542014-04-03 13:08:04 +110070
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100071 function get_sparkline_url(pipeline_name) {
72 if (options.graphite_url !== '') {
73 if (!(pipeline_name in zuul_sparkline_urls)) {
74 zuul_sparkline_urls[pipeline_name] = $.fn.graphite
75 .geturl({
76 url: options.graphite_url,
77 from: "-8hours",
78 width: 100,
79 height: 26,
80 margin: 0,
81 hideLegend: true,
82 hideAxes: true,
83 hideGrid: true,
84 target: [
85 "color(stats.gauges.zuul.pipeline." + pipeline_name
Timo Tijhof4be9f742015-04-02 01:13:19 +010086 + ".current_changes, '6b8182')"
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100087 ]
Joshua Hesketh298c4912014-03-20 16:06:25 +110088 });
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100089 }
90 return zuul_sparkline_urls[pipeline_name];
91 }
92 return false;
93 }
Joshua Hesketh298c4912014-03-20 16:06:25 +110094
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +100095 var format = {
Joshua Hesketh6b1a2182014-03-21 14:40:04 +110096 job: function(job) {
Joshua Hesketh9e6ce532014-04-01 13:11:53 +110097 var $job_line = $('<span />');
98
Monty Taylore78211d2017-07-21 09:48:41 +090099 if (job.result !== null) {
100 $job_line.append(
101 $('<a />')
102 .addClass('zuul-job-name')
103 .attr('href', job.report_url)
104 .text(job.name)
105 );
106 }
107 else if (job.url !== null) {
Joshua Hesketh9e6ce532014-04-01 13:11:53 +1100108 $job_line.append(
109 $('<a />')
110 .addClass('zuul-job-name')
111 .attr('href', job.url)
112 .text(job.name)
113 );
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100114 }
Joshua Hesketh9e6ce532014-04-01 13:11:53 +1100115 else {
116 $job_line.append(
117 $('<span />')
118 .addClass('zuul-job-name')
119 .text(job.name)
120 );
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100121 }
Joshua Hesketh9e6ce532014-04-01 13:11:53 +1100122
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000123 $job_line.append(this.job_status(job));
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100124
125 if (job.voting === false) {
126 $job_line.append(
Joshua Hesketh9e6ce532014-04-01 13:11:53 +1100127 $(' <small />')
128 .addClass('zuul-non-voting-desc')
129 .text(' (non-voting)')
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100130 );
131 }
Joshua Hesketh9e6ce532014-04-01 13:11:53 +1100132
Joshua Hesketha95fd552014-08-21 11:21:05 +1000133 $job_line.append($('<div style="clear: both"></div>'));
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100134 return $job_line;
135 },
136
137 job_status: function(job) {
138 var result = job.result ? job.result.toLowerCase() : null;
139 if (result === null) {
140 result = job.url ? 'in progress' : 'queued';
141 }
142
Monty Taylor860bb0a2014-03-22 09:41:25 -0700143 if (result === 'in progress') {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000144 return this.job_progress_bar(job.elapsed_time,
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100145 job.remaining_time);
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100146 }
147 else {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000148 return this.status_label(result);
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100149 }
150 },
151
152 status_label: function(result) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700153 var $status = $('<span />');
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100154 $status.addClass('zuul-job-result label');
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100155
156 switch (result) {
157 case 'success':
158 $status.addClass('label-success');
159 break;
160 case 'failure':
161 $status.addClass('label-danger');
162 break;
163 case 'unstable':
164 $status.addClass('label-warning');
165 break;
Alexander Evseev3103a842015-11-17 10:12:45 +0300166 case 'skipped':
167 $status.addClass('label-info');
168 break;
Antoine Musso4c2053d2016-02-04 23:35:23 +0100169 // 'in progress' 'queued' 'lost' 'aborted' ...
170 default:
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100171 $status.addClass('label-default');
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100172 }
173 $status.text(result);
174 return $status;
175 },
176
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100177 job_progress_bar: function(elapsed_time, remaining_time) {
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100178 var progress_percent = 100 * (elapsed_time / (elapsed_time +
179 remaining_time));
180 var $bar_inner = $('<div />')
181 .addClass('progress-bar')
182 .attr('role', 'progressbar')
183 .attr('aria-valuenow', 'progressbar')
184 .attr('aria-valuemin', progress_percent)
185 .attr('aria-valuemin', '0')
186 .attr('aria-valuemax', '100')
187 .css('width', progress_percent + '%');
188
189 var $bar_outter = $('<div />')
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100190 .addClass('progress zuul-job-result')
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100191 .append($bar_inner);
192
193 return $bar_outter;
194 },
195
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100196 enqueue_time: function(ms) {
197 // Special format case for enqueue time to add style
198 var hours = 60 * 60 * 1000;
199 var now = Date.now();
200 var delta = now - ms;
Monty Taylor860bb0a2014-03-22 09:41:25 -0700201 var status = 'text-success';
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000202 var text = this.time(delta, true);
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100203 if (delta > (4 * hours)) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700204 status = 'text-danger';
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100205 } else if (delta > (2 * hours)) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700206 status = 'text-warning';
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100207 }
208 return '<span class="' + status + '">' + text + '</span>';
209 },
210
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100211 time: function(ms, words) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700212 if (typeof(words) === 'undefined') {
213 words = false;
214 }
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100215 var seconds = (+ms)/1000;
216 var minutes = Math.floor(seconds/60);
217 var hours = Math.floor(minutes/60);
218 seconds = Math.floor(seconds % 60);
219 minutes = Math.floor(minutes % 60);
Monty Taylor860bb0a2014-03-22 09:41:25 -0700220 var r = '';
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100221 if (words) {
222 if (hours) {
223 r += hours;
224 r += ' hr ';
225 }
226 r += minutes + ' min';
227 } else {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700228 if (hours < 10) {
229 r += '0';
230 }
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100231 r += hours + ':';
Monty Taylor860bb0a2014-03-22 09:41:25 -0700232 if (minutes < 10) {
233 r += '0';
234 }
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100235 r += minutes + ':';
Monty Taylor860bb0a2014-03-22 09:41:25 -0700236 if (seconds < 10) {
237 r += '0';
238 }
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100239 r += seconds;
240 }
241 return r;
242 },
243
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100244 change_total_progress_bar: function(change) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700245 var job_percent = Math.floor(100 / change.jobs.length);
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100246 var $bar_outter = $('<div />')
247 .addClass('progress zuul-change-total-result');
248
249 $.each(change.jobs, function (i, job) {
250 var result = job.result ? job.result.toLowerCase() : null;
251 if (result === null) {
252 result = job.url ? 'in progress' : 'queued';
253 }
254
Monty Taylor860bb0a2014-03-22 09:41:25 -0700255 if (result !== 'queued') {
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100256 var $bar_inner = $('<div />')
257 .addClass('progress-bar');
258
259 switch (result) {
260 case 'success':
261 $bar_inner.addClass('progress-bar-success');
262 break;
263 case 'lost':
264 case 'failure':
265 $bar_inner.addClass('progress-bar-danger');
266 break;
267 case 'unstable':
268 $bar_inner.addClass('progress-bar-warning');
269 break;
270 case 'in progress':
271 case 'queued':
272 break;
273 }
274 $bar_inner.attr('title', job.name)
275 .css('width', job_percent + '%');
276 $bar_outter.append($bar_inner);
277 }
278 });
279 return $bar_outter;
280 },
281
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100282 change_header: function(change) {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700283 var change_id = change.id || 'NA';
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100284 if (change_id.length === 40) {
285 change_id = change_id.substr(0, 7);
Joshua Hesketh298c4912014-03-20 16:06:25 +1100286 }
Timo Tijhof51516cd2013-04-09 01:32:29 +0200287
Monty Taylor860bb0a2014-03-22 09:41:25 -0700288 var $change_link = $('<small />');
Joshua Hesketh298c4912014-03-20 16:06:25 +1100289 if (change.url !== null) {
Jamie Lennoxa6b33ba2017-02-10 11:33:44 +1100290 var github_id = change.id.match(/^([0-9]+),([0-9a-f]{40})$/);
291 if (github_id) {
292 $change_link.append(
293 $('<a />').attr('href', change.url).append(
294 $('<abbr />')
295 .attr('title', change.id)
296 .text('#' + github_id[1])
297 )
298 );
299 } else if (/^[0-9a-f]{40}$/.test(change.id)) {
Joshua Heskethcd7a0772014-08-21 11:32:44 +1000300 var change_id_short = change.id.slice(0, 7);
301 $change_link.append(
302 $('<a />').attr('href', change.url).append(
303 $('<abbr />')
304 .attr('title', change.id)
305 .text(change_id_short)
306 )
307 );
308 }
309 else {
310 $change_link.append(
311 $('<a />').attr('href', change.url).text(change.id)
312 );
313 }
Timo Tijhof51516cd2013-04-09 01:32:29 +0200314 }
Joshua Hesketh298c4912014-03-20 16:06:25 +1100315 else {
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100316 $change_link.text(change_id);
Timo Tijhof51516cd2013-04-09 01:32:29 +0200317 }
Timo Tijhof51516cd2013-04-09 01:32:29 +0200318
Monty Taylor860bb0a2014-03-22 09:41:25 -0700319 var $change_progress_row_left = $('<div />')
Timo Tijhofa62e8492015-04-02 03:05:04 +0100320 .addClass('col-xs-4')
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100321 .append($change_link);
Monty Taylor860bb0a2014-03-22 09:41:25 -0700322 var $change_progress_row_right = $('<div />')
Timo Tijhofa62e8492015-04-02 03:05:04 +0100323 .addClass('col-xs-8')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000324 .append(this.change_total_progress_bar(change));
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100325
Monty Taylor860bb0a2014-03-22 09:41:25 -0700326 var $change_progress_row = $('<div />')
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100327 .addClass('row')
328 .append($change_progress_row_left)
Monty Taylor860bb0a2014-03-22 09:41:25 -0700329 .append($change_progress_row_right);
Joshua Heskethf1b06ca2014-03-21 17:01:12 +1100330
Monty Taylor860bb0a2014-03-22 09:41:25 -0700331 var $project_span = $('<span />')
Joshua Heskethace48892014-03-22 17:18:31 +1100332 .addClass('change_project')
333 .text(change.project);
334
Monty Taylor860bb0a2014-03-22 09:41:25 -0700335 var $left = $('<div />')
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100336 .addClass('col-xs-8')
Joshua Hesketh1751e4f2014-04-01 13:24:51 +1100337 .append($project_span, $change_progress_row);
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100338
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000339 var remaining_time = this.time(
Monty Taylor860bb0a2014-03-22 09:41:25 -0700340 change.remaining_time, true);
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000341 var enqueue_time = this.enqueue_time(
Monty Taylor860bb0a2014-03-22 09:41:25 -0700342 change.enqueue_time);
343 var $remaining_time = $('<small />').addClass('time')
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100344 .attr('title', 'Remaining Time').html(remaining_time);
Monty Taylor860bb0a2014-03-22 09:41:25 -0700345 var $enqueue_time = $('<small />').addClass('time')
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100346 .attr('title', 'Elapsed Time').html(enqueue_time);
347
James E. Blair6dc954b2015-02-11 18:32:19 -0800348 var $right = $('<div />');
349 if (change.live === true) {
350 $right.addClass('col-xs-4 text-right')
351 .append($remaining_time, $('<br />'), $enqueue_time);
352 }
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100353
Monty Taylor860bb0a2014-03-22 09:41:25 -0700354 var $header = $('<div />')
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100355 .addClass('row')
356 .append($left, $right);
357 return $header;
358 },
359
360 change_list: function(jobs) {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000361 var format = this;
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100362 var $list = $('<ul />')
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100363 .addClass('list-group zuul-patchset-body');
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100364
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100365 $.each(jobs, function (i, job) {
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100366 var $item = $('<li />')
367 .addClass('list-group-item')
368 .addClass('zuul-change-job')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000369 .append(format.job(job));
Joshua Hesketh298c4912014-03-20 16:06:25 +1100370 $list.append($item);
Timo Tijhof51516cd2013-04-09 01:32:29 +0200371 });
372
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100373 return $list;
374 },
375
376 change_panel: function (change) {
377 var $header = $('<div />')
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100378 .addClass('panel-heading zuul-patchset-header')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000379 .append(this.change_header(change));
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100380
Joshua Heskethdb8046e2014-03-21 18:42:25 +1100381 var panel_id = change.id ? change.id.replace(',', '_')
382 : change.project.replace('/', '_') +
Monty Taylor860bb0a2014-03-22 09:41:25 -0700383 '-' + change.enqueue_time;
Joshua Heskethdb8046e2014-03-21 18:42:25 +1100384 var $panel = $('<div />')
Monty Taylor860bb0a2014-03-22 09:41:25 -0700385 .attr('id', panel_id)
Joshua Hesketh0ca1e2e2014-03-21 16:49:05 +1100386 .addClass('panel panel-default zuul-change')
387 .append($header)
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000388 .append(this.change_list(change.jobs));
Joshua Heskethdb8046e2014-03-21 18:42:25 +1100389
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000390 $header.click(this.toggle_patchset);
Joshua Heskethdb8046e2014-03-21 18:42:25 +1100391 return $panel;
Timo Tijhof51516cd2013-04-09 01:32:29 +0200392 },
393
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100394 change_status_icon: function(change) {
395 var icon_name = 'green.png';
396 var icon_title = 'Succeeding';
397
398 if (change.active !== true) {
399 // Grey icon
400 icon_name = 'grey.png';
401 icon_title = 'Waiting until closer to head of queue to' +
402 ' start jobs';
403 }
James E. Blair107c3852015-02-07 08:23:10 -0800404 else if (change.live !== true) {
405 // Grey icon
406 icon_name = 'grey.png';
Joshua Hesketh6bc619d2015-02-11 09:30:21 +1100407 icon_title = 'Dependent change required for testing';
James E. Blair107c3852015-02-07 08:23:10 -0800408 }
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100409 else if (change.failing_reasons &&
410 change.failing_reasons.length > 0) {
411 var reason = change.failing_reasons.join(', ');
412 icon_title = 'Failing because ' + reason;
413 if (reason.match(/merge conflict/)) {
414 // Black icon
415 icon_name = 'black.png';
416 }
417 else {
418 // Red icon
419 icon_name = 'red.png';
420 }
421 }
422
423 var $icon = $('<img />')
424 .attr('src', 'images/' + icon_name)
425 .attr('title', icon_title)
426 .css('margin-top', '-6px');
427
428 return $icon;
429 },
430
431 change_with_status_tree: function(change, change_queue) {
432 var $change_row = $('<tr />');
433
434 for (var i = 0; i < change_queue._tree_columns; i++) {
435 var $tree_cell = $('<td />')
436 .css('height', '100%')
437 .css('padding', '0 0 10px 0')
438 .css('margin', '0')
439 .css('width', '16px')
440 .css('min-width', '16px')
441 .css('overflow', 'hidden')
442 .css('vertical-align', 'top');
443
444 if (i < change._tree.length && change._tree[i] !== null) {
445 $tree_cell.css('background-image',
446 'url(\'images/line.png\')')
447 .css('background-repeat', 'repeat-y');
448 }
449
450 if (i === change._tree_index) {
451 $tree_cell.append(
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000452 this.change_status_icon(change));
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100453 }
454 if (change._tree_branches.indexOf(i) !== -1) {
455 var $image = $('<img />')
456 .css('vertical-align', 'baseline');
457 if (change._tree_branches.indexOf(i) ===
458 change._tree_branches.length - 1) {
459 // Angle line
460 $image.attr('src', 'images/line-angle.png');
461 }
462 else {
463 // T line
464 $image.attr('src', 'images/line-t.png');
465 }
466 $tree_cell.append($image);
467 }
468 $change_row.append($tree_cell);
469 }
470
471 var change_width = 360 - 16*change_queue._tree_columns;
472 var $change_column = $('<td />')
473 .css('width', change_width + 'px')
474 .addClass('zuul-change-cell')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000475 .append(this.change_panel(change));
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100476
477 $change_row.append($change_column);
478
479 var $change_table = $('<table />')
480 .addClass('zuul-change-box')
481 .css('-moz-box-sizing', 'content-box')
482 .css('box-sizing', 'content-box')
483 .append($change_row);
484
485 return $change_table;
486 },
487
Joshua Hesketh9d013542014-04-03 13:08:04 +1100488 pipeline_sparkline: function(pipeline_name) {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000489 if (options.graphite_url !== '') {
Joshua Hesketh9d013542014-04-03 13:08:04 +1100490 var $sparkline = $('<img />')
491 .addClass('pull-right')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000492 .attr('src', get_sparkline_url(pipeline_name));
Joshua Hesketh9d013542014-04-03 13:08:04 +1100493 return $sparkline;
494 }
495 return false;
496 },
497
498 pipeline_header: function(pipeline, count) {
499 // Format the pipeline name, sparkline and description
500 var $header_div = $('<div />')
501 .addClass('zuul-pipeline-header');
502
503 var $heading = $('<h3 />')
504 .css('vertical-align', 'middle')
505 .text(pipeline.name)
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100506 .append(
Joshua Hesketh9d013542014-04-03 13:08:04 +1100507 $('<span />')
508 .addClass('badge pull-right')
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100509 .css('vertical-align', 'middle')
Joshua Hesketh9d013542014-04-03 13:08:04 +1100510 .css('margin-top', '0.5em')
511 .text(count)
512 )
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000513 .append(this.pipeline_sparkline(pipeline.name));
Joshua Hesketh9d013542014-04-03 13:08:04 +1100514
515 $header_div.append($heading);
Joshua Hesketh298c4912014-03-20 16:06:25 +1100516
Timo Tijhof51516cd2013-04-09 01:32:29 +0200517 if (typeof pipeline.description === 'string') {
Alexander Evseev057aed12015-10-28 17:17:04 +0300518 var descr = $('<small />')
519 $.each( pipeline.description.split(/\r?\n\r?\n/), function(index, descr_part){
520 descr.append($('<p />').text(descr_part));
521 });
Joshua Hesketh9d013542014-04-03 13:08:04 +1100522 $header_div.append(
Alexander Evseev057aed12015-10-28 17:17:04 +0300523 $('<p />').append(descr)
Joshua Hesketh298c4912014-03-20 16:06:25 +1100524 );
Timo Tijhof51516cd2013-04-09 01:32:29 +0200525 }
Joshua Hesketh9d013542014-04-03 13:08:04 +1100526 return $header_div;
527 },
528
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000529 pipeline: function (pipeline, count) {
530 var format = this;
Joshua Hesketh9d013542014-04-03 13:08:04 +1100531 var $html = $('<div />')
532 .addClass('zuul-pipeline col-md-4')
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000533 .append(this.pipeline_header(pipeline, count));
Timo Tijhof51516cd2013-04-09 01:32:29 +0200534
Joshua Heskethcbdcca12014-03-20 16:06:25 +1100535 $.each(pipeline.change_queues,
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100536 function (queue_i, change_queue) {
537 $.each(change_queue.heads, function (head_i, changes) {
Joshua Heskethcbdcca12014-03-20 16:06:25 +1100538 if (pipeline.change_queues.length > 1 &&
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100539 head_i === 0) {
540 var name = change_queue.name;
Joshua Hesketh6b1a2182014-03-21 14:40:04 +1100541 var short_name = name;
542 if (short_name.length > 32) {
543 short_name = short_name.substr(0, 32) + '...';
Timo Tijhof51516cd2013-04-09 01:32:29 +0200544 }
Joshua Hesketh298c4912014-03-20 16:06:25 +1100545 $html.append(
546 $('<p />')
547 .text('Queue: ')
548 .append(
549 $('<abbr />')
550 .attr('title', name)
551 .text(short_name)
552 )
553 );
Timo Tijhof51516cd2013-04-09 01:32:29 +0200554 }
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100555
556 $.each(changes, function (change_i, change) {
Monty Taylord9f1f822017-08-30 10:16:29 -0500557 // Only add a change when it has jobs
558 if (change.jobs.length > 0) {
559 var $change_box =
560 format.change_with_status_tree(
561 change, change_queue);
562 $html.append($change_box);
563 format.display_patchset($change_box);
564 }
Timo Tijhof51516cd2013-04-09 01:32:29 +0200565 });
566 });
567 });
Joshua Hesketh298c4912014-03-20 16:06:25 +1100568 return $html;
Joshua Heskethace48892014-03-22 17:18:31 +1100569 },
570
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000571 toggle_patchset: function(e) {
572 // Toggle showing/hiding the patchset when the header is
573 // clicked.
574
575 // Grab the patchset panel
576 var $panel = $(e.target).parents('.zuul-change');
577 var $body = $panel.children('.zuul-patchset-body');
578 $body.toggle(200);
579 var collapsed_index = collapsed_exceptions.indexOf(
580 $panel.attr('id'));
581 if (collapsed_index === -1 ) {
582 // Currently not an exception, add it to list
583 collapsed_exceptions.push($panel.attr('id'));
584 }
585 else {
586 // Currently an except, remove from exceptions
587 collapsed_exceptions.splice(collapsed_index, 1);
588 }
589 },
590
591 display_patchset: function($change_box, animate) {
592 // Determine if to show or hide the patchset and/or the results
593 // when loaded
594
595 // See if we should hide the body/results
596 var $panel = $change_box.find('.zuul-change');
597 var panel_change = $panel.attr('id');
598 var $body = $panel.children('.zuul-patchset-body');
599 var expand_by_default = $('#expand_by_default')
600 .prop('checked');
601
602 var collapsed_index = collapsed_exceptions
603 .indexOf(panel_change);
604
605 if (expand_by_default && collapsed_index === -1 ||
606 !expand_by_default && collapsed_index !== -1) {
607 // Expand by default, or is an exception
608 $body.show(animate);
609 }
610 else {
611 $body.hide(animate);
612 }
613
614 // Check if we should hide the whole panel
615 var panel_project = $panel.find('.change_project').text()
616 .toLowerCase();
617
618
619 var panel_pipeline = $change_box
620 .parents('.zuul-pipeline')
621 .find('.zuul-pipeline-header > h3')
622 .html()
623 .toLowerCase();
624
625 if (current_filter !== '') {
626 var show_panel = false;
627 var filter = current_filter.trim().split(/[\s,]+/);
628 $.each(filter, function(index, f_val) {
629 if (f_val !== '') {
630 f_val = f_val.toLowerCase();
631 if (panel_project.indexOf(f_val) !== -1 ||
632 panel_pipeline.indexOf(f_val) !== -1 ||
633 panel_change.indexOf(f_val) !== -1) {
634 show_panel = true;
635 }
636 }
637 });
638 if (show_panel === true) {
639 $change_box.show(animate);
640 }
641 else {
642 $change_box.hide(animate);
643 }
644 }
645 else {
646 $change_box.show(animate);
647 }
648 },
649 };
650
651 var app = {
652 schedule: function (app) {
Timo Tijhof4be9f742015-04-02 01:13:19 +0100653 app = app || this;
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000654 if (!options.enabled) {
655 setTimeout(function() {app.schedule(app);}, 5000);
656 return;
657 }
658 app.update().complete(function () {
659 setTimeout(function() {app.schedule(app);}, 5000);
660 });
661
662 /* Only update graphs every minute */
663 if (zuul_graph_update_count > 11) {
664 zuul_graph_update_count = 0;
665 zuul.update_sparklines();
666 }
667 },
668
669 /** @return {jQuery.Promise} */
670 update: function () {
671 // Cancel the previous update if it hasn't completed yet.
672 if (xhr) {
673 xhr.abort();
674 }
675
676 this.emit('update-start');
677 var app = this;
678
Timo Tijhof4be9f742015-04-02 01:13:19 +0100679 var $msg = $(options.msg_id);
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000680 xhr = $.getJSON(options.source)
681 .done(function (data) {
682 if ('message' in data) {
683 $msg.removeClass('alert-danger')
684 .addClass('alert-info')
685 .text(data.message)
686 .show();
687 } else {
688 $msg.empty()
689 .hide();
690 }
691
692 if ('zuul_version' in data) {
693 $('#zuul-version-span').text(data.zuul_version);
694 }
695 if ('last_reconfigured' in data) {
696 var last_reconfigured =
697 new Date(data.last_reconfigured);
698 $('#last-reconfigured-span').text(
699 last_reconfigured.toString());
700 }
701
702 var $pipelines = $(options.pipelines_id);
703 $pipelines.html('');
704 $.each(data.pipelines, function (i, pipeline) {
705 var count = app.create_tree(pipeline);
706 $pipelines.append(
707 format.pipeline(pipeline, count));
708 });
709
710 $(options.queue_events_num).text(
711 data.trigger_event_queue ?
712 data.trigger_event_queue.length : '0'
713 );
714 $(options.queue_results_num).text(
715 data.result_event_queue ?
716 data.result_event_queue.length : '0'
717 );
718 })
Timo Tijhof67f4ac12015-04-10 00:33:50 +0100719 .fail(function (jqXHR, statusText, errMsg) {
720 if (statusText === 'abort') {
721 return;
722 }
Joshua Heskethd50eb582014-04-30 19:51:22 +1000723 $msg.text(options.source + ': ' + errMsg)
724 .addClass('alert-danger')
725 .removeClass('zuul-msg-wrap-off')
726 .show();
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000727 })
728 .complete(function () {
729 xhr = undefined;
730 app.emit('update-end');
731 });
732
733 return xhr;
734 },
735
736 update_sparklines: function() {
737 $.each(zuul_sparkline_urls, function(name, url) {
738 var newimg = new Image();
739 var parts = url.split('#');
740 newimg.src = parts[0] + '#' + new Date().getTime();
Timo Tijhof4be9f742015-04-02 01:13:19 +0100741 $(newimg).load(function () {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000742 zuul_sparkline_urls[name] = newimg.src;
743 });
744 });
745 },
746
747 emit: function () {
748 $jq.trigger.apply($jq, arguments);
749 return this;
750 },
751 on: function () {
752 $jq.on.apply($jq, arguments);
753 return this;
754 },
755 one: function () {
756 $jq.one.apply($jq, arguments);
757 return this;
758 },
759
760 control_form: function() {
761 // Build the filter form filling anything from cookies
762
763 var $control_form = $('<form />')
764 .attr('role', 'form')
765 .addClass('form-inline')
766 .submit(this.handle_filter_change);
767
768 $control_form
769 .append(this.filter_form_group())
770 .append(this.expand_form_group());
771
772 return $control_form;
773 },
774
Joshua Hesketh1ed6f9d2014-03-31 22:53:06 +1100775 filter_form_group: function() {
Joshua Heskethace48892014-03-22 17:18:31 +1100776 // Update the filter form with a clear button if required
777
778 var $label = $('<label />')
779 .addClass('control-label')
780 .attr('for', 'filter_string')
781 .text('Filters')
782 .css('padding-right', '0.5em');
783
784 var $input = $('<input />')
785 .attr('type', 'text')
786 .attr('id', 'filter_string')
787 .addClass('form-control')
788 .attr('title',
789 'project(s), pipeline(s) or review(s) comma ' +
790 'separated')
Joshua Hesketh1ed6f9d2014-03-31 22:53:06 +1100791 .attr('value', current_filter);
Joshua Heskethace48892014-03-22 17:18:31 +1100792
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000793 $input.change(this.handle_filter_change);
Joshua Heskethace48892014-03-22 17:18:31 +1100794
795 var $clear_icon = $('<span />')
796 .addClass('form-control-feedback')
797 .addClass('glyphicon glyphicon-remove-circle')
798 .attr('id', 'filter_form_clear_box')
799 .attr('title', 'clear filter')
800 .css('cursor', 'pointer');
801
802 $clear_icon.click(function() {
803 $('#filter_string').val('').change();
804 });
805
Joshua Hesketh1ed6f9d2014-03-31 22:53:06 +1100806 if (current_filter === '') {
Joshua Heskethace48892014-03-22 17:18:31 +1100807 $clear_icon.hide();
808 }
809
810 var $form_group = $('<div />')
811 .addClass('form-group has-feedback')
812 .append($label, $input, $clear_icon);
813 return $form_group;
814 },
815
Joshua Heskethae230f62014-03-22 22:14:44 +1100816 expand_form_group: function() {
Monty Taylor860bb0a2014-03-22 09:41:25 -0700817 var expand_by_default = (
Joshua Heskethae230f62014-03-22 22:14:44 +1100818 read_cookie('zuul_expand_by_default', false) === 'true');
819
Monty Taylor860bb0a2014-03-22 09:41:25 -0700820 var $checkbox = $('<input />')
Joshua Heskethae230f62014-03-22 22:14:44 +1100821 .attr('type', 'checkbox')
822 .attr('id', 'expand_by_default')
823 .prop('checked', expand_by_default)
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000824 .change(this.handle_expand_by_default);
Joshua Heskethae230f62014-03-22 22:14:44 +1100825
Monty Taylor860bb0a2014-03-22 09:41:25 -0700826 var $label = $('<label />')
Joshua Heskethae230f62014-03-22 22:14:44 +1100827 .css('padding-left', '1em')
828 .html('Expand by default: ')
829 .append($checkbox);
830
831 var $form_group = $('<div />')
832 .addClass('checkbox')
833 .append($label);
834 return $form_group;
835 },
836
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000837 handle_filter_change: function() {
838 // Update the filter and save it to a cookie
839 current_filter = $('#filter_string').val();
840 set_cookie('zuul_filter_string', current_filter);
841 if (current_filter === '') {
842 $('#filter_form_clear_box').hide();
Joshua Heskethace48892014-03-22 17:18:31 +1100843 }
844 else {
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000845 $('#filter_form_clear_box').show();
Joshua Heskethace48892014-03-22 17:18:31 +1100846 }
Joshua Heskethace48892014-03-22 17:18:31 +1100847
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000848 $('.zuul-change-box').each(function(index, obj) {
849 var $change_box = $(obj);
850 format.display_patchset($change_box, 200);
Joshua Hesketh5caf4f62014-04-01 12:52:43 +1100851 });
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000852 return false;
Timo Tijhof51516cd2013-04-09 01:32:29 +0200853 },
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000854
855 handle_expand_by_default: function(e) {
856 // Handle toggling expand by default
857 set_cookie('zuul_expand_by_default', e.target.checked);
858 collapsed_exceptions = [];
859 $('.zuul-change-box').each(function(index, obj) {
860 var $change_box = $(obj);
861 format.display_patchset($change_box, 200);
862 });
863 },
864
865 create_tree: function(pipeline) {
866 var count = 0;
867 var pipeline_max_tree_columns = 1;
868 $.each(pipeline.change_queues, function(change_queue_i,
869 change_queue) {
870 var tree = [];
871 var max_tree_columns = 1;
872 var changes = [];
873 var last_tree_length = 0;
874 $.each(change_queue.heads, function(head_i, head) {
875 $.each(head, function(change_i, change) {
876 changes[change.id] = change;
877 change._tree_position = change_i;
878 });
879 });
880 $.each(change_queue.heads, function(head_i, head) {
881 $.each(head, function(change_i, change) {
James E. Blaird1d3ce32015-02-11 17:56:45 -0800882 if (change.live === true) {
883 count += 1;
884 }
Joshua Hesketh0f5c66a2014-04-30 19:23:36 +1000885 var idx = tree.indexOf(change.id);
886 if (idx > -1) {
887 change._tree_index = idx;
888 // remove...
889 tree[idx] = null;
890 while (tree[tree.length - 1] === null) {
891 tree.pop();
892 }
893 } else {
894 change._tree_index = 0;
895 }
896 change._tree_branches = [];
897 change._tree = [];
898 if (typeof(change.items_behind) === 'undefined') {
899 change.items_behind = [];
900 }
901 change.items_behind.sort(function(a, b) {
902 return (changes[b]._tree_position -
903 changes[a]._tree_position);
904 });
905 $.each(change.items_behind, function(i, id) {
906 tree.push(id);
907 if (tree.length>last_tree_length &&
908 last_tree_length > 0) {
909 change._tree_branches.push(
910 tree.length - 1);
911 }
912 });
913 if (tree.length > max_tree_columns) {
914 max_tree_columns = tree.length;
915 }
916 if (tree.length > pipeline_max_tree_columns) {
917 pipeline_max_tree_columns = tree.length;
918 }
919 change._tree = tree.slice(0); // make a copy
920 last_tree_length = tree.length;
921 });
922 });
923 change_queue._tree_columns = max_tree_columns;
924 });
925 pipeline._tree_columns = pipeline_max_tree_columns;
926 return count;
927 },
928 };
929
930 $jq = $(app);
931 return {
932 options: options,
933 format: format,
934 app: app,
935 jq: $jq
936 };
Timo Tijhof4be9f742015-04-02 01:13:19 +0100937 };
Timo Tijhof51516cd2013-04-09 01:32:29 +0200938}(jQuery));