|
3 | 3 |
|
4 | 4 | angular.module('tc.profile').controller('ProfileAboutController', ProfileAboutController);
|
5 | 5 |
|
6 |
| - ProfileAboutController.$inject = ['$log', '$scope', 'ProfileService', 'ExternalAccountService']; |
| 6 | + ProfileAboutController.$inject = ['$log', '$scope', 'ProfileService', 'ExternalAccountService', 'UserService', 'CONSTANTS']; |
7 | 7 |
|
8 |
| - function ProfileAboutController($log, $scope, ProfileService, ExternalAccountService, UserService) { |
| 8 | + function ProfileAboutController($log, $scope, ProfileService, ExternalAccountService, UserService, CONSTANTS) { |
9 | 9 | var vm = this;
|
10 | 10 | $log = $log.getInstance("ProfileAboutController");
|
11 | 11 | var profileVm = $scope.$parent.profileVm;
|
|
24 | 24 |
|
25 | 25 | profileVm.externalLinksPromise.then(function() {
|
26 | 26 | vm.linkedExternalAccountsData = profileVm.linkedExternalAccountsData;
|
27 |
| - vm.linkedExternalAccounts = profileVm.linkedExternalAccounts; |
| 27 | + |
28 | 28 | // show section if user is viewing his/her own profile OR if we have data
|
29 |
| - vm.hasLinks = vm.linkedExternalAccounts.length; |
30 |
| - //vm.hasLinks = _.any(_.valuesIn(_.omit(vm.linkedExternalAccountsData, ['userId', 'updatedAt','createdAt','createdBy','updatedBy','handle']))); |
| 29 | + //vm.hasLinks = profileVm.linkedExternalAccounts.length; |
| 30 | + vm.hasLinks = _.any(_.valuesIn(_.omit(vm.linkedExternalAccountsData, ['userId', 'updatedAt','createdAt','createdBy','updatedBy','handle']))); |
31 | 31 | vm.displaySection.externalLinks = profileVm.showEditProfileLink || vm.hasLinks;
|
| 32 | + |
| 33 | + // if user is authenticated, call for profiles end point |
| 34 | + if (profileVm.isUser) { |
| 35 | + var userId = UserService.getUserIdentity().userId; |
| 36 | + ExternalAccountService.getLinkedExternalAccounts(userId).then(function(data) { |
| 37 | + vm.linkedExternalAccounts = data; |
| 38 | + profileVm.status.externalLinks = CONSTANTS.STATE_READY; |
| 39 | + }).catch(function(err) { |
| 40 | + profileVm.status.externalLinks = CONSTANTS.STATE_ERROR; |
| 41 | + }); |
| 42 | + } else { |
| 43 | + vm.linkedExternalAccounts = []; |
| 44 | + // remove all keys except the provider keys |
| 45 | + var accounts = _.omit(vm.linkedExternalAccountsData, ['userId', 'updatedAt','createdAt','createdBy','updatedBy','handle']); |
| 46 | + // populate the externalLinks for external-account-data directive with info from ext accounts data |
| 47 | + for(var provider in accounts) { |
| 48 | + if (accounts[provider]) { |
| 49 | + vm.linkedExternalAccounts.push({ |
| 50 | + providerType: provider |
| 51 | + }); |
| 52 | + } |
| 53 | + } |
| 54 | + profileVm.status.externalLinks = CONSTANTS.STATE_READY; |
| 55 | + } |
32 | 56 | });
|
33 | 57 |
|
34 | 58 | profileVm.statsPromise.then(function() {
|
|
0 commit comments