blob: 640437b00dc96c1a7d8013915b8805f4b052cd49 [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
Timo Tijhof89bb8cf2015-04-03 03:41:17 +010042/**
43 * @return The $.zuul instance
44 */
Joshua Hesketh4db99cb2014-05-23 11:28:08 +100045function zuul_start($) {
46 // Start the zuul app (expects default dom)
47
48 var $container, $indicator;
49 var demo = location.search.match(/[?&]demo=([^?&]*)/),
50 source_url = location.search.match(/[?&]source_url=([^?&]*)/),
51 source = demo ? './status-' + (demo[1] || 'basic') + '.json-sample' :
52 'status.json';
53 source = source_url ? source_url[1] : source;
54
55 var zuul = $.zuul({
56 source: source,
57 //graphite_url: 'http://graphite.openstack.org/render/'
58 });
59
60 zuul.jq.on('update-start', function () {
61 $container.addClass('zuul-container-loading');
62 $indicator.addClass('zuul-spinner-on');
63 });
64
65 zuul.jq.on('update-end', function () {
66 $container.removeClass('zuul-container-loading');
67 setTimeout(function () {
68 $indicator.removeClass('zuul-spinner-on');
69 }, 500);
70 });
71
72 zuul.jq.one('update-end', function () {
73 // Do this asynchronous so that if the first update adds a
74 // message, it will not animate while we fade in the content.
75 // Instead it simply appears with the rest of the content.
76 setTimeout(function () {
77 // Fade in the content
78 $container.addClass('zuul-container-ready');
79 });
80 });
81
82 $(function ($) {
83 // DOM ready
84 $container = $('#zuul-container');
85 $indicator = $('#zuul-spinner');
86 $('#zuul_controls').append(zuul.app.control_form());
87
88 zuul.app.schedule();
89
90 $(document).on({
91 'show.visibility': function () {
92 zuul.options.enabled = true;
93 zuul.app.update();
94 },
95 'hide.visibility': function () {
96 zuul.options.enabled = false;
97 }
98 });
99 });
Timo Tijhof89bb8cf2015-04-03 03:41:17 +0100100
101 return zuul;
102}