|
47 | 47 | challengeType = $location.search().type || 'develop';
|
48 | 48 |
|
49 | 49 | var vm = this;
|
| 50 | + |
| 51 | + //Set mockUserRole to array ['value'] to mock a user role, undefined will set userRole value via challenge API |
| 52 | + //you can test for a user role using checkRole('role') function for true/false value. |
| 53 | + vm.mockUserRole = undefined; |
50 | 54 | // default review style
|
51 | 55 | vm.reviewStyle = "";
|
52 | 56 | vm.reviewStyleTooltip = "";
|
|
65 | 69 | }
|
66 | 70 | vm.activeTab = 'details';
|
67 | 71 | vm.domain = tcconfig.domain;
|
68 |
| - |
| 72 | + |
69 | 73 | if (window.location.hash == '#viewRegistrant' || window.location.hash == '#/viewRegistrant') vm.activeTab = 'registrants';
|
70 | 74 | else if (window.location.hash == '#winner' || window.location.hash == '#/winner') vm.activeTab = 'results';
|
71 | 75 | else if (window.location.hash == '#submissions' || window.location.hash == '#/submissions') vm.activeTab = 'submissions';
|
|
81 | 85 | vm.checkpointPassedScreeningSubmissionPercentage = 0;
|
82 | 86 | vm.phaseProgram = null;
|
83 | 87 | vm.termsList = [];
|
| 88 | + vm.challengeApiParams = { |
| 89 | + filter: 'id=' + challengeId |
| 90 | + } |
84 | 91 |
|
85 | 92 | $interval(function () {
|
86 | 93 | if (vm.challenge && vm.challenge.currentPhaseRemainingTime) {
|
|
91 | 98 | // Methods
|
92 | 99 | vm.registerToChallenge = registerToChallenge;
|
93 | 100 | vm.unregisterFromChallenge = unregisterFromChallenge;
|
94 |
| - |
| 101 | + vm.checkRole = checkRole; |
95 | 102 | // functions
|
96 | 103 | $scope.round = Math.round;
|
97 | 104 | $scope.range = rangeFunction;
|
|
131 | 138 | initChallengeDetail(handle, vm, ChallengeService);
|
132 | 139 | }
|
133 | 140 | );
|
134 |
| - |
| 141 | + /** |
| 142 | + * |
| 143 | + * @param checkRole |
| 144 | + * @returns {true|false} |
| 145 | + */ |
| 146 | + function checkRole(checkRole) { |
| 147 | + return _.some(vm.userRole, function(role) { |
| 148 | + return role === checkRole; |
| 149 | + }) |
| 150 | + } |
135 | 151 | /**
|
136 | 152 | *
|
137 | 153 | * @param x
|
|
166 | 182 | ChallengeService.getChallengeTerms(challengeId).then(function(termsList) {
|
167 | 183 | vm.termsList = termsList;
|
168 | 184 | });
|
| 185 | + ChallengeService |
| 186 | + .getUserChallenges(vm.handle, vm.challengeApiParams) |
| 187 | + .then(function (challenge) { |
| 188 | + if (challenge[0] && challenge[0].result.content.length) { |
| 189 | + challenge = challenge[0].result.content[0]; |
| 190 | + vm.userRole = challenge.userDetails ? challenge.userDetails.roles : []; |
| 191 | + } else { |
| 192 | + vm.userRole = []; |
| 193 | + } |
| 194 | + //Set to test value if defined |
| 195 | + vm.userRole = vm.mockUserRole ? vm.mockUserRole : vm.userRole; |
| 196 | + }); |
169 | 197 | ChallengeService
|
170 | 198 | .getChallenge(challengeId)
|
171 | 199 | .then(function (challenge) {
|
|
176 | 204 | }, 100);
|
177 | 205 | $('#cdNgMain').show();
|
178 | 206 | });
|
179 |
| - |
180 | 207 | }
|
181 | 208 |
|
182 | 209 | function updateChallengeDetail() {
|
|
334 | 361 | if (regList.indexOf(handle) == -1) {
|
335 | 362 | vm.isRegistered = false;
|
336 | 363 | }
|
337 |
| - |
| 364 | + |
338 | 365 | var hasSubmitted = false;
|
339 | 366 | if (submitters.indexOf(handle) >= 0) {
|
340 | 367 | hasSubmitted = true;
|
|
0 commit comments