2015-04-08 22:43:59 +00:00
|
|
|
(function () {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ReposCtrl responsible for rendering the user's
|
|
|
|
* repository home screen.
|
2015-04-25 00:06:46 +00:00
|
|
|
*/
|
2015-05-06 03:22:02 +00:00
|
|
|
function ReposCtrl($scope, $routeParams, repos, users) {
|
2015-04-08 22:43:59 +00:00
|
|
|
|
2015-04-25 00:06:46 +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-25 00:06:46 +00:00
|
|
|
|
2015-04-08 22:43:59 +00:00
|
|
|
// Gets a list of repos to display in the
|
|
|
|
// dropdown.
|
|
|
|
repos.list().then(function(payload){
|
|
|
|
$scope.repos = angular.isArray(payload.data) ? payload.data : [];
|
|
|
|
}).catch(function(err){
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RepoAddCtrl responsible for activaing a new
|
|
|
|
* repository.
|
2015-04-25 00:06:46 +00:00
|
|
|
*/
|
2015-04-08 22:43:59 +00:00
|
|
|
function RepoAddCtrl($scope, $location, repos, users) {
|
2015-05-22 00:00:31 +00:00
|
|
|
|
|
|
|
// Gets the currently authenticated user
|
|
|
|
users.getCached().then(function(payload){
|
|
|
|
$scope.user = payload.data;
|
|
|
|
});
|
2015-05-27 05:58:48 +00:00
|
|
|
|
2015-04-08 22:43:59 +00:00
|
|
|
$scope.add = function(slug) {
|
|
|
|
repos.post(slug).then(function(payload) {
|
|
|
|
$location.path('/'+slug);
|
|
|
|
}).catch(function(err){
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RepoEditCtrl responsible for editing a repository.
|
2015-04-25 00:06:46 +00:00
|
|
|
*/
|
2015-05-22 00:00:31 +00:00
|
|
|
function RepoEditCtrl($scope, $window, $location, $routeParams, repos, users) {
|
2015-04-08 22:43:59 +00:00
|
|
|
var owner = $routeParams.owner;
|
|
|
|
var name = $routeParams.name;
|
|
|
|
var fullName = owner+'/'+name;
|
|
|
|
|
2015-05-22 00:00:31 +00:00
|
|
|
// Inject window for composing url
|
|
|
|
$scope.window = $window;
|
|
|
|
|
2015-04-25 00:06:46 +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-25 00:06:46 +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;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.save = function(repo) {
|
2015-05-27 05:58:48 +00:00
|
|
|
repo.timeout = parseInt(repo.timeout);
|
2015-04-08 22:43:59 +00:00
|
|
|
repos.update(repo).then(function(payload) {
|
|
|
|
$scope.repo = payload.data;
|
|
|
|
}).catch(function(err){
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.delete = function(repo) {
|
|
|
|
repos.delete(repo).then(function(payload) {
|
|
|
|
$location.path('/');
|
|
|
|
}).catch(function(err){
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.param={}
|
|
|
|
$scope.addParam = function(param) {
|
|
|
|
if (!$scope.repo.params) {
|
|
|
|
$scope.repo.params = {}
|
|
|
|
}
|
|
|
|
$scope.repo.params[param.key]=param.value;
|
|
|
|
$scope.param={}
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.deleteParam = function(key) {
|
|
|
|
delete $scope.repo.params[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('drone')
|
|
|
|
.controller('ReposCtrl', ReposCtrl)
|
|
|
|
.controller('RepoAddCtrl', RepoAddCtrl)
|
|
|
|
.controller('RepoEditCtrl', RepoEditCtrl);
|
2015-04-25 00:06:46 +00:00
|
|
|
})();
|