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-04-25 00:06:46 +00:00
|
|
|
function BuildsCtrl($scope, $routeParams, builds, repos, users, feed) {
|
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) {
|
|
|
|
$scope.repo.subscription = payload.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.unwatch = function(repo) {
|
|
|
|
repos.unwatch(repo.full_name).then(function() {
|
|
|
|
delete $scope.repo.subscription;
|
|
|
|
});
|
|
|
|
}
|
2015-04-25 00:06:46 +00:00
|
|
|
|
|
|
|
feed.subscribe(function(event) {
|
|
|
|
if (event.repo.full_name !== fullName) {
|
|
|
|
return; // ignore
|
|
|
|
}
|
|
|
|
// update repository
|
|
|
|
$scope.repo = event.repo;
|
2015-04-26 04:27:24 +00:00
|
|
|
$scope.$apply();
|
2015-04-25 00:06:46 +00:00
|
|
|
|
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];
|
|
|
|
if (event.build.number !== build.number) {
|
|
|
|
continue; // ignore
|
|
|
|
}
|
|
|
|
// update the build status
|
|
|
|
build.state = event.build.state;
|
|
|
|
build.started_at = event.build.started_at;
|
|
|
|
build.finished_at = event.build.finished_at;
|
|
|
|
build.duration = event.build.duration;
|
|
|
|
$scope.builds[i] = build;
|
|
|
|
$scope.$apply();
|
|
|
|
added = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!added) {
|
|
|
|
$scope.builds.push(event.build);
|
|
|
|
$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-04-25 00:06:46 +00:00
|
|
|
function BuildCtrl($scope, $routeParams, logs, builds, repos, users, feed) {
|
2015-04-08 22:43:59 +00:00
|
|
|
|
|
|
|
var step = parseInt($routeParams.step) || 1;
|
|
|
|
var number = $routeParams.number;
|
|
|
|
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 the build
|
|
|
|
builds.get(fullName, number).then(function(payload){
|
|
|
|
$scope.build = payload.data;
|
2015-04-16 22:05:00 +00:00
|
|
|
$scope.task = payload.data.tasks[step-1];
|
|
|
|
|
|
|
|
if ($scope.task.state === 'pending') {
|
|
|
|
// do nothing
|
|
|
|
} else if ($scope.task.state === 'running') {
|
|
|
|
// stream the build
|
|
|
|
} 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() {
|
|
|
|
builds.restart(fullName, number).catch(function(err){
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.cancel = function() {
|
|
|
|
builds.cancel(fullName, number).catch(function(err) {
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
};
|
2015-04-21 22:48:26 +00:00
|
|
|
|
2015-04-25 00:06:46 +00:00
|
|
|
feed.subscribe(function(event) {
|
|
|
|
if (event.repo.full_name !== fullName) {
|
|
|
|
return; // ignore
|
|
|
|
}
|
|
|
|
if (event.build.number !== parseInt(number)) {
|
|
|
|
return; // ignore
|
|
|
|
}
|
|
|
|
// update the build status
|
|
|
|
$scope.build.state = event.build.state;
|
2015-04-26 04:27:24 +00:00
|
|
|
$scope.build.started_at = event.build.started_at;
|
|
|
|
$scope.build.finished_at = event.build.finished_at;
|
2015-04-25 00:06:46 +00:00
|
|
|
$scope.build.duration = event.build.duration;
|
|
|
|
$scope.$apply();
|
|
|
|
|
|
|
|
if (!event.task || event.task.number !== step) {
|
|
|
|
return; // ignore
|
|
|
|
}
|
|
|
|
// update the task status
|
|
|
|
$scope.task.state = event.task.state;
|
2015-04-26 04:27:24 +00:00
|
|
|
$scope.task.started_at = event.task.started_at;
|
|
|
|
$scope.task.finished_at = event.task.finished_at;
|
2015-04-25 00:06:46 +00:00
|
|
|
$scope.task.duration = event.task.duration;
|
|
|
|
$scope.task.exit_code = event.task.exit_code;
|
|
|
|
$scope.$apply();
|
|
|
|
});
|
|
|
|
|
2015-04-21 22:48:26 +00:00
|
|
|
// var convert = new Filter({stream:true,newline:false});
|
|
|
|
// var term = document.getElementById("term")
|
|
|
|
// var stdout = document.getElementById("stdout").innerText.split("\n")
|
|
|
|
// stdout.forEach(function(line, i) {
|
|
|
|
// setTimeout(function () {
|
|
|
|
// term.innerHTML += convert.toHtml(line+"\n");
|
|
|
|
// }, i*i);
|
|
|
|
// });
|
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
|
|
|
})();
|