blob: 6f87a92c4db6eb0c45ff7b43f1c990c2bcf8424c [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
20function zuul_build_dom($, container) {
21 // Build a default-looking DOM
22 default_layout = '<div class="container">'
23 + '<h1>Zuul Status</h1>'
24 + '<p>Real-time status monitor of Zuul, the pipeline manager between Gerrit and Workers.</p>'
25 + '<div class="zuul-container" id="zuul-container">'
26 + '<div style="display: none;" class="alert" id="zuul_msg"></div>'
27 + '<button class="btn pull-right zuul-spinner">updating <span class="glyphicon glyphicon-refresh"></span></button>'
28 + '<p>Queue lengths: <span id="zuul_queue_events_num">0</span> events, <span id="zuul_queue_results_num">0</span> results.</p>'
29 + '<div id="zuul_controls"></div>'
30 + '<div id="zuul_pipelines" class="row"></div>'
31 + '<p>Zuul version: <span id="zuul-version-span"></span></p>'
32 + '<p>Last reconfigured: <span id="last-reconfigured-span"></span></p>'
33 + '</div></div>';
34
35 $(function ($) {
36 // DOM ready
37 $container = $(container);
38 $container.html(default_layout);
39 });
40}
41
42function zuul_start($) {
43 // Start the zuul app (expects default dom)
44
45 var $container, $indicator;
46 var demo = location.search.match(/[?&]demo=([^?&]*)/),
47 source_url = location.search.match(/[?&]source_url=([^?&]*)/),
48 source = demo ? './status-' + (demo[1] || 'basic') + '.json-sample' :
49 'status.json';
50 source = source_url ? source_url[1] : source;
51
52 var zuul = $.zuul({
53 source: source,
54 //graphite_url: 'http://graphite.openstack.org/render/'
55 });
56
57 zuul.jq.on('update-start', function () {
58 $container.addClass('zuul-container-loading');
59 $indicator.addClass('zuul-spinner-on');
60 });
61
62 zuul.jq.on('update-end', function () {
63 $container.removeClass('zuul-container-loading');
64 setTimeout(function () {
65 $indicator.removeClass('zuul-spinner-on');
66 }, 500);
67 });
68
69 zuul.jq.one('update-end', function () {
70 // Do this asynchronous so that if the first update adds a
71 // message, it will not animate while we fade in the content.
72 // Instead it simply appears with the rest of the content.
73 setTimeout(function () {
74 // Fade in the content
75 $container.addClass('zuul-container-ready');
76 });
77 });
78
79 $(function ($) {
80 // DOM ready
81 $container = $('#zuul-container');
82 $indicator = $('#zuul-spinner');
83 $('#zuul_controls').append(zuul.app.control_form());
84
85 zuul.app.schedule();
86
87 $(document).on({
88 'show.visibility': function () {
89 zuul.options.enabled = true;
90 zuul.app.update();
91 },
92 'hide.visibility': function () {
93 zuul.options.enabled = false;
94 }
95 });
96 });
97}