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

Commit 5bfb378

Browse files
author
vikasrohit
committed
Merge pull request #613 from appirio-tech/feature/sup-2728-skill-picker-ios-community
SUP-2728, Add iOS community to Onboarding page (Skill picker)
2 parents 480c675 + 45d2b8d commit 5bfb378

File tree

6 files changed

+475
-51
lines changed

6 files changed

+475
-51
lines changed

app/skill-picker/skill-picker.controller.js

Lines changed: 143 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,123 @@
33

44
angular.module('tc.skill-picker').controller('SkillPickerController', SkillPickerController);
55

6-
SkillPickerController.$inject = ['CONSTANTS', 'ProfileService', '$state', 'userProfile', 'featuredSkills', '$log', 'toaster'];
6+
SkillPickerController.$inject = ['$scope', 'CONSTANTS', 'ProfileService', '$state', 'userProfile', 'featuredSkills', '$log', 'toaster', 'MemberCertService', '$q'];
77

8-
function SkillPickerController(CONSTANTS, ProfileService, $state, userProfile, featuredSkills, $log, toaster) {
8+
function SkillPickerController($scope, CONSTANTS, ProfileService, $state, userProfile, featuredSkills, $log, toaster, MemberCertService, $q) {
99
var vm = this;
1010
$log = $log.getInstance("SkillPickerController");
1111
vm.ASSET_PREFIX = CONSTANTS.ASSET_PREFIX;
12+
vm.IOS_PROGRAM_ID = CONSTANTS.SWIFT_PROGRAM_ID;
1213
vm.submitSkills = submitSkills;
1314
vm.featuredSkills = featuredSkills;
15+
vm.userId = userProfile.userId;
1416
vm.username = userProfile.handle;
1517
vm.toggleSkill = toggleSkill;
1618
vm.tracks = {};
1719
vm.mySkills = [];
1820
vm.disableDoneButton = false;
21+
vm.showCommunity = false;
22+
vm.loadingCommunities = false;
23+
vm.communities = {};
24+
vm.isPageDirty = isPageDirty;
1925
///////
2026
activate();
2127

28+
/**
29+
* Activates the controller.
30+
*/
2231
function activate() {
23-
$log.debug("init")
32+
$log.debug("init");
33+
initCommunities();
34+
checkCommunityStatus();
2435
}
2536

37+
/**
38+
* Verfies if the page state has been modified by the user in any way.
39+
*/
40+
function isPageDirty() {
41+
return isTracksDirty() || isCommunitiesDirty();
42+
}
43+
44+
/**
45+
* Verfies if the tracks section state has been modified by the user in any way.
46+
*/
47+
function isTracksDirty() {
48+
return vm.tracks.DESIGN || vm.tracks.DEVELOP || vm.tracks.DATA_SCIENCE;
49+
}
50+
51+
/**
52+
* Verfies if the communities section state has been modified by the user in any way.
53+
*/
54+
function isCommunitiesDirty() {
55+
var community = _.findWhere(vm.communities, {dirty: true});
56+
return !!community;
57+
}
58+
59+
/**
60+
* Initializes the communities to show in the communities section.
61+
*/
62+
function initCommunities() {
63+
vm.communities['ios'] = { displayName: 'iOS', programId: vm.IOS_PROGRAM_ID, status: false, dirty: false, display: true};
64+
_addWatchToCommunity(vm.communities['ios']);
65+
}
66+
67+
/**
68+
* Helper method to add watch to given object.
69+
*/
70+
function _addWatchToCommunity(community) {
71+
community.unregister = $scope.$watch(
72+
function() { return community; },
73+
function(newValue, oldValue) {
74+
if (oldValue && newValue.status !== oldValue.status) {
75+
newValue.dirty = oldValue.dirty ? false : true;
76+
}
77+
},
78+
true
79+
);
80+
}
81+
82+
/**
83+
* Checks registration status of each community and updates the state of each community.
84+
*/
85+
function checkCommunityStatus() {
86+
var promises = [];
87+
for (var name in vm.communities) {
88+
var community = vm.communities[name];
89+
promises.push(MemberCertService.getMemberRegistration(vm.userId, community.programId));
90+
}
91+
vm.loadingCommunities = true;
92+
$q.all(promises).then(function(responses) {
93+
vm.loadingCommunities = false;
94+
responses.forEach(function(program) {
95+
if (program) {
96+
var community = _.findWhere(vm.communities, {programId: program.eventId});
97+
if (community) {
98+
// set display false to avoid showing already enabled/registered program
99+
// we expect display property to be modified after first load of the page
100+
community.display = false;
101+
community.status = true;
102+
if (community.unregister){
103+
community.unregister();
104+
_addWatchToCommunity(community);
105+
}
106+
}
107+
}
108+
});
109+
// if there exists at least 1 community which can be displayed, set showCommunity flag to true
110+
var community = _.findWhere(vm.communities, {display: true});
111+
if (community) {
112+
vm.showCommunity = true;
113+
}
114+
})
115+
.catch(function(error) {
116+
vm.loadingCommunities = false;
117+
});
118+
}
119+
120+
/**
121+
* Toggles the given skill for the user. If it is not added, adds it and if already added, removes it.
122+
*/
26123
function toggleSkill(tagId) {
27124
var _idx = vm.mySkills.indexOf(tagId.toString());
28125
if (_idx > -1) {
@@ -34,50 +131,56 @@
34131
}
35132
}
36133

134+
/**
135+
* Persists the user's altered information.
136+
*/
37137
function submitSkills() {
38138

39139
vm.saving = true;
40-
// save tracks
41-
userProfile.tracks = _.reduce(vm.tracks, function(result, isInterested, trackName) {
42-
if (isInterested) {
43-
result.push(trackName);
44-
}
45-
return result;
46-
}, []);
47140

48-
userProfile.save().then(function(data) {
49-
if (vm.mySkills.length > 0) {
50-
// save skills
51-
var data = {};
52-
for (var i = 0; i < vm.mySkills.length; i++) {
53-
data[vm.mySkills[i]] = {
54-
hidden: false
55-
};
141+
var promises = [];
142+
if (isTracksDirty()) {
143+
// save tracks
144+
userProfile.tracks = _.reduce(vm.tracks, function(result, isInterested, trackName) {
145+
if (isInterested) {
146+
result.push(trackName);
147+
}
148+
return result;
149+
}, []);
150+
promises.push(userProfile.save());
151+
}
152+
if (vm.mySkills.length > 0) {
153+
// save skills
154+
var data = {};
155+
for (var i = 0; i < vm.mySkills.length; i++) {
156+
data[vm.mySkills[i]] = {
157+
hidden: false
158+
};
159+
}
160+
promises.push(ProfileService.updateUserSkills(vm.username, data));
161+
}
162+
$log.debug('isCommunitiesDirty: ' + isCommunitiesDirty());
163+
if (isCommunitiesDirty()) {
164+
for(var communityName in vm.communities) {
165+
var community = vm.communities[communityName];
166+
if (community.dirty === true) {
167+
if (community.status === true) {
168+
promises.push(MemberCertService.registerMember(vm.userId, community.programId));
56169
}
57-
ProfileService.updateUserSkills(vm.username, data)
58-
.then(function(resp) {
59-
vm.saving = false;
60-
toaster.pop('success', "Success!", "Your skills have been updated.");
61-
vm.disableDoneButton = true;
62-
$state.go('dashboard');
63-
})
64-
.catch(function(data) {
65-
vm.saving = false;
66-
toaster.pop('error', "Whoops", "Something went wrong. Please try again later.");
67-
})
68-
} else {
69-
vm.saving = false;
70-
toaster.pop('success', "Success!", "Your skills have been updated.");
71-
vm.disableDoneButton = true;
72-
$state.go('dashboard');
73170
}
171+
}
172+
}
74173

75-
})
76-
.catch(function(resp) {
77-
vm.saving = false;
78-
toaster.pop('error', "Whoops", "Something went wrong. Please try again later.");
79-
})
80-
174+
$q.all(promises).then(function(responses) {
175+
vm.saving = false;
176+
toaster.pop('success', "Success!", "Your skills have been updated.");
177+
vm.disableDoneButton = true;
178+
//$state.go('dashboard');
179+
})
180+
.catch(function(resp) {
181+
vm.saving = false;
182+
toaster.pop('error', "Whoops!", "Something went wrong. Please try again later.");
183+
});
81184
}
82185
}
83186
})();

app/skill-picker/skill-picker.jade

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@
33

44
p.instruction Hi {{vm.username}}! Your account is now active. To help other members get to know you, select the tracks in which you're interested, and specify some of your skills. You can edit this information later on your Profile.
55

6+
.communities(ng-show="!vm.loadingCommunities && vm.showCommunity")
7+
.communities__title Communities
8+
.communities__description Topcoder regularly establishes exclusive communities to help members develop expertise and earn money in particular technologies. Join a featured community to be notified of events and challenges.
9+
.communities__list
10+
.community(ng-repeat="(communityKey, community) in vm.communities", ng-class="{'community--disabled': !community.status}", ng-if="community.display")
11+
.community__details
12+
.community__icon(ng-class="{'community__icon--disabled': !community.status}")
13+
img(ng-if="communityKey == 'ios' && community.status", src="/images/ico-ios-community.svg")
14+
img(ng-if="communityKey == 'ios' && !community.status", src="/images/ico-ios-community-grey.svg")
15+
16+
.community__text
17+
span.community__title(class="{{!community.status && 'disabled'}}") {{community.displayName}}
18+
.community__description
19+
span(ng-if="communityKey == 'ios'") Mobile app design and development for iOS, with Swift emphasis
20+
21+
onoff-switch(model="community.status", unique-id="'community-' + communityKey")
22+
23+
24+
625
.tracks-container
726
.title tracks
827
.description Topcoder's three categories of challenges… please pick at least one based on your skills and interests.
@@ -51,4 +70,4 @@
5170
type="button",
5271
tc-busy-button, tc-busy-when="vm.saving",
5372
ng-click="vm.submitSkills()",
54-
ng-disabled="vm.disableDoneButton || (!vm.tracks.DESIGN && !vm.tracks.DEVELOP && !vm.tracks.DATA_SCIENCE)") Done
73+
ng-disabled="vm.disableDoneButton || !vm.isPageDirty()") Done

0 commit comments

Comments
 (0)