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