diff options
author | Adam Coldrick <adam@sotk.co.uk> | 2015-09-26 15:31:31 +0100 |
---|---|---|
committer | Adam Coldrick <adam@sotk.co.uk> | 2015-09-28 20:20:09 +0100 |
commit | 0c5c7de3be7472137375bdcc51856b18c783818e (patch) | |
tree | b6b28ea00c8d5d8d630c01e9dd70f0257e9104ab | |
parent | 67dbe8e29e26c6daa5d72242fef779a2201fe2af (diff) | |
download | ciat-ui-0c5c7de3be7472137375bdcc51856b18c783818e.tar.gz |
Try to autorefresh data
-rw-r--r-- | js/main.js | 66 |
1 files changed, 40 insertions, 26 deletions
@@ -20,31 +20,45 @@ app.controller('VisualisationController', ['$scope', '$http', }; } - $scope.steps = []; - $http.get('http://ciat.baserock.org:8010/json/builders') - .then(function(builders) { - angular.forEach(builders.data, function(value, key) { - var lastBuildID = -1; - if (value.state === 'building') { - lastBuildID = value.cachedBuilds[value.cachedBuilds.length - 2]; - } else { - lastBuildID = value.cachedBuilds[value.cachedBuilds.length - 1]; - } - - var previous = null; - if (lastBuildID != -1) { - var buildsPath = 'http://ciat.baserock.org:8010/json/builders/' + - key + '/builds/' + lastBuildID; - previous = $http.get(buildsPath).then(formatBuild); - } - - var step = { - name: key, - lastBuild: previous, - data: value - } - $scope.steps.push(step); - }); - }); + 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 = -1; + if (value.state === 'building') { + lastBuildID = value.cachedBuilds[value.cachedBuilds.length - 2]; + } else { + lastBuildID = value.cachedBuilds[value.cachedBuilds.length - 1]; + } + + var previous = null; + if (lastBuildID != -1) { + var buildsPath = 'http://ciat.baserock.org:8010/json/builders/' + + key + '/builds/' + lastBuildID; + previous = $http.get(buildsPath).then(formatBuild); + } + + var step = { + name: key, + lastBuild: previous, + data: value + } + $scope.steps.push(step); + }); + }); + } + + function cancelRefresh() { + if (angular.isDefined(autorefresh)) { + $interval.cancel(autorefresh); + autorefresh = undefined; + } + + var autorefresh = $interval(load, 60000); + + $scope.$on('$destroy', function() { + cancelRefresh(); + }); } ]); |