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