2015-02-20 23:15:48 +00:00
|
|
|
(function() {
|
|
|
|
/**
|
|
|
|
* Page to create a new repository.
|
|
|
|
*/
|
|
|
|
angular.module('quayPages').config(['pages', function(pages) {
|
2015-04-06 16:45:12 +00:00
|
|
|
pages.create('new-repo', 'new-repo.html', NewRepoCtrl, {
|
|
|
|
'newLayout': true,
|
2015-02-23 19:23:54 +00:00
|
|
|
'title': 'New Repository',
|
|
|
|
'description': 'Create a new Docker repository'
|
2015-06-29 09:33:00 +00:00
|
|
|
})
|
2015-02-20 23:15:48 +00:00
|
|
|
}]);
|
|
|
|
|
2016-09-21 17:53:09 +00:00
|
|
|
function NewRepoCtrl($scope, $location, $http, $timeout, $routeParams, UserService, ApiService, PlanService, TriggerService, Features) {
|
2015-02-20 23:15:48 +00:00
|
|
|
UserService.updateUserIn($scope);
|
|
|
|
|
|
|
|
$scope.Features = Features;
|
2015-05-12 16:40:26 +00:00
|
|
|
$scope.TriggerService = TriggerService;
|
2015-02-20 23:15:48 +00:00
|
|
|
|
|
|
|
$scope.repo = {
|
|
|
|
'is_public': 0,
|
|
|
|
'description': '',
|
2016-09-21 17:53:09 +00:00
|
|
|
'initialize': '',
|
2017-03-23 21:16:19 +00:00
|
|
|
'name': $routeParams['name'],
|
|
|
|
'repo_kind': 'image'
|
2015-02-20 23:15:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.changeNamespace = function(namespace) {
|
|
|
|
$scope.repo.namespace = namespace;
|
|
|
|
};
|
|
|
|
|
2016-09-29 13:19:21 +00:00
|
|
|
$scope.$watch('repo.name', function() {
|
|
|
|
$scope.createError = null;
|
|
|
|
});
|
2015-02-20 23:15:48 +00:00
|
|
|
|
2016-09-29 13:19:21 +00:00
|
|
|
$scope.startBuild = function() {
|
|
|
|
$scope.buildStarting = true;
|
|
|
|
$scope.startBuildCallback(function(status, messageOrBuild) {
|
|
|
|
if (status) {
|
|
|
|
$location.url('/repository/' + $scope.created.namespace + '/' + $scope.created.name +
|
|
|
|
'?tab=builds');
|
|
|
|
} else {
|
|
|
|
bootbox.alert(messageOrBuild || 'Could not start build');
|
2015-02-20 23:15:48 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-09-29 13:19:21 +00:00
|
|
|
$scope.readyForBuild = function(startBuild) {
|
|
|
|
$scope.startBuildCallback = startBuild;
|
|
|
|
};
|
2015-02-20 23:15:48 +00:00
|
|
|
|
2016-06-23 20:24:36 +00:00
|
|
|
$scope.createNewRepo = function() {
|
2015-02-20 23:15:48 +00:00
|
|
|
$scope.creating = true;
|
|
|
|
var repo = $scope.repo;
|
|
|
|
var data = {
|
|
|
|
'namespace': repo.namespace,
|
|
|
|
'repository': repo.name,
|
|
|
|
'visibility': repo.is_public == '1' ? 'public' : 'private',
|
2017-03-23 21:16:19 +00:00
|
|
|
'description': repo.description,
|
|
|
|
'repo_kind': repo.repo_kind
|
2015-02-20 23:15:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.createRepo(data).then(function(created) {
|
|
|
|
$scope.creating = false;
|
|
|
|
$scope.created = created;
|
|
|
|
|
2017-03-23 21:16:19 +00:00
|
|
|
if (repo.repo_kind == 'application') {
|
|
|
|
$location.path('/application/' + created.namespace + '/' + created.name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-29 13:19:21 +00:00
|
|
|
// Start the build if applicable.
|
2015-02-20 23:15:48 +00:00
|
|
|
if ($scope.repo.initialize == 'dockerfile' || $scope.repo.initialize == 'zipfile') {
|
|
|
|
$scope.createdForBuild = created;
|
2016-09-29 13:19:21 +00:00
|
|
|
$scope.startBuild();
|
2015-02-20 23:15:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-12 16:40:26 +00:00
|
|
|
// Conduct the SCM redirect if applicable.
|
|
|
|
var redirectUrl = TriggerService.getRedirectUrl($scope.repo.initialize, repo.namespace, repo.name);
|
|
|
|
if (redirectUrl) {
|
|
|
|
window.location = redirectUrl;
|
2015-02-20 23:15:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, redirect to the repo page.
|
|
|
|
$location.path('/repository/' + created.namespace + '/' + created.name);
|
|
|
|
}, function(result) {
|
|
|
|
$scope.creating = false;
|
2016-06-23 20:24:36 +00:00
|
|
|
$scope.createError = ApiService.getErrorMessage(result);
|
2015-02-20 23:15:48 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
})();
|