Note: This badge contains a token so the badge can be seen by external users. The token does not grant any other access and is safe to share!
diff --git a/static/js/directives/ui/repo-count-checker.js b/static/js/directives/ui/repo-count-checker.js
new file mode 100644
index 000000000..9cec0f1c4
--- /dev/null
+++ b/static/js/directives/ui/repo-count-checker.js
@@ -0,0 +1,81 @@
+/**
+ * An element which displays a message when the maximum number of private repositories has been
+ * reached.
+ */
+angular.module('quay').directive('repoCountChecker', function () {
+ var directiveDefinitionObject = {
+ priority: 0,
+ templateUrl: '/static/directives/repo-count-checker.html',
+ replace: false,
+ transclude: true,
+ restrict: 'C',
+ scope: {
+ 'namespace': '=namespace',
+ 'planRequired': '=planRequired',
+ 'isEnabled': '=isEnabled'
+ },
+ controller: function($scope, $element, ApiService, UserService, PlanService, Features) {
+ var refresh = function() {
+ $scope.planRequired = null;
+
+ if (!$scope.isEnabled || !$scope.namespace || !Features.BILLING) {
+ return;
+ }
+
+ $scope.checkingPlan = true;
+ $scope.isUserNamespace = UserService.isUserNamespace($scope.namespace);
+
+ ApiService.getPrivateAllowed($scope.isUserNamespace ? null : $scope.namespace).then(function(resp) {
+ $scope.checkingPlan = false;
+
+ if (resp['privateAllowed']) {
+ $scope.planRequired = null;
+ return;
+ }
+
+ if (resp['privateCount'] == null) {
+ // Organization where we are not the admin.
+ $scope.planRequired = {};
+ return;
+ }
+
+ // Otherwise, lookup the matching plan.
+ PlanService.getMinimumPlan(resp['privateCount'] + 1, !$scope.isUserNamespace, function(minimum) {
+ $scope.planRequired = minimum;
+ });
+ });
+ };
+
+ var subscribedToPlan = function(sub) {
+ $scope.planChanging = false;
+ $scope.subscription = sub;
+
+ PlanService.getPlan(sub.plan, function(subscribedPlan) {
+ $scope.subscribedPlan = subscribedPlan;
+ refresh();
+ });
+ };
+
+ $scope.$watch('namespace', refresh);
+ $scope.$watch('isEnabled', refresh);
+
+ $scope.upgradePlan = function() {
+ var callbacks = {
+ 'started': function() { $scope.planChanging = true; },
+ 'opened': function() { $scope.planChanging = true; },
+ 'closed': function() { $scope.planChanging = false; },
+ 'success': subscribedToPlan,
+ 'failure': function(resp) {
+ $('#couldnotsubscribeModal').modal();
+ $scope.planChanging = false;
+ }
+ };
+
+ var isUserNamespace = UserService.isUserNamespace($scope.namespace);
+ var namespace = isUserNamespace ? null : $scope.namespace;
+ PlanService.changePlan($scope, namespace, $scope.planRequired.stripeId, callbacks);
+ };
+ }
+ };
+ return directiveDefinitionObject;
+});
\ No newline at end of file
diff --git a/static/js/pages/new-repo.js b/static/js/pages/new-repo.js
index a4145d735..2e532ab9b 100644
--- a/static/js/pages/new-repo.js
+++ b/static/js/pages/new-repo.js
@@ -22,22 +22,6 @@
'initialize': ''
};
- // Watch the namespace on the repo. If it changes, we update the plan and the public/private
- // accordingly.
- $scope.isUserNamespace = true;
- $scope.$watch('repo.namespace', function(namespace) {
- // Note: Can initially be undefined.
- if (!namespace) { return; }
-
- var isUserNamespace = (namespace == $scope.user.username);
-
- $scope.planRequired = null;
- $scope.isUserNamespace = isUserNamespace;
-
- // Determine whether private repositories are allowed for the namespace.
- checkPrivateAllowed();
- });
-
$scope.changeNamespace = function(namespace) {
$scope.repo.namespace = namespace;
};
@@ -108,65 +92,5 @@
});
});
};
-
- $scope.upgradePlan = function() {
- var callbacks = {
- 'started': function() { $scope.planChanging = true; },
- 'opened': function() { $scope.planChanging = true; },
- 'closed': function() { $scope.planChanging = false; },
- 'success': subscribedToPlan,
- 'failure': function(resp) {
- $('#couldnotsubscribeModal').modal();
- $scope.planChanging = false;
- }
- };
-
- var namespace = $scope.isUserNamespace ? null : $scope.repo.namespace;
- PlanService.changePlan($scope, namespace, $scope.planRequired.stripeId, callbacks);
- };
-
- var checkPrivateAllowed = function() {
- if (!$scope.repo || !$scope.repo.namespace) { return; }
-
- if (!Features.BILLING) {
- $scope.checkingPlan = false;
- $scope.planRequired = null;
- return;
- }
-
- $scope.checkingPlan = true;
-
- var isUserNamespace = $scope.isUserNamespace;
- ApiService.getPrivateAllowed(isUserNamespace ? null : $scope.repo.namespace).then(function(resp) {
- $scope.checkingPlan = false;
-
- if (resp['privateAllowed']) {
- $scope.planRequired = null;
- return;
- }
-
- if (resp['privateCount'] == null) {
- // Organization where we are not the admin.
- $scope.planRequired = {};
- return;
- }
-
- // Otherwise, lookup the matching plan.
- PlanService.getMinimumPlan(resp['privateCount'] + 1, !isUserNamespace, function(minimum) {
- $scope.planRequired = minimum;
- });
- });
- };
-
- var subscribedToPlan = function(sub) {
- $scope.planChanging = false;
- $scope.subscription = sub;
-
- PlanService.getPlan(sub.plan, function(subscribedPlan) {
- $scope.subscribedPlan = subscribedPlan;
- $scope.planRequired = null;
- checkPrivateAllowed();
- });
- };
}
})();
\ No newline at end of file
diff --git a/static/js/services/user-service.js b/static/js/services/user-service.js
index d6bce37cc..10e5460f2 100644
--- a/static/js/services/user-service.js
+++ b/static/js/services/user-service.js
@@ -126,6 +126,10 @@ function(ApiService, CookieService, $rootScope, Config) {
return userResponse;
};
+ userService.isUserNamespace = function(namespace) {
+ return namespace == userResponse.username;
+ };
+
// Update the user in the root scope.
userService.updateUserIn($rootScope);
diff --git a/static/partials/new-repo.html b/static/partials/new-repo.html
index a8975e747..03a034e84 100644
--- a/static/partials/new-repo.html
+++ b/static/partials/new-repo.html
@@ -88,31 +88,9 @@
-
-
- In order to make this repository private under
- your personal namespace
- organization {{ repo.namespace }}, you will need to upgrade your plan to
-
- {{ planRequired.title }}
- .
- This will cost ${{ planRequired.price / 100 }}/month.
-
-
Upgrade now
-
or did you mean to create this repository
- under {{ user.organizations[0].name }}?
-
+
-
-
-
-
-
- This organization has reached its private repository limit. Please contact your administrator.
-
-
-