Make live updates to the commits without needing to reload

This commit is contained in:
Andy Gardner 2015-01-20 15:13:53 +02:00
parent aed6f17db6
commit 217cf0bc23

View file

@ -14,6 +14,18 @@ angular.module('app').controller("RepoController", function($scope, $http, $rout
// commit details, allowing the user to
// reload the page.
$scope.msg = item;
// Try find an existing commit for this SHA. If found, replace it
var sha_updated = $scope.commits.some(function(element, index) {
if (element.sha == item.commit.sha)
$scope.commits[index] = item.commit;
return element.sha == item.commit.sha;
});
// Add a new commit if the SHA couldn't be found but the new build status is 'Started'
if ( ! sha_updated && item.commit.status == 'Started')
$scope.commits.unshift(item.commit);
$scope.$apply();
} else {
// we trigger a toast (or html5) notification so the