@@ -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,10 @@ 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
45
42
46
43
// identifies the previous state
47
44
if ( $scope . $root . previousState && $scope . $root . previousState . name . length > 0 ) {
@@ -65,14 +62,33 @@ import _ from 'lodash'
65
62
// gets member's profile
66
63
ProfileService . getUserProfile ( vm . handle ) . then ( function ( profile ) {
67
64
vm . profile = profile
68
- vm . handleColor = ProfileService . getUserHandleColor ( vm . profile )
69
65
70
- if ( ! $scope . hideMoney ) {
71
- displayMoneyEarned ( vm . handle )
72
- } else {
73
- vm . loading = false
74
- }
66
+ // get members dashboard badge
67
+ UserService . getV2UserProfile ( vm . handle ) . then ( function ( resp ) {
68
+ // Calling the mock to return a badge
69
+ // In actuality filtering should be done by whether the achievement contains a field 'forDashboard' or not.
70
+ var dashboardAchievement = _filterDashboardAchievement ( resp . Achievements || [ ] ) [ 0 ]
71
+
72
+ if ( dashboardAchievement ) {
73
+ vm . dashboardBadge = BadgeService . getAchievementVm ( dashboardAchievement )
74
+ }
75
+ } )
76
+
77
+ } )
78
+
79
+ // get member's challenges to display number of active challenges
80
+ $q . all ( [
81
+ ChallengeService . getUserMarathonMatches ( vm . handle , { filter : 'status=active' } ) ,
82
+ ChallengeService . getUserChallenges ( vm . handle , { filter : 'status=active' } )
83
+ ] ) . then ( function ( challenges ) {
84
+ var marathonMatches = challenges [ 0 ]
85
+ var devDesignChallenges = challenges [ 1 ]
86
+
87
+ vm . activeChallenges = marathonMatches . length + devDesignChallenges . length
75
88
} )
89
+
90
+ displayMoneyEarned ( vm . handle )
91
+
76
92
}
77
93
78
94
function backHandler ( ) {
@@ -100,15 +116,39 @@ import _ from 'lodash'
100
116
if ( ! vm . moneyEarned ) {
101
117
$scope . hideMoney = true
102
118
}
103
-
104
- vm . loading = false
105
119
} )
106
120
. catch ( function ( err ) {
107
121
$scope . hideMoney = true
108
- vm . loading = false
109
122
110
123
logger . error ( 'Could not get user financial information' , err )
111
124
} )
112
125
}
126
+
127
+ // Temporary function to simulate dashboard achievement
128
+ function _filterDashboardAchievement ( achievements ) {
129
+ // If forceBadge is true, it displays the achievement in _mock, whether the user has that achievement or not
130
+ var _forceBadge = false
131
+
132
+ // temoprary config object that maps usernames to badge name
133
+ var _mock = {
134
+ ronakkaria : 'First Win' ,
135
+ birdofpreyru : 'Predix Community'
136
+ }
137
+
138
+ var dashboardBadgeName = _mock [ vm . handle ]
139
+ if ( ! dashboardBadgeName ) { return [ ] }
140
+
141
+ if ( _forceBadge ) {
142
+ return [ {
143
+ date : new Date ( ) ,
144
+ description : _mock [ vm . handle ]
145
+ } ]
146
+ }
147
+
148
+ return achievements . filter ( function ( achievement ) {
149
+ return ( achievement . description === dashboardBadgeName )
150
+ } )
151
+ }
152
+
113
153
}
114
154
} ) ( )
0 commit comments