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