// Copyright 2012-2013 OpenStack Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); you may // not use this file except in compliance with the License. You may obtain // a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations // under the License. window.zuul_enable_status_updates = true; window.zuul_filter = []; function format_time(ms, words) { if (ms == null) { return "unknown"; } var seconds = (+ms)/1000; var minutes = Math.floor(seconds/60); var hours = Math.floor(minutes/60); seconds = Math.floor(seconds % 60); minutes = Math.floor(minutes % 60); r = ''; if (words) { if (hours) { r += hours; r += ' hr '; } r += minutes + ' min'; } else { if (hours < 10) r += '0'; r += hours + ':'; if (minutes < 10) r += '0'; r += minutes + ':'; if (seconds < 10) r += '0'; r += seconds; } return r; } function format_progress(elapsed, remaining) { if (remaining != null) { total = elapsed + remaining; } else { total = null; } r = ''; return r; } function is_hide_project(project) { var filters = window.zuul_filter; if (filters.length == 0) { return false; } var hide = true; $.each(filters, function(filter_i, filter) { if(project.indexOf(filter) != -1) hide = false; }); return hide; } function remove(l, idx) { l[idx] = null; while (l[l.length-1] === null) { l.pop(); } } function create_graph(pipeline) { var count = 0; var pipeline_max_graph_columns = 1; $.each(pipeline['change_queues'], function(change_queue_i, change_queue) { var graph = []; var max_graph_columns = 1; var changes = []; var last_graph_length = 0; $.each(change_queue['heads'], function(head_i, head) { $.each(head, function(change_i, change) { changes[change['id']] = change; change['_graph_position'] = change_i; }); }); $.each(change_queue['heads'], function(head_i, head) { $.each(head, function(change_i, change) { count += 1; var idx = graph.indexOf(change['id']); if (idx > -1) { change['_graph_index'] = idx; remove(graph, idx); } else { change['_graph_index'] = 0; } change['_graph_branches'] = []; change['_graph'] = []; change['items_behind'].sort(function(a, b) { return changes[b]['_graph_position'] - changes[a]['_graph_position']; }); $.each(change['items_behind'], function(i, id) { graph.push(id); if (last_graph_length>0 && graph.length>last_graph_length) change['_graph_branches'].push(graph.length-1); }); if (graph.length > max_graph_columns) { max_graph_columns = graph.length; } if (graph.length > pipeline_max_graph_columns) { pipeline_max_graph_columns = graph.length; } change['_graph'] = graph.slice(0); // make a copy last_graph_length = graph.length; }); }); change_queue['_graph_columns'] = max_graph_columns; }); pipeline['_graph_columns'] = pipeline_max_graph_columns; return count; } function get_sparkline_url(pipeline_name) { if (!(pipeline_name in window.zuul_sparkline_urls)) { window.zuul_sparkline_urls[pipeline_name] = $.fn.graphite.geturl({ url: "http://graphite.openstack.org/render/", from: "-8hours", width: 100, height: 16, margin: 0, hideLegend: true, hideAxes: true, hideGrid: true, target: [ "color(stats.gauges.zuul.pipeline."+pipeline_name+".current_changes, '6b8182')", ], }); } return window.zuul_sparkline_urls[pipeline_name]; } function format_pipeline(data) { var count = create_graph(data); var width = (16 * data['_graph_columns']) + 300; var html = '
'+data['description']+'
'; } $.each(data['change_queues'], function(change_queue_i, change_queue) { $.each(change_queue['heads'], function(head_i, head) { var projects = ""; var hide_queue = true; $.each(head, function(change_i, change) { projects += change['project'] + "|"; hide_queue &= is_hide_project(change['project']); }); html += ' ' }); }); html += '