2015-04-08 22:43:59 +00:00
|
|
|
(function () {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BuildsCtrl responsible for rendering the repo's
|
|
|
|
* recent build history.
|
2015-04-16 21:45:05 +00:00
|
|
|
*/
|
2015-05-06 02:46:26 +00:00
|
|
|
function BuildsCtrl($scope, $routeParams, builds, repos, users, logs) {
|
2015-04-08 22:43:59 +00:00
|
|
|
|
|
|
|
var owner = $routeParams.owner;
|
|
|
|
var name = $routeParams.name;
|
|
|
|
var fullName = owner+'/'+name;
|
|
|
|
|
2015-04-16 21:45:05 +00:00
|
|
|
// Gets the currently authenticated user
|
2015-04-08 22:43:59 +00:00
|
|
|
users.getCached().then(function(payload){
|
|
|
|
$scope.user = payload.data;
|
|
|
|
});
|
2015-04-16 21:45:05 +00:00
|
|
|
|
2015-04-08 22:43:59 +00:00
|
|
|
// Gets a repository
|
|
|
|
repos.get(fullName).then(function(payload){
|
|
|
|
$scope.repo = payload.data;
|
|
|
|
}).catch(function(err){
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Gets a list of builds
|
|
|
|
builds.list(fullName).then(function(payload){
|
|
|
|
$scope.builds = angular.isArray(payload.data) ? payload.data : [];
|
|
|
|
}).catch(function(err){
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.watch = function(repo) {
|
|
|
|
repos.watch(repo.full_name).then(function(payload) {
|
2015-05-11 07:45:31 +00:00
|
|
|
$scope.repo.starred = true;
|
2015-04-08 22:43:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.unwatch = function(repo) {
|
|
|
|
repos.unwatch(repo.full_name).then(function() {
|
2015-05-11 07:45:31 +00:00
|
|
|
$scope.repo.starred = false;
|
2015-04-08 22:43:59 +00:00
|
|
|
});
|
|
|
|
}
|
2015-04-25 00:06:46 +00:00
|
|
|
|
2015-05-06 03:22:02 +00:00
|
|
|
repos.subscribe(fullName, function(event) {
|
2015-04-26 04:27:24 +00:00
|
|
|
var added = false;
|
|
|
|
for (var i=0;i<$scope.builds.length;i++) {
|
|
|
|
var build = $scope.builds[i];
|
2015-05-11 07:45:31 +00:00
|
|
|
if (event.sequence !== build.sequence) {
|
2015-04-26 04:27:24 +00:00
|
|
|
continue; // ignore
|
|
|
|
}
|
|
|
|
// update the build status
|
2015-05-06 02:46:26 +00:00
|
|
|
$scope.builds[i] = event;
|
2015-04-26 04:27:24 +00:00
|
|
|
$scope.$apply();
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!added) {
|
2015-05-06 02:46:26 +00:00
|
|
|
$scope.builds.push(event);
|
2015-04-26 04:27:24 +00:00
|
|
|
$scope.$apply();
|
2015-04-25 00:06:46 +00:00
|
|
|
}
|
|
|
|
});
|
2015-04-08 22:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BuildCtrl responsible for rendering a build.
|
2015-04-16 21:45:05 +00:00
|
|
|
*/
|
2015-05-06 02:46:26 +00:00
|
|
|
function BuildCtrl($scope, $routeParams, $window, logs, builds, repos, users) {
|
2015-04-08 22:43:59 +00:00
|
|
|
|
2015-05-11 07:53:56 +00:00
|
|
|
var step = parseInt($routeParams.step) || 1;
|
2015-04-08 22:43:59 +00:00
|
|
|
var number = $routeParams.number;
|
|
|
|
var owner = $routeParams.owner;
|
|
|
|
var name = $routeParams.name;
|
|
|
|
var fullName = owner+'/'+name;
|
2015-05-06 02:46:26 +00:00
|
|
|
var streaming = false;
|
2015-04-30 07:20:48 +00:00
|
|
|
var tail = false;
|
2015-04-08 22:43:59 +00:00
|
|
|
|
2015-04-30 02:57:43 +00:00
|
|
|
// Initiates streaming a build.
|
|
|
|
var stream = function() {
|
2015-05-06 02:46:26 +00:00
|
|
|
if (streaming) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
streaming = true;
|
|
|
|
|
2015-04-30 02:57:43 +00:00
|
|
|
var convert = new Filter({stream:true,newline:false});
|
|
|
|
var term = document.getElementById("term");
|
|
|
|
term.innerHTML = "";
|
|
|
|
|
2015-04-30 07:20:48 +00:00
|
|
|
// subscribes to the build otuput.
|
2015-04-30 02:57:43 +00:00
|
|
|
logs.subscribe(fullName, number, step, function(data){
|
2015-05-18 06:07:10 +00:00
|
|
|
term.innerHTML += convert.toHtml(data.replace("\\n","\n"));
|
2015-04-30 07:20:48 +00:00
|
|
|
if (tail) {
|
|
|
|
// scrolls to the bottom of the page if enabled
|
|
|
|
$window.scrollTo(0, $window.document.body.scrollHeight);
|
|
|
|
}
|
2015-04-30 02:57:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-04-16 21:45:05 +00:00
|
|
|
// Gets the currently authenticated user
|
2015-04-08 22:43:59 +00:00
|
|
|
users.getCached().then(function(payload){
|
|
|
|
$scope.user = payload.data;
|
|
|
|
});
|
2015-04-16 21:45:05 +00:00
|
|
|
|
2015-04-08 22:43:59 +00:00
|
|
|
// Gets a repository
|
|
|
|
repos.get(fullName).then(function(payload){
|
|
|
|
$scope.repo = payload.data;
|
|
|
|
}).catch(function(err){
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Gets the build
|
|
|
|
builds.get(fullName, number).then(function(payload){
|
|
|
|
$scope.build = payload.data;
|
2015-05-11 07:45:31 +00:00
|
|
|
$scope.task = payload.data.builds[step-1];
|
2015-04-16 22:05:00 +00:00
|
|
|
|
2015-04-28 23:36:13 +00:00
|
|
|
if (['pending', 'killed'].indexOf($scope.task.state) !== -1) {
|
2015-04-16 22:05:00 +00:00
|
|
|
// do nothing
|
|
|
|
} else if ($scope.task.state === 'running') {
|
|
|
|
// stream the build
|
2015-04-30 02:57:43 +00:00
|
|
|
stream();
|
2015-04-16 22:05:00 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// fetch the logs for the finished build.
|
|
|
|
logs.get(fullName, number, step).then(function(payload){
|
2015-04-26 04:27:24 +00:00
|
|
|
var convert = new Filter({stream:false,newline:false});
|
|
|
|
var term = document.getElementById("term")
|
|
|
|
term.innerHTML = convert.toHtml(payload.data);
|
2015-04-16 22:05:00 +00:00
|
|
|
}).catch(function(err){
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
}
|
2015-04-08 22:43:59 +00:00
|
|
|
}).catch(function(err){
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
|
2015-04-17 05:07:13 +00:00
|
|
|
$scope.restart = function() {
|
2015-04-28 23:27:30 +00:00
|
|
|
builds.restart(fullName, number).then(function(payload){
|
|
|
|
$scope.build = payload.data;
|
2015-05-11 07:45:31 +00:00
|
|
|
$scope.task = payload.data.builds[step-1];
|
2015-04-28 23:27:30 +00:00
|
|
|
}).catch(function(err){
|
2015-04-17 05:07:13 +00:00
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.cancel = function() {
|
2015-04-28 23:27:30 +00:00
|
|
|
builds.cancel(fullName, number).then(function(payload){
|
|
|
|
$scope.build = payload.data;
|
2015-05-11 07:45:31 +00:00
|
|
|
$scope.task = payload.data.builds[step-1];
|
2015-04-28 23:27:30 +00:00
|
|
|
}).catch(function(err) {
|
2015-04-17 05:07:13 +00:00
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
};
|
2015-04-21 22:48:26 +00:00
|
|
|
|
2015-04-30 07:20:48 +00:00
|
|
|
$scope.tail = function() {
|
|
|
|
tail = !tail;
|
|
|
|
};
|
|
|
|
|
2015-05-06 02:46:26 +00:00
|
|
|
repos.subscribe(fullName, function(event) {
|
2015-05-11 07:45:31 +00:00
|
|
|
if (event.sequence !== parseInt(number)) {
|
2015-04-25 00:06:46 +00:00
|
|
|
return; // ignore
|
|
|
|
}
|
2015-05-06 02:46:26 +00:00
|
|
|
// update the build
|
|
|
|
$scope.build = event;
|
2015-05-11 07:45:31 +00:00
|
|
|
$scope.task = event.builds[step-1];
|
2015-04-25 00:06:46 +00:00
|
|
|
$scope.$apply();
|
|
|
|
|
2015-05-06 02:46:26 +00:00
|
|
|
// start streaming the current build
|
|
|
|
if ($scope.task.state === 'running') {
|
2015-04-30 02:57:43 +00:00
|
|
|
stream();
|
2015-05-06 02:46:26 +00:00
|
|
|
} else {
|
|
|
|
// resets our streaming state
|
|
|
|
streaming = false;
|
2015-04-30 02:57:43 +00:00
|
|
|
}
|
2015-04-25 00:06:46 +00:00
|
|
|
});
|
|
|
|
|
2015-04-30 02:57:43 +00:00
|
|
|
|
2015-04-08 22:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('drone')
|
|
|
|
.controller('BuildCtrl', BuildCtrl)
|
|
|
|
.controller('BuildsCtrl', BuildsCtrl);
|
2015-04-16 21:45:05 +00:00
|
|
|
})();
|