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 | + '<div class="zuul-container" id="zuul-container">' |
| 32 | + '<div style="display: none;" class="alert" id="zuul_msg"></div>' |
| 33 | + '<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] | 34 | + '<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] | 35 | + '<div id="zuul_controls"></div>' |
| 36 | + '<div id="zuul_pipelines" class="row"></div>' |
| 37 | + '<p>Zuul version: <span id="zuul-version-span"></span></p>' |
| 38 | + '<p>Last reconfigured: <span id="last-reconfigured-span"></span></p>' |
| 39 | + '</div></div>'; |
| 40 | |
| 41 | $(function ($) { |
| 42 | // DOM ready |
Timo Tijhof | 4be9f74 | 2015-04-02 01:13:19 +0100 | [diff] [blame] | 43 | var $container = $(container); |
Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 44 | $container.html(default_layout); |
| 45 | }); |
| 46 | } |
| 47 | |
Timo Tijhof | 89bb8cf | 2015-04-03 03:41:17 +0100 | [diff] [blame] | 48 | /** |
| 49 | * @return The $.zuul instance |
| 50 | */ |
Joshua Hesketh | 4db99cb | 2014-05-23 11:28:08 +1000 | [diff] [blame] | 51 | function zuul_start($) { |
| 52 | // Start the zuul app (expects default dom) |
| 53 | |
| 54 | var $container, $indicator; |
| 55 | var demo = location.search.match(/[?&]demo=([^?&]*)/), |
| 56 | source_url = location.search.match(/[?&]source_url=([^?&]*)/), |
| 57 | source = demo ? './status-' + (demo[1] || 'basic') + '.json-sample' : |
| 58 | 'status.json'; |
| 59 | source = source_url ? source_url[1] : source; |
| 60 | |
| 61 | var zuul = $.zuul({ |
| 62 | source: source, |
| 63 | //graphite_url: 'http://graphite.openstack.org/render/' |
| 64 | }); |
| 65 | |
| 66 | zuul.jq.on('update-start', function () { |
| 67 | $container.addClass('zuul-container-loading'); |
| 68 | $indicator.addClass('zuul-spinner-on'); |
| 69 | }); |
| 70 | |
| 71 | zuul.jq.on('update-end', function () { |
| 72 | $container.removeClass('zuul-container-loading'); |
| 73 | setTimeout(function () { |
| 74 | $indicator.removeClass('zuul-spinner-on'); |
| 75 | }, 500); |
| 76 | }); |
| 77 | |
| 78 | zuul.jq.one('update-end', function () { |
| 79 | // Do this asynchronous so that if the first update adds a |
| 80 | // message, it will not animate while we fade in the content. |
| 81 | // Instead it simply appears with the rest of the content. |
| 82 | setTimeout(function () { |
| 83 | // Fade in the content |
| 84 | $container.addClass('zuul-container-ready'); |
| 85 | }); |
| 86 | }); |
| 87 | |
| 88 | $(function ($) { |
| 89 | // DOM ready |
| 90 | $container = $('#zuul-container'); |
| 91 | $indicator = $('#zuul-spinner'); |
| 92 | $('#zuul_controls').append(zuul.app.control_form()); |
| 93 | |
| 94 | zuul.app.schedule(); |
| 95 | |
| 96 | $(document).on({ |
| 97 | 'show.visibility': function () { |
| 98 | zuul.options.enabled = true; |
| 99 | zuul.app.update(); |
| 100 | }, |
| 101 | 'hide.visibility': function () { |
| 102 | zuul.options.enabled = false; |
| 103 | } |
| 104 | }); |
| 105 | }); |
Timo Tijhof | 89bb8cf | 2015-04-03 03:41:17 +0100 | [diff] [blame] | 106 | |
| 107 | return zuul; |
| 108 | } |