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