summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam@sotk.co.uk>2015-09-26 15:31:31 +0100
committerAdam Coldrick <adam@sotk.co.uk>2015-09-28 20:20:09 +0100
commit0c5c7de3be7472137375bdcc51856b18c783818e (patch)
treeb6b28ea00c8d5d8d630c01e9dd70f0257e9104ab
parent67dbe8e29e26c6daa5d72242fef779a2201fe2af (diff)
downloadciat-ui-0c5c7de3be7472137375bdcc51856b18c783818e.tar.gz
Try to autorefresh data
-rw-r--r--js/main.js66
1 files changed, 40 insertions, 26 deletions
diff --git a/js/main.js b/js/main.js
index e5df047..de76cf5 100644
--- a/js/main.js
+++ b/js/main.js
@@ -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();
+ });
}
]);