Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit c21c590

Browse files
authored
Merge pull request #479 from Colinh84/issue_1002
TC App Issue 1002: role-dependent customization of the challenge details page
2 parents 5cbfdb2 + 20d14a3 commit c21c590

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

src/js/app/challenge-details/js/controllers/challenge-details-controller.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
challengeType = $location.search().type || 'develop';
4848

4949
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;
5054
// default review style
5155
vm.reviewStyle = "";
5256
vm.reviewStyleTooltip = "";
@@ -65,7 +69,7 @@
6569
}
6670
vm.activeTab = 'details';
6771
vm.domain = tcconfig.domain;
68-
72+
6973
if (window.location.hash == '#viewRegistrant' || window.location.hash == '#/viewRegistrant') vm.activeTab = 'registrants';
7074
else if (window.location.hash == '#winner' || window.location.hash == '#/winner') vm.activeTab = 'results';
7175
else if (window.location.hash == '#submissions' || window.location.hash == '#/submissions') vm.activeTab = 'submissions';
@@ -81,6 +85,9 @@
8185
vm.checkpointPassedScreeningSubmissionPercentage = 0;
8286
vm.phaseProgram = null;
8387
vm.termsList = [];
88+
vm.challengeApiParams = {
89+
filter: 'id=' + challengeId
90+
}
8491

8592
$interval(function () {
8693
if (vm.challenge && vm.challenge.currentPhaseRemainingTime) {
@@ -91,7 +98,7 @@
9198
// Methods
9299
vm.registerToChallenge = registerToChallenge;
93100
vm.unregisterFromChallenge = unregisterFromChallenge;
94-
101+
vm.checkRole = checkRole;
95102
// functions
96103
$scope.round = Math.round;
97104
$scope.range = rangeFunction;
@@ -131,7 +138,16 @@
131138
initChallengeDetail(handle, vm, ChallengeService);
132139
}
133140
);
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+
}
135151
/**
136152
*
137153
* @param x
@@ -166,6 +182,18 @@
166182
ChallengeService.getChallengeTerms(challengeId).then(function(termsList) {
167183
vm.termsList = termsList;
168184
});
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+
});
169197
ChallengeService
170198
.getChallenge(challengeId)
171199
.then(function (challenge) {
@@ -176,7 +204,6 @@
176204
}, 100);
177205
$('#cdNgMain').show();
178206
});
179-
180207
}
181208

182209
function updateChallengeDetail() {
@@ -334,7 +361,7 @@
334361
if (regList.indexOf(handle) == -1) {
335362
vm.isRegistered = false;
336363
}
337-
364+
338365
var hasSubmitted = false;
339366
if (submitters.indexOf(handle) >= 0) {
340367
hasSubmitted = true;

src/js/app/challenge-details/js/services/challenge-details-services.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@
303303
return defer.promise;
304304
};
305305

306+
service.getUserChallenges = function(handle, params) {
307+
return servicev3.one('members', handle.toLowerCase()).all('challenges/').getList(params)
308+
}
309+
306310
return service;
307311
}
308312

0 commit comments

Comments
 (0)