@@ -16,12 +16,12 @@ import _ from 'lodash'
16
16
hideMoney : '=' ,
17
17
defaultState : '@'
18
18
} ,
19
- controller : [ 'CONSTANTS' , '$rootScope' , '$scope' , 'ProfileService' , 'logger' , '$state' , pageStateHeader ] ,
19
+ controller : [ 'CONSTANTS' , '$rootScope' , '$scope' , 'ProfileService' , 'logger' , '$state' , 'ChallengeService' , '$q' , 'UserService' , 'BadgeService' , pageStateHeader ] ,
20
20
controllerAs : 'vm'
21
21
}
22
22
} )
23
23
24
- function pageStateHeader ( CONSTANTS , $rootScope , $scope , ProfileService , logger , $state ) {
24
+ function pageStateHeader ( CONSTANTS , $rootScope , $scope , ProfileService , logger , $state , ChallengeService , $q , UserService , BadgeService ) {
25
25
var vm = this
26
26
vm . backHandler = backHandler
27
27
@@ -35,13 +35,12 @@ import _ from 'lodash'
35
35
function activate ( ) {
36
36
vm . handle = $scope . handle
37
37
vm . profile = null
38
- vm . handleColor = null
39
38
$scope . hideMoney = _ . get ( $scope , 'hideMoney' , true )
40
39
vm . previousStateName = null
41
40
vm . previousStateLabel = null
42
41
vm . previousState = null
43
- vm . showBackLink = _ . get ( $scope , 'showBackLink' , false )
44
- vm . loading = true
42
+ vm . dashboardBadgeName = null
43
+
45
44
46
45
// identifies the previous state
47
46
if ( $scope . $root . previousState && $scope . $root . previousState . name . length > 0 ) {
@@ -65,14 +64,32 @@ import _ from 'lodash'
65
64
// gets member's profile
66
65
ProfileService . getUserProfile ( vm . handle ) . then ( function ( profile ) {
67
66
vm . profile = profile
68
- vm . handleColor = ProfileService . getUserHandleColor ( vm . profile )
69
67
70
- if ( ! $scope . hideMoney ) {
71
- displayMoneyEarned ( vm . handle )
72
- } else {
73
- vm . loading = false
74
- }
68
+ // get members dashboard badge
69
+ UserService . getV2UserProfile ( vm . handle ) . then ( function ( resp ) {
70
+
71
+ var dashboardAchievement = _filterDashboardAchievement ( resp . Achievements || [ ] ) [ 0 ]
72
+ if ( dashboardAchievement ) {
73
+ //Get dashboard badges
74
+ vm . dashboardBadge = BadgeService . getAchievementVm ( dashboardAchievement )
75
+ }
76
+ } )
77
+
75
78
} )
79
+
80
+ // get member's challenges to display number of active challenges
81
+ $q . all ( [
82
+ ChallengeService . getUserMarathonMatches ( vm . handle , { filter : 'status=active' } ) ,
83
+ ChallengeService . getUserChallenges ( vm . handle , { filter : 'status=active' } )
84
+ ] ) . then ( function ( challenges ) {
85
+ var marathonMatches = challenges [ 0 ]
86
+ var devDesignChallenges = challenges [ 1 ]
87
+
88
+ vm . activeChallenges = marathonMatches . length + devDesignChallenges . length
89
+ } )
90
+
91
+ displayMoneyEarned ( vm . handle )
92
+
76
93
}
77
94
78
95
function backHandler ( ) {
@@ -100,15 +117,21 @@ import _ from 'lodash'
100
117
if ( ! vm . moneyEarned ) {
101
118
$scope . hideMoney = true
102
119
}
103
-
104
- vm . loading = false
105
120
} )
106
121
. catch ( function ( err ) {
107
122
$scope . hideMoney = true
108
- vm . loading = false
109
-
110
123
logger . error ( 'Could not get user financial information' , err )
111
124
} )
112
125
}
126
+
127
+ function _filterDashboardAchievement ( achievements ) {
128
+ //Currently only one batch is shown on the dashboard
129
+ vm . dashboardBadgeName = 'SRM Engagement Honor'
130
+
131
+ return achievements . filter ( function ( achievement ) {
132
+ return ( achievement . description === vm . dashboardBadgeName )
133
+ } )
134
+ }
135
+
113
136
}
114
137
} ) ( )
0 commit comments