|
1 | 1 | (function() {
|
2 | 2 | 'use strict';
|
3 | 3 | var _supportedAccounts = [
|
4 |
| - { provider: "dribbble", className: "fa-dribbble", displayName: "Dribbble", disabled: false, order: 6, colorClass: 'el-dribble'}, |
| 4 | + { provider: "dribbble", className: "fa-dribbble", displayName: "Dribbble", disabled: false, order: 6, colorClass: 'el-dribbble'}, |
5 | 5 | { provider: "linkedin", className: "fa-linkedin", displayName: "LinkedIn", disabled: true, order: 5, colorClass: 'el-linkedin'},
|
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'},
|
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: '=', |
| 22 | + // linksData: '=', |
24 | 23 | readOnly: '='
|
25 | 24 | },
|
26 | 25 | controller: ['$log', '$scope', 'ExternalAccountService', 'toaster',
|
27 | 26 | function($log, $scope, ExternalAccountService, toaster) {
|
| 27 | + |
28 | 28 | $log = $log.getInstance("ExtAccountDirectiveCtrl")
|
29 |
| - $scope.accountList = _.clone(_supportedAccounts, true); |
| 29 | + |
| 30 | + var _accountList = _.clone(_supportedAccounts, true); |
| 31 | + _.remove(_accountList, function(al) { return al.order < 0}); |
30 | 32 | $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'; |
| 33 | + if (newValue && newValue != oldValue) { |
| 34 | + angular.forEach(_accountList, function(account) { |
| 35 | + var _linkedAccount = _.find(newValue, function(p) { |
| 36 | + return p.provider === account.provider |
| 37 | + }); |
| 38 | + if (!_linkedAccount) { |
| 39 | + account.status = 'unlinked'; |
| 40 | + } else if(_linkedAccount.status && _linkedAccount.status.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; |
45 | 47 | }
|
46 | 48 | });
|
47 | 49 |
|
|
89 | 91 | .then(function(resp) {
|
90 | 92 | $log.debug("Social account unlinked: " + JSON.stringify(resp));
|
91 | 93 | var toRemove = _.findIndex($scope.linkedAccounts, function(la) {
|
92 |
| - return la.providerType === provider.provider; |
| 94 | + return la.provider === provider.provider; |
93 | 95 | });
|
94 | 96 | // remove from both links array and links data array
|
95 | 97 | $scope.linkedAccounts.splice(toRemove, 1);
|
96 |
| - delete $scope.linksData[provider.provider]; |
| 98 | + // delete $scope.linksData[provider.provider]; |
97 | 99 | toaster.pop('success', "Success",
|
98 | 100 | String.supplant(
|
99 | 101 | "Your {provider} account has been unlinked.",
|
|
117 | 119 | ]
|
118 | 120 | };
|
119 | 121 | })
|
120 |
| - .directive('externalLinksData', function() { |
121 |
| - return { |
122 |
| - restrict: 'E', |
123 |
| - templateUrl: 'directives/external-account/external-link-data.directive.html', |
124 |
| - scope: { |
125 |
| - linkedAccountsData: '=', |
126 |
| - externalLinks: '=' |
127 |
| - }, |
128 |
| - controller: ['$log', '$scope', 'ExternalAccountService', |
129 |
| - function($log, $scope, ExternalAccountService) { |
130 |
| - $log = $log.getInstance('ExternalLinksDataDirective'); |
131 |
| - function reCalcData(links, data) { |
132 |
| - $scope.linkedAccounts = []; |
133 |
| - angular.forEach(links, function(link) { |
134 |
| - var provider = link.providerType; |
135 |
| - |
136 |
| - if (!data[provider]) { |
137 |
| - $scope.linkedAccounts.push({ |
138 |
| - provider: provider, |
139 |
| - data: { |
140 |
| - handle: link.name, |
141 |
| - status: 'PENDING' |
142 |
| - } |
143 |
| - }); |
144 |
| - } else { |
145 |
| - // add data |
146 |
| - $scope.linkedAccounts.push({ |
147 |
| - provider: provider, |
148 |
| - data: data[provider] |
149 |
| - }); |
150 |
| - } |
151 |
| - }); |
152 |
| - } |
153 |
| - |
154 |
| - |
155 |
| - $scope.$watch('linkedAccountsData', function(newValue, oldValue) { |
156 |
| - reCalcData($scope.externalLinks, newValue); |
157 |
| - }); |
158 |
| - |
159 |
| - $scope.$watchCollection('externalLinks', function(newValue, oldValue) { |
160 |
| - reCalcData(newValue, $scope.linkedAccountsData); |
161 |
| - }); |
162 |
| - } |
163 |
| - ] |
164 |
| - } |
165 |
| - }) |
166 |
| - .directive('externalWebLink', function() { |
167 |
| - return { |
168 |
| - restrict: 'E', |
169 |
| - templateUrl: 'directives/external-account/external-web-link.directive.html', |
170 |
| - scope: { |
171 |
| - linkedAccounts: '=', |
172 |
| - userData: "=" |
173 |
| - }, |
174 |
| - controller: ['$log', '$scope', 'ExternalAccountService', |
175 |
| - function($log, $scope, ExternalAccountService) { |
176 |
| - $log = $log.getInstance('ExternalWebLinkDirective'); |
177 |
| - $scope.addingWebLink = false; |
178 |
| - $scope.errorMessage = null; |
179 |
| - |
180 |
| - $log.debug("userData: " + $scope.userData.handle); |
181 |
| - |
182 |
| - $scope.addWebLink = function() { |
183 |
| - $log.debug("URL: " + $scope.url); |
184 |
| - $scope.addingWebLink = true; |
185 |
| - $scope.errorMessage = null; |
186 |
| - ExternalAccountService.addWebLink($scope.userData.userId, $scope.userData.handle, $scope.url) |
187 |
| - .then(function(resp) { |
188 |
| - $scope.addingWebLink = false; |
189 |
| - $log.debug("Web link added: " + JSON.stringify(resp)); |
190 |
| - $scope.linkedAccounts.push(resp.profile); |
191 |
| - toaster.pop('success', "Success", |
192 |
| - String.supplant( |
193 |
| - "Your link has been added. Data from your link will be visible on your profile shortly.", |
194 |
| - {provider: extAccountProvider} |
195 |
| - ) |
196 |
| - ); |
197 |
| - }) |
198 |
| - .catch(function(resp) { |
199 |
| - $scope.addingWebLink = false; |
200 |
| - $log.debug(JSON.stringify(resp)); |
201 |
| - if (resp.status === 'SOCIAL_PROFILE_ALREADY_EXISTS') { |
202 |
| - $log.info("Social profile already linked to another account"); |
203 |
| - toaster.pop('error', "Whoops!", |
204 |
| - String.supplant( |
205 |
| - "This {provider} account is linked to another account. \ |
206 |
| - If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.", |
207 |
| - {provider: extAccountProvider } |
208 |
| - ) |
209 |
| - ); |
210 |
| - } else { |
211 |
| - $log.info("Server error:" + resp.content); |
212 |
| - $scope.errorMessage = "Sorry, we are unable add web link. If problem persist please contact [email protected]"; |
213 |
| - } |
214 |
| - }); |
215 |
| - }; |
216 |
| - } |
217 |
| - ] |
218 |
| - } |
219 |
| - }) |
220 | 122 | .filter('providerData', function() {
|
221 | 123 | return function(input, field) {
|
222 | 124 | return _.result(_.find(_supportedAccounts, function(s) {
|
|
0 commit comments