Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 1 | // Client script for Zuul status page |
| 2 | // |
Tristan Cacqueray | 48ddd9e | 2017-05-21 10:19:02 +0000 | [diff] [blame] | 3 | // @licstart The following is the entire license notice for the |
| 4 | // JavaScript code in this page. |
| 5 | // |
Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 6 | // Copyright 2013 OpenStack Foundation |
| 7 | // Copyright 2013 Timo Tijhof |
| 8 | // Copyright 2013 Wikimedia Foundation |
| 9 | // Copyright 2014 Rackspace Australia |
| 10 | // |
| 11 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 12 | // not use this file except in compliance with the License. You may obtain |
| 13 | // a copy of the License at |
| 14 | // |
| 15 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 16 | // |
| 17 | // Unless required by applicable law or agreed to in writing, software |
| 18 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 19 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 20 | // License for the specific language governing permissions and limitations |
| 21 | // under the License. |
Tristan Cacqueray | 48ddd9e | 2017-05-21 10:19:02 +0000 | [diff] [blame] | 22 | // |
| 23 | // @licend The above is the entire license notice |
| 24 | // for the JavaScript code in this page. |
Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 25 | |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 26 | /*exported zuul_build_dom, zuul_start */ |
| 27 | |
Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 28 | function zuul_build_dom($, container) { |
| 29 | // Build a default-looking DOM |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 30 | var default_layout = '<div class="container">' |
Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 31 | + '<h1>Zuul Status</h1>' |
| 32 | + '<p>Real-time status monitor of Zuul, the pipeline manager between Gerrit and Workers.</p>' |
| 33 | + '<div class="zuul-container" id="zuul-container">' |
| 34 | + '<div style="display: none;" class="alert" id="zuul_msg"></div>' |
| 35 | + '<button class="btn pull-right zuul-spinner">updating <span class="glyphicon glyphicon-refresh"></span></button>' |
Tobias Henkel | 02ec07f | 2017-10-19 07:10:37 +0200 | [diff] [blame] | 36 | + '<p>Queue lengths: <span id="zuul_queue_events_num">0</span> events, <span id="zuul_queue_management_events_num">0</span> management events, <span id="zuul_queue_results_num">0</span> results.</p>' |
Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 37 | + '<div id="zuul_controls"></div>' |
| 38 | + '<div id="zuul_pipelines" class="row"></div>' |
| 39 | + '<p>Zuul version: <span id="zuul-version-span"></span></p>' |
| 40 | + '<p>Last reconfigured: <span id="last-reconfigured-span"></span></p>' |
| 41 | + '</div></div>'; |
| 42 | |
| 43 | $(function ($) { |
| 44 | // DOM ready |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 45 | var $container = $(container); |
Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 46 | $container.html(default_layout); |
| 47 | }); |
| 48 | } |
| 49 | |
Timo Tijhof | 89bb8cf | 2015-04-03 03:41:17 +0100 | [diff] [blame] | 50 | /** |
| 51 | * @return The $.zuul instance |
| 52 | */ |
Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 53 | function zuul_start($) { |
| 54 | // Start the zuul app (expects default dom) |
| 55 | |
| 56 | var $container, $indicator; |
| 57 | var demo = location.search.match(/[?&]demo=([^?&]*)/), |
| 58 | source_url = location.search.match(/[?&]source_url=([^?&]*)/), |
| 59 | source = demo ? './status-' + (demo[1] || 'basic') + '.json-sample' : |
| 60 | 'status.json'; |
| 61 | source = source_url ? source_url[1] : source; |
| 62 | |
| 63 | var zuul = $.zuul({ |
| 64 | source: source, |
| 65 | //graphite_url: 'http://graphite.openstack.org/render/' |
| 66 | }); |
| 67 | |
| 68 | zuul.jq.on('update-start', function () { |
| 69 | $container.addClass('zuul-container-loading'); |
| 70 | $indicator.addClass('zuul-spinner-on'); |
| 71 | }); |
| 72 | |
| 73 | zuul.jq.on('update-end', function () { |
| 74 | $container.removeClass('zuul-container-loading'); |
| 75 | setTimeout(function () { |
| 76 | $indicator.removeClass('zuul-spinner-on'); |
| 77 | }, 500); |
| 78 | }); |
| 79 | |
| 80 | zuul.jq.one('update-end', function () { |
| 81 | // Do this asynchronous so that if the first update adds a |
| 82 | // message, it will not animate while we fade in the content. |
| 83 | // Instead it simply appears with the rest of the content. |
| 84 | setTimeout(function () { |
| 85 | // Fade in the content |
| 86 | $container.addClass('zuul-container-ready'); |
| 87 | }); |
| 88 | }); |
| 89 | |
| 90 | $(function ($) { |
| 91 | // DOM ready |
| 92 | $container = $('#zuul-container'); |
| 93 | $indicator = $('#zuul-spinner'); |
| 94 | $('#zuul_controls').append(zuul.app.control_form()); |
| 95 | |
| 96 | zuul.app.schedule(); |
| 97 | |
| 98 | $(document).on({ |
| 99 | 'show.visibility': function () { |
| 100 | zuul.options.enabled = true; |
| 101 | zuul.app.update(); |
| 102 | }, |
| 103 | 'hide.visibility': function () { |
| 104 | zuul.options.enabled = false; |
| 105 | } |
| 106 | }); |
| 107 | }); |
Timo Tijhof | 89bb8cf | 2015-04-03 03:41:17 +0100 | [diff] [blame] | 108 | |
| 109 | return zuul; |
| 110 | } |