From 9d26c79db088010de8b0382c1fe8a8a2f924ea39 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 15 Jan 2014 19:15:38 -0500 Subject: [PATCH] Better messaging in create repo --- endpoints/api.py | 6 ++++-- static/js/app.js | 13 ++++++++++++- static/js/controllers.js | 8 +++++++- static/partials/new-repo.html | 2 ++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/endpoints/api.py b/endpoints/api.py index 383f85ad5..530672d87 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -146,7 +146,8 @@ def user_view(user): 'name': o.username, 'gravatar': compute_hash(o.email), 'is_org_admin': admin_org.can(), - 'can_create_repo': admin_org.can() or CreateRepositoryPermission(o.username).can() + 'can_create_repo': admin_org.can() or CreateRepositoryPermission(o.username).can(), + 'preferred_namespace': not (o.stripe_id is None) } organizations = model.get_user_organizations(user.username) @@ -169,7 +170,8 @@ def user_view(user): 'organizations': [org_view(o) for o in organizations], 'logins': [login_view(login) for login in logins], 'can_create_repo': True, - 'invoice_email': user.invoice_email + 'invoice_email': user.invoice_email, + 'preferred_namespace': not (user.stripe_id is None) } diff --git a/static/js/app.js b/static/js/app.js index da399eb04..ba105f079 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -2167,15 +2167,20 @@ quayApp.directive('namespaceSelector', function () { $scope.namespaces = {}; $scope.initialize = function(user) { + var preferredNamespace = user.username; var namespaces = {}; namespaces[user.username] = user; if (user.organizations) { for (var i = 0; i < user.organizations.length; ++i) { namespaces[user.organizations[i].name] = user.organizations[i]; + if (user.organizations[i].preferred_namespace) { + preferredNamespace = user.organizations[i].name; + } } } - var initialNamespace = $routeParams['namespace'] || CookieService.get('quay.namespace') || $scope.user.username; + var initialNamespace = $routeParams['namespace'] || CookieService.get('quay.namespace') || + preferredNamespace || $scope.user.username; $scope.namespaces = namespaces; $scope.setNamespace($scope.namespaces[initialNamespace]); }; @@ -2198,6 +2203,12 @@ quayApp.directive('namespaceSelector', function () { } }; + $scope.$watch('namespace', function(namespace) { + if ($scope.namespaceObj && namespace && namespace != $scope.namespaceObj.username) { + $scope.setNamespace($scope.namespaces[namespace]); + } + }); + $scope.$watch('user', function(user) { $scope.user = user; $scope.initialize(user); diff --git a/static/js/controllers.js b/static/js/controllers.js index 268a23fe6..b9114a236 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -878,7 +878,8 @@ function RepoAdminCtrl($scope, Restangular, ApiService, $routeParams, $rootScope fetchRepository(); } -function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, UserService, KeyService, $routeParams, $http) { +function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, UserService, CookieService, KeyService, + $routeParams, $http) { if ($routeParams['migrate']) { $('#migrateTab').tab('show') } @@ -956,6 +957,7 @@ function UserAdminCtrl($scope, $timeout, $location, ApiService, PlanService, Use }; ApiService.convertUserToOrganization(data).then(function(resp) { + CookieService.putPermanent('quay.namespace', $scope.cuser.username); UserService.load(); $location.path('/'); }, function(resp) { @@ -1168,6 +1170,10 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, ApiService } }); + $scope.changeNamespace = function(namespace) { + $scope.repo.namespace = namespace; + }; + $scope.createNewRepo = function() { $('#repoName').popover('hide'); diff --git a/static/partials/new-repo.html b/static/partials/new-repo.html index 3f61d9c7e..30d686525 100644 --- a/static/partials/new-repo.html +++ b/static/partials/new-repo.html @@ -81,6 +81,8 @@ This will cost ${{ planRequired.price / 100 }}/month. Upgrade now + or did you mean to create this repository + under {{ user.organizations[0].name }}?