blob: ae950e8e2ff0b66956d9bb3485c49e4994c8cc76 [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 + '<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>'
36 + '<p>Queue lengths: <span id="zuul_queue_events_num">0</span> events, <span id="zuul_queue_results_num">0</span> results.</p>'
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 Tijhof4be9f742015-04-02 01:13:19 +010045 var $container = $(container);
Joshua Hesketh4db99cb2014-05-23 11:28:08 +100046 $container.html(default_layout);
47 });
48}
49
Timo Tijhof89bb8cf2015-04-03 03:41:17 +010050/**
51 * @return The $.zuul instance
52 */
Joshua Hesketh4db99cb2014-05-23 11:28:08 +100053function 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 Tijhof89bb8cf2015-04-03 03:41:17 +0100108
109 return zuul;
110}