Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 1 | // jquery plugin for Zuul status page |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 2 | // |
Tristan Cacqueray | 48ddd9e | 2017-05-21 10:19:02 +0000 | [diff] [blame] | 3 | // @licstart The following is the entire license notice for the |
| 4 | // JavaScript code in this page. |
| 5 | // |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 6 | // Copyright 2012 OpenStack Foundation |
| 7 | // Copyright 2013 Timo Tijhof |
| 8 | // Copyright 2013 Wikimedia Foundation |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 9 | // Copyright 2014 Rackspace Australia |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 10 | // |
| 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 Cacqueray | 48ddd9e | 2017-05-21 10:19:02 +0000 | [diff] [blame] | 22 | // |
| 23 | // @licend The above is the entire license notice |
| 24 | // for the JavaScript code in this page. |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 25 | |
| 26 | (function ($) { |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 27 | 'use strict'; |
| 28 | |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 29 | function set_cookie(name, value) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 30 | document.cookie = name + '=' + value + '; path=/'; |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | function read_cookie(name, default_value) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 34 | var nameEQ = name + '='; |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 35 | var ca = document.cookie.split(';'); |
| 36 | for(var i=0;i < ca.length;i++) { |
| 37 | var c = ca[i]; |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 38 | while (c.charAt(0) === ' ') { |
| 39 | c = c.substring(1, c.length); |
| 40 | } |
| 41 | if (c.indexOf(nameEQ) === 0) { |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 42 | return c.substring(nameEQ.length, c.length); |
| 43 | } |
| 44 | } |
| 45 | return default_value; |
| 46 | } |
| 47 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 48 | $.zuul = function(options) { |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 49 | options = $.extend({ |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 50 | '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', |
Tobias Henkel | 02ec07f | 2017-10-19 07:10:37 +0200 | [diff] [blame] | 56 | 'queue_management_events_num': '#zuul_queue_management_events_num', |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 57 | 'queue_results_num': '#zuul_queue_results_num', |
| 58 | }, options); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 59 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 60 | var collapsed_exceptions = []; |
Joshua Hesketh | 6f94dd1 | 2014-08-20 16:14:53 +1000 | [diff] [blame] | 61 | var current_filter = read_cookie('zuul_filter_string', ''); |
Jan Hruban | ddeb95a | 2017-01-03 15:12:41 +0100 | [diff] [blame] | 62 | 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 Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 66 | var $jq; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 67 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 68 | var xhr, |
| 69 | zuul_graph_update_count = 0, |
| 70 | zuul_sparkline_urls = {}; |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 71 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 72 | 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 Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 87 | + ".current_changes, '6b8182')" |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 88 | ] |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 89 | }); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 90 | } |
| 91 | return zuul_sparkline_urls[pipeline_name]; |
| 92 | } |
| 93 | return false; |
| 94 | } |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 95 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 96 | var format = { |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 97 | job: function(job) { |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 98 | var $job_line = $('<span />'); |
| 99 | |
Monty Taylor | e78211d | 2017-07-21 09:48:41 +0900 | [diff] [blame] | 100 | 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 Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 109 | $job_line.append( |
| 110 | $('<a />') |
| 111 | .addClass('zuul-job-name') |
| 112 | .attr('href', job.url) |
| 113 | .text(job.name) |
| 114 | ); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 115 | } |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 116 | else { |
| 117 | $job_line.append( |
| 118 | $('<span />') |
| 119 | .addClass('zuul-job-name') |
| 120 | .text(job.name) |
| 121 | ); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 122 | } |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 123 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 124 | $job_line.append(this.job_status(job)); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 125 | |
| 126 | if (job.voting === false) { |
| 127 | $job_line.append( |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 128 | $(' <small />') |
| 129 | .addClass('zuul-non-voting-desc') |
| 130 | .text(' (non-voting)') |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 131 | ); |
| 132 | } |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 133 | |
Joshua Hesketh | a95fd55 | 2014-08-21 11:21:05 +1000 | [diff] [blame] | 134 | $job_line.append($('<div style="clear: both"></div>')); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 135 | 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 Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 144 | if (result === 'in progress') { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 145 | return this.job_progress_bar(job.elapsed_time, |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 146 | job.remaining_time); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 147 | } |
| 148 | else { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 149 | return this.status_label(result); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 150 | } |
| 151 | }, |
| 152 | |
| 153 | status_label: function(result) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 154 | var $status = $('<span />'); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 155 | $status.addClass('zuul-job-result label'); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 156 | |
| 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 Evseev | 3103a84 | 2015-11-17 10:12:45 +0300 | [diff] [blame] | 167 | case 'skipped': |
| 168 | $status.addClass('label-info'); |
| 169 | break; |
Antoine Musso | 4c2053d | 2016-02-04 23:35:23 +0100 | [diff] [blame] | 170 | // 'in progress' 'queued' 'lost' 'aborted' ... |
| 171 | default: |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 172 | $status.addClass('label-default'); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 173 | } |
| 174 | $status.text(result); |
| 175 | return $status; |
| 176 | }, |
| 177 | |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 178 | job_progress_bar: function(elapsed_time, remaining_time) { |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 179 | 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 Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 191 | .addClass('progress zuul-job-result') |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 192 | .append($bar_inner); |
| 193 | |
| 194 | return $bar_outter; |
| 195 | }, |
| 196 | |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 197 | 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 Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 202 | var status = 'text-success'; |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 203 | var text = this.time(delta, true); |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 204 | if (delta > (4 * hours)) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 205 | status = 'text-danger'; |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 206 | } else if (delta > (2 * hours)) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 207 | status = 'text-warning'; |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 208 | } |
| 209 | return '<span class="' + status + '">' + text + '</span>'; |
| 210 | }, |
| 211 | |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 212 | time: function(ms, words) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 213 | if (typeof(words) === 'undefined') { |
| 214 | words = false; |
| 215 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 216 | 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 Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 221 | var r = ''; |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 222 | if (words) { |
| 223 | if (hours) { |
| 224 | r += hours; |
| 225 | r += ' hr '; |
| 226 | } |
| 227 | r += minutes + ' min'; |
| 228 | } else { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 229 | if (hours < 10) { |
| 230 | r += '0'; |
| 231 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 232 | r += hours + ':'; |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 233 | if (minutes < 10) { |
| 234 | r += '0'; |
| 235 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 236 | r += minutes + ':'; |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 237 | if (seconds < 10) { |
| 238 | r += '0'; |
| 239 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 240 | r += seconds; |
| 241 | } |
| 242 | return r; |
| 243 | }, |
| 244 | |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 245 | change_total_progress_bar: function(change) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 246 | var job_percent = Math.floor(100 / change.jobs.length); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 247 | 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 Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 256 | if (result !== 'queued') { |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 257 | 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 Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 283 | change_header: function(change) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 284 | var change_id = change.id || 'NA'; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 285 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 286 | var $change_link = $('<small />'); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 287 | if (change.url !== null) { |
Jens Harbott | 898a8bf | 2017-10-04 13:12:04 +0000 | [diff] [blame] | 288 | var github_id = change_id.match(/^([0-9]+),([0-9a-f]{40})$/); |
Jamie Lennox | a6b33ba | 2017-02-10 11:33:44 +1100 | [diff] [blame] | 289 | if (github_id) { |
| 290 | $change_link.append( |
| 291 | $('<a />').attr('href', change.url).append( |
| 292 | $('<abbr />') |
Jens Harbott | 898a8bf | 2017-10-04 13:12:04 +0000 | [diff] [blame] | 293 | .attr('title', change_id) |
Jamie Lennox | a6b33ba | 2017-02-10 11:33:44 +1100 | [diff] [blame] | 294 | .text('#' + github_id[1]) |
| 295 | ) |
| 296 | ); |
Jens Harbott | 898a8bf | 2017-10-04 13:12:04 +0000 | [diff] [blame] | 297 | } else if (/^[0-9a-f]{40}$/.test(change_id)) { |
| 298 | var change_id_short = change_id.slice(0, 7); |
Joshua Hesketh | cd7a077 | 2014-08-21 11:32:44 +1000 | [diff] [blame] | 299 | $change_link.append( |
| 300 | $('<a />').attr('href', change.url).append( |
| 301 | $('<abbr />') |
Jens Harbott | 898a8bf | 2017-10-04 13:12:04 +0000 | [diff] [blame] | 302 | .attr('title', change_id) |
Joshua Hesketh | cd7a077 | 2014-08-21 11:32:44 +1000 | [diff] [blame] | 303 | .text(change_id_short) |
| 304 | ) |
| 305 | ); |
| 306 | } |
| 307 | else { |
| 308 | $change_link.append( |
Jens Harbott | 898a8bf | 2017-10-04 13:12:04 +0000 | [diff] [blame] | 309 | $('<a />').attr('href', change.url).text(change_id) |
Joshua Hesketh | cd7a077 | 2014-08-21 11:32:44 +1000 | [diff] [blame] | 310 | ); |
| 311 | } |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 312 | } |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 313 | else { |
Jens Harbott | 898a8bf | 2017-10-04 13:12:04 +0000 | [diff] [blame] | 314 | if (change_id.length === 40) { |
| 315 | change_id = change_id.substr(0, 7); |
| 316 | } |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 317 | $change_link.text(change_id); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 318 | } |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 319 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 320 | var $change_progress_row_left = $('<div />') |
Timo Tijhof | a62e849 | 2015-04-02 03:05:04 +0100 | [diff] [blame] | 321 | .addClass('col-xs-4') |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 322 | .append($change_link); |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 323 | var $change_progress_row_right = $('<div />') |
Timo Tijhof | a62e849 | 2015-04-02 03:05:04 +0100 | [diff] [blame] | 324 | .addClass('col-xs-8') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 325 | .append(this.change_total_progress_bar(change)); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 326 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 327 | var $change_progress_row = $('<div />') |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 328 | .addClass('row') |
| 329 | .append($change_progress_row_left) |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 330 | .append($change_progress_row_right); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 331 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 332 | var $project_span = $('<span />') |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 333 | .addClass('change_project') |
| 334 | .text(change.project); |
| 335 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 336 | var $left = $('<div />') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 337 | .addClass('col-xs-8') |
Joshua Hesketh | 1751e4f | 2014-04-01 13:24:51 +1100 | [diff] [blame] | 338 | .append($project_span, $change_progress_row); |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 339 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 340 | var remaining_time = this.time( |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 341 | change.remaining_time, true); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 342 | var enqueue_time = this.enqueue_time( |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 343 | change.enqueue_time); |
| 344 | var $remaining_time = $('<small />').addClass('time') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 345 | .attr('title', 'Remaining Time').html(remaining_time); |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 346 | var $enqueue_time = $('<small />').addClass('time') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 347 | .attr('title', 'Elapsed Time').html(enqueue_time); |
| 348 | |
James E. Blair | 6dc954b | 2015-02-11 18:32:19 -0800 | [diff] [blame] | 349 | 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 Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 354 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 355 | var $header = $('<div />') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 356 | .addClass('row') |
| 357 | .append($left, $right); |
| 358 | return $header; |
| 359 | }, |
| 360 | |
| 361 | change_list: function(jobs) { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 362 | var format = this; |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 363 | var $list = $('<ul />') |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 364 | .addClass('list-group zuul-patchset-body'); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 365 | |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 366 | $.each(jobs, function (i, job) { |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 367 | var $item = $('<li />') |
| 368 | .addClass('list-group-item') |
| 369 | .addClass('zuul-change-job') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 370 | .append(format.job(job)); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 371 | $list.append($item); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 372 | }); |
| 373 | |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 374 | return $list; |
| 375 | }, |
| 376 | |
| 377 | change_panel: function (change) { |
| 378 | var $header = $('<div />') |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 379 | .addClass('panel-heading zuul-patchset-header') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 380 | .append(this.change_header(change)); |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 381 | |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 382 | var panel_id = change.id ? change.id.replace(',', '_') |
| 383 | : change.project.replace('/', '_') + |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 384 | '-' + change.enqueue_time; |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 385 | var $panel = $('<div />') |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 386 | .attr('id', panel_id) |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 387 | .addClass('panel panel-default zuul-change') |
| 388 | .append($header) |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 389 | .append(this.change_list(change.jobs)); |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 390 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 391 | $header.click(this.toggle_patchset); |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 392 | return $panel; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 393 | }, |
| 394 | |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 395 | 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. Blair | 107c385 | 2015-02-07 08:23:10 -0800 | [diff] [blame] | 405 | else if (change.live !== true) { |
| 406 | // Grey icon |
| 407 | icon_name = 'grey.png'; |
Joshua Hesketh | 6bc619d | 2015-02-11 09:30:21 +1100 | [diff] [blame] | 408 | icon_title = 'Dependent change required for testing'; |
James E. Blair | 107c385 | 2015-02-07 08:23:10 -0800 | [diff] [blame] | 409 | } |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 410 | 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 Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 453 | this.change_status_icon(change)); |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 454 | } |
| 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 Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 476 | .append(this.change_panel(change)); |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 477 | |
| 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 Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 489 | pipeline_sparkline: function(pipeline_name) { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 490 | if (options.graphite_url !== '') { |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 491 | var $sparkline = $('<img />') |
| 492 | .addClass('pull-right') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 493 | .attr('src', get_sparkline_url(pipeline_name)); |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 494 | 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 Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 507 | .append( |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 508 | $('<span />') |
| 509 | .addClass('badge pull-right') |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 510 | .css('vertical-align', 'middle') |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 511 | .css('margin-top', '0.5em') |
| 512 | .text(count) |
| 513 | ) |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 514 | .append(this.pipeline_sparkline(pipeline.name)); |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 515 | |
| 516 | $header_div.append($heading); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 517 | |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 518 | if (typeof pipeline.description === 'string') { |
Alexander Evseev | 057aed1 | 2015-10-28 17:17:04 +0300 | [diff] [blame] | 519 | 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 Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 523 | $header_div.append( |
Alexander Evseev | 057aed1 | 2015-10-28 17:17:04 +0300 | [diff] [blame] | 524 | $('<p />').append(descr) |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 525 | ); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 526 | } |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 527 | return $header_div; |
| 528 | }, |
| 529 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 530 | pipeline: function (pipeline, count) { |
| 531 | var format = this; |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 532 | var $html = $('<div />') |
| 533 | .addClass('zuul-pipeline col-md-4') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 534 | .append(this.pipeline_header(pipeline, count)); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 535 | |
Joshua Hesketh | cbdcca1 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 536 | $.each(pipeline.change_queues, |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 537 | function (queue_i, change_queue) { |
| 538 | $.each(change_queue.heads, function (head_i, changes) { |
Joshua Hesketh | cbdcca1 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 539 | if (pipeline.change_queues.length > 1 && |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 540 | head_i === 0) { |
| 541 | var name = change_queue.name; |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 542 | var short_name = name; |
| 543 | if (short_name.length > 32) { |
| 544 | short_name = short_name.substr(0, 32) + '...'; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 545 | } |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 546 | $html.append( |
| 547 | $('<p />') |
| 548 | .text('Queue: ') |
| 549 | .append( |
| 550 | $('<abbr />') |
| 551 | .attr('title', name) |
| 552 | .text(short_name) |
| 553 | ) |
| 554 | ); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 555 | } |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 556 | |
| 557 | $.each(changes, function (change_i, change) { |
James E. Blair | 13c5ffc | 2017-09-05 07:59:13 -0700 | [diff] [blame] | 558 | 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 Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 563 | }); |
| 564 | }); |
| 565 | }); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 566 | return $html; |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 567 | }, |
| 568 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 569 | toggle_patchset: function(e) { |
| 570 | // Toggle showing/hiding the patchset when the header is |
| 571 | // clicked. |
| 572 | |
Timo Tijhof | 0445c27 | 2017-09-19 19:46:09 +0100 | [diff] [blame] | 573 | if (e.target.nodeName.toLowerCase() === 'a') { |
| 574 | // Ignore clicks from gerrit patch set link |
| 575 | return; |
| 576 | } |
| 577 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 578 | // 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 Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 656 | app = app || this; |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 657 | if (!options.enabled) { |
| 658 | setTimeout(function() {app.schedule(app);}, 5000); |
| 659 | return; |
| 660 | } |
Timo Tijhof | 9a2362d | 2017-08-24 12:55:00 -0600 | [diff] [blame] | 661 | app.update().always(function () { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 662 | 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 Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 682 | var $msg = $(options.msg_id); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 683 | 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 Henkel | 02ec07f | 2017-10-19 07:10:37 +0200 | [diff] [blame] | 717 | $(options.queue_management_events_num).text( |
| 718 | data.management_event_queue ? |
| 719 | data.management_event_queue.length : '0' |
| 720 | ); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 721 | $(options.queue_results_num).text( |
| 722 | data.result_event_queue ? |
| 723 | data.result_event_queue.length : '0' |
| 724 | ); |
| 725 | }) |
Timo Tijhof | 67f4ac1 | 2015-04-10 00:33:50 +0100 | [diff] [blame] | 726 | .fail(function (jqXHR, statusText, errMsg) { |
| 727 | if (statusText === 'abort') { |
| 728 | return; |
| 729 | } |
Joshua Hesketh | d50eb58 | 2014-04-30 19:51:22 +1000 | [diff] [blame] | 730 | $msg.text(options.source + ': ' + errMsg) |
| 731 | .addClass('alert-danger') |
| 732 | .removeClass('zuul-msg-wrap-off') |
| 733 | .show(); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 734 | }) |
Timo Tijhof | 9a2362d | 2017-08-24 12:55:00 -0600 | [diff] [blame] | 735 | .always(function () { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 736 | 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 Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 748 | $(newimg).load(function () { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 749 | 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 Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 782 | filter_form_group: function() { |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 783 | // 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 Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 798 | .attr('value', current_filter); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 799 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 800 | $input.change(this.handle_filter_change); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 801 | |
| 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 Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 813 | if (current_filter === '') { |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 814 | $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 Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 823 | expand_form_group: function() { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 824 | var expand_by_default = ( |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 825 | read_cookie('zuul_expand_by_default', false) === 'true'); |
| 826 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 827 | var $checkbox = $('<input />') |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 828 | .attr('type', 'checkbox') |
| 829 | .attr('id', 'expand_by_default') |
| 830 | .prop('checked', expand_by_default) |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 831 | .change(this.handle_expand_by_default); |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 832 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 833 | var $label = $('<label />') |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 834 | .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 Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 844 | 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 Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 850 | } |
| 851 | else { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 852 | $('#filter_form_clear_box').show(); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 853 | } |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 854 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 855 | $('.zuul-change-box').each(function(index, obj) { |
| 856 | var $change_box = $(obj); |
| 857 | format.display_patchset($change_box, 200); |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 858 | }); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 859 | return false; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 860 | }, |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 861 | |
| 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. Blair | d1d3ce3 | 2015-02-11 17:56:45 -0800 | [diff] [blame] | 889 | if (change.live === true) { |
| 890 | count += 1; |
| 891 | } |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 892 | 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 Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 944 | }; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 945 | }(jQuery)); |