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 | // |
| 3 | // Copyright 2012 OpenStack Foundation |
| 4 | // Copyright 2013 Timo Tijhof |
| 5 | // Copyright 2013 Wikimedia Foundation |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 6 | // Copyright 2014 Rackspace Australia |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 7 | // |
| 8 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 9 | // not use this file except in compliance with the License. You may obtain |
| 10 | // a copy of the License at |
| 11 | // |
| 12 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | // |
| 14 | // Unless required by applicable law or agreed to in writing, software |
| 15 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 16 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 17 | // License for the specific language governing permissions and limitations |
| 18 | // under the License. |
| 19 | |
| 20 | (function ($) { |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 21 | 'use strict'; |
| 22 | |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 23 | function set_cookie(name, value) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 24 | document.cookie = name + '=' + value + '; path=/'; |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | function read_cookie(name, default_value) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 28 | var nameEQ = name + '='; |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 29 | var ca = document.cookie.split(';'); |
| 30 | for(var i=0;i < ca.length;i++) { |
| 31 | var c = ca[i]; |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 32 | while (c.charAt(0) === ' ') { |
| 33 | c = c.substring(1, c.length); |
| 34 | } |
| 35 | if (c.indexOf(nameEQ) === 0) { |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 36 | return c.substring(nameEQ.length, c.length); |
| 37 | } |
| 38 | } |
| 39 | return default_value; |
| 40 | } |
| 41 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 42 | $.zuul = function(options) { |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 43 | options = $.extend({ |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 44 | 'enabled': true, |
| 45 | 'graphite_url': '', |
| 46 | 'source': 'status.json', |
| 47 | 'msg_id': '#zuul_msg', |
| 48 | 'pipelines_id': '#zuul_pipelines', |
| 49 | 'queue_events_num': '#zuul_queue_events_num', |
| 50 | 'queue_results_num': '#zuul_queue_results_num', |
| 51 | }, options); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 52 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 53 | var collapsed_exceptions = []; |
Joshua Hesketh | 6f94dd1 | 2014-08-20 16:14:53 +1000 | [diff] [blame] | 54 | var current_filter = read_cookie('zuul_filter_string', ''); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 55 | var $jq; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 56 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 57 | var xhr, |
| 58 | zuul_graph_update_count = 0, |
| 59 | zuul_sparkline_urls = {}; |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 60 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 61 | function get_sparkline_url(pipeline_name) { |
| 62 | if (options.graphite_url !== '') { |
| 63 | if (!(pipeline_name in zuul_sparkline_urls)) { |
| 64 | zuul_sparkline_urls[pipeline_name] = $.fn.graphite |
| 65 | .geturl({ |
| 66 | url: options.graphite_url, |
| 67 | from: "-8hours", |
| 68 | width: 100, |
| 69 | height: 26, |
| 70 | margin: 0, |
| 71 | hideLegend: true, |
| 72 | hideAxes: true, |
| 73 | hideGrid: true, |
| 74 | target: [ |
| 75 | "color(stats.gauges.zuul.pipeline." + pipeline_name |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 76 | + ".current_changes, '6b8182')" |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 77 | ] |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 78 | }); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 79 | } |
| 80 | return zuul_sparkline_urls[pipeline_name]; |
| 81 | } |
| 82 | return false; |
| 83 | } |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 84 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 85 | var format = { |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 86 | job: function(job) { |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 87 | var $job_line = $('<span />'); |
| 88 | |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 89 | if (job.url !== null) { |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 90 | $job_line.append( |
| 91 | $('<a />') |
| 92 | .addClass('zuul-job-name') |
| 93 | .attr('href', job.url) |
| 94 | .text(job.name) |
| 95 | ); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 96 | } |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 97 | else { |
| 98 | $job_line.append( |
| 99 | $('<span />') |
| 100 | .addClass('zuul-job-name') |
| 101 | .text(job.name) |
| 102 | ); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 103 | } |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 104 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 105 | $job_line.append(this.job_status(job)); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 106 | |
| 107 | if (job.voting === false) { |
| 108 | $job_line.append( |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 109 | $(' <small />') |
| 110 | .addClass('zuul-non-voting-desc') |
| 111 | .text(' (non-voting)') |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 112 | ); |
| 113 | } |
Joshua Hesketh | 9e6ce53 | 2014-04-01 13:11:53 +1100 | [diff] [blame] | 114 | |
Joshua Hesketh | a95fd55 | 2014-08-21 11:21:05 +1000 | [diff] [blame] | 115 | $job_line.append($('<div style="clear: both"></div>')); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 116 | return $job_line; |
| 117 | }, |
| 118 | |
| 119 | job_status: function(job) { |
| 120 | var result = job.result ? job.result.toLowerCase() : null; |
| 121 | if (result === null) { |
| 122 | result = job.url ? 'in progress' : 'queued'; |
| 123 | } |
| 124 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 125 | if (result === 'in progress') { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 126 | return this.job_progress_bar(job.elapsed_time, |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 127 | job.remaining_time); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 128 | } |
| 129 | else { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 130 | return this.status_label(result); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 131 | } |
| 132 | }, |
| 133 | |
| 134 | status_label: function(result) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 135 | var $status = $('<span />'); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 136 | $status.addClass('zuul-job-result label'); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 137 | |
| 138 | switch (result) { |
| 139 | case 'success': |
| 140 | $status.addClass('label-success'); |
| 141 | break; |
| 142 | case 'failure': |
| 143 | $status.addClass('label-danger'); |
| 144 | break; |
| 145 | case 'unstable': |
| 146 | $status.addClass('label-warning'); |
| 147 | break; |
Alexander Evseev | 3103a84 | 2015-11-17 10:12:45 +0300 | [diff] [blame] | 148 | case 'skipped': |
| 149 | $status.addClass('label-info'); |
| 150 | break; |
Antoine Musso | 4c2053d | 2016-02-04 23:35:23 +0100 | [diff] [blame] | 151 | // 'in progress' 'queued' 'lost' 'aborted' ... |
| 152 | default: |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 153 | $status.addClass('label-default'); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 154 | } |
| 155 | $status.text(result); |
| 156 | return $status; |
| 157 | }, |
| 158 | |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 159 | job_progress_bar: function(elapsed_time, remaining_time) { |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 160 | var progress_percent = 100 * (elapsed_time / (elapsed_time + |
| 161 | remaining_time)); |
| 162 | var $bar_inner = $('<div />') |
| 163 | .addClass('progress-bar') |
| 164 | .attr('role', 'progressbar') |
| 165 | .attr('aria-valuenow', 'progressbar') |
| 166 | .attr('aria-valuemin', progress_percent) |
| 167 | .attr('aria-valuemin', '0') |
| 168 | .attr('aria-valuemax', '100') |
| 169 | .css('width', progress_percent + '%'); |
| 170 | |
| 171 | var $bar_outter = $('<div />') |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 172 | .addClass('progress zuul-job-result') |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 173 | .append($bar_inner); |
| 174 | |
| 175 | return $bar_outter; |
| 176 | }, |
| 177 | |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 178 | enqueue_time: function(ms) { |
| 179 | // Special format case for enqueue time to add style |
| 180 | var hours = 60 * 60 * 1000; |
| 181 | var now = Date.now(); |
| 182 | var delta = now - ms; |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 183 | var status = 'text-success'; |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 184 | var text = this.time(delta, true); |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 185 | if (delta > (4 * hours)) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 186 | status = 'text-danger'; |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 187 | } else if (delta > (2 * hours)) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 188 | status = 'text-warning'; |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 189 | } |
| 190 | return '<span class="' + status + '">' + text + '</span>'; |
| 191 | }, |
| 192 | |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 193 | time: function(ms, words) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 194 | if (typeof(words) === 'undefined') { |
| 195 | words = false; |
| 196 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 197 | var seconds = (+ms)/1000; |
| 198 | var minutes = Math.floor(seconds/60); |
| 199 | var hours = Math.floor(minutes/60); |
| 200 | seconds = Math.floor(seconds % 60); |
| 201 | minutes = Math.floor(minutes % 60); |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 202 | var r = ''; |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 203 | if (words) { |
| 204 | if (hours) { |
| 205 | r += hours; |
| 206 | r += ' hr '; |
| 207 | } |
| 208 | r += minutes + ' min'; |
| 209 | } else { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 210 | if (hours < 10) { |
| 211 | r += '0'; |
| 212 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 213 | r += hours + ':'; |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 214 | if (minutes < 10) { |
| 215 | r += '0'; |
| 216 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 217 | r += minutes + ':'; |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 218 | if (seconds < 10) { |
| 219 | r += '0'; |
| 220 | } |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 221 | r += seconds; |
| 222 | } |
| 223 | return r; |
| 224 | }, |
| 225 | |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 226 | change_total_progress_bar: function(change) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 227 | var job_percent = Math.floor(100 / change.jobs.length); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 228 | var $bar_outter = $('<div />') |
| 229 | .addClass('progress zuul-change-total-result'); |
| 230 | |
| 231 | $.each(change.jobs, function (i, job) { |
| 232 | var result = job.result ? job.result.toLowerCase() : null; |
| 233 | if (result === null) { |
| 234 | result = job.url ? 'in progress' : 'queued'; |
| 235 | } |
| 236 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 237 | if (result !== 'queued') { |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 238 | var $bar_inner = $('<div />') |
| 239 | .addClass('progress-bar'); |
| 240 | |
| 241 | switch (result) { |
| 242 | case 'success': |
| 243 | $bar_inner.addClass('progress-bar-success'); |
| 244 | break; |
| 245 | case 'lost': |
| 246 | case 'failure': |
| 247 | $bar_inner.addClass('progress-bar-danger'); |
| 248 | break; |
| 249 | case 'unstable': |
| 250 | $bar_inner.addClass('progress-bar-warning'); |
| 251 | break; |
| 252 | case 'in progress': |
| 253 | case 'queued': |
| 254 | break; |
| 255 | } |
| 256 | $bar_inner.attr('title', job.name) |
| 257 | .css('width', job_percent + '%'); |
| 258 | $bar_outter.append($bar_inner); |
| 259 | } |
| 260 | }); |
| 261 | return $bar_outter; |
| 262 | }, |
| 263 | |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 264 | change_header: function(change) { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 265 | var change_id = change.id || 'NA'; |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 266 | if (change_id.length === 40) { |
| 267 | change_id = change_id.substr(0, 7); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 268 | } |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 269 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 270 | var $change_link = $('<small />'); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 271 | if (change.url !== null) { |
Joshua Hesketh | cd7a077 | 2014-08-21 11:32:44 +1000 | [diff] [blame] | 272 | if (/^[0-9a-f]{40}$/.test(change.id)) { |
| 273 | var change_id_short = change.id.slice(0, 7); |
| 274 | $change_link.append( |
| 275 | $('<a />').attr('href', change.url).append( |
| 276 | $('<abbr />') |
| 277 | .attr('title', change.id) |
| 278 | .text(change_id_short) |
| 279 | ) |
| 280 | ); |
| 281 | } |
| 282 | else { |
| 283 | $change_link.append( |
| 284 | $('<a />').attr('href', change.url).text(change.id) |
| 285 | ); |
| 286 | } |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 287 | } |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 288 | else { |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 289 | $change_link.text(change_id); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 290 | } |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 291 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 292 | var $change_progress_row_left = $('<div />') |
Timo Tijhof | a62e849 | 2015-04-02 03:05:04 +0100 | [diff] [blame] | 293 | .addClass('col-xs-4') |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 294 | .append($change_link); |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 295 | var $change_progress_row_right = $('<div />') |
Timo Tijhof | a62e849 | 2015-04-02 03:05:04 +0100 | [diff] [blame] | 296 | .addClass('col-xs-8') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 297 | .append(this.change_total_progress_bar(change)); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 298 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 299 | var $change_progress_row = $('<div />') |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 300 | .addClass('row') |
| 301 | .append($change_progress_row_left) |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 302 | .append($change_progress_row_right); |
Joshua Hesketh | f1b06ca | 2014-03-21 17:01:12 +1100 | [diff] [blame] | 303 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 304 | var $project_span = $('<span />') |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 305 | .addClass('change_project') |
| 306 | .text(change.project); |
| 307 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 308 | var $left = $('<div />') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 309 | .addClass('col-xs-8') |
Joshua Hesketh | 1751e4f | 2014-04-01 13:24:51 +1100 | [diff] [blame] | 310 | .append($project_span, $change_progress_row); |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 311 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 312 | var remaining_time = this.time( |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 313 | change.remaining_time, true); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 314 | var enqueue_time = this.enqueue_time( |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 315 | change.enqueue_time); |
| 316 | var $remaining_time = $('<small />').addClass('time') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 317 | .attr('title', 'Remaining Time').html(remaining_time); |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 318 | var $enqueue_time = $('<small />').addClass('time') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 319 | .attr('title', 'Elapsed Time').html(enqueue_time); |
| 320 | |
James E. Blair | 6dc954b | 2015-02-11 18:32:19 -0800 | [diff] [blame] | 321 | var $right = $('<div />'); |
| 322 | if (change.live === true) { |
| 323 | $right.addClass('col-xs-4 text-right') |
| 324 | .append($remaining_time, $('<br />'), $enqueue_time); |
| 325 | } |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 326 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 327 | var $header = $('<div />') |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 328 | .addClass('row') |
| 329 | .append($left, $right); |
| 330 | return $header; |
| 331 | }, |
| 332 | |
| 333 | change_list: function(jobs) { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 334 | var format = this; |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 335 | var $list = $('<ul />') |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 336 | .addClass('list-group zuul-patchset-body'); |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 337 | |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 338 | $.each(jobs, function (i, job) { |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 339 | var $item = $('<li />') |
| 340 | .addClass('list-group-item') |
| 341 | .addClass('zuul-change-job') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 342 | .append(format.job(job)); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 343 | $list.append($item); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 344 | }); |
| 345 | |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 346 | return $list; |
| 347 | }, |
| 348 | |
| 349 | change_panel: function (change) { |
| 350 | var $header = $('<div />') |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 351 | .addClass('panel-heading zuul-patchset-header') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 352 | .append(this.change_header(change)); |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 353 | |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 354 | var panel_id = change.id ? change.id.replace(',', '_') |
| 355 | : change.project.replace('/', '_') + |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 356 | '-' + change.enqueue_time; |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 357 | var $panel = $('<div />') |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 358 | .attr('id', panel_id) |
Joshua Hesketh | 0ca1e2e | 2014-03-21 16:49:05 +1100 | [diff] [blame] | 359 | .addClass('panel panel-default zuul-change') |
| 360 | .append($header) |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 361 | .append(this.change_list(change.jobs)); |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 362 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 363 | $header.click(this.toggle_patchset); |
Joshua Hesketh | db8046e | 2014-03-21 18:42:25 +1100 | [diff] [blame] | 364 | return $panel; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 365 | }, |
| 366 | |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 367 | change_status_icon: function(change) { |
| 368 | var icon_name = 'green.png'; |
| 369 | var icon_title = 'Succeeding'; |
| 370 | |
| 371 | if (change.active !== true) { |
| 372 | // Grey icon |
| 373 | icon_name = 'grey.png'; |
| 374 | icon_title = 'Waiting until closer to head of queue to' + |
| 375 | ' start jobs'; |
| 376 | } |
James E. Blair | 107c385 | 2015-02-07 08:23:10 -0800 | [diff] [blame] | 377 | else if (change.live !== true) { |
| 378 | // Grey icon |
| 379 | icon_name = 'grey.png'; |
Joshua Hesketh | 6bc619d | 2015-02-11 09:30:21 +1100 | [diff] [blame] | 380 | icon_title = 'Dependent change required for testing'; |
James E. Blair | 107c385 | 2015-02-07 08:23:10 -0800 | [diff] [blame] | 381 | } |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 382 | else if (change.failing_reasons && |
| 383 | change.failing_reasons.length > 0) { |
| 384 | var reason = change.failing_reasons.join(', '); |
| 385 | icon_title = 'Failing because ' + reason; |
| 386 | if (reason.match(/merge conflict/)) { |
| 387 | // Black icon |
| 388 | icon_name = 'black.png'; |
| 389 | } |
| 390 | else { |
| 391 | // Red icon |
| 392 | icon_name = 'red.png'; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | var $icon = $('<img />') |
| 397 | .attr('src', 'images/' + icon_name) |
| 398 | .attr('title', icon_title) |
| 399 | .css('margin-top', '-6px'); |
| 400 | |
| 401 | return $icon; |
| 402 | }, |
| 403 | |
| 404 | change_with_status_tree: function(change, change_queue) { |
| 405 | var $change_row = $('<tr />'); |
| 406 | |
| 407 | for (var i = 0; i < change_queue._tree_columns; i++) { |
| 408 | var $tree_cell = $('<td />') |
| 409 | .css('height', '100%') |
| 410 | .css('padding', '0 0 10px 0') |
| 411 | .css('margin', '0') |
| 412 | .css('width', '16px') |
| 413 | .css('min-width', '16px') |
| 414 | .css('overflow', 'hidden') |
| 415 | .css('vertical-align', 'top'); |
| 416 | |
| 417 | if (i < change._tree.length && change._tree[i] !== null) { |
| 418 | $tree_cell.css('background-image', |
| 419 | 'url(\'images/line.png\')') |
| 420 | .css('background-repeat', 'repeat-y'); |
| 421 | } |
| 422 | |
| 423 | if (i === change._tree_index) { |
| 424 | $tree_cell.append( |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 425 | this.change_status_icon(change)); |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 426 | } |
| 427 | if (change._tree_branches.indexOf(i) !== -1) { |
| 428 | var $image = $('<img />') |
| 429 | .css('vertical-align', 'baseline'); |
| 430 | if (change._tree_branches.indexOf(i) === |
| 431 | change._tree_branches.length - 1) { |
| 432 | // Angle line |
| 433 | $image.attr('src', 'images/line-angle.png'); |
| 434 | } |
| 435 | else { |
| 436 | // T line |
| 437 | $image.attr('src', 'images/line-t.png'); |
| 438 | } |
| 439 | $tree_cell.append($image); |
| 440 | } |
| 441 | $change_row.append($tree_cell); |
| 442 | } |
| 443 | |
| 444 | var change_width = 360 - 16*change_queue._tree_columns; |
| 445 | var $change_column = $('<td />') |
| 446 | .css('width', change_width + 'px') |
| 447 | .addClass('zuul-change-cell') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 448 | .append(this.change_panel(change)); |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 449 | |
| 450 | $change_row.append($change_column); |
| 451 | |
| 452 | var $change_table = $('<table />') |
| 453 | .addClass('zuul-change-box') |
| 454 | .css('-moz-box-sizing', 'content-box') |
| 455 | .css('box-sizing', 'content-box') |
| 456 | .append($change_row); |
| 457 | |
| 458 | return $change_table; |
| 459 | }, |
| 460 | |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 461 | pipeline_sparkline: function(pipeline_name) { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 462 | if (options.graphite_url !== '') { |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 463 | var $sparkline = $('<img />') |
| 464 | .addClass('pull-right') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 465 | .attr('src', get_sparkline_url(pipeline_name)); |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 466 | return $sparkline; |
| 467 | } |
| 468 | return false; |
| 469 | }, |
| 470 | |
| 471 | pipeline_header: function(pipeline, count) { |
| 472 | // Format the pipeline name, sparkline and description |
| 473 | var $header_div = $('<div />') |
| 474 | .addClass('zuul-pipeline-header'); |
| 475 | |
| 476 | var $heading = $('<h3 />') |
| 477 | .css('vertical-align', 'middle') |
| 478 | .text(pipeline.name) |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 479 | .append( |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 480 | $('<span />') |
| 481 | .addClass('badge pull-right') |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 482 | .css('vertical-align', 'middle') |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 483 | .css('margin-top', '0.5em') |
| 484 | .text(count) |
| 485 | ) |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 486 | .append(this.pipeline_sparkline(pipeline.name)); |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 487 | |
| 488 | $header_div.append($heading); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 489 | |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 490 | if (typeof pipeline.description === 'string') { |
Alexander Evseev | 057aed1 | 2015-10-28 17:17:04 +0300 | [diff] [blame] | 491 | var descr = $('<small />') |
| 492 | $.each( pipeline.description.split(/\r?\n\r?\n/), function(index, descr_part){ |
| 493 | descr.append($('<p />').text(descr_part)); |
| 494 | }); |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 495 | $header_div.append( |
Alexander Evseev | 057aed1 | 2015-10-28 17:17:04 +0300 | [diff] [blame] | 496 | $('<p />').append(descr) |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 497 | ); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 498 | } |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 499 | return $header_div; |
| 500 | }, |
| 501 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 502 | pipeline: function (pipeline, count) { |
| 503 | var format = this; |
Joshua Hesketh | 9d01354 | 2014-04-03 13:08:04 +1100 | [diff] [blame] | 504 | var $html = $('<div />') |
| 505 | .addClass('zuul-pipeline col-md-4') |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 506 | .append(this.pipeline_header(pipeline, count)); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 507 | |
Joshua Hesketh | cbdcca1 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 508 | $.each(pipeline.change_queues, |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 509 | function (queue_i, change_queue) { |
| 510 | $.each(change_queue.heads, function (head_i, changes) { |
Joshua Hesketh | cbdcca1 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 511 | if (pipeline.change_queues.length > 1 && |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 512 | head_i === 0) { |
| 513 | var name = change_queue.name; |
Joshua Hesketh | 6b1a218 | 2014-03-21 14:40:04 +1100 | [diff] [blame] | 514 | var short_name = name; |
| 515 | if (short_name.length > 32) { |
| 516 | short_name = short_name.substr(0, 32) + '...'; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 517 | } |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 518 | $html.append( |
| 519 | $('<p />') |
| 520 | .text('Queue: ') |
| 521 | .append( |
| 522 | $('<abbr />') |
| 523 | .attr('title', name) |
| 524 | .text(short_name) |
| 525 | ) |
| 526 | ); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 527 | } |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 528 | |
| 529 | $.each(changes, function (change_i, change) { |
| 530 | var $change_box = |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 531 | format.change_with_status_tree( |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 532 | change, change_queue); |
| 533 | $html.append($change_box); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 534 | format.display_patchset($change_box); |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 535 | }); |
| 536 | }); |
| 537 | }); |
Joshua Hesketh | 298c491 | 2014-03-20 16:06:25 +1100 | [diff] [blame] | 538 | return $html; |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 539 | }, |
| 540 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 541 | toggle_patchset: function(e) { |
| 542 | // Toggle showing/hiding the patchset when the header is |
| 543 | // clicked. |
| 544 | |
Timo Tijhof | 7fadbbf | 2017-09-19 19:46:09 +0100 | [diff] [blame] | 545 | if (e.target.nodeName.toLowerCase() === 'a') { |
| 546 | // Ignore clicks from gerrit patch set link |
| 547 | return; |
| 548 | } |
| 549 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 550 | // Grab the patchset panel |
| 551 | var $panel = $(e.target).parents('.zuul-change'); |
| 552 | var $body = $panel.children('.zuul-patchset-body'); |
| 553 | $body.toggle(200); |
| 554 | var collapsed_index = collapsed_exceptions.indexOf( |
| 555 | $panel.attr('id')); |
| 556 | if (collapsed_index === -1 ) { |
| 557 | // Currently not an exception, add it to list |
| 558 | collapsed_exceptions.push($panel.attr('id')); |
| 559 | } |
| 560 | else { |
| 561 | // Currently an except, remove from exceptions |
| 562 | collapsed_exceptions.splice(collapsed_index, 1); |
| 563 | } |
| 564 | }, |
| 565 | |
| 566 | display_patchset: function($change_box, animate) { |
| 567 | // Determine if to show or hide the patchset and/or the results |
| 568 | // when loaded |
| 569 | |
| 570 | // See if we should hide the body/results |
| 571 | var $panel = $change_box.find('.zuul-change'); |
| 572 | var panel_change = $panel.attr('id'); |
| 573 | var $body = $panel.children('.zuul-patchset-body'); |
| 574 | var expand_by_default = $('#expand_by_default') |
| 575 | .prop('checked'); |
| 576 | |
| 577 | var collapsed_index = collapsed_exceptions |
| 578 | .indexOf(panel_change); |
| 579 | |
| 580 | if (expand_by_default && collapsed_index === -1 || |
| 581 | !expand_by_default && collapsed_index !== -1) { |
| 582 | // Expand by default, or is an exception |
| 583 | $body.show(animate); |
| 584 | } |
| 585 | else { |
| 586 | $body.hide(animate); |
| 587 | } |
| 588 | |
| 589 | // Check if we should hide the whole panel |
| 590 | var panel_project = $panel.find('.change_project').text() |
| 591 | .toLowerCase(); |
| 592 | |
| 593 | |
| 594 | var panel_pipeline = $change_box |
| 595 | .parents('.zuul-pipeline') |
| 596 | .find('.zuul-pipeline-header > h3') |
| 597 | .html() |
| 598 | .toLowerCase(); |
| 599 | |
| 600 | if (current_filter !== '') { |
| 601 | var show_panel = false; |
| 602 | var filter = current_filter.trim().split(/[\s,]+/); |
| 603 | $.each(filter, function(index, f_val) { |
| 604 | if (f_val !== '') { |
| 605 | f_val = f_val.toLowerCase(); |
| 606 | if (panel_project.indexOf(f_val) !== -1 || |
| 607 | panel_pipeline.indexOf(f_val) !== -1 || |
| 608 | panel_change.indexOf(f_val) !== -1) { |
| 609 | show_panel = true; |
| 610 | } |
| 611 | } |
| 612 | }); |
| 613 | if (show_panel === true) { |
| 614 | $change_box.show(animate); |
| 615 | } |
| 616 | else { |
| 617 | $change_box.hide(animate); |
| 618 | } |
| 619 | } |
| 620 | else { |
| 621 | $change_box.show(animate); |
| 622 | } |
| 623 | }, |
| 624 | }; |
| 625 | |
| 626 | var app = { |
| 627 | schedule: function (app) { |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 628 | app = app || this; |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 629 | if (!options.enabled) { |
| 630 | setTimeout(function() {app.schedule(app);}, 5000); |
| 631 | return; |
| 632 | } |
Timo Tijhof | 3dbedbf | 2017-08-24 12:55:00 -0600 | [diff] [blame] | 633 | app.update().always(function () { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 634 | setTimeout(function() {app.schedule(app);}, 5000); |
| 635 | }); |
| 636 | |
| 637 | /* Only update graphs every minute */ |
| 638 | if (zuul_graph_update_count > 11) { |
| 639 | zuul_graph_update_count = 0; |
| 640 | zuul.update_sparklines(); |
| 641 | } |
| 642 | }, |
| 643 | |
| 644 | /** @return {jQuery.Promise} */ |
| 645 | update: function () { |
| 646 | // Cancel the previous update if it hasn't completed yet. |
| 647 | if (xhr) { |
| 648 | xhr.abort(); |
| 649 | } |
| 650 | |
| 651 | this.emit('update-start'); |
| 652 | var app = this; |
| 653 | |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 654 | var $msg = $(options.msg_id); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 655 | xhr = $.getJSON(options.source) |
| 656 | .done(function (data) { |
| 657 | if ('message' in data) { |
| 658 | $msg.removeClass('alert-danger') |
| 659 | .addClass('alert-info') |
| 660 | .text(data.message) |
| 661 | .show(); |
| 662 | } else { |
| 663 | $msg.empty() |
| 664 | .hide(); |
| 665 | } |
| 666 | |
| 667 | if ('zuul_version' in data) { |
| 668 | $('#zuul-version-span').text(data.zuul_version); |
| 669 | } |
| 670 | if ('last_reconfigured' in data) { |
| 671 | var last_reconfigured = |
| 672 | new Date(data.last_reconfigured); |
| 673 | $('#last-reconfigured-span').text( |
| 674 | last_reconfigured.toString()); |
| 675 | } |
| 676 | |
| 677 | var $pipelines = $(options.pipelines_id); |
| 678 | $pipelines.html(''); |
| 679 | $.each(data.pipelines, function (i, pipeline) { |
| 680 | var count = app.create_tree(pipeline); |
| 681 | $pipelines.append( |
| 682 | format.pipeline(pipeline, count)); |
| 683 | }); |
| 684 | |
| 685 | $(options.queue_events_num).text( |
| 686 | data.trigger_event_queue ? |
| 687 | data.trigger_event_queue.length : '0' |
| 688 | ); |
| 689 | $(options.queue_results_num).text( |
| 690 | data.result_event_queue ? |
| 691 | data.result_event_queue.length : '0' |
| 692 | ); |
| 693 | }) |
Timo Tijhof | 67f4ac1 | 2015-04-10 00:33:50 +0100 | [diff] [blame] | 694 | .fail(function (jqXHR, statusText, errMsg) { |
| 695 | if (statusText === 'abort') { |
| 696 | return; |
| 697 | } |
Joshua Hesketh | d50eb58 | 2014-04-30 19:51:22 +1000 | [diff] [blame] | 698 | $msg.text(options.source + ': ' + errMsg) |
| 699 | .addClass('alert-danger') |
| 700 | .removeClass('zuul-msg-wrap-off') |
| 701 | .show(); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 702 | }) |
Timo Tijhof | 3dbedbf | 2017-08-24 12:55:00 -0600 | [diff] [blame] | 703 | .always(function () { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 704 | xhr = undefined; |
| 705 | app.emit('update-end'); |
| 706 | }); |
| 707 | |
| 708 | return xhr; |
| 709 | }, |
| 710 | |
| 711 | update_sparklines: function() { |
| 712 | $.each(zuul_sparkline_urls, function(name, url) { |
| 713 | var newimg = new Image(); |
| 714 | var parts = url.split('#'); |
| 715 | newimg.src = parts[0] + '#' + new Date().getTime(); |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 716 | $(newimg).load(function () { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 717 | zuul_sparkline_urls[name] = newimg.src; |
| 718 | }); |
| 719 | }); |
| 720 | }, |
| 721 | |
| 722 | emit: function () { |
| 723 | $jq.trigger.apply($jq, arguments); |
| 724 | return this; |
| 725 | }, |
| 726 | on: function () { |
| 727 | $jq.on.apply($jq, arguments); |
| 728 | return this; |
| 729 | }, |
| 730 | one: function () { |
| 731 | $jq.one.apply($jq, arguments); |
| 732 | return this; |
| 733 | }, |
| 734 | |
| 735 | control_form: function() { |
| 736 | // Build the filter form filling anything from cookies |
| 737 | |
| 738 | var $control_form = $('<form />') |
| 739 | .attr('role', 'form') |
| 740 | .addClass('form-inline') |
| 741 | .submit(this.handle_filter_change); |
| 742 | |
| 743 | $control_form |
| 744 | .append(this.filter_form_group()) |
| 745 | .append(this.expand_form_group()); |
| 746 | |
| 747 | return $control_form; |
| 748 | }, |
| 749 | |
Joshua Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 750 | filter_form_group: function() { |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 751 | // Update the filter form with a clear button if required |
| 752 | |
| 753 | var $label = $('<label />') |
| 754 | .addClass('control-label') |
| 755 | .attr('for', 'filter_string') |
| 756 | .text('Filters') |
| 757 | .css('padding-right', '0.5em'); |
| 758 | |
| 759 | var $input = $('<input />') |
| 760 | .attr('type', 'text') |
| 761 | .attr('id', 'filter_string') |
| 762 | .addClass('form-control') |
| 763 | .attr('title', |
| 764 | 'project(s), pipeline(s) or review(s) comma ' + |
| 765 | 'separated') |
Joshua Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 766 | .attr('value', current_filter); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 767 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 768 | $input.change(this.handle_filter_change); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 769 | |
| 770 | var $clear_icon = $('<span />') |
| 771 | .addClass('form-control-feedback') |
| 772 | .addClass('glyphicon glyphicon-remove-circle') |
| 773 | .attr('id', 'filter_form_clear_box') |
| 774 | .attr('title', 'clear filter') |
| 775 | .css('cursor', 'pointer'); |
| 776 | |
| 777 | $clear_icon.click(function() { |
| 778 | $('#filter_string').val('').change(); |
| 779 | }); |
| 780 | |
Joshua Hesketh | 1ed6f9d | 2014-03-31 22:53:06 +1100 | [diff] [blame] | 781 | if (current_filter === '') { |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 782 | $clear_icon.hide(); |
| 783 | } |
| 784 | |
| 785 | var $form_group = $('<div />') |
| 786 | .addClass('form-group has-feedback') |
| 787 | .append($label, $input, $clear_icon); |
| 788 | return $form_group; |
| 789 | }, |
| 790 | |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 791 | expand_form_group: function() { |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 792 | var expand_by_default = ( |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 793 | read_cookie('zuul_expand_by_default', false) === 'true'); |
| 794 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 795 | var $checkbox = $('<input />') |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 796 | .attr('type', 'checkbox') |
| 797 | .attr('id', 'expand_by_default') |
| 798 | .prop('checked', expand_by_default) |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 799 | .change(this.handle_expand_by_default); |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 800 | |
Monty Taylor | 860bb0a | 2014-03-22 09:41:25 -0700 | [diff] [blame] | 801 | var $label = $('<label />') |
Joshua Hesketh | ae230f6 | 2014-03-22 22:14:44 +1100 | [diff] [blame] | 802 | .css('padding-left', '1em') |
| 803 | .html('Expand by default: ') |
| 804 | .append($checkbox); |
| 805 | |
| 806 | var $form_group = $('<div />') |
| 807 | .addClass('checkbox') |
| 808 | .append($label); |
| 809 | return $form_group; |
| 810 | }, |
| 811 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 812 | handle_filter_change: function() { |
| 813 | // Update the filter and save it to a cookie |
| 814 | current_filter = $('#filter_string').val(); |
| 815 | set_cookie('zuul_filter_string', current_filter); |
| 816 | if (current_filter === '') { |
| 817 | $('#filter_form_clear_box').hide(); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 818 | } |
| 819 | else { |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 820 | $('#filter_form_clear_box').show(); |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 821 | } |
Joshua Hesketh | ace4889 | 2014-03-22 17:18:31 +1100 | [diff] [blame] | 822 | |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 823 | $('.zuul-change-box').each(function(index, obj) { |
| 824 | var $change_box = $(obj); |
| 825 | format.display_patchset($change_box, 200); |
Joshua Hesketh | 5caf4f6 | 2014-04-01 12:52:43 +1100 | [diff] [blame] | 826 | }); |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 827 | return false; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 828 | }, |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 829 | |
| 830 | handle_expand_by_default: function(e) { |
| 831 | // Handle toggling expand by default |
| 832 | set_cookie('zuul_expand_by_default', e.target.checked); |
| 833 | collapsed_exceptions = []; |
| 834 | $('.zuul-change-box').each(function(index, obj) { |
| 835 | var $change_box = $(obj); |
| 836 | format.display_patchset($change_box, 200); |
| 837 | }); |
| 838 | }, |
| 839 | |
| 840 | create_tree: function(pipeline) { |
| 841 | var count = 0; |
| 842 | var pipeline_max_tree_columns = 1; |
| 843 | $.each(pipeline.change_queues, function(change_queue_i, |
| 844 | change_queue) { |
| 845 | var tree = []; |
| 846 | var max_tree_columns = 1; |
| 847 | var changes = []; |
| 848 | var last_tree_length = 0; |
| 849 | $.each(change_queue.heads, function(head_i, head) { |
| 850 | $.each(head, function(change_i, change) { |
| 851 | changes[change.id] = change; |
| 852 | change._tree_position = change_i; |
| 853 | }); |
| 854 | }); |
| 855 | $.each(change_queue.heads, function(head_i, head) { |
| 856 | $.each(head, function(change_i, change) { |
James E. Blair | d1d3ce3 | 2015-02-11 17:56:45 -0800 | [diff] [blame] | 857 | if (change.live === true) { |
| 858 | count += 1; |
| 859 | } |
Joshua Hesketh | 0f5c66a | 2014-04-30 19:23:36 +1000 | [diff] [blame] | 860 | var idx = tree.indexOf(change.id); |
| 861 | if (idx > -1) { |
| 862 | change._tree_index = idx; |
| 863 | // remove... |
| 864 | tree[idx] = null; |
| 865 | while (tree[tree.length - 1] === null) { |
| 866 | tree.pop(); |
| 867 | } |
| 868 | } else { |
| 869 | change._tree_index = 0; |
| 870 | } |
| 871 | change._tree_branches = []; |
| 872 | change._tree = []; |
| 873 | if (typeof(change.items_behind) === 'undefined') { |
| 874 | change.items_behind = []; |
| 875 | } |
| 876 | change.items_behind.sort(function(a, b) { |
| 877 | return (changes[b]._tree_position - |
| 878 | changes[a]._tree_position); |
| 879 | }); |
| 880 | $.each(change.items_behind, function(i, id) { |
| 881 | tree.push(id); |
| 882 | if (tree.length>last_tree_length && |
| 883 | last_tree_length > 0) { |
| 884 | change._tree_branches.push( |
| 885 | tree.length - 1); |
| 886 | } |
| 887 | }); |
| 888 | if (tree.length > max_tree_columns) { |
| 889 | max_tree_columns = tree.length; |
| 890 | } |
| 891 | if (tree.length > pipeline_max_tree_columns) { |
| 892 | pipeline_max_tree_columns = tree.length; |
| 893 | } |
| 894 | change._tree = tree.slice(0); // make a copy |
| 895 | last_tree_length = tree.length; |
| 896 | }); |
| 897 | }); |
| 898 | change_queue._tree_columns = max_tree_columns; |
| 899 | }); |
| 900 | pipeline._tree_columns = pipeline_max_tree_columns; |
| 901 | return count; |
| 902 | }, |
| 903 | }; |
| 904 | |
| 905 | $jq = $(app); |
| 906 | return { |
| 907 | options: options, |
| 908 | format: format, |
| 909 | app: app, |
| 910 | jq: $jq |
| 911 | }; |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 912 | }; |
Timo Tijhof | 51516cd | 2013-04-09 01:32:29 +0200 | [diff] [blame] | 913 | }(jQuery)); |