blob: 81658e624edbda94f56e8e142a04170fd2ee4455 [file] [log] [blame]
Monty Taylor4a781a72017-07-25 07:28:04 -04001/* global jQuery, URL, DemoStatusBasic, DemoStatusOpenStack, DemoStatusTree, BuiltinConfig */
2// Client script for Zuul status page
3//
4// @licstart The following is the entire license notice for the
5// JavaScript code in this page.
6//
7// Copyright 2013 OpenStack Foundation
8// Copyright 2013 Timo Tijhof
9// Copyright 2013 Wikimedia Foundation
10// Copyright 2014 Rackspace Australia
11//
12// Licensed under the Apache License, Version 2.0 (the "License"); you may
13// not use this file except in compliance with the License. You may obtain
14// a copy of the License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
21// License for the specific language governing permissions and limitations
22// under the License.
23//
24// @licend The above is the entire license notice
25// for the JavaScript code in this page.
26
27import 'bootstrap/dist/css/bootstrap.css'
28import 'jquery-visibility/jquery-visibility'
29import 'graphitejs/jquery.graphite.js'
30import angular from 'angular'
31
32import './styles/zuul.css'
33import './jquery.zuul'
34import { getSourceUrl } from './util'
35
36/**
37 * @return The $.zuul instance
38 */
39function zuulStart ($) {
40 // Start the zuul app (expects default dom)
41
42 let $container, $indicator
43
44 let url = new URL(window.location)
45 let params = {
46 // graphite_url: 'http://graphite.openstack.org/render/'
47 }
48
49 if (typeof BuiltinConfig !== 'undefined') {
50 params['source'] = BuiltinConfig.api_endpoint + '/' + 'status'
51 } else if (url.searchParams.has('source_url')) {
52 params['source'] = url.searchParams.get('source_url') + '/' + 'status'
53 } else if (url.searchParams.has('demo')) {
54 let demo = url.searchParams.get('demo') || 'basic'
55 if (demo === 'basic') {
56 params['source_data'] = DemoStatusBasic
57 } else if (demo === 'openstack') {
58 params['source_data'] = DemoStatusOpenStack
59 } else if (demo === 'tree') {
60 params['source_data'] = DemoStatusTree
61 }
62 } else {
63 params['source'] = getSourceUrl('status')
64 }
65
66 let zuul = $.zuul(params)
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.controlForm())
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 })
108
109 return zuul
110}
111
112if (module.hot) {
113 // This doesn't fully work with our jquery plugin because $.zuul is already
114 // instantiated. Leaving it here to show where a hook can happen if we can
115 // figure out a way to live update it. When it's not there, an update to
116 // jquery.zuul.js triggers a page reload.
117 // module.hot.accept('./jquery.zuul', function() {
118 // console.log('Accepting the updated module!');
119 // })
120}
121
122angular.module('zuulStatus', []).controller(
123 'mainController', function ($scope, $http) {
124 zuulStart(jQuery)
125 }
126)