From e9aaaaba7425cfb127954327460afb8a4e189f40 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Mon, 28 Sep 2015 17:30:22 +0100 Subject: Import Adam Coldrick and Michael Drake work --- js/main.js | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 js/main.js (limited to 'js/main.js') diff --git a/js/main.js b/js/main.js new file mode 100644 index 0000000..a31c5f0 --- /dev/null +++ b/js/main.js @@ -0,0 +1,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(); + }); + } +); -- cgit v1.2.1