|
5 | 5 | { provider: "linkedin", className: "fa-linkedin", displayName: "LinkedIn", disabled: true, order: 5, colorClass: 'el-linkedin', featured: true},
|
6 | 6 | { provider: "stackoverflow", className: "fa-stack-overflow", displayName: "Stack Overflow", disabled: false, order: 3, colorClass: 'el-stackoverflow'},
|
7 | 7 | { provider: "behance", className: "fa-behance", displayName: "Behance", disabled: true, order: 2, colorClass: 'el-behance'},
|
8 |
| - // { provider: "google-oauth2", className: "fa-google-plus", displayName: "Google+", disabled: true, order: }, colorClass: 'el-dribble', |
9 | 8 | { provider: "github", className: "fa-github", displayName: "Github", disabled: false, order: 1, colorClass: 'el-github', featured: true},
|
10 | 9 | { provider: "bitbucket", className: "fa-bitbucket", displayName: "Bitbucket", disabled: false, order: 7, colorClass: 'el-bitbucket'},
|
11 | 10 | { provider: "twitter", className: "fa-twitter", displayName: "Twitter", disabled: true, order: 4, colorClass: 'el-twitter'},
|
12 |
| - { provider: "weblinks", className: "fa-globe", displayName: "Web Links", disabled: true, order: 8, colorClass: 'el-weblinks'} |
| 11 | + { provider: "weblink", className: "fa-globe", displayName: "Web Links", disabled: true, order: -1, colorClass: 'el-weblinks'} |
13 | 12 | // TODO add more
|
14 | 13 | ];
|
15 | 14 |
|
|
20 | 19 | templateUrl: 'directives/external-account/external-account.directive.html',
|
21 | 20 | scope: {
|
22 | 21 | linkedAccounts: '=',
|
23 |
| - linksData: '=', |
24 | 22 | readOnly: '='
|
25 | 23 | },
|
26 | 24 | controller: ['$log', '$scope', 'ExternalAccountService', 'toaster',
|
27 | 25 | function($log, $scope, ExternalAccountService, toaster) {
|
| 26 | + |
28 | 27 | $log = $log.getInstance("ExtAccountDirectiveCtrl")
|
29 |
| - $scope.accountList = _.clone(_supportedAccounts, true); |
| 28 | + |
| 29 | + var _accountList = _.clone(_supportedAccounts, true); |
| 30 | + _.remove(_accountList, function(al) { return al.order < 0}); |
30 | 31 | $scope.$watchCollection('linkedAccounts', function(newValue, oldValue) {
|
31 |
| - for (var i=0;i<$scope.accountList.length;i++) { |
32 |
| - var _idx = _.findIndex(newValue, function(a) { |
33 |
| - return $scope.accountList[i].provider === a.providerType; |
34 |
| - }); |
35 |
| - if (_idx == -1) { |
36 |
| - $scope.accountList[i].status = 'unlinked'; |
37 |
| - } else { |
38 |
| - // check if data |
39 |
| - if ($scope.linksData[$scope.accountList[i].provider]) { |
40 |
| - $scope.accountList[i].status = 'linked'; |
| 32 | + if (newValue) { |
| 33 | + angular.forEach(_accountList, function(account) { |
| 34 | + var _linkedAccount = _.find(newValue, function(p) { |
| 35 | + return p.provider === account.provider |
| 36 | + }); |
| 37 | + var accountStatus = _.get(_linkedAccount, 'data.status', null); |
| 38 | + if (!_linkedAccount) { |
| 39 | + account.status = 'unlinked'; |
| 40 | + } else if(accountStatus && accountStatus.toLowerCase() === 'pending') { |
| 41 | + account.status = 'pending'; |
41 | 42 | } else {
|
42 |
| - $scope.accountList[i].status = 'pending'; |
| 43 | + account.status = 'linked'; |
43 | 44 | }
|
44 |
| - } |
| 45 | + }); |
| 46 | + $scope.accountList = _accountList; |
| 47 | + } else { |
| 48 | + // reset the status for all accounts |
| 49 | + angular.forEach(_accountList, function(account) { |
| 50 | + delete account.status; |
| 51 | + }); |
45 | 52 | }
|
46 | 53 | });
|
47 | 54 |
|
|
62 | 69 | ExternalAccountService.linkExternalAccount(provider.provider, null)
|
63 | 70 | .then(function(resp) {
|
64 | 71 | $log.debug("Social account linked: " + JSON.stringify(resp));
|
65 |
| - $scope.linkedAccounts.push(resp.profile); |
| 72 | + $scope.linkedAccounts.push(resp.linkedAccount); |
66 | 73 | toaster.pop('success', "Success",
|
67 | 74 | String.supplant(
|
68 | 75 | "Your {provider} account has been linked. Data from your linked account will be visible on your profile shortly.",
|
|
92 | 99 | .then(function(resp) {
|
93 | 100 | $log.debug("Social account unlinked: " + JSON.stringify(resp));
|
94 | 101 | var toRemove = _.findIndex($scope.linkedAccounts, function(la) {
|
95 |
| - return la.providerType === provider.provider; |
| 102 | + return la.provider === provider.provider; |
96 | 103 | });
|
97 |
| - // remove from both links array and links data array |
98 |
| - $scope.linkedAccounts.splice(toRemove, 1); |
99 |
| - delete $scope.linksData[provider.provider]; |
| 104 | + if (toRemove > -1) { |
| 105 | + // remove from the linkedAccounts array |
| 106 | + $scope.linkedAccounts.splice(toRemove, 1); |
| 107 | + } |
100 | 108 | toaster.pop('success', "Success",
|
101 | 109 | String.supplant(
|
102 | 110 | "Your {provider} account has been unlinked.",
|
|
120 | 128 | ]
|
121 | 129 | };
|
122 | 130 | })
|
123 |
| - .directive('externalLinksData', function() { |
124 |
| - return { |
125 |
| - restrict: 'E', |
126 |
| - templateUrl: 'directives/external-account/external-link-data.directive.html', |
127 |
| - scope: { |
128 |
| - linkedAccountsData: '=', |
129 |
| - externalLinks: '=' |
130 |
| - }, |
131 |
| - controller: ['$log', '$scope', 'ExternalAccountService', |
132 |
| - function($log, $scope, ExternalAccountService) { |
133 |
| - $log = $log.getInstance('ExternalLinksDataDirective'); |
134 |
| - var validProviders = _.pluck(_supportedAccounts, 'provider'); |
135 |
| - function reCalcData(links, data) { |
136 |
| - $scope.linkedAccounts = []; |
137 |
| - angular.forEach(links, function(link) { |
138 |
| - |
139 |
| - var provider = link.providerType; |
140 |
| - var isValidProviderIdx = _.findIndex(validProviders, function(p) { |
141 |
| - return p === provider; |
142 |
| - }); |
143 |
| - // skip if we dont care about this provider |
144 |
| - if (isValidProviderIdx == -1) |
145 |
| - return; |
146 |
| - |
147 |
| - if (!data[provider]) { |
148 |
| - $scope.linkedAccounts.push({ |
149 |
| - provider: provider, |
150 |
| - data: { |
151 |
| - handle: link.name, |
152 |
| - status: 'PENDING' |
153 |
| - } |
154 |
| - }); |
155 |
| - } else { |
156 |
| - // add data |
157 |
| - $scope.linkedAccounts.push({ |
158 |
| - provider: provider, |
159 |
| - data: data[provider] |
160 |
| - }); |
161 |
| - } |
162 |
| - }); |
163 |
| - } |
164 |
| - |
165 |
| - |
166 |
| - $scope.$watch('linkedAccountsData', function(newValue, oldValue) { |
167 |
| - reCalcData($scope.externalLinks, newValue); |
168 |
| - }); |
169 |
| - |
170 |
| - $scope.$watchCollection('externalLinks', function(newValue, oldValue) { |
171 |
| - reCalcData(newValue, $scope.linkedAccountsData); |
172 |
| - }); |
173 |
| - } |
174 |
| - ] |
175 |
| - } |
176 |
| - }) |
177 | 131 | .filter('providerData', function() {
|
178 | 132 | return function(input, field) {
|
179 | 133 | return _.result(_.find(_supportedAccounts, function(s) {
|
|
0 commit comments