From 20284f57f330bd6158966da59044958ab50def28 Mon Sep 17 00:00:00 2001 From: EvB Date: Fri, 26 May 2017 14:27:28 -0400 Subject: [PATCH] fix(user-service): make sync calls to update user async --- static/js/services/user-service.js | 37 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/static/js/services/user-service.js b/static/js/services/user-service.js index 7cc8388c9..d9bc0f9a0 100644 --- a/static/js/services/user-service.js +++ b/static/js/services/user-service.js @@ -3,9 +3,9 @@ * about the user. */ angular.module('quay') - .factory('UserService', ['ApiService', 'CookieService', '$rootScope', 'Config', '$location', + .factory('UserService', ['ApiService', 'CookieService', '$rootScope', 'Config', '$location', '$timeout', -function(ApiService, CookieService, $rootScope, Config, $location) { +function(ApiService, CookieService, $rootScope, Config, $location, $timeout) { var userResponse = { verified: false, anonymous: true, @@ -25,10 +25,14 @@ function(ApiService, CookieService, $rootScope, Config, $location) { userService.updateUserIn = function(scope, opt_callback) { scope.$watch(function () { return userService.currentUser(); }, function (currentUser) { - scope.user = currentUser; - if (opt_callback) { - opt_callback(currentUser); - } + if (currentUser) { + $timeout(function(){ + scope.user = currentUser; + if (opt_callback) { + opt_callback(currentUser); + } + }, 0, false); + }; }, true); }; @@ -185,25 +189,20 @@ function(ApiService, CookieService, $rootScope, Config, $location) { var deleteNamespaceItself = function() { info.progress = 1; info.progressMessage = 'Deleting namespace...'; - - if (info.user) { - ApiService.deleteCurrentUser().then(function(resp) { - // Reload the user. - userService.load(); + var cb = function(resp) { + userService.load(function(currentUser) { callback(true); $location.path('/'); - }, errorDisplay); + }); + } + + if (info.user) { + ApiService.deleteCurrentUser().then(cb, errorDisplay) } else { var delParams = { 'orgname': info.organization.name }; - - ApiService.deleteAdminedOrganization(null, delParams).then(function(resp) { - // Reload the user. - userService.load(); - callback(true); - $location.path('/'); - }, errorDisplay); + ApiService.deleteAdminedOrganization(null, delParams).then(cb, errorDisplay); } };