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