blob: 6e35eb3440369d99e474f3a0058e4514e0f26cdd [file] [log] [blame]
Joshua Hesketh4db99cb2014-05-23 11:28:08 +10001// Client script for Zuul status page
2//
Tristan Cacqueray48ddd9e2017-05-21 10:19:02 +00003// @licstart The following is the entire license notice for the
4// JavaScript code in this page.
5//
Joshua Hesketh4db99cb2014-05-23 11:28:08 +10006// 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 Cacqueray48ddd9e2017-05-21 10:19:02 +000022//
23// @licend The above is the entire license notice
24// for the JavaScript code in this page.
Joshua Hesketh4db99cb2014-05-23 11:28:08 +100025
Timo Tijhof4be9f742015-04-02 01:13:19 +010026/*exported zuul_build_dom, zuul_start */
27
Joshua Hesketh4db99cb2014-05-23 11:28:08 +100028function zuul_build_dom($, container) {
29 // Build a default-looking DOM
Timo Tijhof4be9f742015-04-02 01:13:19 +010030 var default_layout = '<div class="container">'
Joshua Hesketh4db99cb2014-05-23 11:28:08 +100031 + '<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 Henkel02ec07f2017-10-19 07:10:37 +020034 + '<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 Hesketh4db99cb2014-05-23 11:28:08 +100035 + '<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 Tijhof4be9f742015-04-02 01:13:19 +010043 var $container = $(container);
Joshua Hesketh4db99cb2014-05-23 11:28:08 +100044 $container.html(default_layout);
45 });
46}
47
Timo Tijhof89bb8cf2015-04-03 03:41:17 +010048/**
49 * @return The $.zuul instance
50 */
Joshua Hesketh4db99cb2014-05-23 11:28:08 +100051function 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' :
Monty Taylor9010dc52018-02-17 13:29:28 -060058 'status';
Joshua Hesketh4db99cb2014-05-23 11:28:08 +100059 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 Tijhof89bb8cf2015-04-03 03:41:17 +0100106
107 return zuul;
108}