blob: 77884e5b5058a54f9f1a5925c083d7ac458ddbf6 [file] [log] [blame]
Monty Taylor4a781a72017-07-25 07:28:04 -04001// @licstart The following is the entire license notice for the
2// JavaScript code in this page.
3//
4// Copyright 2017 Red Hat
5//
6// Licensed under the Apache License, Version 2.0 (the "License"); you may
7// not use this file except in compliance with the License. You may obtain
8// a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15// License for the specific language governing permissions and limitations
16// under the License.
17//
18// @licend The above is the entire license notice
19// for the JavaScript code in this page.
20
21import 'bootstrap/dist/css/bootstrap.css'
22import angular from 'angular'
23
24import './styles/zuul.css'
25import './jquery.zuul'
26import { getSourceUrl } from './util'
27
28angular.module('zuulTenants', []).controller(
29 'mainController', function ($scope, $http, $location) {
30 $scope.tenants = undefined
31 $scope.tenants_fetch = function () {
32 $http.get(getSourceUrl('tenants', $location))
33 .then(function success (result) {
34 $scope.tenants = result.data
35 })
36 }
37 $scope.tenants_fetch()
38 })
39
40angular.module('zuulJobs', [], function ($locationProvider) {
41 $locationProvider.html5Mode({
42 enabled: true,
43 requireBase: false
44 })
45}).controller(
46 'mainController', function ($scope, $http, $location) {
47 $scope.jobs = undefined
48 $scope.jobs_fetch = function () {
49 $http.get(getSourceUrl('jobs', $location))
50 .then(function success (result) {
51 $scope.jobs = result.data
52 })
53 }
54 $scope.jobs_fetch()
55 })
56
57angular.module('zuulBuilds', [], function ($locationProvider) {
58 $locationProvider.html5Mode({
59 enabled: true,
60 requireBase: false
61 })
62}).controller('mainController', function ($scope, $http, $location) {
63 $scope.rowClass = function (build) {
64 if (build.result === 'SUCCESS') {
65 return 'success'
66 } else {
67 return 'warning'
68 }
69 }
70 let queryArgs = $location.search()
71 let url = $location.url()
72 if (queryArgs['source_url']) {
73 $scope.tenant = undefined
74 } else {
75 let tenantStart = url.lastIndexOf(
76 '/', url.lastIndexOf('/builds.html') - 1) + 1
77 let tenantLength = url.lastIndexOf('/builds.html') - tenantStart
78 $scope.tenant = url.substr(tenantStart, tenantLength)
79 }
80 $scope.builds = undefined
81 if (queryArgs['pipeline']) {
82 $scope.pipeline = queryArgs['pipeline']
83 } else { $scope.pipeline = '' }
84 if (queryArgs['job_name']) {
85 $scope.job_name = queryArgs['job_name']
86 } else { $scope.job_name = '' }
87 if (queryArgs['project']) {
88 $scope.project = queryArgs['project']
89 } else { $scope.project = '' }
90 $scope.builds_fetch = function () {
91 let queryString = ''
92 if ($scope.tenant) { queryString += '&tenant=' + $scope.tenant }
93 if ($scope.pipeline) { queryString += '&pipeline=' + $scope.pipeline }
94 if ($scope.job_name) { queryString += '&job_name=' + $scope.job_name }
95 if ($scope.project) { queryString += '&project=' + $scope.project }
96 if (queryString !== '') { queryString = '?' + queryString.substr(1) }
97 $http.get(getSourceUrl('builds', $location) + queryString)
98 .then(function success (result) {
99 for (let buildPos = 0;
100 buildPos < result.data.length;
101 buildPos += 1) {
102 let build = result.data[buildPos]
103 if (build.node_name == null) {
104 build.node_name = 'master'
105 }
106 /* Fix incorect url for post_failure job */
107 if (build.log_url === build.job_name) {
108 build.log_url = undefined
109 }
110 }
111 $scope.builds = result.data
112 })
113 }
114 $scope.builds_fetch()
115})