Merge branch 'master' of ssh://bitbucket.org/yackob03/quay

This commit is contained in:
yackob03 2013-11-11 18:05:29 -05:00
commit 6be20ff626
4 changed files with 76 additions and 56 deletions

View file

@ -347,6 +347,7 @@ def get_organization(orgname):
is_admin = admin_org.can() is_admin = admin_org.can()
return { return {
'name': o.username, 'name': o.username,
'email': o.email if is_admin else '',
'gravatar': compute_hash(o.email), 'gravatar': compute_hash(o.email),
'teams': {t.name : team_view(orgname, t) for t in teams}, 'teams': {t.name : team_view(orgname, t) for t in teams},
'is_admin': is_admin 'is_admin': is_admin

View file

@ -48,7 +48,7 @@ function getMarkedDown(string) {
// Start the application code itself. // Start the application code itself.
quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics', 'angulartics.mixpanel', '$strap.directives', 'ngCookies'], function($provide) { quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics', 'angulartics.mixpanel', '$strap.directives', 'ngCookies'], function($provide) {
$provide.factory('UserService', ['Restangular', 'PlanService', function(Restangular, PlanService) { $provide.factory('UserService', ['Restangular', function(Restangular) {
var userResponse = { var userResponse = {
verified: false, verified: false,
anonymous: true, anonymous: true,
@ -59,7 +59,6 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
} }
var userService = {} var userService = {}
var currentSubscription = null;
userService.load = function() { userService.load = function() {
var userFetch = Restangular.one('user/'); var userFetch = Restangular.one('user/');
@ -80,21 +79,21 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
}); });
}; };
userService.resetCurrentSubscription = function() { userService.getOrganization = function(name) {
currentSubscription = null; if (!userResponse || !userResponse.organizations) { return null; }
}; for (var i = 0; i < userResponse.organizations.length; ++i) {
var org = userResponse.organizations[i];
if (org.name == name) {
return org;
}
}
userService.getCurrentSubscription = function(callback, failure) { return null;
if (currentSubscription) { callback(currentSubscription); }
PlanService.getSubscription(null, function(sub) {
currentSubscription = sub;
callback(sub);
}, failure);
}; };
userService.currentUser = function() { userService.currentUser = function() {
return userResponse; return userResponse;
} };
// Load the user the first time. // Load the user the first time.
userService.load(); userService.load();
@ -116,7 +115,7 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
return keyService; return keyService;
}]); }]);
$provide.factory('PlanService', ['Restangular', 'KeyService', function(Restangular, KeyService) { $provide.factory('PlanService', ['Restangular', 'KeyService', 'UserService', function(Restangular, KeyService, UserService) {
var plans = null; var plans = null;
var planDict = {}; var planDict = {};
var planService = {} var planService = {}
@ -213,37 +212,60 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
createSubscriptionRequest.customPUT(subscriptionDetails).then(success, failure); createSubscriptionRequest.customPUT(subscriptionDetails).then(success, failure);
}; };
planService.changePlan = function($scope, orgname, planId, hasExistingSubscription, started, success, failure) { planService.changePlan = function($scope, orgname, planId, hasExistingSubscription, callbacks) {
if (!hasExistingSubscription) { if (!hasExistingSubscription) {
planService.showSubscribeDialog($scope, orgname, planId, started, success, failure); planService.showSubscribeDialog($scope, orgname, planId, callbacks);
return; return;
} }
started(); if (callbacks['started']) {
planService.setSubscription(orgname, planId, success, failure); callbacks['started']();
}
planService.setSubscription(orgname, planId, callbacks['success'], callbacks['failure']);
}; };
planService.showSubscribeDialog = function($scope, orgname, planId, started, success, failure) { planService.showSubscribeDialog = function($scope, orgname, planId, callbacks) {
if (callbacks['opening']) {
callbacks['opening']();
}
var submitToken = function(token) { var submitToken = function(token) {
mixpanel.track('plan_subscribe'); mixpanel.track('plan_subscribe');
$scope.$apply(function() { $scope.$apply(function() {
started(); if (callbacks['started']) {
planService.setSubscription(orgname, planId, success, failure); callbacks['started']();
}
planService.setSubscription(orgname, planId, callbacks['success'], callbacks['failure']);
}); });
}; };
planService.getPlan(planId, function(planDetails) { planService.getPlan(planId, function(planDetails) {
var email = null;
if (UserService.currentUser()) {
email = UserService.currentUser().email;
if (orgname) {
org = UserService.getOrganization(orgname);
if (org) {
emaiil = org.email;
}
}
}
StripeCheckout.open({ StripeCheckout.open({
key: KeyService.stripePublishableKey, key: KeyService.stripePublishableKey,
address: false, address: false,
email: email,
amount: planDetails.price, amount: planDetails.price,
currency: 'usd', currency: 'usd',
name: 'Quay ' + planDetails.title + ' Subscription', name: 'Quay ' + planDetails.title + ' Subscription',
description: 'Up to ' + planDetails.privateRepos + ' private repositories', description: 'Up to ' + planDetails.privateRepos + ' private repositories',
panelLabel: 'Subscribe', panelLabel: 'Subscribe',
token: submitToken, token: submitToken,
image: 'static/img/quay-icon-stripe.png' image: 'static/img/quay-icon-stripe.png',
opened: function() { $scope.$apply(function() { callbacks['opened']() }); },
closed: function() { $scope.$apply(function() { callbacks['closed']() }); }
}); });
}); });
}; };
@ -617,16 +639,16 @@ quayApp.directive('planManager', function () {
$scope.changeSubscription = function(planId) { $scope.changeSubscription = function(planId) {
if ($scope.planChanging) { return; } if ($scope.planChanging) { return; }
PlanService.changePlan($scope, $scope.organization, planId, hasSubscription, function() { var callbacks = {
// Started. 'opening': function() { $scope.planChanging = true; },
$scope.planChanging = true; 'started': function() { $scope.planChanging = true; },
}, function(sub) { 'opened': function() { $scope.planChanging = true; },
// Success. 'closed': function() { $scope.planChanging = false; },
subscribedToPlan(sub); 'success': subscribedToPlan,
}, function() { 'failure': function() { $scope.planChanging = false; }
// Failure. };
$scope.planChanging = false;
}); PlanService.changePlan($scope, $scope.organization, planId, hasSubscription, callbacks);
}; };
$scope.cancelSubscription = function() { $scope.cancelSubscription = function() {

View file

@ -1038,18 +1038,14 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula
}; };
$scope.upgradePlan = function() { $scope.upgradePlan = function() {
PlanService.changePlan($scope, null, $scope.planRequired.stripeId, null, function() { var callbacks = {
// Subscribing. 'opened': function() { $scope.planChanging = true; },
$scope.planChanging = true; 'closed': function() { $scope.planChanging = false; },
}, function(plan) { 'success': subscribedToPlan,
// Subscribed. 'failure': function() { $('#couldnotsubscribeModal').modal(); $scope.planChanging = false; }
UserService.resetCurrentSubscription(); };
subscribedToPlan(plan);
}, function() { PlanService.changePlan($scope, null, $scope.planRequired.stripeId, null, callbacks);
// Failure.
$('#couldnotsubscribeModal').modal();
$scope.planChanging = false;
});
}; };
// Watch the namespace on the repo. If it changes, we update the plan and the public/private // Watch the namespace on the repo. If it changes, we update the plan and the public/private
@ -1067,7 +1063,7 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula
if (isUserNamespace) { if (isUserNamespace) {
// Load the user's subscription information in case they want to create a private // Load the user's subscription information in case they want to create a private
// repository. // repository.
UserService.getCurrentSubscription(subscribedToPlan, function() { PlanService.getSubscription(null, subscribedToPlan, function() {
PlanService.getMinimumPlan(1, false, function(minimum) { $scope.planRequired = minimum; }); PlanService.getMinimumPlan(1, false, function(minimum) { $scope.planRequired = minimum; });
}); });
} else { } else {
@ -1365,24 +1361,25 @@ function NewOrgCtrl($scope, $routeParams, $timeout, $location, UserService, Plan
// Reset the organizations list. // Reset the organizations list.
UserService.load(); UserService.load();
var showOrg = function() {
$location.path('/organization/' + org.name + '/');
};
// If the selected plan is free, simply move to the org page. // If the selected plan is free, simply move to the org page.
if ($scope.currentPlan.price == 0) { if ($scope.currentPlan.price == 0) {
$location.path('/organization/' + org.name + '/'); showOrg();
return; return;
} }
// Otherwise, show the subscribe for the plan. // Otherwise, show the subscribe for the plan.
PlanService.changePlan($scope, org.name, $scope.currentPlan.stripeId, false, function() { var callbacks = {
// Started. 'opened': function() { $scope.creating = true; },
$scope.creating = true; 'closed': showOrg,
}, function(sub) { 'success': showOrg,
// Success. 'failure': showOrg
$location.path('/organization/' + org.name + '/'); };
}, function() {
// Failure.
$location.path('/organization/' + org.name + '/');
});
PlanService.changePlan($scope, org.name, $scope.currentPlan.stripeId, false, callbacks);
}, function(result) { }, function(result) {
$scope.creating = false; $scope.creating = false;
$scope.createError = result.data.message || result.data; $scope.createError = result.data.message || result.data;

View file

@ -16,7 +16,7 @@
{% endblock %} {% endblock %}
{% block added_dependencies %} {% block added_dependencies %}
<script src="https://checkout.stripe.com/v2/checkout.js"></script> <script src="https://checkout.stripe.com/checkout.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.2.1/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.3.3/d3.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.3.3/d3.min.js"></script>