This repository was archived by the owner on Mar 4, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +42
-34
lines changed
my-dashboard/my-challenges Expand file tree Collapse file tree 3 files changed +42
-34
lines changed Original file line number Diff line number Diff line change 42
42
activate ( ) ;
43
43
44
44
function activate ( ) {
45
- _checkForParticipation ( ) . then ( function ( ) {
46
- vm . isCopilot = _ . includes ( userIdentity . roles , 'copilot' ) ;
47
- vm . myChallenges = [ ] ;
48
- changeFilter ( vm . statusFilter ) ;
49
- } ) ;
45
+ vm . isCopilot = _ . includes ( userIdentity . roles , 'copilot' ) ;
46
+ vm . myChallenges = [ ] ;
47
+ changeFilter ( vm . statusFilter ) ;
50
48
}
51
49
52
50
function changeView ( view ) {
85
83
$q . all ( promises )
86
84
. then ( function ( data ) {
87
85
// data should be an array of 2 objects each with it's own array (2D array with metadata)
88
- vm . loading = CONSTANTS . STATE_READY ;
89
86
90
87
vm . totalCount = _ . sum ( _ . pluck ( data , 'metadata.totalCount' ) ) ;
91
88
vm . myChallenges = vm . myChallenges . concat ( _ . union ( data [ 0 ] , data [ 1 ] ) ) ;
89
+ if ( vm . totalCount === 0 ) {
90
+ _checkForParticipation ( ) . then ( function ( ) {
91
+ vm . loading = CONSTANTS . STATE_READY ;
92
+ } ) ;
93
+ } else {
94
+ vm . loading = CONSTANTS . STATE_READY ;
95
+ }
92
96
} )
93
97
. catch ( function ( resp ) {
94
98
$log . error ( resp ) ;
146
150
}
147
151
148
152
function _checkForParticipation ( ) {
149
- var params = {
150
- limit : 1 ,
151
- offset : 0
152
- } ;
153
- return ChallengeService . getUserChallenges ( vm . handle , params ) . then ( function ( challenges ) {
154
- if ( challenges . metadata . totalCount > 0 ) {
155
- vm . neverParticipated = false ;
156
- } else {
157
- vm . neverParticipated = true ;
158
- }
153
+ return ChallengeService . checkChallengeParticipation ( vm . handle , function ( participated ) {
154
+ vm . neverParticipated = ! participated ;
159
155
} ) ;
160
156
}
161
157
}
Original file line number Diff line number Diff line change 20
20
21
21
function activate ( ) {
22
22
vm . myChallenges = [ ] ;
23
- _checkForParticipation ( ) . then ( function ( ) {
24
- getChallenges ( ) ;
25
- } ) ;
23
+ getChallenges ( ) ;
26
24
}
27
25
28
26
function getChallenges ( ) {
47
45
48
46
if ( ! marathonMatches . length && ! devDesignChallenges . length ) {
49
47
vm . userHasChallenges = false ;
50
- vm . loading = false ;
48
+ _checkForParticipation ( ) . then ( function ( ) {
49
+ vm . loading = false ;
50
+ } ) ;
51
51
52
52
} else {
53
53
ChallengeService . processActiveDevDesignChallenges ( devDesignChallenges ) ;
54
54
ChallengeService . processActiveMarathonMatches ( marathonMatches ) ;
55
55
var userChallenges = marathonMatches . concat ( devDesignChallenges ) ;
56
56
57
57
userChallenges = _ . sortBy ( userChallenges , function ( n ) {
58
- return n . registrationEndDate
58
+ return n . registrationEndDate ;
59
59
} ) ;
60
60
vm . myChallenges = userChallenges . reverse ( ) . slice ( 0 , 8 ) ;
61
61
vm . userHasChallenges = true ;
76
76
}
77
77
78
78
function _checkForParticipation ( ) {
79
- var params = {
80
- limit : 1 ,
81
- offset : 0
82
- } ;
83
- return ChallengeService . getUserChallenges ( handle , params ) . then ( function ( challenges ) {
84
- if ( challenges . metadata . totalCount > 0 ) {
85
- vm . neverParticipated = true ;
86
- } else {
87
- vm . neverParticipated = true ;
88
- }
79
+ return ChallengeService . checkChallengeParticipation ( handle , function ( participated ) {
80
+ vm . neverParticipated = ! participated ;
89
81
} ) ;
90
82
}
91
83
}
Original file line number Diff line number Diff line change 3
3
4
4
angular . module ( 'tc.services' ) . factory ( 'ChallengeService' , ChallengeService ) ;
5
5
6
- ChallengeService . $inject = [ 'CONSTANTS' , 'ApiService' ] ;
6
+ ChallengeService . $inject = [ 'CONSTANTS' , 'ApiService' , '$q' ] ;
7
7
8
- function ChallengeService ( CONSTANTS , ApiService ) {
8
+ function ChallengeService ( CONSTANTS , ApiService , $q ) {
9
9
var api = ApiService . restangularV3 ;
10
10
11
11
var service = {
18
18
processActiveMarathonMatches : processActiveMarathonMatches ,
19
19
processPastMarathonMatch : processPastMarathonMatch ,
20
20
processPastSRM : processPastSRM ,
21
- processPastChallenges : processPastChallenges
21
+ processPastChallenges : processPastChallenges ,
22
+ checkChallengeParticipation : checkChallengeParticipation
22
23
} ;
23
24
24
25
return service ;
207
208
}
208
209
} ) ;
209
210
}
211
+
212
+ function checkChallengeParticipation ( handle , callback ) {
213
+ var params = {
214
+ limit : 1 ,
215
+ offset : 0
216
+ } ;
217
+ return $q . all ( [
218
+ getUserMarathonMatches ( handle , params ) ,
219
+ getUserChallenges ( handle , params )
220
+ ] ) . then ( function ( data ) {
221
+ var mms = data [ 0 ] ;
222
+ var challenges = data [ 1 ] ;
223
+ if ( challenges . metadata . totalCount > 0 || mms . metadata . totalCount > 0 ) {
224
+ callback ( true ) ;
225
+ } else {
226
+ callback ( false ) ;
227
+ }
228
+ } ) ;
229
+ }
210
230
} ;
211
231
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments