@@ -6,14 +6,15 @@ import _ from 'lodash'
6
6
7
7
angular . module ( 'tc.skill-picker' ) . controller ( 'SkillPickerController' , SkillPickerController )
8
8
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' ]
10
10
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 ) {
12
12
var vm = this
13
13
vm . ASSET_PREFIX = CONSTANTS . ASSET_PREFIX
14
14
vm . IOS_PROGRAM_ID = parseInt ( CONSTANTS . SWIFT_PROGRAM_ID )
15
15
vm . PREDIX_PROGRAM_ID = parseInt ( CONSTANTS . PREDIX_PROGRAM_ID )
16
16
vm . IBM_COGNITIVE_PROGRAM_ID = parseInt ( CONSTANTS . IBM_COGNITIVE_PROGRAM_ID )
17
+ vm . BLOCKCHAIN_PROGRAM_ID = parseInt ( CONSTANTS . BLOCKCHAIN_PROGRAM_ID )
17
18
vm . submitSkills = submitSkills
18
19
vm . featuredSkills = featuredSkills
19
20
vm . userId = userProfile . userId
@@ -22,7 +23,7 @@ import _ from 'lodash'
22
23
vm . tracks = { }
23
24
vm . mySkills = [ ]
24
25
vm . disableDoneButton = false
25
- vm . showCommunity = false
26
+ vm . showCommunity = true
26
27
vm . loadingCommunities = false
27
28
vm . communities = { }
28
29
vm . isPageDirty = isPageDirty
@@ -82,6 +83,14 @@ import _ from 'lodash'
82
83
dirty : true ,
83
84
display : true
84
85
}
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
+ }
85
94
vm . communities [ 'ios' ] = {
86
95
displayName : 'iOS' ,
87
96
programId : vm . IOS_PROGRAM_ID ,
@@ -95,10 +104,11 @@ import _ from 'lodash'
95
104
status : false ,
96
105
dirty : false ,
97
106
display : true
98
- }
107
+ }
99
108
_addWatchToCommunity ( vm . communities [ 'ios' ] )
109
+ _addWatchToCommunity ( vm . communities [ 'blockchain' ] )
100
110
_addWatchToCommunity ( vm . communities [ 'predix' ] )
101
- _addWatchToCommunity ( vm . communities [ 'ibm_cognitive' ] )
111
+ _addWatchToCommunity ( vm . communities [ 'ibm_cognitive' ] )
102
112
}
103
113
104
114
/**
@@ -120,42 +130,59 @@ import _ from 'lodash'
120
130
* Checks registration status of each community and updates the state of each community.
121
131
*/
122
132
function checkCommunityStatus ( ) {
123
- var promises = [ ]
133
+ var eventAPIpromises = [ ] , groupAPIPromises = [ ]
124
134
for ( var name in vm . communities ) {
125
135
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
+ }
127
141
}
142
+
128
143
vm . loadingCommunities = true
129
144
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 )
131
161
. then ( function ( responses ) {
132
162
vm . loadingCommunities = false
133
163
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 )
144
166
}
145
167
} )
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
- }
151
168
} )
152
169
. catch ( function ( err ) {
153
170
logger . error ( 'Could not load communities with member cert registration data' , err )
154
-
155
171
vm . loadingCommunities = false
156
172
} )
157
173
}
158
174
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
+
159
186
/**
160
187
* Toggles the given skill for the user. If it is not added, adds it and if already added, removes it.
161
188
*/
@@ -204,7 +231,11 @@ import _ from 'lodash'
204
231
var community = vm . communities [ communityName ]
205
232
if ( community . dirty === true ) {
206
233
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
+ }
208
239
}
209
240
}
210
241
}
@@ -219,9 +250,7 @@ import _ from 'lodash'
219
250
} )
220
251
. catch ( function ( err ) {
221
252
logger . error ( 'Could not update update user skills or register members for community' , err )
222
-
223
253
vm . saving = false
224
-
225
254
toaster . pop ( 'error' , 'Whoops!' , 'Something went wrong. Please try again later.' )
226
255
} )
227
256
}
0 commit comments