@@ -24,20 +24,21 @@ import _ from 'lodash'
2424 linkedAccounts : '=' ,
2525 readOnly : '='
2626 } ,
27- controller : [ '$log' , 'logger' , '$scope' , 'ExternalAccountService' , 'toaster' ,
28- function ( $log , logger , $scope , ExternalAccountService , toaster ) {
29-
30- $log = $log . getInstance ( 'ExtAccountDirectiveCtrl' )
31-
27+ controller : [ 'logger' , '$scope' , 'ExternalAccountService' , 'toaster' ,
28+ function ( logger , $scope , ExternalAccountService , toaster ) {
3229 var _accountList = _ . clone ( _supportedAccounts , true )
30+
3331 _ . remove ( _accountList , function ( al ) { return al . order < 0 } )
32+
3433 $scope . $watchCollection ( 'linkedAccounts' , function ( newValue , oldValue ) {
3534 if ( newValue ) {
3635 angular . forEach ( _accountList , function ( account ) {
3736 var _linkedAccount = _ . find ( newValue , function ( p ) {
3837 return p . provider === account . provider
3938 } )
39+
4040 var accountStatus = _ . get ( _linkedAccount , 'data.status' , null )
41+
4142 if ( ! _linkedAccount ) {
4243 account . status = 'unlinked'
4344 } else if ( accountStatus && accountStatus . toLowerCase ( ) === 'pending' ) {
@@ -46,9 +47,11 @@ import _ from 'lodash'
4647 account . status = 'linked'
4748 }
4849 } )
50+
4951 $scope . accountList = _accountList
52+
5053 } else {
51- // reset the status for all accounts
54+ // Reset the status for all accounts
5255 angular . forEach ( _accountList , function ( account ) {
5356 delete account . status
5457 } )
@@ -59,20 +62,26 @@ import _ from 'lodash'
5962 provider = _ . find ( _supportedAccounts , function ( s ) {
6063 return s . provider === provider
6164 } )
65+
6266 if ( status === 'linked' ) {
63- $log . debug ( String . supplant ( 'UnLinking to ' + provider . displayName ) )
67+ logger . debug ( String . supplant ( 'UnLinking to ' + provider . displayName ) )
68+
6469 _unlink ( provider )
70+
6571 } else if ( status === 'unlinked' ) {
66- $log . debug ( String . supplant ( 'Linking to ' + provider . displayName ) )
72+ logger . debug ( String . supplant ( 'Linking to ' + provider . displayName ) )
73+
6774 _link ( provider )
6875 }
6976 }
7077
7178 function _link ( provider ) {
7279 ExternalAccountService . linkExternalAccount ( provider . provider , null )
7380 . then ( function ( resp ) {
74- $log . debug ( 'Social account linked: ' + JSON . stringify ( resp ) )
81+ logger . debug ( 'Social account linked: ' + JSON . stringify ( resp ) )
82+
7583 $scope . linkedAccounts . push ( resp . linkedAccount )
84+
7685 toaster . pop ( 'success' , 'Success' ,
7786 String . supplant (
7887 'Your {provider} account has been linked. Data from your linked account will be visible on your profile shortly.' ,
@@ -82,7 +91,7 @@ import _ from 'lodash'
8291 } )
8392 . catch ( function ( err ) {
8493 if ( err . status === 'SOCIAL_PROFILE_ALREADY_EXISTS' ) {
85- $log . info ( 'Social profile already linked to another account' )
94+ logger . info ( 'Social profile already linked to another account' )
8695
8796 toaster . pop ( 'error' , 'Whoops!' ,
8897 String . supplant (
@@ -102,10 +111,12 @@ import _ from 'lodash'
102111 function _unlink ( provider ) {
103112 return ExternalAccountService . unlinkExternalAccount ( provider . provider )
104113 . then ( function ( resp ) {
105- $log . debug ( 'Social account unlinked: ' + JSON . stringify ( resp ) )
114+ logger . debug ( 'Social account unlinked: ' + JSON . stringify ( resp ) )
115+
106116 var toRemove = _ . findIndex ( $scope . linkedAccounts , function ( la ) {
107117 return la . provider === provider . provider
108118 } )
119+
109120 if ( toRemove > - 1 ) {
110121 // remove from the linkedAccounts array
111122 $scope . linkedAccounts . splice ( toRemove , 1 )
@@ -121,7 +132,7 @@ import _ from 'lodash'
121132 var msg = err . msg
122133
123134 if ( err . status === 'SOCIAL_PROFILE_NOT_EXIST' ) {
124- $log . info ( 'Social profile not linked to account' )
135+ logger . info ( 'Social profile not linked to account' )
125136
126137 msg = '{provider} account is not linked to your account. If you think this is an error please contact <a href=\"mailTo:support@topcoder.com\">support@topcoder.com</a>.'
127138 } else {
0 commit comments