|
| 1 | +import angular from 'angular' |
| 2 | +import moment from 'moment-timezone' |
| 3 | + |
1 | 4 | (function () {
|
2 |
| - 'use strict'; |
| 5 | + 'use strict' |
| 6 | + |
| 7 | + angular.module('tc.profile').controller('BadgesController', BadgeCtrl) |
3 | 8 |
|
4 |
| - /** |
5 |
| - * The controller for badges section of member-profile page. |
6 |
| - */ |
7 |
| - var BadgeCtrl = function ($scope, CONSTANTS, ProfileService, UserService, userHandle, profile) { |
8 |
| - $scope.achievements = profile.badges.Achievements; |
9 |
| - var badgeCtrl = this; |
10 |
| - // use logged in user's handle for showing badges if not injected into the controller |
11 |
| - badgeCtrl.userHandle = userHandle ? userHandle : UserService.getUserIdentity().username; |
12 |
| - badgeCtrl.init($scope); |
13 |
| - badgeCtrl.mapBadges(); |
14 |
| - badgeCtrl.profile = profile; |
15 |
| - badgeCtrl.dealWithBadgeData($scope, ProfileService); |
| 9 | + BadgeCtrl.$inject = ['$scope', 'CONSTANTS', 'ProfileService', 'UserService', 'userHandle', 'profile'] |
16 | 10 |
|
| 11 | + // The controller for badges section of member-profile page. |
| 12 | + function BadgeCtrl($scope, CONSTANTS, ProfileService, UserService, userHandle, profile) { |
| 13 | + $scope.achievements = profile.badges.Achievements |
| 14 | + var badgeCtrl = this |
17 | 15 |
|
18 |
| - }; |
19 |
| - /** |
20 |
| - * Deal with badge data when we have the user profile ready. |
21 |
| - */ |
| 16 | + // Use logged in user's handle for showing badges if not injected into the controller |
| 17 | + badgeCtrl.userHandle = userHandle ? userHandle : UserService.getUserIdentity().username |
| 18 | + badgeCtrl.init($scope) |
| 19 | + badgeCtrl.mapBadges() |
| 20 | + badgeCtrl.profile = profile |
| 21 | + badgeCtrl.dealWithBadgeData($scope, ProfileService) |
| 22 | + } |
| 23 | + |
| 24 | + // Deal with badge data when we have the user profile ready. |
22 | 25 | BadgeCtrl.prototype.dealWithBadgeData = function($scope, ProfileService){
|
23 |
| - var badgeCtrl = this; |
24 |
| - /* |
25 |
| - The service method getUser( handle ) already contains achievements information. |
26 |
| - So we don't need another more service method here. |
27 |
| - */ |
28 |
| - |
29 |
| - var excluded_badgesID = [1,6, 11, 16, 21, 52, 1000, 1001, 1002, 1003, 1004, 1005, 1006]; // few data is not available, so lets exclude them. |
30 |
| - |
31 |
| - if($scope.achievements) { |
| 26 | + var badgeCtrl = this |
| 27 | + // The service method getUser( handle ) already contains achievements information. |
| 28 | + // So we don't need another more service method here. |
| 29 | + |
| 30 | + // Some data is not available, so lets exclude them. |
| 31 | + // var excluded_badgesID = [1,6, 11, 16, 21, 52, 1000, 1001, 1002, 1003, 1004, 1005, 1006] |
| 32 | + |
| 33 | + if ($scope.achievements) { |
32 | 34 | angular.forEach($scope.achievements, function(achievement){
|
33 |
| - var desc = achievement.description; |
34 |
| - /* Fix Studio Badges */ |
| 35 | + var desc = achievement.description |
| 36 | + // Fix Studio Badges |
35 | 37 | if(badgeCtrl.map[achievement.description] === undefined && desc.indexOf('Studio ') === 0) {
|
36 |
| - desc = desc.substring(7); |
| 38 | + desc = desc.substring(7) |
37 | 39 | }
|
38 |
| - /* Fix Studio bad badge name */ |
| 40 | + // Fix Studio bad badge name |
39 | 41 | if(desc === 'Fifty Milestone Prize' || desc === 'One Hundred Milestone Prize' || desc === 'Two Hundred And Fifty Milestone Prize') {
|
40 |
| - desc = desc + 's'; |
| 42 | + desc = desc + 's' |
41 | 43 | }
|
42 | 44 | if(desc.indexOf('Designer of the Month') !== -1) {
|
43 |
| - desc = 'Designer of the Month'; |
| 45 | + desc = 'Designer of the Month' |
44 | 46 | }
|
45 | 47 | if(desc.indexOf('Member of the Month') !== -1) {
|
46 |
| - desc = 'Member of the Month'; |
| 48 | + desc = 'Member of the Month' |
47 | 49 | }
|
48 |
| - var value = badgeCtrl.map[desc]; |
49 |
| - //activate all active badges. |
| 50 | + var value = badgeCtrl.map[desc] |
| 51 | + // Activate all active badges. |
50 | 52 | if(value){
|
51 |
| - value.date = badgeCtrl.formatDate(achievement.date); |
52 |
| - value.active = true; |
| 53 | + value.date = badgeCtrl.formatDate(achievement.date) |
| 54 | + value.active = true |
53 | 55 | if(achievement.description.indexOf('Studio ') === 0) {
|
54 |
| - value.isStudio = true; |
| 56 | + value.isStudio = true |
55 | 57 | }
|
56 | 58 | }
|
57 |
| - }); |
| 59 | + }) |
58 | 60 | }
|
59 |
| - }; |
| 61 | + } |
60 | 62 |
|
61 |
| - /** |
62 |
| - * Construct a map contains all badges. |
63 |
| - */ |
| 63 | + // Construct a map containing all badges. |
64 | 64 | BadgeCtrl.prototype.mapBadges = function(){
|
65 |
| - var badgeCtrl = this; |
66 |
| - badgeCtrl.map = {}; |
| 65 | + var badgeCtrl = this |
| 66 | + badgeCtrl.map = {} |
67 | 67 | angular.forEach(badgeCtrl.achievementGroups, function(achievementGroup){
|
68 |
| - //var achievementGroup = this; |
69 | 68 | angular.forEach(achievementGroup.specificAchievements, function(achievement){
|
70 |
| - achievement.id = achievementGroup.id; |
71 |
| - badgeCtrl.map[achievement.name] = achievement; |
72 |
| - }); |
73 |
| - }); |
| 69 | + achievement.id = achievementGroup.id |
| 70 | + badgeCtrl.map[achievement.name] = achievement |
| 71 | + }) |
| 72 | + }) |
74 | 73 | angular.forEach(badgeCtrl.singleAchievements, function(achievement){
|
75 |
| - badgeCtrl.map[achievement.name] = achievement; |
76 |
| - }); |
77 |
| - }; |
| 74 | + badgeCtrl.map[achievement.name] = achievement |
| 75 | + }) |
| 76 | + } |
78 | 77 |
|
79 |
| - /** |
80 |
| - * Convert the date with format like 'Sep 09,2013' |
81 |
| - */ |
| 78 | + // Convert the date with format like 'Sep 09,2013' |
82 | 79 | BadgeCtrl.prototype.formatDate = function(date) {
|
83 |
| - //some function is passing in undefined timezone_string variable causing js errors, |
| 80 | + // Some function is passing in undefined timezone_string variable causing js errors, |
84 | 81 | // so check if undefined and set default:
|
85 | 82 | if (typeof timezone_string === 'undefined') {
|
86 |
| - var timezone_string = "America/New_York"; // lets set to TC timezone |
| 83 | + var timezone_string = 'America/New_York' // lets set to TC timezone |
87 | 84 | }
|
88 |
| - return moment(date).tz(timezone_string).format("MMM DD,YYYY"); |
89 |
| - }; |
| 85 | + return moment(date).tz(timezone_string).format('MMM DD,YYYY') |
| 86 | + } |
90 | 87 |
|
91 |
| - /** |
92 |
| - * Construct the data 'currentlyEarned'. |
93 |
| - */ |
| 88 | + // Construct the data 'currentlyEarned'. |
94 | 89 | BadgeCtrl.prototype.populateData = function(destination, count){
|
95 |
| - var quantifier = ""; |
| 90 | + var quantifier = '' |
96 | 91 | switch(destination.id){
|
97 |
| - case "1": |
98 |
| - quantifier = "Post"; |
99 |
| - break; |
100 |
| - case "6": |
101 |
| - quantifier = "Submission"; |
102 |
| - break; |
103 |
| - case "11": |
104 |
| - quantifier = "Prize"; |
105 |
| - break; |
106 |
| - case "16": |
107 |
| - case "117": |
108 |
| - quantifier = "Placement"; |
109 |
| - break; |
110 |
| - case "89": |
111 |
| - quantifier = "SRM"; |
112 |
| - break; |
113 |
| - case "99": |
114 |
| - case "126": |
115 |
| - case "127": |
116 |
| - quantifier = "Problem"; |
117 |
| - break; |
118 |
| - default: |
119 |
| - quantifier = "Win"; |
120 |
| - break; |
| 92 | + case '1': |
| 93 | + quantifier = 'Post' |
| 94 | + break |
| 95 | + case '6': |
| 96 | + quantifier = 'Submission' |
| 97 | + break |
| 98 | + case '11': |
| 99 | + quantifier = 'Prize' |
| 100 | + break |
| 101 | + case '16': |
| 102 | + case '117': |
| 103 | + quantifier = 'Placement' |
| 104 | + break |
| 105 | + case '89': |
| 106 | + quantifier = 'SRM' |
| 107 | + break |
| 108 | + case '99': |
| 109 | + case '126': |
| 110 | + case '127': |
| 111 | + quantifier = 'Problem' |
| 112 | + break |
| 113 | + default: |
| 114 | + quantifier = 'Win' |
| 115 | + break |
121 | 116 | }
|
122 | 117 |
|
123 | 118 | if (count && count > 1) {
|
124 |
| - quantifier += "s"; |
| 119 | + quantifier += 's' |
125 | 120 | }
|
126 | 121 | if(count){
|
127 |
| - destination.currentlyEarned = count + ' ' + quantifier; |
| 122 | + destination.currentlyEarned = count + ' ' + quantifier |
128 | 123 | }
|
129 |
| - }; |
130 |
| - /** |
131 |
| - * Initialize the data array needed by badge section. |
132 |
| - */ |
| 124 | + } |
| 125 | + // Initialize the data array needed by badge section. |
133 | 126 | BadgeCtrl.prototype.init = function($scope){
|
134 |
| - this.scope = $scope; |
| 127 | + this.scope = $scope |
135 | 128 |
|
136 | 129 | this.achievementGroups =
|
137 | 130 | [
|
|
533 | 526 | }
|
534 | 527 | ]
|
535 | 528 | }
|
536 |
| - ]; |
| 529 | + ] |
537 | 530 |
|
538 | 531 | this.singleAchievements =
|
539 | 532 | [
|
|
657 | 650 | groupClass : 'Member-of-the-Month',
|
658 | 651 | active : false
|
659 | 652 | }
|
660 |
| - ]; |
661 |
| - }; |
662 |
| - |
663 |
| - angular |
664 |
| - .module('tc.profile') |
665 |
| - .controller('BadgesController', BadgeCtrl); |
666 |
| - |
667 |
| - BadgeCtrl.$inject = ['$scope', 'CONSTANTS', 'ProfileService', 'UserService', 'userHandle', 'profile']; |
668 |
| -})(); |
| 653 | + ] |
| 654 | + } |
| 655 | +})() |
0 commit comments