@@ -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,12 +23,13 @@ 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
29
30
vm . isTracksDirty = isTracksDirty
30
31
vm . isCommunitySelected = isCommunitySelected
32
+ vm . isPageStateDirty = false
31
33
///////
32
34
activate ( )
33
35
@@ -42,20 +44,22 @@ import _ from 'lodash'
42
44
/**
43
45
* Verfies if the page state has been modified by the user in any way.
44
46
*/
45
- function isPageDirty ( ) {
47
+ function isPageDirty ( ) {
46
48
return isTracksDirty ( ) || isCommunitiesDirty ( )
47
49
}
48
50
49
51
/**
50
52
* Verfies if the tracks section state has been modified by the user in any way.
51
53
*/
52
54
function isTracksDirty ( ) {
55
+ vm . isPageStateDirty = true
53
56
return vm . tracks . DESIGN || vm . tracks . DEVELOP || vm . tracks . DATA_SCIENCE
54
57
}
55
58
/**
56
59
* Verfies if the communities section state has been modified by the user in any way.
57
60
*/
58
61
function isCommunitySelected ( ) {
62
+ vm . isPageStateDirty = true
59
63
var community = _ . find ( vm . communities , { status : true , display : true } )
60
64
return ! ! community
61
65
}
@@ -79,6 +83,14 @@ import _ from 'lodash'
79
83
dirty : true ,
80
84
display : true
81
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
+ }
82
94
vm . communities [ 'ios' ] = {
83
95
displayName : 'iOS' ,
84
96
programId : vm . IOS_PROGRAM_ID ,
@@ -92,10 +104,11 @@ import _ from 'lodash'
92
104
status : false ,
93
105
dirty : false ,
94
106
display : true
95
- }
107
+ }
96
108
_addWatchToCommunity ( vm . communities [ 'ios' ] )
109
+ _addWatchToCommunity ( vm . communities [ 'blockchain' ] )
97
110
_addWatchToCommunity ( vm . communities [ 'predix' ] )
98
- _addWatchToCommunity ( vm . communities [ 'ibm_cognitive' ] )
111
+ _addWatchToCommunity ( vm . communities [ 'ibm_cognitive' ] )
99
112
}
100
113
101
114
/**
@@ -117,43 +130,59 @@ import _ from 'lodash'
117
130
* Checks registration status of each community and updates the state of each community.
118
131
*/
119
132
function checkCommunityStatus ( ) {
120
- var promises = [ ]
133
+ var eventAPIpromises = [ ] , groupAPIPromises = [ ]
121
134
for ( var name in vm . communities ) {
122
135
var community = vm . communities [ name ]
123
- 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
+ }
124
141
}
142
+
125
143
vm . loadingCommunities = true
126
144
127
- $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 )
128
161
. then ( function ( responses ) {
129
162
vm . loadingCommunities = false
130
163
responses . forEach ( function ( program ) {
131
- if ( program ) {
132
- var community = _ . find ( vm . communities , { programId : program . eventId } )
133
- if ( community ) {
134
- // set display false to avoid showing already enabled/registered program
135
- // we expect display property to be modified after first load of the page
136
- // community.status = true
137
- if ( community . unregister ) {
138
- community . unregister ( )
139
- _addWatchToCommunity ( community )
140
- }
141
- }
164
+ if ( program ) {
165
+ addWatchToExistingCommunity ( program . eventId )
142
166
}
143
167
} )
144
- // if there exists at least 1 community which can be displayed, set showCommunity flag to true
145
- var community = _ . find ( vm . communities , { display : true } )
146
- if ( community ) {
147
- vm . showCommunity = true
148
- }
149
168
} )
150
169
. catch ( function ( err ) {
151
170
logger . error ( 'Could not load communities with member cert registration data' , err )
152
-
153
171
vm . loadingCommunities = false
154
172
} )
155
173
}
156
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
+
157
186
/**
158
187
* Toggles the given skill for the user. If it is not added, adds it and if already added, removes it.
159
188
*/
@@ -202,7 +231,11 @@ import _ from 'lodash'
202
231
var community = vm . communities [ communityName ]
203
232
if ( community . dirty === true ) {
204
233
if ( community . status === true ) {
205
- 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
+ }
206
239
}
207
240
}
208
241
}
@@ -217,9 +250,7 @@ import _ from 'lodash'
217
250
} )
218
251
. catch ( function ( err ) {
219
252
logger . error ( 'Could not update update user skills or register members for community' , err )
220
-
221
253
vm . saving = false
222
-
223
254
toaster . pop ( 'error' , 'Whoops!' , 'Something went wrong. Please try again later.' )
224
255
} )
225
256
}
0 commit comments