2013-09-30 23:08:24 +00:00
|
|
|
function getFirstTextLine(commentString) {
|
|
|
|
if (!commentString) { return; }
|
|
|
|
|
|
|
|
var lines = commentString.split('\n');
|
2013-10-01 23:37:33 +00:00
|
|
|
var MARKDOWN_CHARS = {
|
|
|
|
'#': true,
|
|
|
|
'-': true,
|
|
|
|
'>': true,
|
|
|
|
'`': true
|
|
|
|
};
|
2013-09-30 23:08:24 +00:00
|
|
|
|
|
|
|
for (var i = 0; i < lines.length; ++i) {
|
|
|
|
// Skip code lines.
|
|
|
|
if (lines[i].indexOf(' ') == 0) {
|
2013-10-01 23:37:33 +00:00
|
|
|
continue;
|
2013-09-30 23:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Skip empty lines.
|
|
|
|
if ($.trim(lines[i]).length == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip control lines.
|
|
|
|
if (MARKDOWN_CHARS[$.trim(lines[i])[0]]) {
|
2013-10-01 23:37:33 +00:00
|
|
|
continue;
|
2013-09-30 23:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return getMarkedDown(lines[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMarkedDown(string) {
|
|
|
|
return Markdown.getSanitizingConverter().makeHtml(string || '');
|
|
|
|
}
|
|
|
|
|
2013-09-26 23:59:58 +00:00
|
|
|
function HeaderCtrl($scope, UserService) {
|
|
|
|
$scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) {
|
|
|
|
$scope.user = currentUser;
|
|
|
|
}, true);
|
2013-09-27 23:21:54 +00:00
|
|
|
|
|
|
|
$('#repoSearch').typeahead({
|
|
|
|
name: 'repositories',
|
|
|
|
remote: {
|
2013-10-01 23:39:28 +00:00
|
|
|
url: '/api/find/repository?query=%QUERY',
|
2013-10-01 23:37:33 +00:00
|
|
|
filter: function(data) {
|
|
|
|
var datums = [];
|
|
|
|
for (var i = 0; i < data.repositories.length; ++i) {
|
|
|
|
var repo = data.repositories[i];
|
|
|
|
datums.push({
|
|
|
|
'value': repo.name,
|
|
|
|
'tokens': [repo.name, repo.namespace],
|
|
|
|
'repo': repo
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return datums;
|
|
|
|
}
|
2013-09-27 23:21:54 +00:00
|
|
|
},
|
|
|
|
template: function (datum) {
|
2013-10-01 23:37:33 +00:00
|
|
|
template = '<div class="repo-mini-listing">';
|
|
|
|
template += '<i class="icon-hdd icon-large"></i>'
|
|
|
|
template += '<span class="name">' + datum.repo.namespace +'/' + datum.repo.name + '</span>'
|
|
|
|
if (datum.repo.description) {
|
|
|
|
template += '<span class="description">' + getFirstTextLine(datum.repo.description) + '</span>'
|
|
|
|
}
|
|
|
|
|
|
|
|
template += '</div>'
|
|
|
|
return template;
|
2013-09-27 23:21:54 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#repoSearch').on('typeahead:selected', function (e, datum) {
|
|
|
|
$('#repoSearch').typeahead('setQuery', '');
|
|
|
|
document.location = '#/repository/' + datum.repo.namespace + '/' + datum.repo.name
|
|
|
|
});
|
2013-09-26 23:59:58 +00:00
|
|
|
}
|
|
|
|
|
2013-10-02 04:28:24 +00:00
|
|
|
function GuideCtrl($scope, Restangular) {
|
|
|
|
}
|
|
|
|
|
2013-09-24 22:21:14 +00:00
|
|
|
function RepoListCtrl($scope, Restangular) {
|
2013-09-30 23:08:24 +00:00
|
|
|
$scope.getCommentFirstLine = function(commentString) {
|
|
|
|
return getMarkedDown(getFirstTextLine(commentString));
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getMarkedDown = function(string) {
|
|
|
|
if (!string) { return ''; }
|
|
|
|
return getMarkedDown(string);
|
|
|
|
};
|
2013-10-01 20:42:20 +00:00
|
|
|
|
|
|
|
$('.spin').spin();
|
|
|
|
$scope.loading = true;
|
2013-10-02 04:28:24 +00:00
|
|
|
$scope.public_repositories = null;
|
|
|
|
$scope.private_repositories = null;
|
|
|
|
|
|
|
|
// Load the list of personal repositories.
|
|
|
|
var repositoryPrivateFetch = Restangular.all('repository/');
|
|
|
|
repositoryPrivateFetch.getList({'public': false, 'sort': true}).then(function(resp) {
|
|
|
|
$scope.private_repositories = resp.repositories;
|
|
|
|
$scope.loading = !($scope.public_repositories && $scope.private_repositories);
|
|
|
|
});
|
2013-10-01 20:42:20 +00:00
|
|
|
|
2013-10-02 04:28:24 +00:00
|
|
|
// Load the list of public repositories.
|
|
|
|
var options = {'public': true, 'private': false, 'sort': true, 'limit': 10};
|
|
|
|
var repositoryPublicFetch = Restangular.all('repository/');
|
|
|
|
repositoryPublicFetch.getList(options).then(function(resp) {
|
|
|
|
$scope.public_repositories = resp.repositories;
|
|
|
|
$scope.loading = !($scope.public_repositories && $scope.private_repositories);
|
2013-10-01 20:42:20 +00:00
|
|
|
});
|
2013-09-24 22:21:14 +00:00
|
|
|
}
|
|
|
|
|
2013-10-01 23:37:33 +00:00
|
|
|
function LandingCtrl($scope, $timeout, Restangular, UserService) {
|
|
|
|
$('.form-signup').popover();
|
2013-10-02 02:13:43 +00:00
|
|
|
$('.spin').spin();
|
2013-09-24 22:21:14 +00:00
|
|
|
|
2013-10-01 23:37:33 +00:00
|
|
|
$scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) {
|
2013-10-02 04:28:24 +00:00
|
|
|
if (!currentUser.anonymous) {
|
|
|
|
$scope.loadMyRepos();
|
|
|
|
}
|
|
|
|
|
2013-10-01 23:37:33 +00:00
|
|
|
$scope.user = currentUser;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
$scope.awaitingConfirmation = false;
|
2013-10-02 02:13:43 +00:00
|
|
|
$scope.registering = false;
|
|
|
|
|
2013-10-02 04:28:24 +00:00
|
|
|
$scope.getCommentFirstLine = function(commentString) {
|
|
|
|
return getMarkedDown(getFirstTextLine(commentString));
|
|
|
|
};
|
|
|
|
|
2013-10-02 02:28:39 +00:00
|
|
|
$scope.browseRepos = function() {
|
|
|
|
document.location = '/#/repository';
|
|
|
|
};
|
|
|
|
|
2013-10-01 23:37:33 +00:00
|
|
|
$scope.register = function() {
|
2013-10-02 02:13:43 +00:00
|
|
|
$('.form-signup').popover('hide');
|
|
|
|
$scope.registering = true;
|
|
|
|
|
2013-10-01 23:37:33 +00:00
|
|
|
var newUserPost = Restangular.one('user/');
|
|
|
|
newUserPost.customPOST($scope.newUser).then(function() {
|
|
|
|
$scope.awaitingConfirmation = true;
|
2013-10-02 02:13:43 +00:00
|
|
|
$scope.registering = false;
|
2013-10-01 23:37:33 +00:00
|
|
|
}, function(result) {
|
|
|
|
console.log("Displaying error message.");
|
2013-10-02 02:13:43 +00:00
|
|
|
$scope.registering = false;
|
2013-10-01 23:37:33 +00:00
|
|
|
$scope.registerError = result.data.message;
|
|
|
|
$timeout(function() {
|
|
|
|
$('.form-signup').popover('show');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2013-10-02 04:28:24 +00:00
|
|
|
|
|
|
|
$scope.loadMyRepos = function() {
|
|
|
|
$scope.loadingmyrepos = true;
|
|
|
|
|
|
|
|
// Load the list of repositories.
|
|
|
|
var params = {
|
|
|
|
'limit': 5,
|
|
|
|
'public': false,
|
|
|
|
'sort': true
|
|
|
|
};
|
|
|
|
|
|
|
|
var repositoryFetch = Restangular.all('repository/');
|
|
|
|
repositoryFetch.getList(params).then(function(resp) {
|
|
|
|
$scope.myrepos = resp.repositories;
|
|
|
|
$scope.loadingmyrepos = false;
|
|
|
|
});
|
|
|
|
};
|
2013-09-24 22:21:14 +00:00
|
|
|
}
|
2013-09-26 21:59:20 +00:00
|
|
|
|
|
|
|
function RepoCtrl($scope, Restangular, $routeParams, $rootScope) {
|
2013-09-27 21:01:45 +00:00
|
|
|
var tabs = ['current-image', 'image-history'];
|
|
|
|
|
2013-09-26 21:59:20 +00:00
|
|
|
$rootScope.title = 'Loading...';
|
|
|
|
|
2013-09-27 21:01:45 +00:00
|
|
|
$scope.showTab = function(tabName) {
|
2013-10-01 23:37:33 +00:00
|
|
|
for (var i = 0; i < tabs.length; ++i) {
|
|
|
|
$('#' + tabs[i]).hide();
|
|
|
|
$('#' + tabs[i] + '-tab').removeClass('active');
|
|
|
|
}
|
2013-09-27 21:01:45 +00:00
|
|
|
|
2013-10-01 23:37:33 +00:00
|
|
|
$('#' + tabName).show();
|
|
|
|
$('#' + tabName + '-tab').addClass('active');
|
2013-09-27 21:01:45 +00:00
|
|
|
|
2013-10-01 23:37:33 +00:00
|
|
|
if (tabName == 'image-history') {
|
|
|
|
$scope.listImages();
|
|
|
|
}
|
2013-09-27 21:01:45 +00:00
|
|
|
};
|
|
|
|
|
2013-09-26 21:59:20 +00:00
|
|
|
$scope.editDescription = function() {
|
2013-09-26 23:07:25 +00:00
|
|
|
if (!$scope.repo.can_write) { return; }
|
2013-09-30 23:08:24 +00:00
|
|
|
|
|
|
|
if (!$scope.markdownDescriptionEditor) {
|
2013-10-01 23:37:33 +00:00
|
|
|
var converter = Markdown.getSanitizingConverter();
|
|
|
|
var editor = new Markdown.Editor(converter, '-description');
|
|
|
|
editor.run();
|
|
|
|
$scope.markdownDescriptionEditor = editor;
|
2013-09-30 23:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$('#wmd-input-description')[0].value = $scope.repo.description;
|
2013-09-26 23:07:25 +00:00
|
|
|
$('#editModal').modal({});
|
2013-09-26 21:59:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.saveDescription = function() {
|
2013-09-26 23:07:25 +00:00
|
|
|
$('#editModal').modal('hide');
|
2013-09-30 23:08:24 +00:00
|
|
|
$scope.repo.description = $('#wmd-input-description')[0].value;
|
2013-09-26 23:07:25 +00:00
|
|
|
$scope.repo.put();
|
2013-09-27 19:26:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.parseDate = function(dateString) {
|
|
|
|
return Date.parse(dateString);
|
|
|
|
};
|
2013-09-30 23:08:24 +00:00
|
|
|
|
|
|
|
$scope.getCommentFirstLine = function(commentString) {
|
|
|
|
return getMarkedDown(getFirstTextLine(commentString));
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.getMarkedDown = function(string) {
|
|
|
|
if (!string) { return ''; }
|
|
|
|
return getMarkedDown(string);
|
|
|
|
};
|
2013-09-27 21:01:45 +00:00
|
|
|
|
|
|
|
$scope.listImages = function() {
|
2013-10-01 23:37:33 +00:00
|
|
|
if ($scope.imageHistory) { return; }
|
2013-09-27 21:01:45 +00:00
|
|
|
|
2013-10-02 04:48:03 +00:00
|
|
|
var imageFetch = Restangular.one('repository/' + namespace + '/' + name + '/tag/' + $scope.currentTag.name + '/images');
|
2013-10-01 23:37:33 +00:00
|
|
|
imageFetch.get().then(function(resp) {
|
|
|
|
$scope.imageHistory = resp.images;
|
|
|
|
});
|
2013-09-27 21:01:45 +00:00
|
|
|
};
|
2013-09-26 21:59:20 +00:00
|
|
|
|
2013-10-02 05:05:36 +00:00
|
|
|
$scope.getTagCount = function(repo) {
|
|
|
|
if (!repo) { return 0; }
|
|
|
|
var count = 0;
|
|
|
|
for (var tag in repo.tags) {
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
};
|
|
|
|
|
2013-09-26 21:59:20 +00:00
|
|
|
var namespace = $routeParams.namespace;
|
|
|
|
var name = $routeParams.name;
|
|
|
|
var tag = $routeParams.tag || 'latest';
|
|
|
|
|
2013-10-01 20:42:20 +00:00
|
|
|
$('.spin').spin();
|
|
|
|
$scope.loading = true;
|
|
|
|
|
2013-09-26 21:59:20 +00:00
|
|
|
var repositoryFetch = Restangular.one('repository/' + namespace + '/' + name);
|
|
|
|
repositoryFetch.get().then(function(repo) {
|
2013-09-26 23:07:25 +00:00
|
|
|
$rootScope.title = namespace + '/' + name;
|
|
|
|
$scope.repo = repo;
|
|
|
|
$scope.currentTag = repo.tags[tag] || repo.tags['latest'];
|
2013-09-27 20:12:51 +00:00
|
|
|
|
2013-10-01 20:42:20 +00:00
|
|
|
var clip = new ZeroClipboard($('#copyClipboard'), { 'moviePath': 'static/lib/ZeroClipboard.swf' });
|
|
|
|
clip.on('complete', function() {
|
2013-10-01 23:37:33 +00:00
|
|
|
// Resets the animation.
|
|
|
|
var elem = $('#clipboardCopied')[0];
|
|
|
|
elem.style.display = 'none';
|
|
|
|
|
|
|
|
// Show the notification.
|
|
|
|
setTimeout(function() {
|
|
|
|
elem.style.display = 'block';
|
|
|
|
}, 1);
|
2013-10-01 20:42:20 +00:00
|
|
|
});
|
2013-09-27 20:28:21 +00:00
|
|
|
|
2013-10-01 20:42:20 +00:00
|
|
|
$scope.loading = false;
|
2013-09-26 21:59:20 +00:00
|
|
|
}, function() {
|
2013-09-26 23:07:25 +00:00
|
|
|
$scope.repo = null;
|
2013-10-01 20:42:20 +00:00
|
|
|
$scope.loading = false;
|
2013-09-26 23:07:25 +00:00
|
|
|
$rootScope.title = 'Unknown Repository';
|
2013-09-26 21:59:20 +00:00
|
|
|
});
|
2013-09-26 23:59:58 +00:00
|
|
|
}
|
2013-09-27 00:34:58 +00:00
|
|
|
|
2013-09-27 19:26:16 +00:00
|
|
|
function RepoAdminCtrl($scope, Restangular, $routeParams, $rootScope) {
|
|
|
|
var namespace = $routeParams.namespace;
|
|
|
|
var name = $routeParams.name;
|
|
|
|
|
2013-10-01 20:42:20 +00:00
|
|
|
$('#userSearch').typeahead({
|
2013-10-01 23:37:33 +00:00
|
|
|
name: 'users',
|
|
|
|
remote: {
|
|
|
|
url: '/api/users/%QUERY',
|
|
|
|
filter: function(data) {
|
|
|
|
var datums = [];
|
|
|
|
for (var i = 0; i < data.users.length; ++i) {
|
|
|
|
var user = data.users[i];
|
|
|
|
datums.push({
|
|
|
|
'value': user,
|
|
|
|
'tokens': [user],
|
|
|
|
'username': user
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return datums;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
template: function (datum) {
|
|
|
|
template = '<div class="user-mini-listing">';
|
|
|
|
template += '<i class="icon-user icon-large"></i>'
|
|
|
|
template += '<span class="name">' + datum.username + '</span>'
|
|
|
|
template += '</div>'
|
|
|
|
return template;
|
|
|
|
},
|
2013-09-28 05:23:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#userSearch').on('typeahead:selected', function(e, datum) {
|
2013-10-01 23:37:33 +00:00
|
|
|
$('#userSearch').typeahead('setQuery', '');
|
|
|
|
$scope.addNewPermission(datum.username);
|
2013-09-28 05:23:00 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$scope.addNewPermission = function(username) {
|
|
|
|
// Don't allow duplicates.
|
|
|
|
if ($scope.permissions[username]) { return; }
|
|
|
|
|
|
|
|
// Need the $scope.apply for both the permission stuff to change and for
|
|
|
|
// the XHR call to be made.
|
|
|
|
$scope.$apply(function() {
|
2013-10-01 23:37:33 +00:00
|
|
|
$scope.addRole(username, 'read')
|
2013-09-28 05:23:00 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteRole = function(username) {
|
|
|
|
var permissionDelete = Restangular.one('repository/' + namespace + '/' + name + '/permissions/' + username);
|
|
|
|
permissionDelete.customDELETE().then(function() {
|
2013-10-01 23:37:33 +00:00
|
|
|
delete $scope.permissions[username];
|
2013-09-28 05:23:00 +00:00
|
|
|
}, function(result) {
|
2013-10-01 23:37:33 +00:00
|
|
|
if (result.status == 409) {
|
|
|
|
$('#onlyadminModal').modal({});
|
|
|
|
} else {
|
|
|
|
$('#cannotchangeModal').modal({});
|
|
|
|
}
|
2013-09-28 05:23:00 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.addRole = function(username, role) {
|
|
|
|
var permission = {
|
2013-10-01 23:37:33 +00:00
|
|
|
'role': role
|
2013-09-28 05:23:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var permissionPost = Restangular.one('repository/' + namespace + '/' + name + '/permissions/' + username);
|
|
|
|
permissionPost.customPOST(permission).then(function() {
|
2013-10-01 23:37:33 +00:00
|
|
|
$scope.permissions[username] = permission;
|
|
|
|
$scope.permissions = $scope.permissions;
|
2013-09-28 05:23:00 +00:00
|
|
|
}, function(result) {
|
2013-10-01 23:37:33 +00:00
|
|
|
$('#cannotchangeModal').modal({});
|
2013-09-28 05:23:00 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-09-27 19:26:16 +00:00
|
|
|
$scope.setRole = function(username, role) {
|
|
|
|
var permission = $scope.permissions[username];
|
2013-09-28 05:23:00 +00:00
|
|
|
var currentRole = permission.role;
|
2013-09-27 19:26:16 +00:00
|
|
|
permission.role = role;
|
2013-09-28 05:23:00 +00:00
|
|
|
|
2013-09-27 19:26:16 +00:00
|
|
|
var permissionPut = Restangular.one('repository/' + namespace + '/' + name + '/permissions/' + username);
|
2013-09-27 19:48:54 +00:00
|
|
|
permissionPut.customPUT(permission).then(function() {}, function(result) {
|
2013-10-01 23:37:33 +00:00
|
|
|
if (result.status == 409) {
|
|
|
|
permission.role = currentRole;
|
|
|
|
$('#onlyadminModal').modal({});
|
|
|
|
} else {
|
|
|
|
$('#cannotchangeModal').modal({});
|
|
|
|
}
|
2013-09-27 19:48:54 +00:00
|
|
|
});
|
2013-09-27 19:26:16 +00:00
|
|
|
};
|
|
|
|
|
2013-09-28 21:11:10 +00:00
|
|
|
$scope.askChangeAccess = function(newAccess) {
|
2013-10-01 23:37:33 +00:00
|
|
|
$('#make' + newAccess + 'Modal').modal({});
|
2013-09-28 21:11:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.changeAccess = function(newAccess) {
|
2013-10-01 23:37:33 +00:00
|
|
|
$('#make' + newAccess + 'Modal').modal('hide');
|
|
|
|
|
|
|
|
var visibility = {
|
|
|
|
'visibility': newAccess
|
|
|
|
};
|
|
|
|
var visibilityPost = Restangular.one('repository/' + namespace + '/' + name + '/changevisibility');
|
|
|
|
visibilityPost.customPOST(visibility).then(function() {
|
|
|
|
$scope.repo.is_public = newAccess == 'public';
|
|
|
|
}, function() {
|
|
|
|
$('#cannotchangeModal').modal({});
|
|
|
|
});
|
2013-09-28 21:11:10 +00:00
|
|
|
};
|
|
|
|
|
2013-10-01 18:14:30 +00:00
|
|
|
$scope.askDelete = function() {
|
2013-10-01 23:37:33 +00:00
|
|
|
$('#confirmdeleteModal').modal({});
|
2013-10-01 18:14:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.deleteRepo = function() {
|
2013-10-01 23:37:33 +00:00
|
|
|
$('#confirmdeleteModal').modal('hide');
|
|
|
|
|
|
|
|
var deleteAction = Restangular.one('repository/' + namespace + '/' + name);
|
|
|
|
deleteAction.customDELETE().then(function() {
|
|
|
|
$scope.repo = null;
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
document.location = '/#/repository';
|
|
|
|
}, 1000);
|
|
|
|
}, function() {
|
|
|
|
$('#cannotchangeModal').modal({});
|
|
|
|
});
|
2013-10-01 18:14:30 +00:00
|
|
|
};
|
2013-10-02 05:05:36 +00:00
|
|
|
|
2013-10-01 20:42:20 +00:00
|
|
|
$('.spin').spin();
|
|
|
|
$scope.loading = true;
|
2013-10-01 18:14:30 +00:00
|
|
|
|
2013-09-28 21:11:10 +00:00
|
|
|
// Fetch the repository information.
|
|
|
|
var repositoryFetch = Restangular.one('repository/' + namespace + '/' + name);
|
|
|
|
repositoryFetch.get().then(function(repo) {
|
|
|
|
$scope.repo = repo;
|
2013-10-01 20:42:20 +00:00
|
|
|
$scope.loading = !($scope.permissions && $scope.repo);
|
|
|
|
}, function() {
|
|
|
|
$scope.permissions = null;
|
|
|
|
$rootScope.title = 'Unknown Repository';
|
|
|
|
$scope.loading = false;
|
2013-09-28 21:11:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Fetch the permissions.
|
2013-09-27 19:26:16 +00:00
|
|
|
var permissionsFetch = Restangular.one('repository/' + namespace + '/' + name + '/permissions');
|
|
|
|
permissionsFetch.get().then(function(resp) {
|
2013-09-28 05:23:00 +00:00
|
|
|
$rootScope.title = 'Settings - ' + namespace + '/' + name;
|
2013-09-27 19:26:16 +00:00
|
|
|
$scope.permissions = resp.permissions;
|
2013-10-01 20:42:20 +00:00
|
|
|
$scope.loading = !($scope.permissions && $scope.repo);
|
2013-09-27 19:26:16 +00:00
|
|
|
}, function() {
|
|
|
|
$scope.permissions = null;
|
|
|
|
$rootScope.title = 'Unknown Repository';
|
2013-10-01 20:42:20 +00:00
|
|
|
$scope.loading = false;
|
2013-09-27 19:26:16 +00:00
|
|
|
});
|
2013-10-02 04:48:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function UserAdminCtrl($scope, Restangular) {
|
|
|
|
$scope.plans = [
|
|
|
|
{
|
|
|
|
title: 'Micro',
|
|
|
|
price: 700,
|
|
|
|
privateRepos: 5,
|
|
|
|
stripeId: 'micro',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Small',
|
|
|
|
price: 1200,
|
|
|
|
privateRepos: 10,
|
|
|
|
stripeId: 'small',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Medium',
|
|
|
|
price: 2200,
|
|
|
|
privateRepos: 20,
|
|
|
|
stripeId: 'medium',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
var planDict = {};
|
|
|
|
var i;
|
|
|
|
for(i = 0; i < $scope.plans.length; i++) {
|
|
|
|
planDict[$scope.plans[i].stripeId] = $scope.plans[i];
|
|
|
|
}
|
|
|
|
|
2013-10-02 05:03:48 +00:00
|
|
|
$('.spin').spin();
|
|
|
|
|
2013-10-02 05:40:11 +00:00
|
|
|
var subscribedToPlan = function(sub) {
|
2013-10-02 04:48:03 +00:00
|
|
|
$scope.subscription = sub;
|
2013-10-02 05:40:11 +00:00
|
|
|
$scope.subscribedPlan = planDict[sub.plan];
|
|
|
|
$scope.planUsagePercent = sub.usedPrivateRepos * 100 / $scope.subscribedPlan.privateRepos;
|
|
|
|
$scope.planLoading = false;
|
2013-10-02 06:05:53 +00:00
|
|
|
$scope.planChanging = false;
|
2013-10-02 05:40:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.planLoading = true;
|
|
|
|
var getSubscription = Restangular.one('user/plan');
|
|
|
|
getSubscription.get().then(subscribedToPlan, function() {
|
|
|
|
// User has no subscription
|
|
|
|
$scope.planLoading = false;
|
2013-10-02 04:48:03 +00:00
|
|
|
});
|
|
|
|
|
2013-10-02 06:05:53 +00:00
|
|
|
$scope.planChanging = false;
|
2013-10-02 04:48:03 +00:00
|
|
|
$scope.subscribe = function(planId) {
|
|
|
|
var submitToken = function(token) {
|
|
|
|
$scope.$apply(function() {
|
2013-10-02 06:05:53 +00:00
|
|
|
$scope.planChanging = true;
|
|
|
|
$scope.errorMessage = undefined;
|
|
|
|
|
2013-10-02 04:48:03 +00:00
|
|
|
var subscriptionDetails = {
|
|
|
|
token: token.id,
|
|
|
|
plan: planId,
|
|
|
|
};
|
|
|
|
|
|
|
|
console.log(subscriptionDetails);
|
|
|
|
|
|
|
|
var createSubscriptionRequest = Restangular.one('user/plan');
|
2013-10-02 05:40:11 +00:00
|
|
|
createSubscriptionRequest.customPUT(subscriptionDetails).then(subscribedToPlan, function() {
|
2013-10-02 04:48:03 +00:00
|
|
|
// Failure
|
2013-10-02 06:05:53 +00:00
|
|
|
$scope.errorMessage = 'Unable to subscribe.';
|
2013-10-02 04:48:03 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
console.log('Got request for plan: ' + planId);
|
|
|
|
var planDetails = planDict[planId]
|
|
|
|
StripeCheckout.open({
|
|
|
|
key: 'pk_test_uEDHANKm9CHCvVa2DLcipGRh',
|
|
|
|
address: false, // TODO change to true
|
|
|
|
amount: planDetails.price,
|
|
|
|
currency: 'usd',
|
|
|
|
name: 'Quay ' + planDetails.title + ' Subscription',
|
|
|
|
description: 'Up to ' + planDetails.privateRepos + ' private repositories',
|
|
|
|
panelLabel: 'Subscribe',
|
|
|
|
token: submitToken
|
|
|
|
});
|
|
|
|
};
|
2013-10-02 06:05:53 +00:00
|
|
|
|
|
|
|
$scope.changeSubscription = function(planId) {
|
|
|
|
$scope.planChanging = true;
|
|
|
|
$scope.errorMessage = undefined;
|
|
|
|
|
|
|
|
var subscriptionDetails = {
|
|
|
|
plan: planId,
|
|
|
|
};
|
|
|
|
|
|
|
|
var changeSubscriptionRequest = Restangular.one('user/plan');
|
|
|
|
changeSubscriptionRequest.customPUT(subscriptionDetails).then(subscribedToPlan, function() {
|
|
|
|
// Failure
|
|
|
|
$scope.errorMessage = 'Unable to change subscription.';
|
|
|
|
$scope.planChanging = false;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.cancelSubscription = function() {
|
|
|
|
$scope.planChanging = true;
|
|
|
|
$scope.errorMessage = undefined;
|
|
|
|
var unsubscribeRequest = Restangular.one('user/plan');
|
|
|
|
unsubscribeRequest.customDELETE().then(function() {
|
|
|
|
$scope.subscription = undefined;
|
|
|
|
$scope.subscribedPlan = undefined;
|
|
|
|
$scope.planUsagePercent = 0;
|
|
|
|
$scope.planChanging = false;
|
|
|
|
}, function() {
|
|
|
|
// Failure
|
|
|
|
$scope.errorMessage = 'Unable to unsubscribe.';
|
|
|
|
$scope.planChanging = false;
|
|
|
|
});
|
|
|
|
};
|
2013-09-27 00:34:58 +00:00
|
|
|
}
|