summaryrefslogtreecommitdiff
path: root/js/main.js
blob: a31c5f06aebb938991e0b0e74474f670b11ea74d (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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, $interval) {
        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'),
                                steps: response.data.steps,
                                sourceStamps: response.data.sourceStamps,
                                number: response.data.number
                            };
                            $scope.steps.push({
                                name: key,
                                lastBuild: details,
                                data: value
                            });
                            $scope.steps.sort(function(a, b) {
                                return a.name.charAt(0) > b.name.charAt(0);
                            });
                        });
                    });
                });
        }

        $scope.selected = null;
        $scope.select = function(step, e) {
            if (e) {
                e.stopPropagation();
            }
            $scope.selected = step;
        };

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

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

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