2014-06-21 21:22:38 +00:00
|
|
|
'use strict';
|
2014-07-11 20:46:04 +00:00
|
|
|
|
2015-01-28 12:15:20 +00:00
|
|
|
angular.module('app').controller("RepoController", function($scope, $filter, $http, $routeParams, $route, repos, feed, repo) {
|
2014-07-11 20:46:04 +00:00
|
|
|
$scope.repo = repo;
|
2014-10-05 22:30:50 +00:00
|
|
|
$scope.activating = false;
|
2015-01-28 12:15:20 +00:00
|
|
|
$scope.build_filter = 'build_history';
|
|
|
|
$scope.layout = 'grid';
|
2014-07-11 20:46:04 +00:00
|
|
|
|
|
|
|
// subscribes to the global feed to receive
|
|
|
|
// build status updates.
|
|
|
|
feed.subscribe(function(item) {
|
|
|
|
if (item.repo.host == repo.host &&
|
|
|
|
item.repo.owner == repo.owner &&
|
|
|
|
item.repo.name == repo.name) {
|
|
|
|
// display a toast message with the
|
|
|
|
// commit details, allowing the user to
|
|
|
|
// reload the page.
|
2015-01-20 13:13:53 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
});
|
|
|
|
|
2015-01-22 08:53:10 +00:00
|
|
|
// Add a build message if the SHA couldn't be found and the new build status is 'Started'
|
|
|
|
if ( ! sha_updated && item.commit.status == 'Started') {
|
|
|
|
// $scope.commits.unshift(item.commit);
|
|
|
|
$scope.msg = item;
|
|
|
|
}
|
2015-01-20 13:13:53 +00:00
|
|
|
|
2014-07-11 20:46:04 +00:00
|
|
|
$scope.$apply();
|
|
|
|
} else {
|
2014-07-13 23:46:49 +00:00
|
|
|
// we trigger a toast (or html5) notification so the
|
2014-07-11 20:46:04 +00:00
|
|
|
// user is aware another build started
|
2014-07-13 23:46:49 +00:00
|
|
|
|
2014-07-11 20:46:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// load the repo commit feed
|
2014-10-02 14:11:13 +00:00
|
|
|
repos.commits(repo.host, repo.owner, repo.name).success(function (commits) {
|
|
|
|
$scope.commits = (typeof commits==='string')?[]:commits;
|
2014-07-11 20:46:04 +00:00
|
|
|
$scope.state = 1;
|
|
|
|
})
|
|
|
|
.error(function (error) {
|
|
|
|
$scope.commits = undefined;
|
|
|
|
$scope.state = 1;
|
|
|
|
});
|
|
|
|
|
2014-10-07 14:57:01 +00:00
|
|
|
//$http({method: 'GET', url: '/api/repos/'+repo.host+'/'+repo.owner+"/"+repo.name+"/feed"}).
|
2014-07-11 20:46:04 +00:00
|
|
|
// success(function(data, status, headers, config) {
|
|
|
|
// $scope.commits = (typeof data==='string')?[]:data;
|
|
|
|
// }).
|
|
|
|
// error(function(data, status, headers, config) {
|
|
|
|
// console.log(data);
|
|
|
|
// });
|
|
|
|
|
|
|
|
$scope.activate = function() {
|
2014-10-05 22:30:50 +00:00
|
|
|
$scope.activating = true;
|
|
|
|
|
2014-07-11 20:46:04 +00:00
|
|
|
// request to create a new repository
|
2014-09-30 07:43:50 +00:00
|
|
|
$http({method: 'POST', url: '/api/repos/'+repo.host+'/'+repo.owner+"/"+repo.name }).
|
2014-07-11 20:46:04 +00:00
|
|
|
success(function(data, status, headers, config) {
|
|
|
|
$scope.repo = data;
|
2014-10-05 22:30:50 +00:00
|
|
|
$scope.activating = false;
|
2014-07-11 20:46:04 +00:00
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
$scope.failure = data;
|
2014-10-05 22:30:50 +00:00
|
|
|
$scope.activating = false;
|
2014-07-11 20:46:04 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
$scope.reload = function() {
|
|
|
|
$route.reload();
|
|
|
|
};
|
|
|
|
|
|
|
|
//$scope.activate = function() {
|
|
|
|
// repos.activate($scope.host, $scope.name).success(function () {
|
|
|
|
// window.location.href="/admin/users";
|
|
|
|
// })
|
|
|
|
// .error(function (error) {
|
|
|
|
// console.log(error);
|
|
|
|
// });
|
|
|
|
//};
|
|
|
|
|
2015-01-28 12:15:20 +00:00
|
|
|
$scope.setCommitFilter = function(filter) {
|
|
|
|
$scope.build_filter = filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.setLayout = function(layout) {
|
|
|
|
$scope.layout = layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.filteredCommits = function() {
|
|
|
|
var filteredCommits;
|
|
|
|
switch ($scope.build_filter) {
|
|
|
|
// Latest commit for each branch (excluding PR branches)
|
|
|
|
case 'branch_summary':
|
|
|
|
filteredCommits = $filter('filter')($scope.commits, { pull_request: '' }, true);
|
|
|
|
filteredCommits = $filter('unique')($scope.commits, 'branch');
|
|
|
|
break;
|
|
|
|
// Latest commit for each PR
|
|
|
|
case 'pull_requests':
|
|
|
|
filteredCommits = $filter('pullRequests')($scope.commits);
|
|
|
|
filteredCommits = $filter('unique')(filteredCommits, 'pull_request');
|
|
|
|
break;
|
|
|
|
// All commits for a full build history
|
|
|
|
default:
|
|
|
|
filteredCommits = $scope.commits;
|
|
|
|
}
|
|
|
|
|
|
|
|
return filteredCommits;
|
|
|
|
}
|
2014-07-11 20:46:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-05 22:30:50 +00:00
|
|
|
angular.module('app').controller("RepoConfigController", function($scope, $http, $timeout, $routeParams, user) {
|
2014-07-11 20:46:04 +00:00
|
|
|
$scope.user = user;
|
2014-10-05 22:30:50 +00:00
|
|
|
$scope.saving = false;
|
2014-07-11 20:46:04 +00:00
|
|
|
|
|
|
|
var remote = $routeParams.remote;
|
|
|
|
var owner = $routeParams.owner;
|
|
|
|
var name = $routeParams.name;
|
|
|
|
|
|
|
|
// load the repo meta-data
|
|
|
|
// request admin details for the repository as well.
|
2014-09-30 07:43:50 +00:00
|
|
|
$http({method: 'GET', url: '/api/repos/'+remote+'/'+owner+"/"+name+"?admin=1"}).
|
2014-07-11 20:46:04 +00:00
|
|
|
success(function(data, status, headers, config) {
|
|
|
|
$scope.repo = data;
|
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.save = function() {
|
2014-10-05 22:30:50 +00:00
|
|
|
$scope.saving = true;
|
|
|
|
|
2014-07-11 20:46:04 +00:00
|
|
|
// request to create a new repository
|
2014-09-30 07:43:50 +00:00
|
|
|
$http({method: 'PUT', url: '/api/repos/'+remote+'/'+owner+"/"+name, data: $scope.repo }).
|
2014-07-11 20:46:04 +00:00
|
|
|
success(function(data, status, headers, config) {
|
|
|
|
delete $scope.failure;
|
2014-10-05 22:30:50 +00:00
|
|
|
|
|
|
|
// yes, for UX reasons we make this request look like it
|
|
|
|
// is taking longer than it really is. Otherwise the loading
|
|
|
|
// button just instantly flickers.
|
|
|
|
$timeout(function(){
|
|
|
|
$scope.saving = false;
|
|
|
|
}, 1500);
|
2014-07-11 20:46:04 +00:00
|
|
|
}).
|
|
|
|
error(function(data, status, headers, config) {
|
|
|
|
$scope.failure = data;
|
2014-10-05 22:30:50 +00:00
|
|
|
$scope.saving = false;
|
2014-07-11 20:46:04 +00:00
|
|
|
});
|
2014-10-05 22:30:50 +00:00
|
|
|
|
2014-07-11 20:46:04 +00:00
|
|
|
};
|
|
|
|
});
|