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', |
| 56 | 'queue_results_num': '#zuul_queue_results_num', |
| 57 | }, options); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 58 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 59 | var collapsed_exceptions = []; |
Joshua Hesketh | 6f94dd1 | 2014-08-20 16:14:53 +1000 | [diff] [blame] | 60 | var current_filter = read_cookie('zuul_filter_string', ''); |
Jan Hruban | ddeb95a | 2017-01-03 15:12:41 +0100 | [diff] [blame] | 61 | 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 Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 65 | var $jq; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 66 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 67 | var xhr, |
| 68 | zuul_graph_update_count = 0, |
| 69 | zuul_sparkline_urls = {}; |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 70 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 71 | 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 Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 86 | + ".current_changes, '6b8182')" |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 87 | ] |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 88 | }); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 89 | } |
| 90 | return zuul_sparkline_urls[pipeline_name]; |
| 91 | } |
| 92 | return false; |
| 93 | } |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 94 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 95 | var format = { |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 96 | job: function(job) { |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 97 | var $job_line = $('<span />'); |
| 98 | |
Monty Taylor | e78211d | 2017-07-21 09:48:41 +0900 | [diff] [blame] | 99 | 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 Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 108 | $job_line.append( |
| 109 | $('<a />') |
| 110 | .addClass('zuul-job-name') |
| 111 | .attr('href', job.url) |
| 112 | .text(job.name) |
| 113 | ); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 114 | } |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 115 | else { |
| 116 | $job_line.append( |
| 117 | $('<span />') |
| 118 | .addClass('zuul-job-name') |
| 119 | .text(job.name) |
| 120 | ); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 121 | } |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 122 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 123 | $job_line.append(this.job_status(job)); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 124 | |
| 125 | if (job.voting === false) { |
| 126 | $job_line.append( |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 127 | $(' <small />') |
| 128 | .addClass('zuul-non-voting-desc') |
| 129 | .text(' (non-voting)') |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 130 | ); |
| 131 | } |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 132 | |
Joshua Hesketh | a95fd55 | 2014-08-21 11:21:05 +1000 | [diff] [blame] | 133 | $job_line.append($('<div style="clear: both"></div>')); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 134 | 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 Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 143 | if (result === 'in progress') { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 144 | return this.job_progress_bar(job.elapsed_time, |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 145 | job.remaining_time); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 146 | } |
| 147 | else { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 148 | return this.status_label(result); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 149 | } |
| 150 | }, |
| 151 | |
| 152 | status_label: function(result) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 153 | var $status = $('<span />'); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 154 | $status.addClass('zuul-job-result label'); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 155 | |
| 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 Evseev | 3103a84 | 2015-11-17 10:12:45 +0300 | [diff] [blame] | 166 | case 'skipped': |
| 167 | $status.addClass('label-info'); |
| 168 | break; |
Antoine Musso | 4c2053d | 2016-02-04 23:35:23 +0100 | [diff] [blame] | 169 | // 'in progress' 'queued' 'lost' 'aborted' ... |
| 170 | default: |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 171 | $status.addClass('label-default'); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 172 | } |
| 173 | $status.text(result); |
| 174 | return $status; |
| 175 | }, |
| 176 | |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 177 | job_progress_bar: function(elapsed_time, remaining_time) { |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 178 | 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 Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 190 | .addClass('progress zuul-job-result') |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 191 | .append($bar_inner); |
| 192 | |
| 193 | return $bar_outter; |
| 194 | }, |
| 195 | |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 196 | 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 Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 201 | var status = 'text-success'; |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 202 | var text = this.time(delta, true); |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 203 | if (delta > (4 * hours)) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 204 | status = 'text-danger'; |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 205 | } else if (delta > (2 * hours)) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 206 | status = 'text-warning'; |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 207 | } |
| 208 | return '<span class="' + status + '">' + text + '</span>'; |
| 209 | }, |
| 210 | |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 211 | time: function(ms, words) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 212 | if (typeof(words) === 'undefined') { |
| 213 | words = false; |
| 214 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 215 | 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 Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 220 | var r = ''; |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 221 | if (words) { |
| 222 | if (hours) { |
| 223 | r += hours; |
| 224 | r += ' hr '; |
| 225 | } |
| 226 | r += minutes + ' min'; |
| 227 | } else { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 228 | if (hours < 10) { |
| 229 | r += '0'; |
| 230 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 231 | r += hours + ':'; |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 232 | if (minutes < 10) { |
| 233 | r += '0'; |
| 234 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 235 | r += minutes + ':'; |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 236 | if (seconds < 10) { |
| 237 | r += '0'; |
| 238 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 239 | r += seconds; |
| 240 | } |
| 241 | return r; |
| 242 | }, |
| 243 | |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 244 | change_total_progress_bar: function(change) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 245 | var job_percent = Math.floor(100 / change.jobs.length); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 246 | 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 Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 255 | if (result !== 'queued') { |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 256 | 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 Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 282 | change_header: function(change) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 283 | var change_id = change.id || 'NA'; |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 284 | if (change_id.length === 40) { |
| 285 | change_id = change_id.substr(0, 7); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 286 | } |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 287 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 288 | var $change_link = $('<small />'); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 289 | if (change.url !== null) { |
Jamie Lennox | a6b33ba | 2017-02-10 11:33:44 +1100 | [diff] [blame] | 290 | 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 Hesketh | cd7a077 | 2014-08-21 11:32:44 +1000 | [diff] [blame] | 300 | 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 Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 314 | } |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 315 | else { |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 316 | $change_link.text(change_id); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 317 | } |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 318 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 319 | var $change_progress_row_left = $('<div />') |
Timo Tijhof | a62e849 | 2015-04-02 03:05:04 +0100 | [diff] [blame] | 320 | .addClass('col-xs-4') |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 321 | .append($change_link); |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 322 | var $change_progress_row_right = $('<div />') |
Timo Tijhof | a62e849 | 2015-04-02 03:05:04 +0100 | [diff] [blame] | 323 | .addClass('col-xs-8') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 324 | .append(this.change_total_progress_bar(change)); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 325 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 326 | var $change_progress_row = $('<div />') |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 327 | .addClass('row') |
| 328 | .append($change_progress_row_left) |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 329 | .append($change_progress_row_right); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 330 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 331 | var $project_span = $('<span />') |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 332 | .addClass('change_project') |
| 333 | .text(change.project); |
| 334 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 335 | var $left = $('<div />') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 336 | .addClass('col-xs-8') |
Joshua Hesketh | 1751e4f | 2014-04-01 13:24:51 +1100 | [diff] [blame] | 337 | .append($project_span, $change_progress_row); |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 338 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 339 | var remaining_time = this.time( |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 340 | change.remaining_time, true); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 341 | var enqueue_time = this.enqueue_time( |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 342 | change.enqueue_time); |
| 343 | var $remaining_time = $('<small />').addClass('time') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 344 | .attr('title', 'Remaining Time').html(remaining_time); |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 345 | var $enqueue_time = $('<small />').addClass('time') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 346 | .attr('title', 'Elapsed Time').html(enqueue_time); |
| 347 | |
James E. Blair | 6dc954b | 2015-02-11 18:32:19 -0800 | [diff] [blame] | 348 | 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 Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 353 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 354 | var $header = $('<div />') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 355 | .addClass('row') |
| 356 | .append($left, $right); |
| 357 | return $header; |
| 358 | }, |
| 359 | |
| 360 | change_list: function(jobs) { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 361 | var format = this; |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 362 | var $list = $('<ul />') |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 363 | .addClass('list-group zuul-patchset-body'); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 364 | |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 365 | $.each(jobs, function (i, job) { |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 366 | var $item = $('<li />') |
| 367 | .addClass('list-group-item') |
| 368 | .addClass('zuul-change-job') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 369 | .append(format.job(job)); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 370 | $list.append($item); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 371 | }); |
| 372 | |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 373 | return $list; |
| 374 | }, |
| 375 | |
| 376 | change_panel: function (change) { |
| 377 | var $header = $('<div />') |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 378 | .addClass('panel-heading zuul-patchset-header') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 379 | .append(this.change_header(change)); |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 380 | |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 381 | var panel_id = change.id ? change.id.replace(',', '_') |
| 382 | : change.project.replace('/', '_') + |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 383 | '-' + change.enqueue_time; |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 384 | var $panel = $('<div />') |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 385 | .attr('id', panel_id) |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 386 | .addClass('panel panel-default zuul-change') |
| 387 | .append($header) |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 388 | .append(this.change_list(change.jobs)); |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 389 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 390 | $header.click(this.toggle_patchset); |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 391 | return $panel; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 392 | }, |
| 393 | |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 394 | 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. Blair | 107c385 | 2015-02-07 08:23:10 -0800 | [diff] [blame] | 404 | else if (change.live !== true) { |
| 405 | // Grey icon |
| 406 | icon_name = 'grey.png'; |
Joshua Hesketh | 6bc619d | 2015-02-11 09:30:21 +1100 | [diff] [blame] | 407 | icon_title = 'Dependent change required for testing'; |
James E. Blair | 107c385 | 2015-02-07 08:23:10 -0800 | [diff] [blame] | 408 | } |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 409 | 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 Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 452 | this.change_status_icon(change)); |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 453 | } |
| 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 Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 475 | .append(this.change_panel(change)); |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 476 | |
| 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 Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 488 | pipeline_sparkline: function(pipeline_name) { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 489 | if (options.graphite_url !== '') { |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 490 | var $sparkline = $('<img />') |
| 491 | .addClass('pull-right') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 492 | .attr('src', get_sparkline_url(pipeline_name)); |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 493 | 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 Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 506 | .append( |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 507 | $('<span />') |
| 508 | .addClass('badge pull-right') |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 509 | .css('vertical-align', 'middle') |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 510 | .css('margin-top', '0.5em') |
| 511 | .text(count) |
| 512 | ) |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 513 | .append(this.pipeline_sparkline(pipeline.name)); |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 514 | |
| 515 | $header_div.append($heading); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 516 | |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 517 | if (typeof pipeline.description === 'string') { |
Alexander Evseev | 057aed1 | 2015-10-28 17:17:04 +0300 | [diff] [blame] | 518 | 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 Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 522 | $header_div.append( |
Alexander Evseev | 057aed1 | 2015-10-28 17:17:04 +0300 | [diff] [blame] | 523 | $('<p />').append(descr) |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 524 | ); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 525 | } |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 526 | return $header_div; |
| 527 | }, |
| 528 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 529 | pipeline: function (pipeline, count) { |
| 530 | var format = this; |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 531 | var $html = $('<div />') |
| 532 | .addClass('zuul-pipeline col-md-4') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 533 | .append(this.pipeline_header(pipeline, count)); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 534 | |
Joshua Hesketh | cbdcca1 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 535 | $.each(pipeline.change_queues, |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 536 | function (queue_i, change_queue) { |
| 537 | $.each(change_queue.heads, function (head_i, changes) { |
Joshua Hesketh | cbdcca1 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 538 | if (pipeline.change_queues.length > 1 && |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 539 | head_i === 0) { |
| 540 | var name = change_queue.name; |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 541 | var short_name = name; |
| 542 | if (short_name.length > 32) { |
| 543 | short_name = short_name.substr(0, 32) + '...'; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 544 | } |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 545 | $html.append( |
| 546 | $('<p />') |
| 547 | .text('Queue: ') |
| 548 | .append( |
| 549 | $('<abbr />') |
| 550 | .attr('title', name) |
| 551 | .text(short_name) |
| 552 | ) |
| 553 | ); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 554 | } |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 555 | |
| 556 | $.each(changes, function (change_i, change) { |
Monty Taylor | d9f1f82 | 2017-08-30 10:16:29 -0500 | [diff] [blame] | 557 | // 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 Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 565 | }); |
| 566 | }); |
| 567 | }); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 568 | return $html; |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 569 | }, |
| 570 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 571 | 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 Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 653 | app = app || this; |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 654 | 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 Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 679 | var $msg = $(options.msg_id); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 680 | 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 Tijhof | 67f4ac1 | 2015-04-10 00:33:50 +0100 | [diff] [blame] | 719 | .fail(function (jqXHR, statusText, errMsg) { |
| 720 | if (statusText === 'abort') { |
| 721 | return; |
| 722 | } |
Joshua Hesketh | d50eb58 | 2014-04-30 19:51:22 +1000 | [diff] [blame] | 723 | $msg.text(options.source + ': ' + errMsg) |
| 724 | .addClass('alert-danger') |
| 725 | .removeClass('zuul-msg-wrap-off') |
| 726 | .show(); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 727 | }) |
| 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 Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 741 | $(newimg).load(function () { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 742 | 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 Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 775 | filter_form_group: function() { |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 776 | // 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 Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 791 | .attr('value', current_filter); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 792 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 793 | $input.change(this.handle_filter_change); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 794 | |
| 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 Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 806 | if (current_filter === '') { |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 807 | $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 Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 816 | expand_form_group: function() { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 817 | var expand_by_default = ( |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 818 | read_cookie('zuul_expand_by_default', false) === 'true'); |
| 819 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 820 | var $checkbox = $('<input />') |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 821 | .attr('type', 'checkbox') |
| 822 | .attr('id', 'expand_by_default') |
| 823 | .prop('checked', expand_by_default) |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 824 | .change(this.handle_expand_by_default); |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 825 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 826 | var $label = $('<label />') |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 827 | .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 Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 837 | 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 Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 843 | } |
| 844 | else { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 845 | $('#filter_form_clear_box').show(); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 846 | } |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 847 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 848 | $('.zuul-change-box').each(function(index, obj) { |
| 849 | var $change_box = $(obj); |
| 850 | format.display_patchset($change_box, 200); |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 851 | }); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 852 | return false; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 853 | }, |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 854 | |
| 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. Blair | d1d3ce3 | 2015-02-11 17:56:45 -0800 | [diff] [blame] | 882 | if (change.live === true) { |
| 883 | count += 1; |
| 884 | } |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 885 | 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 Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 937 | }; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 938 | }(jQuery)); |