summaryrefslogtreecommitdiff
path: root/js/main.js
blob: 4e6416d04e4345b0051b23b08fba0368ed4c113c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var app = angular.module('ciat', []);

app.config(['$httpProvider', function($httpProvider) {
        $httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With'];
    }
]);

app.controller('VisualisationController', function($scope, $http, $q) {
        function checkInArray(array, key) {
            if (array) {
                if (array.indexOf(key) > -1) {
                    return true;
                }
            }
            return False;
        }

        function load() {
            $scope.steps = [];
            $http.get('http://ciat.baserock.org:8010/json/builders')
                .then(function(builders) {
                    angular.forEach(builders.data, function(value, key) {
                        var lastBuildID;
                        if (value.state === 'building') {
                            lastBuildID = value.cachedBuilds[value.cachedBuilds.length - 2];
                        } else {
                            lastBuildID = value.cachedBuilds[value.cachedBuilds.length - 1];
                        }

                    var buildsPath = 'http://ciat.baserock.org:8010/json/builders/' +
                                      key + '/builds/' + lastBuildID;
                    $http.get(buildsPath).then(function(response) {
                        var details = {
                            success: checkInArray(response.data.text, 'successful'),
                            failed: checkInArray(response.data.text, 'failed')
                        };
                        $scope.steps.push({
                            name: key,
                            lastBuild: details,
                            data: value
                        });
                    });
                });
        }

        function cancelRefresh() {
            if (angular.isDefined(autorefresh)) {
                $interval.cancel(autorefresh);
                autorefresh = undefined;
            }
        }

        load();
        var autorefresh = $interval(load, 60000);

        $scope.$on('$destroy', function() {
          cancelRefresh();
        });
    }
]);