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

Commit c254046

Browse files
author
vikasrohit
committed
SUP-2481, intergrate-web-links-api
Merge branch 'feature/sup-1611-web-link-support-ui' into feature/sup-2481-intergrate-web-links-api * feature/sup-1611-web-link-support-ui: more fixes major refactoring, moving data processing to services SUP-1611, Settings: Support adding an external web link. Conflicts: app/directives/challenge-tile/challenge-tile.directive.jade app/directives/external-account/external-account.directive.js app/directives/external-account/external-link-data.directive.jade app/profile/about/about.jade app/settings/edit-profile/edit-profile.controller.js app/specs.html
2 parents 27c08db + 5a62e35 commit c254046

24 files changed

+854
-376
lines changed

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

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

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

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

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

Lines changed: 20 additions & 72 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,31 @@
2019
templateUrl: 'directives/external-account/external-account.directive.html',
2120
scope: {
2221
linkedAccounts: '=',
23-
linksData: '=',
22+
// linksData: '=',
2423
readOnly: '='
2524
},
2625
controller: ['$log', '$scope', 'ExternalAccountService', 'toaster',
2726
function($log, $scope, ExternalAccountService, toaster) {
27+
2828
$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});
3032
$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';
4142
} else {
42-
$scope.accountList[i].status = 'pending';
43+
account.status = 'linked';
4344
}
44-
}
45+
});
46+
$scope.accountList = _accountList;
4547
}
4648
});
4749

@@ -92,11 +94,11 @@
9294
.then(function(resp) {
9395
$log.debug("Social account unlinked: " + JSON.stringify(resp));
9496
var toRemove = _.findIndex($scope.linkedAccounts, function(la) {
95-
return la.providerType === provider.provider;
97+
return la.provider === provider.provider;
9698
});
9799
// remove from both links array and links data array
98100
$scope.linkedAccounts.splice(toRemove, 1);
99-
delete $scope.linksData[provider.provider];
101+
// delete $scope.linksData[provider.provider];
100102
toaster.pop('success', "Success",
101103
String.supplant(
102104
"Your {provider} account has been unlinked.",
@@ -120,60 +122,6 @@
120122
]
121123
};
122124
})
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-
})
177125
.filter('providerData', function() {
178126
return function(input, field) {
179127
return _.result(_.find(_supportedAccounts, function(s) {

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

Lines changed: 18 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -14,127 +14,44 @@ describe('External Accounts Directive', function() {
1414
describe('Linked external accounts', function() {
1515
var linkedAccounts = [
1616
{
17-
providerType: 'linkedin',
17+
provider: 'linkedin',
1818
// don't care about other details
1919
},
2020
{
21-
providerType: 'github'
21+
provider: 'github'
2222
}
2323
];
24-
var linksData = {
25-
'linkedin' : {provider: 'linkedin', name: 'name-linkedin'},
26-
'github' : {provider: 'github', name: 'name-github'}
27-
};
2824
var externalAccounts;
2925

3026
beforeEach(function() {
3127
scope.linkedAccounts = linkedAccounts;
32-
scope.linksData = linksData;
33-
element = angular.element('<external-accounts linked-accounts="linkedAccounts", links-data="linksData"></external-accounts>)');
28+
element = angular.element('<external-accounts linked-accounts="linkedAccounts"></external-accounts>)');
3429
externalAccounts = $compile(element)(scope);
35-
scope.$digest();
36-
// scope.$apply();
30+
// externalAccounts.scope().$digest();
31+
// externalAccounts.scope().$apply();
3732
});
3833

3934
it('should have added account list to scope', function() {
40-
expect(element.isolateScope().accountList).to.exist;
41-
35+
inject(function($timeout) {
36+
scope.$digest();
37+
$timeout(function() {
38+
expect(element.isolateScope().accountList).to.exist;
39+
}, 0)
40+
});
4241
});
4342

4443
it('should have "linked" property set for github & linkedin', function() {
45-
var githubAccount = _.find(element.isolateScope().accountList, function(a) { return a.provider === 'github'});
46-
expect(githubAccount).to.have.property('status')
47-
.that.equals('linked');
44+
inject(function($timeout) {
45+
scope.$digest();
46+
$timeout(function() {
47+
var githubAccount = _.find(element.isolateScope().accountList, function(a) { return a.provider === 'github'});
48+
expect(githubAccount).to.have.property('status').that.equals('linked');
49+
}, 0)
50+
});
4851

4952
// var linkeindAccount = _.find(element.isolateScope().accountList, function(a) { return a.provider === 'linkedin'});
5053
// expect(linkeindAccount).to.have.property('linked')
5154
// .that.equals(true);
5255
});
5356
});
5457
});
55-
56-
describe('External Links Data Directive', function() {
57-
var scope;
58-
var element;
59-
60-
beforeEach(function() {
61-
bard.appModule('topcoder');
62-
bard.inject(this, '$compile', '$rootScope');
63-
scope = $rootScope.$new();
64-
});
65-
66-
bard.verifyNoOutstandingHttpRequests();
67-
68-
describe('Linked external accounts', function() {
69-
var externalLinks = [
70-
{
71-
providerType: 'linkedin',
72-
// don't care about other details
73-
},
74-
{
75-
providerType: 'github'
76-
},
77-
{
78-
providerType: 'behance'
79-
},
80-
{
81-
providerType: 'dribbble'
82-
},
83-
{
84-
providerType: 'bitbucket'
85-
}
86-
];
87-
var linkedAccounts = {
88-
github: {
89-
handle: "github-handle",
90-
followers: 1,
91-
publicRepos: 1
92-
},
93-
stackoverflow: {
94-
handle: 'so-handle',
95-
reputation: 2,
96-
answers: 2
97-
},
98-
behance: {
99-
name: 'behance name',
100-
projectViews: 3,
101-
projectAppreciations: 3
102-
},
103-
dribbble: {
104-
handle: 'dribble-handle',
105-
followers: 4,
106-
likes: 4
107-
},
108-
bitbucket: {
109-
username: 'bitbucket-username',
110-
followers: 5,
111-
repositories: 5
112-
},
113-
twitter: {
114-
handle: 'twitter-handle',
115-
noOfTweets: 6,
116-
followers: 6
117-
},
118-
linkedin: {
119-
name: 'linkedin name',
120-
title: 'linkedin title'
121-
}
122-
};
123-
var externalLinksData;
124-
125-
beforeEach(function() {
126-
scope.linkedAccounts = linkedAccounts;
127-
scope.externalLinks = externalLinks;
128-
element = angular.element('<external-links-data linked-accounts-data="linkedAccounts" external-links="externalLinks"></external-links-data>)');
129-
externalLinksData = $compile(element)(scope);
130-
scope.$digest();
131-
});
132-
133-
it('should have added linkedAccounts to scope', function() {
134-
expect(element.isolateScope().linkedAccounts).to.exist;
135-
// linkedAccounts should have 5 entries because externalLinks contains only 5 records
136-
expect(element.isolateScope().linkedAccounts).to.have.length(5);
137-
});
138-
139-
});
140-
});

app/directives/external-account/external-link-data.directive.jade

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.external-link-list
2-
div.external-link-tile(ng-repeat="account in linkedAccounts")
2+
div.external-link-tile(ng-repeat="account in linkedAccountsData")
33
.top
44
div.logo
55
i.fa(ng-class="(account|providerData:'className') || 'fa-globe'")
@@ -97,3 +97,8 @@
9797
.handle {{account.data.name}}
9898

9999
.title {{account.data.title}}
100+
101+
div(ng-switch-when="weblink")
102+
.handle My Portfoilo
103+
104+
.title {{account.data.title}}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(function() {
2+
'use strict';
3+
4+
/**
5+
* @desc links data card directive
6+
* @example <external-links-data></external-links-data>
7+
*/
8+
angular
9+
.module('tcUIComponents')
10+
.directive('externalLinksData', externalLinksData);
11+
12+
function externalLinksData() {
13+
var directive = {
14+
restrict: 'E',
15+
templateUrl: 'directives/external-account/external-link-data.directive.html',
16+
scope: {
17+
linkedAccountsData: '='
18+
}
19+
};
20+
return directive;
21+
}
22+
})();

0 commit comments

Comments
 (0)