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) { |
| 557 | var $change_box = |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 558 | format.change_with_status_tree( |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 559 | change, change_queue); |
| 560 | $html.append($change_box); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 561 | format.display_patchset($change_box); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 562 | }); |
| 563 | }); |
| 564 | }); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 565 | return $html; |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 566 | }, |
| 567 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 568 | toggle_patchset: function(e) { |
| 569 | // Toggle showing/hiding the patchset when the header is |
| 570 | // clicked. |
| 571 | |
| 572 | // Grab the patchset panel |
| 573 | var $panel = $(e.target).parents('.zuul-change'); |
| 574 | var $body = $panel.children('.zuul-patchset-body'); |
| 575 | $body.toggle(200); |
| 576 | var collapsed_index = collapsed_exceptions.indexOf( |
| 577 | $panel.attr('id')); |
| 578 | if (collapsed_index === -1 ) { |
| 579 | // Currently not an exception, add it to list |
| 580 | collapsed_exceptions.push($panel.attr('id')); |
| 581 | } |
| 582 | else { |
| 583 | // Currently an except, remove from exceptions |
| 584 | collapsed_exceptions.splice(collapsed_index, 1); |
| 585 | } |
| 586 | }, |
| 587 | |
| 588 | display_patchset: function($change_box, animate) { |
| 589 | // Determine if to show or hide the patchset and/or the results |
| 590 | // when loaded |
| 591 | |
| 592 | // See if we should hide the body/results |
| 593 | var $panel = $change_box.find('.zuul-change'); |
| 594 | var panel_change = $panel.attr('id'); |
| 595 | var $body = $panel.children('.zuul-patchset-body'); |
| 596 | var expand_by_default = $('#expand_by_default') |
| 597 | .prop('checked'); |
| 598 | |
| 599 | var collapsed_index = collapsed_exceptions |
| 600 | .indexOf(panel_change); |
| 601 | |
| 602 | if (expand_by_default && collapsed_index === -1 || |
| 603 | !expand_by_default && collapsed_index !== -1) { |
| 604 | // Expand by default, or is an exception |
| 605 | $body.show(animate); |
| 606 | } |
| 607 | else { |
| 608 | $body.hide(animate); |
| 609 | } |
| 610 | |
| 611 | // Check if we should hide the whole panel |
| 612 | var panel_project = $panel.find('.change_project').text() |
| 613 | .toLowerCase(); |
| 614 | |
| 615 | |
| 616 | var panel_pipeline = $change_box |
| 617 | .parents('.zuul-pipeline') |
| 618 | .find('.zuul-pipeline-header > h3') |
| 619 | .html() |
| 620 | .toLowerCase(); |
| 621 | |
| 622 | if (current_filter !== '') { |
| 623 | var show_panel = false; |
| 624 | var filter = current_filter.trim().split(/[\s,]+/); |
| 625 | $.each(filter, function(index, f_val) { |
| 626 | if (f_val !== '') { |
| 627 | f_val = f_val.toLowerCase(); |
| 628 | if (panel_project.indexOf(f_val) !== -1 || |
| 629 | panel_pipeline.indexOf(f_val) !== -1 || |
| 630 | panel_change.indexOf(f_val) !== -1) { |
| 631 | show_panel = true; |
| 632 | } |
| 633 | } |
| 634 | }); |
| 635 | if (show_panel === true) { |
| 636 | $change_box.show(animate); |
| 637 | } |
| 638 | else { |
| 639 | $change_box.hide(animate); |
| 640 | } |
| 641 | } |
| 642 | else { |
| 643 | $change_box.show(animate); |
| 644 | } |
| 645 | }, |
| 646 | }; |
| 647 | |
| 648 | var app = { |
| 649 | schedule: function (app) { |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 650 | app = app || this; |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 651 | if (!options.enabled) { |
| 652 | setTimeout(function() {app.schedule(app);}, 5000); |
| 653 | return; |
| 654 | } |
| 655 | app.update().complete(function () { |
| 656 | setTimeout(function() {app.schedule(app);}, 5000); |
| 657 | }); |
| 658 | |
| 659 | /* Only update graphs every minute */ |
| 660 | if (zuul_graph_update_count > 11) { |
| 661 | zuul_graph_update_count = 0; |
| 662 | zuul.update_sparklines(); |
| 663 | } |
| 664 | }, |
| 665 | |
| 666 | /** @return {jQuery.Promise} */ |
| 667 | update: function () { |
| 668 | // Cancel the previous update if it hasn't completed yet. |
| 669 | if (xhr) { |
| 670 | xhr.abort(); |
| 671 | } |
| 672 | |
| 673 | this.emit('update-start'); |
| 674 | var app = this; |
| 675 | |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 676 | var $msg = $(options.msg_id); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 677 | xhr = $.getJSON(options.source) |
| 678 | .done(function (data) { |
| 679 | if ('message' in data) { |
| 680 | $msg.removeClass('alert-danger') |
| 681 | .addClass('alert-info') |
| 682 | .text(data.message) |
| 683 | .show(); |
| 684 | } else { |
| 685 | $msg.empty() |
| 686 | .hide(); |
| 687 | } |
| 688 | |
| 689 | if ('zuul_version' in data) { |
| 690 | $('#zuul-version-span').text(data.zuul_version); |
| 691 | } |
| 692 | if ('last_reconfigured' in data) { |
| 693 | var last_reconfigured = |
| 694 | new Date(data.last_reconfigured); |
| 695 | $('#last-reconfigured-span').text( |
| 696 | last_reconfigured.toString()); |
| 697 | } |
| 698 | |
| 699 | var $pipelines = $(options.pipelines_id); |
| 700 | $pipelines.html(''); |
| 701 | $.each(data.pipelines, function (i, pipeline) { |
| 702 | var count = app.create_tree(pipeline); |
| 703 | $pipelines.append( |
| 704 | format.pipeline(pipeline, count)); |
| 705 | }); |
| 706 | |
| 707 | $(options.queue_events_num).text( |
| 708 | data.trigger_event_queue ? |
| 709 | data.trigger_event_queue.length : '0' |
| 710 | ); |
| 711 | $(options.queue_results_num).text( |
| 712 | data.result_event_queue ? |
| 713 | data.result_event_queue.length : '0' |
| 714 | ); |
| 715 | }) |
Timo Tijhof | 67f4ac1 | 2015-04-10 00:33:50 +0100 | [diff] [blame] | 716 | .fail(function (jqXHR, statusText, errMsg) { |
| 717 | if (statusText === 'abort') { |
| 718 | return; |
| 719 | } |
Joshua Hesketh | d50eb58 | 2014-04-30 19:51:22 +1000 | [diff] [blame] | 720 | $msg.text(options.source + ': ' + errMsg) |
| 721 | .addClass('alert-danger') |
| 722 | .removeClass('zuul-msg-wrap-off') |
| 723 | .show(); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 724 | }) |
| 725 | .complete(function () { |
| 726 | xhr = undefined; |
| 727 | app.emit('update-end'); |
| 728 | }); |
| 729 | |
| 730 | return xhr; |
| 731 | }, |
| 732 | |
| 733 | update_sparklines: function() { |
| 734 | $.each(zuul_sparkline_urls, function(name, url) { |
| 735 | var newimg = new Image(); |
| 736 | var parts = url.split('#'); |
| 737 | newimg.src = parts[0] + '#' + new Date().getTime(); |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 738 | $(newimg).load(function () { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 739 | zuul_sparkline_urls[name] = newimg.src; |
| 740 | }); |
| 741 | }); |
| 742 | }, |
| 743 | |
| 744 | emit: function () { |
| 745 | $jq.trigger.apply($jq, arguments); |
| 746 | return this; |
| 747 | }, |
| 748 | on: function () { |
| 749 | $jq.on.apply($jq, arguments); |
| 750 | return this; |
| 751 | }, |
| 752 | one: function () { |
| 753 | $jq.one.apply($jq, arguments); |
| 754 | return this; |
| 755 | }, |
| 756 | |
| 757 | control_form: function() { |
| 758 | // Build the filter form filling anything from cookies |
| 759 | |
| 760 | var $control_form = $('<form />') |
| 761 | .attr('role', 'form') |
| 762 | .addClass('form-inline') |
| 763 | .submit(this.handle_filter_change); |
| 764 | |
| 765 | $control_form |
| 766 | .append(this.filter_form_group()) |
| 767 | .append(this.expand_form_group()); |
| 768 | |
| 769 | return $control_form; |
| 770 | }, |
| 771 | |
Joshua Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 772 | filter_form_group: function() { |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 773 | // Update the filter form with a clear button if required |
| 774 | |
| 775 | var $label = $('<label />') |
| 776 | .addClass('control-label') |
| 777 | .attr('for', 'filter_string') |
| 778 | .text('Filters') |
| 779 | .css('padding-right', '0.5em'); |
| 780 | |
| 781 | var $input = $('<input />') |
| 782 | .attr('type', 'text') |
| 783 | .attr('id', 'filter_string') |
| 784 | .addClass('form-control') |
| 785 | .attr('title', |
| 786 | 'project(s), pipeline(s) or review(s) comma ' + |
| 787 | 'separated') |
Joshua Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 788 | .attr('value', current_filter); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 789 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 790 | $input.change(this.handle_filter_change); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 791 | |
| 792 | var $clear_icon = $('<span />') |
| 793 | .addClass('form-control-feedback') |
| 794 | .addClass('glyphicon glyphicon-remove-circle') |
| 795 | .attr('id', 'filter_form_clear_box') |
| 796 | .attr('title', 'clear filter') |
| 797 | .css('cursor', 'pointer'); |
| 798 | |
| 799 | $clear_icon.click(function() { |
| 800 | $('#filter_string').val('').change(); |
| 801 | }); |
| 802 | |
Joshua Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 803 | if (current_filter === '') { |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 804 | $clear_icon.hide(); |
| 805 | } |
| 806 | |
| 807 | var $form_group = $('<div />') |
| 808 | .addClass('form-group has-feedback') |
| 809 | .append($label, $input, $clear_icon); |
| 810 | return $form_group; |
| 811 | }, |
| 812 | |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 813 | expand_form_group: function() { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 814 | var expand_by_default = ( |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 815 | read_cookie('zuul_expand_by_default', false) === 'true'); |
| 816 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 817 | var $checkbox = $('<input />') |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 818 | .attr('type', 'checkbox') |
| 819 | .attr('id', 'expand_by_default') |
| 820 | .prop('checked', expand_by_default) |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 821 | .change(this.handle_expand_by_default); |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 822 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 823 | var $label = $('<label />') |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 824 | .css('padding-left', '1em') |
| 825 | .html('Expand by default: ') |
| 826 | .append($checkbox); |
| 827 | |
| 828 | var $form_group = $('<div />') |
| 829 | .addClass('checkbox') |
| 830 | .append($label); |
| 831 | return $form_group; |
| 832 | }, |
| 833 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 834 | handle_filter_change: function() { |
| 835 | // Update the filter and save it to a cookie |
| 836 | current_filter = $('#filter_string').val(); |
| 837 | set_cookie('zuul_filter_string', current_filter); |
| 838 | if (current_filter === '') { |
| 839 | $('#filter_form_clear_box').hide(); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 840 | } |
| 841 | else { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 842 | $('#filter_form_clear_box').show(); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 843 | } |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 844 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 845 | $('.zuul-change-box').each(function(index, obj) { |
| 846 | var $change_box = $(obj); |
| 847 | format.display_patchset($change_box, 200); |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 848 | }); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 849 | return false; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 850 | }, |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 851 | |
| 852 | handle_expand_by_default: function(e) { |
| 853 | // Handle toggling expand by default |
| 854 | set_cookie('zuul_expand_by_default', e.target.checked); |
| 855 | collapsed_exceptions = []; |
| 856 | $('.zuul-change-box').each(function(index, obj) { |
| 857 | var $change_box = $(obj); |
| 858 | format.display_patchset($change_box, 200); |
| 859 | }); |
| 860 | }, |
| 861 | |
| 862 | create_tree: function(pipeline) { |
| 863 | var count = 0; |
| 864 | var pipeline_max_tree_columns = 1; |
| 865 | $.each(pipeline.change_queues, function(change_queue_i, |
| 866 | change_queue) { |
| 867 | var tree = []; |
| 868 | var max_tree_columns = 1; |
| 869 | var changes = []; |
| 870 | var last_tree_length = 0; |
| 871 | $.each(change_queue.heads, function(head_i, head) { |
| 872 | $.each(head, function(change_i, change) { |
| 873 | changes[change.id] = change; |
| 874 | change._tree_position = change_i; |
| 875 | }); |
| 876 | }); |
| 877 | $.each(change_queue.heads, function(head_i, head) { |
| 878 | $.each(head, function(change_i, change) { |
James E. Blair | d1d3ce3 | 2015-02-11 17:56:45 -0800 | [diff] [blame] | 879 | if (change.live === true) { |
| 880 | count += 1; |
| 881 | } |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 882 | var idx = tree.indexOf(change.id); |
| 883 | if (idx > -1) { |
| 884 | change._tree_index = idx; |
| 885 | // remove... |
| 886 | tree[idx] = null; |
| 887 | while (tree[tree.length - 1] === null) { |
| 888 | tree.pop(); |
| 889 | } |
| 890 | } else { |
| 891 | change._tree_index = 0; |
| 892 | } |
| 893 | change._tree_branches = []; |
| 894 | change._tree = []; |
| 895 | if (typeof(change.items_behind) === 'undefined') { |
| 896 | change.items_behind = []; |
| 897 | } |
| 898 | change.items_behind.sort(function(a, b) { |
| 899 | return (changes[b]._tree_position - |
| 900 | changes[a]._tree_position); |
| 901 | }); |
| 902 | $.each(change.items_behind, function(i, id) { |
| 903 | tree.push(id); |
| 904 | if (tree.length>last_tree_length && |
| 905 | last_tree_length > 0) { |
| 906 | change._tree_branches.push( |
| 907 | tree.length - 1); |
| 908 | } |
| 909 | }); |
| 910 | if (tree.length > max_tree_columns) { |
| 911 | max_tree_columns = tree.length; |
| 912 | } |
| 913 | if (tree.length > pipeline_max_tree_columns) { |
| 914 | pipeline_max_tree_columns = tree.length; |
| 915 | } |
| 916 | change._tree = tree.slice(0); // make a copy |
| 917 | last_tree_length = tree.length; |
| 918 | }); |
| 919 | }); |
| 920 | change_queue._tree_columns = max_tree_columns; |
| 921 | }); |
| 922 | pipeline._tree_columns = pipeline_max_tree_columns; |
| 923 | return count; |
| 924 | }, |
| 925 | }; |
| 926 | |
| 927 | $jq = $(app); |
| 928 | return { |
| 929 | options: options, |
| 930 | format: format, |
| 931 | app: app, |
| 932 | jq: $jq |
| 933 | }; |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 934 | }; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 935 | }(jQuery)); |