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

Commit 45b84b9

Browse files
authored
Merge pull request #1244 from appirio-tech/skill-picker-blockchain#1241
Skill picker blockchain#1241
2 parents b429f94 + d170e0d commit 45b84b9

File tree

4 files changed

+88
-28
lines changed

4 files changed

+88
-28
lines changed

app/services/group.service.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import angular from 'angular'
2+
3+
(function () {
4+
'use strict'
5+
6+
angular.module('tc.services').factory('GroupService', GroupService)
7+
8+
GroupService.$inject = ['ApiService']
9+
10+
function GroupService(ApiService) {
11+
var service = ApiService.restangularV3
12+
13+
// Retrieves the registration status of the member for the given program
14+
service.getMembers = function(userId, programId) {
15+
return service.one('groups',programId).one('members').get()
16+
}
17+
18+
// Registers the given member for the given program.
19+
service.addMember = function(userId, programId) {
20+
return service.one('groups', programId).one('members').customPOST({
21+
memberId : userId +'', membershipType : 'user'
22+
})
23+
}
24+
25+
return service
26+
}
27+
})()

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

+56-27
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import _ from 'lodash'
66

77
angular.module('tc.skill-picker').controller('SkillPickerController', SkillPickerController)
88

9-
SkillPickerController.$inject = ['$scope', 'CONSTANTS', 'ProfileService', '$state', 'userProfile', 'featuredSkills', 'logger', 'toaster', 'MemberCertService', '$q']
9+
SkillPickerController.$inject = ['$scope', 'CONSTANTS', 'ProfileService', '$state', 'userProfile', 'featuredSkills', 'logger', 'toaster', 'MemberCertService','GroupService', '$q']
1010

11-
function SkillPickerController($scope, CONSTANTS, ProfileService, $state, userProfile, featuredSkills, logger, toaster, MemberCertService, $q) {
11+
function SkillPickerController($scope, CONSTANTS, ProfileService, $state, userProfile, featuredSkills, logger, toaster, MemberCertService, GroupService, $q) {
1212
var vm = this
1313
vm.ASSET_PREFIX = CONSTANTS.ASSET_PREFIX
1414
vm.IOS_PROGRAM_ID = parseInt(CONSTANTS.SWIFT_PROGRAM_ID)
1515
vm.PREDIX_PROGRAM_ID = parseInt(CONSTANTS.PREDIX_PROGRAM_ID)
1616
vm.IBM_COGNITIVE_PROGRAM_ID = parseInt(CONSTANTS.IBM_COGNITIVE_PROGRAM_ID)
17+
vm.BLOCKCHAIN_PROGRAM_ID = parseInt(CONSTANTS.BLOCKCHAIN_PROGRAM_ID)
1718
vm.submitSkills = submitSkills
1819
vm.featuredSkills = featuredSkills
1920
vm.userId = userProfile.userId
@@ -22,7 +23,7 @@ import _ from 'lodash'
2223
vm.tracks = {}
2324
vm.mySkills = []
2425
vm.disableDoneButton = false
25-
vm.showCommunity = false
26+
vm.showCommunity = true
2627
vm.loadingCommunities = false
2728
vm.communities = {}
2829
vm.isPageDirty = isPageDirty
@@ -82,6 +83,14 @@ import _ from 'lodash'
8283
dirty: true,
8384
display: true
8485
}
86+
vm.communities['blockchain'] = {
87+
displayName: 'Blockchain',
88+
programId: vm.BLOCKCHAIN_PROGRAM_ID,
89+
status: false,
90+
dirty: false,
91+
display: true,
92+
groupCommunity: true
93+
}
8594
vm.communities['ios'] = {
8695
displayName: 'iOS',
8796
programId: vm.IOS_PROGRAM_ID,
@@ -95,10 +104,11 @@ import _ from 'lodash'
95104
status: false,
96105
dirty: false,
97106
display: true
98-
}
107+
}
99108
_addWatchToCommunity(vm.communities['ios'])
109+
_addWatchToCommunity(vm.communities['blockchain'])
100110
_addWatchToCommunity(vm.communities['predix'])
101-
_addWatchToCommunity(vm.communities['ibm_cognitive'])
111+
_addWatchToCommunity(vm.communities['ibm_cognitive'])
102112
}
103113

104114
/**
@@ -120,42 +130,59 @@ import _ from 'lodash'
120130
* Checks registration status of each community and updates the state of each community.
121131
*/
122132
function checkCommunityStatus() {
123-
var promises = []
133+
var eventAPIpromises = [], groupAPIPromises = []
124134
for (var name in vm.communities) {
125135
var community = vm.communities[name]
126-
promises.push(MemberCertService.getMemberRegistration(vm.userId, community.programId))
136+
if(community.groupCommunity){
137+
groupAPIPromises.push(GroupService.getMembers(vm.userId, community.programId))
138+
}else{
139+
eventAPIpromises.push(MemberCertService.getMemberRegistration(vm.userId, community.programId))
140+
}
127141
}
142+
128143
vm.loadingCommunities = true
129144

130-
$q.all(promises)
145+
$q.all(groupAPIPromises)
146+
.then(function(responses) {
147+
let members = responses[0] || []
148+
vm.loadingCommunities = false
149+
members.forEach(function(member) {
150+
if (member && member.memberId === vm.userId) {
151+
addWatchToExistingCommunity(member.groupId)
152+
}
153+
})
154+
})
155+
.catch(function(err) {
156+
logger.error('Could not load communities with group data', err)
157+
vm.loadingCommunities = false
158+
})
159+
160+
$q.all(eventAPIpromises)
131161
.then(function(responses) {
132162
vm.loadingCommunities = false
133163
responses.forEach(function(program) {
134-
if (program) {
135-
var community = _.find(vm.communities, {programId: program.eventId})
136-
if (community) {
137-
// Show existing communites selected
138-
community.status = true
139-
if (community.unregister){
140-
community.unregister()
141-
_addWatchToCommunity(community)
142-
}
143-
}
164+
if (program) {
165+
addWatchToExistingCommunity(program.eventId)
144166
}
145167
})
146-
// if there exists at least 1 community which can be displayed, set showCommunity flag to true
147-
var community = _.find(vm.communities, {display: true})
148-
if (community) {
149-
vm.showCommunity = true
150-
}
151168
})
152169
.catch(function(err) {
153170
logger.error('Could not load communities with member cert registration data', err)
154-
155171
vm.loadingCommunities = false
156172
})
157173
}
158174

175+
function addWatchToExistingCommunity(programId){
176+
var community = _.find(vm.communities, {programId: programId})
177+
if (community) {
178+
community.status = true
179+
if (community.unregister){
180+
community.unregister()
181+
_addWatchToCommunity(community)
182+
}
183+
}
184+
}
185+
159186
/**
160187
* Toggles the given skill for the user. If it is not added, adds it and if already added, removes it.
161188
*/
@@ -204,7 +231,11 @@ import _ from 'lodash'
204231
var community = vm.communities[communityName]
205232
if (community.dirty === true) {
206233
if (community.status === true) {
207-
promises.push(MemberCertService.registerMember(vm.userId, community.programId))
234+
if(community.groupCommunity){
235+
promises.push(GroupService.addMember(vm.userId, community.programId))
236+
}else{
237+
promises.push(MemberCertService.registerMember(vm.userId, community.programId))
238+
}
208239
}
209240
}
210241
}
@@ -219,9 +250,7 @@ import _ from 'lodash'
219250
})
220251
.catch(function(err) {
221252
logger.error('Could not update update user skills or register members for community', err)
222-
223253
vm.saving = false
224-
225254
toaster.pop('error', 'Whoops!', 'Something went wrong. Please try again later.')
226255
})
227256
}

app/skill-picker/skill-picker.jade

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
.community__icon(ng-class="{'community__icon--disabled': !community.status}")
1313
img(ng-if="communityKey == 'ibm_cognitive' && community.status", src=require("../../assets/images/ico-ibm_cognitive-community.svg"))
1414
img(ng-if="communityKey == 'ibm_cognitive' && !community.status", src=require("../../assets/images/ico-ibm_cognitive-community-grey.svg"))
15+
img(ng-if="communityKey == 'blockchain' && community.status", src=require("../../assets/images/ico-predix-community.svg"))
16+
img(ng-if="communityKey == 'blockchain' && !community.status", src=require("../../assets/images/ico-predix-community-grey.svg"))
1517
img(ng-if="communityKey == 'ios' && community.status", src=require("../../assets/images/ico-ios-community.svg"))
1618
img(ng-if="communityKey == 'ios' && !community.status", src=require("../../assets/images/ico-ios-community-grey.svg"))
1719
img(ng-if="communityKey == 'predix' && community.status", src=require("../../assets/images/ico-predix-community.svg"))
@@ -21,6 +23,7 @@
2123
span.community__title(class="{{!community.status && 'disabled'}}") {{community.displayName}}
2224
.community__description
2325
span(ng-if="communityKey == 'ibm_cognitive'") Cognitive Community
26+
span(ng-if="communityKey == 'blockchain'") Help create the future of Blockchain-based applications
2427
span(ng-if="communityKey == 'ios'") Mobile app design and development for iOS, with Swift emphasis
2528
span(ng-if="communityKey == 'predix'") Design and development on GE’s platform for the Industrial Internet of Things
2629

app/topcoder.constants.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ angular.module('CONSTANTS', []).constant('CONSTANTS', {
2929
'NEW_CHALLENGES_URL' : 'https://www.topcoder.com/challenges/develop/upcoming/',
3030
'SWIFT_PROGRAM_ID' : 3445,
3131
'PREDIX_PROGRAM_ID' : process.env.PREDIX_PROGRAM_ID || 3448,
32-
'IBM_COGNITIVE_PROGRAM_ID' : process.env.IBM_COGNITIVE_PROGRAM_ID || 3449,
32+
'IBM_COGNITIVE_PROGRAM_ID' : process.env.IBM_COGNITIVE_PROGRAM_ID || 3449,
33+
'BLOCKCHAIN_PROGRAM_ID' : process.env.BLOCKCHAIN_PROGRAM_ID || 20000010,
3334
'UPCOMING_SRMS_URL' : 'https://www.topcoder.com/challenges/data/upcoming/',
3435
'EVENT_USER_LOGGED_IN' : 'user_logged_in',
3536
'EVENT_USER_LOGGED_OUT' : 'user_logged_out',

0 commit comments

Comments
 (0)