2015-04-08 22:43:59 +00:00
|
|
|
(function () {
|
|
|
|
|
2015-07-12 19:32:46 +00:00
|
|
|
/**
|
|
|
|
* ReposCtrl responsible for rendering the user's
|
|
|
|
* repository home screen.
|
|
|
|
*/
|
2015-07-30 02:51:55 +00:00
|
|
|
function ReposCtrl($scope, $location, $stateParams, repos, users) {
|
|
|
|
$scope.loading = true;
|
|
|
|
$scope.waiting = false;
|
|
|
|
|
2015-07-12 19:32:46 +00:00
|
|
|
// Gets the currently authenticated user
|
|
|
|
users.getCached().then(function (payload) {
|
|
|
|
$scope.user = payload.data;
|
2015-07-30 06:50:01 +00:00
|
|
|
$scope.loading = false;
|
2015-07-12 19:32:46 +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;
|
|
|
|
});
|
2015-07-30 02:51:55 +00:00
|
|
|
|
|
|
|
// Adds a repository
|
|
|
|
$scope.add = function (event, fullName) {
|
|
|
|
$scope.error = undefined;
|
|
|
|
if (event.which && event.which !== 13) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$scope.waiting = true;
|
|
|
|
|
|
|
|
repos.post(fullName).then(function (payload) {
|
|
|
|
$location.path('/' + fullName);
|
|
|
|
$scope.waiting = false;
|
|
|
|
}).catch(function (err) {
|
|
|
|
$scope.error = err;
|
|
|
|
$scope.waiting = false;
|
|
|
|
$scope.search_text = undefined;
|
|
|
|
});
|
|
|
|
}
|
2015-07-12 19:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RepoAddCtrl responsible for activaing a new
|
|
|
|
* repository.
|
|
|
|
*/
|
|
|
|
function RepoAddCtrl($scope, $location, repos, users) {
|
|
|
|
|
|
|
|
// Gets the currently authenticated user
|
|
|
|
users.getCached().then(function (payload) {
|
|
|
|
$scope.user = payload.data;
|
|
|
|
});
|
|
|
|
|
|
|
|
$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.
|
|
|
|
*/
|
|
|
|
function RepoEditCtrl($scope, $window, $location, $stateParams, repos, users) {
|
|
|
|
var owner = $stateParams.owner;
|
|
|
|
var name = $stateParams.name;
|
|
|
|
var fullName = owner + '/' + name;
|
|
|
|
|
|
|
|
// Inject window for composing url
|
|
|
|
$scope.window = $window;
|
|
|
|
|
|
|
|
// Gets the currently authenticated user
|
|
|
|
users.getCached().then(function (payload) {
|
|
|
|
$scope.user = payload.data;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Gets a repository
|
|
|
|
repos.get(fullName).then(function (payload) {
|
|
|
|
$scope.repo = payload.data;
|
|
|
|
}).catch(function (err) {
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.save = function (repo) {
|
|
|
|
repo.timeout = parseInt(repo.timeout);
|
|
|
|
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 = {};
|
|
|
|
|
|
|
|
// auto-update
|
|
|
|
repos.update($scope.repo).then(function (payload) {
|
|
|
|
$scope.repo = payload.data;
|
|
|
|
}).catch(function (err) {
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-09-02 23:14:25 +00:00
|
|
|
|
|
|
|
$scope.encrypt = function (plaintext) {
|
2015-09-07 19:13:27 +00:00
|
|
|
repos.encrypt(fullName, plaintext).then(function (payload) {
|
|
|
|
$scope.secure = payload.data;
|
2015-09-02 23:14:25 +00:00
|
|
|
}).catch(function (err) {
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-07-12 19:32:46 +00:00
|
|
|
$scope.deleteParam = function (key) {
|
|
|
|
delete $scope.repo.params[key];
|
|
|
|
|
|
|
|
// auto-update
|
|
|
|
repos.update($scope.repo).then(function (payload) {
|
|
|
|
$scope.repo = payload.data;
|
|
|
|
}).catch(function (err) {
|
|
|
|
$scope.error = err;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 23:14:25 +00:00
|
|
|
function toSnakeCase(str) {
|
|
|
|
return str.replace(/ /g, '_').replace(/([a-z0-9])([A-Z0-9])/g, '$1_$2').toLowerCase();
|
|
|
|
}
|
|
|
|
|
2015-07-12 19:32:46 +00:00
|
|
|
angular
|
|
|
|
.module('drone')
|
|
|
|
.controller('ReposCtrl', ReposCtrl)
|
|
|
|
.controller('RepoAddCtrl', RepoAddCtrl)
|
|
|
|
.controller('RepoEditCtrl', RepoEditCtrl);
|
2015-04-25 00:06:46 +00:00
|
|
|
})();
|