Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 94c2939

Browse files
committed
Merge pull request #556 from appirio-tech/feature/sup-2481-intergrate-web-links-api
SUP-2481 intergrate web links api
2 parents 0d48071 + 0b3e95d commit 94c2939

26 files changed

+1382
-380
lines changed

app/directives/challenge-tile/challenge-tile.directive.jade

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
// Only show if not data science track
3333
p.roles
3434
span(ng-hide="challenge.track === 'DATA_SCIENCE'")
35-
#[span Role: ] #[span {{challenge.userDetails.roles | listRoles}}]
35+
span Role:  
36+
span {{challenge.userDetails.roles | listRoles}}
3637

3738
.completed-challenge(
3839
ng-show="challenge.status === 'COMPLETED' || challenge.status === 'PAST'",
@@ -66,7 +67,8 @@
6667
// Only show if not data science track
6768
p.roles
6869
span(ng-hide="challenge.track === 'DATA_SCIENCE'")
69-
#[span Role: ] #[span {{challenge.userDetails.roles | listRoles}}]
70+
span Role:  
71+
span {{challenge.userDetails.roles | listRoles}}
7072

7173
.challenge.list-view(ng-show="view=='list'", ng-class="challenge.track")
7274
.active-challenge(ng-show="challenge.status === 'ACTIVE'")

app/directives/external-account/external-account.directive.js

Lines changed: 29 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
{ provider: "linkedin", className: "fa-linkedin", displayName: "LinkedIn", disabled: true, order: 5, colorClass: 'el-linkedin', featured: true},
66
{ provider: "stackoverflow", className: "fa-stack-overflow", displayName: "Stack Overflow", disabled: false, order: 3, colorClass: 'el-stackoverflow'},
77
{ 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',
98
{ provider: "github", className: "fa-github", displayName: "Github", disabled: false, order: 1, colorClass: 'el-github', featured: true},
109
{ provider: "bitbucket", className: "fa-bitbucket", displayName: "Bitbucket", disabled: false, order: 7, colorClass: 'el-bitbucket'},
1110
{ 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'}
1312
// TODO add more
1413
];
1514

@@ -20,28 +19,36 @@
2019
templateUrl: 'directives/external-account/external-account.directive.html',
2120
scope: {
2221
linkedAccounts: '=',
23-
linksData: '=',
2422
readOnly: '='
2523
},
2624
controller: ['$log', '$scope', 'ExternalAccountService', 'toaster',
2725
function($log, $scope, ExternalAccountService, toaster) {
26+
2827
$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});
3031
$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';
4142
} else {
42-
$scope.accountList[i].status = 'pending';
43+
account.status = 'linked';
4344
}
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+
});
4552
}
4653
});
4754

@@ -62,7 +69,7 @@
6269
ExternalAccountService.linkExternalAccount(provider.provider, null)
6370
.then(function(resp) {
6471
$log.debug("Social account linked: " + JSON.stringify(resp));
65-
$scope.linkedAccounts.push(resp.profile);
72+
$scope.linkedAccounts.push(resp.linkedAccount);
6673
toaster.pop('success', "Success",
6774
String.supplant(
6875
"Your {provider} account has been linked. Data from your linked account will be visible on your profile shortly.",
@@ -92,11 +99,12 @@
9299
.then(function(resp) {
93100
$log.debug("Social account unlinked: " + JSON.stringify(resp));
94101
var toRemove = _.findIndex($scope.linkedAccounts, function(la) {
95-
return la.providerType === provider.provider;
102+
return la.provider === provider.provider;
96103
});
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+
}
100108
toaster.pop('success', "Success",
101109
String.supplant(
102110
"Your {provider} account has been unlinked.",
@@ -120,60 +128,6 @@
120128
]
121129
};
122130
})
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-
})
177131
.filter('providerData', function() {
178132
return function(input, field) {
179133
return _.result(_.find(_supportedAccounts, function(s) {

0 commit comments

Comments
 (0)