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

Commit 4e4fa38

Browse files
author
vikasrohit
committed
SUP-1611, Settings: Support adding an external web link.
-- Added option to add web link in UI. Seems like API don't have support for adding web links as of now.
1 parent 8721468 commit 4e4fa38

File tree

7 files changed

+165
-3
lines changed

7 files changed

+165
-3
lines changed

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

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{ provider: "github", className: "fa-github", displayName: "Github", disabled: false, order: 1, colorClass: 'el-github'},
1010
{ provider: "bitbucket", className: "fa-bitbucket", displayName: "Bitbucket", disabled: true, order: 7, colorClass: 'el-bitbucket'},
1111
{ 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'}
12+
//{ provider: "weblinks", className: "fa-globe", displayName: "Web Links", disabled: true, order: 8, colorClass: 'el-weblinks'}
1313
// TODO add more
1414
];
1515

@@ -26,6 +26,7 @@
2626
function($log, $scope, ExternalAccountService, toaster) {
2727
$log = $log.getInstance("ExtAccountDirectiveCtrl")
2828
$scope.accountList = _.clone(_supportedAccounts, true);
29+
2930
$scope.$watch('linkedAccounts', function(newValue, oldValue) {
3031
for (var i=0;i<$scope.accountList.length;i++) {
3132
$scope.accountList[i].linked = !!_.find(newValue, function(a) {
@@ -114,6 +115,60 @@
114115
]
115116
}
116117
})
118+
.directive('externalWebLink', function() {
119+
return {
120+
restrict: 'E',
121+
templateUrl: 'directives/external-account/external-web-link.directive.html',
122+
scope: {
123+
linkedAccounts: '=',
124+
userData: "="
125+
},
126+
controller: ['$log', '$scope', 'ExternalAccountService',
127+
function($log, $scope, ExternalAccountService) {
128+
$log = $log.getInstance('ExternalWebLinkDirective');
129+
$scope.addingWebLink = false;
130+
$scope.errorMessage = null;
131+
132+
$log.debug("userData: " + $scope.userData.handle);
133+
134+
$scope.addWebLink = function() {
135+
$log.debug("URL: " + $scope.url);
136+
$scope.addingWebLink = true;
137+
$scope.errorMessage = null;
138+
ExternalAccountService.addWebLink($scope.userData.userId, $scope.userData.handle, $scope.url)
139+
.then(function(resp) {
140+
$scope.addingWebLink = false;
141+
$log.debug("Web link added: " + JSON.stringify(resp));
142+
$scope.linkedAccounts.push(resp.profile);
143+
toaster.pop('success', "Success",
144+
String.supplant(
145+
"Your link has been added. Data from your link will be visible on your profile shortly.",
146+
{provider: extAccountProvider}
147+
)
148+
);
149+
})
150+
.catch(function(resp) {
151+
$scope.addingWebLink = false;
152+
$log.debug(JSON.stringify(resp));
153+
if (resp.status === 'SOCIAL_PROFILE_ALREADY_EXISTS') {
154+
$log.info("Social profile already linked to another account");
155+
toaster.pop('error', "Whoops!",
156+
String.supplant(
157+
"This {provider} account is linked to another account. \
158+
If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.",
159+
{provider: extAccountProvider }
160+
)
161+
);
162+
} else {
163+
$log.info("Server error:" + resp.content);
164+
$scope.errorMessage = "Sorry, we are unable add web link. If problem persist please contact [email protected]";
165+
}
166+
});
167+
};
168+
}
169+
]
170+
}
171+
})
117172
.filter('providerData', function() {
118173
return function(input, field) {
119174
return _.result(_.find(_supportedAccounts, function(s) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.web-link
2+
form(name="addWebLinkFrm", ng-submit="addWebLinkFrm.$valid && addWebLink()", autocomplete="off")
3+
.validation-bar.url(ng-class="{ 'error-bar': (addWebLinkFrm.url.$dirty && addWebLinkFrm.url.$invalid) }")
4+
input.form-field.url(name="url", type="url", ng-model="url", placeholder="http://www.youlink.com", required)
5+
6+
.form-input-error(ng-show="addWebLinkFrm.url.$dirty && addWebLinkFrm.url.$invalid")
7+
p(ng-show="addWebLinkFrm.url.$error.required") This is a required field.
8+
9+
p(ng-show="addWebLinkFrm.url.$error.url") Please enter a vadlid URL
10+
11+
button(type="submit", tc-busy-button, tc-busy-when="addingWebLink", tc-busy-message="Adding", ng-disabled="addWebLinkFrm.$invalid || addWebLinkFrm.$pristine", ng-class="{'enabled-button': addWebLinkFrm.$valid, 'disabled': addWebLinkFrm.$pristine || addWebLinkFrm.$invalid, 'busy' : addingWebLink}") Add
12+
13+
.form-errors(ng-show="errorMessage")
14+
p.form-error {{errorMessage}}

app/index.jade

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ html
6565
link(rel="stylesheet", href="assets/css/directives/ios-card.css")
6666
link(rel="stylesheet", href="assets/css/directives/input-sticky-placeholder.css")
6767
link(rel="stylesheet", href="assets/css/directives/history-graph.css")
68+
link(rel="stylesheet", href="assets/css/directives/external-web-link.css")
6869
link(rel="stylesheet", href="assets/css/directives/external-link-data.css")
6970
link(rel="stylesheet", href="assets/css/directives/external-account.css")
7071
link(rel="stylesheet", href="assets/css/directives/distribution-graph.css")

app/services/externalAccounts.service.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
getLinkedExternalAccounts: getLinkedExternalAccounts,
1616
getLinkedExternalLinksData: getLinkedExternalLinksData,
1717
linkExternalAccount: linkExternalAccount,
18-
unlinkExternalAccount: unlinkExternalAccount
18+
unlinkExternalAccount: unlinkExternalAccount,
19+
addWebLink : addWebLink
1920
};
2021
return service;
2122

@@ -45,6 +46,19 @@
4546
throw new Error("not implemented");
4647
}
4748

49+
function addWebLink(userId, userHandle, url) {
50+
var provider = "url::" + url;
51+
var postData = {
52+
userId: userId,
53+
providerType: provider,
54+
context: {
55+
handle: userHandle
56+
}
57+
};
58+
// delegates to user service
59+
return UserService.addSocialProfile(userId, postData);
60+
}
61+
4862
function linkExternalAccount(provider, callbackUrl) {
4963
return $q(function(resolve, reject) {
5064
// supported backends

app/services/user.service.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
resetPassword: resetPassword,
2525
updatePassword: updatePassword,
2626
getUserProfile: getUserProfile,
27-
getV2UserProfile: getV2UserProfile
27+
getV2UserProfile: getV2UserProfile,
28+
addSocialProfile: addSocialProfile
2829
};
2930
return service;
3031

@@ -99,6 +100,10 @@
99100
return api.one('users', userId).get(queryParams);
100101
}
101102

103+
function addSocialProfile(userId, profileData) {
104+
return api.one('users', userId).customPOST(profileData, "profiles", {}, {});
105+
}
106+
102107
/**
103108
* Temporary end point for getting member's badges/achievements. This endpoint
104109
* should be removed once we have it in v3.

app/settings/edit-profile/edit-profile.jade

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
.description Show off your work and experience outside of Topcoder. Connect accounts from popular services and networks or add a link to any site.
8585

8686
.section-fields
87+
.field-label Add a web link
88+
89+
.web-links
90+
external-web-link(linked-accounts="vm.linkedExternalAccounts", user-data="vm.userData", read-only="false")
91+
8792
.field-label Link Your Accounts
8893

8994
.external-links
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
@import '../partials/combined';
2+
3+
external-web-link {
4+
.web-link {
5+
margin: 6px 0 31px 0;
6+
7+
.form-errors {
8+
position: initial;
9+
width: 100%;
10+
}
11+
12+
form {
13+
display: flex;
14+
flex-flow: row wrap;
15+
16+
17+
.form-label {
18+
@include sofia-pro-regular;
19+
font-size: 12px;
20+
color: black;
21+
text-transform: uppercase;
22+
margin-bottom: 5px;
23+
margin-top: 5px;
24+
}
25+
.form-field {
26+
@include form-field;
27+
@include ui-form-placeholder;
28+
&:disabled {
29+
color: #B7B7B7;
30+
}
31+
}
32+
.form-field-focused {
33+
@include form-field-focused;
34+
}
35+
36+
.validation-bar.url {
37+
flex: 1;
38+
39+
&:before {
40+
height: 40px;
41+
}
42+
}
43+
44+
input.url {
45+
width: 100%;
46+
margin: 0px;
47+
}
48+
49+
button {
50+
@include button-2-m;
51+
font-size: 14px;
52+
line-height: 16px;
53+
height: 40px;
54+
width: 60px;
55+
margin: 0 0 0 10px;
56+
text-transform: uppercase;
57+
58+
&.enabled-button {
59+
@include ui-enabled-button;
60+
}
61+
62+
&.busy {
63+
width: 94px;
64+
}
65+
}
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)