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