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

TC App Issue 1002: role-dependent customization of the challenge details page #479

Merged
merged 1 commit into from
Feb 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
challengeType = $location.search().type || 'develop';

var vm = this;

//Set mockUserRole to array ['value'] to mock a user role, undefined will set userRole value via challenge API
//you can test for a user role using checkRole('role') function for true/false value.
vm.mockUserRole = undefined;
// default review style
vm.reviewStyle = "";
vm.reviewStyleTooltip = "";
Expand All @@ -65,7 +69,7 @@
}
vm.activeTab = 'details';
vm.domain = tcconfig.domain;

if (window.location.hash == '#viewRegistrant' || window.location.hash == '#/viewRegistrant') vm.activeTab = 'registrants';
else if (window.location.hash == '#winner' || window.location.hash == '#/winner') vm.activeTab = 'results';
else if (window.location.hash == '#submissions' || window.location.hash == '#/submissions') vm.activeTab = 'submissions';
Expand All @@ -81,6 +85,9 @@
vm.checkpointPassedScreeningSubmissionPercentage = 0;
vm.phaseProgram = null;
vm.termsList = [];
vm.challengeApiParams = {
filter: 'id=' + challengeId
}

$interval(function () {
if (vm.challenge && vm.challenge.currentPhaseRemainingTime) {
Expand All @@ -91,7 +98,7 @@
// Methods
vm.registerToChallenge = registerToChallenge;
vm.unregisterFromChallenge = unregisterFromChallenge;

vm.checkRole = checkRole;
// functions
$scope.round = Math.round;
$scope.range = rangeFunction;
Expand Down Expand Up @@ -131,7 +138,16 @@
initChallengeDetail(handle, vm, ChallengeService);
}
);

/**
*
* @param checkRole
* @returns {true|false}
*/
function checkRole(checkRole) {
return _.some(vm.userRole, function(role) {
return role === checkRole;
})
}
/**
*
* @param x
Expand Down Expand Up @@ -166,6 +182,18 @@
ChallengeService.getChallengeTerms(challengeId).then(function(termsList) {
vm.termsList = termsList;
});
ChallengeService
.getUserChallenges(vm.handle, vm.challengeApiParams)
.then(function (challenge) {
if (challenge[0] && challenge[0].result.content.length) {
challenge = challenge[0].result.content[0];
vm.userRole = challenge.userDetails ? challenge.userDetails.roles : [];
} else {
vm.userRole = [];
}
//Set to test value if defined
vm.userRole = vm.mockUserRole ? vm.mockUserRole : vm.userRole;
});
ChallengeService
.getChallenge(challengeId)
.then(function (challenge) {
Expand All @@ -176,7 +204,6 @@
}, 100);
$('#cdNgMain').show();
});

}

function updateChallengeDetail() {
Expand Down Expand Up @@ -334,7 +361,7 @@
if (regList.indexOf(handle) == -1) {
vm.isRegistered = false;
}

var hasSubmitted = false;
if (submitters.indexOf(handle) >= 0) {
hasSubmitted = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@
return defer.promise;
};

service.getUserChallenges = function(handle, params) {
return servicev3.one('members', handle.toLowerCase()).all('challenges/').getList(params)
}

return service;
}

Expand Down