@@ -16,12 +16,12 @@ import _ from 'lodash'
1616 hideMoney : '=' ,
1717 defaultState : '@'
1818 } ,
19- controller : [ 'CONSTANTS' , '$rootScope' , '$scope' , 'ProfileService' , 'logger' , '$state' , pageStateHeader ] ,
19+ controller : [ 'CONSTANTS' , '$rootScope' , '$scope' , 'ProfileService' , 'logger' , '$state' , 'ChallengeService' , '$q' , 'UserService' , 'BadgeService' , pageStateHeader ] ,
2020 controllerAs : 'vm'
2121 }
2222 } )
2323
24- function pageStateHeader ( CONSTANTS , $rootScope , $scope , ProfileService , logger , $state ) {
24+ function pageStateHeader ( CONSTANTS , $rootScope , $scope , ProfileService , logger , $state , ChallengeService , $q , UserService , BadgeService ) {
2525 var vm = this
2626 vm . backHandler = backHandler
2727
@@ -35,13 +35,12 @@ import _ from 'lodash'
3535 function activate ( ) {
3636 vm . handle = $scope . handle
3737 vm . profile = null
38- vm . handleColor = null
3938 $scope . hideMoney = _ . get ( $scope , 'hideMoney' , true )
4039 vm . previousStateName = null
4140 vm . previousStateLabel = null
4241 vm . previousState = null
43- vm . showBackLink = _ . get ( $scope , 'showBackLink' , false )
44- vm . loading = true
42+ vm . dashboardBadgeName = null
43+
4544
4645 // identifies the previous state
4746 if ( $scope . $root . previousState && $scope . $root . previousState . name . length > 0 ) {
@@ -65,14 +64,32 @@ import _ from 'lodash'
6564 // gets member's profile
6665 ProfileService . getUserProfile ( vm . handle ) . then ( function ( profile ) {
6766 vm . profile = profile
68- vm . handleColor = ProfileService . getUserHandleColor ( vm . profile )
6967
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+
7578 } )
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+
7693 }
7794
7895 function backHandler ( ) {
@@ -100,15 +117,21 @@ import _ from 'lodash'
100117 if ( ! vm . moneyEarned ) {
101118 $scope . hideMoney = true
102119 }
103-
104- vm . loading = false
105120 } )
106121 . catch ( function ( err ) {
107122 $scope . hideMoney = true
108- vm . loading = false
109-
110123 logger . error ( 'Could not get user financial information' , err )
111124 } )
112125 }
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+
113136 }
114137} ) ( )
0 commit comments