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

SUP-3058, Adapt FE according to new json structure of challenge endpoint #724

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -59,14 +59,6 @@ import _ from 'lodash'
$scope.challenge.thumbnailId = $scope.challenge.userDetails.submissions[0].id
$scope.imageURL = $scope.challenge.userDetails.submissions[0].submissionImage && $scope.challenge.userDetails.submissions[0].submissionImage.full
$scope.selectedImage = $scope.imageURL

$scope.challenge.highestPlacement = _.min($scope.challenge.userDetails.submissions.filter(function(submission) {
return submission.type === CONSTANTS.SUBMISSION_TYPE_CONTEST && submission.placement
}), 'placement').placement

if ($scope.challenge.highestPlacement == 1) {
$scope.challenge.wonFirst = true
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
p.place(ng-class="{ 'first-place': challenge.wonFirst }", ng-show="challenge.highestPlacement") {{challenge.highestPlacement}}#[span {{challenge.highestPlacement | ordinal:true}}] Place
p.place.didnt(ng-show="challenge.userStatus === 'NOT_FINISHED'") Didn't Finish
p.place.passed(ng-show="challenge.userStatus === 'PASSED_SCREENING'") Passed Screening
p.place(ng-show="!challenge.highestPlacement && challenge.userStatus === 'PASSED_REVIEW'") Passed Review
p.place.completed(ng-show="challenge.userStatus === 'COMPLETED'") COMPLETED

.thumbnail(ng-click="!challenge.isPrivate && imageURL && openLightbox()", ng-class="{hidden: challenge.userStatus !== 'PASSED_REVIEW'}")
Expand All @@ -23,6 +24,7 @@
p.place(ng-class="{ 'first-place': challenge.wonFirst }", ng-show="challenge.highestPlacement") {{challenge.highestPlacement}}#[span {{challenge.highestPlacement | ordinal:true}}] Place
p.place.didnt(ng-show="challenge.userStatus === 'NOT_FINISHED'") Didn't Finish
p.place.passed(ng-show="challenge.userStatus === 'PASSED_SCREENING'") Passed Screening
p.place(ng-show="!challenge.highestPlacement && challenge.userStatus === 'PASSED_REVIEW'") Passed Review
p.place.completed(ng-show="challenge.userStatus === 'COMPLETED'") COMPLETED
p.date-completed {{challenge.submissionEndDate | date : 'MMMM yyyy'}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
p.place(ng-class="{ 'first-place': challenge.wonFirst }", ng-show="challenge.highestPlacement") {{challenge.highestPlacement}}#[span {{challenge.highestPlacement | ordinal:true}}] Place
p.place(ng-show="challenge.userStatus === 'NOT_FINISHED'") Didn't Finish
p.place(ng-show="challenge.userStatus === 'PASSED_SCREENING'") Passed Screening
p.place(ng-show="!challenge.highestPlacement && challenge.userStatus === 'PASSED_REVIEW'") Passed Review
p.place(ng-show="challenge.userStatus === 'COMPLETED'") COMPLETED

.challenge-score(ng-hide="challenge.userStatus !== 'PASSED_REVIEW'")
Expand All @@ -14,6 +15,7 @@
p.place(ng-class="{ 'first-place': challenge.wonFirst }", ng-show="challenge.highestPlacement") {{challenge.highestPlacement}}#[span {{challenge.highestPlacement | ordinal:true}}] Place
p.place(ng-show="challenge.userStatus === 'NOT_FINISHED'") Didn't Finish
p.place(ng-show="challenge.userStatus === 'PASSED_SCREENING'") Passed Screening
p.place(ng-show="!challenge.highestPlacement && challenge.userStatus === 'PASSED_REVIEW'") Passed Review
p.place(ng-show="challenge.userStatus === 'COMPLETED'") Completed
p.date-completed {{challenge.submissionEndDate | date : 'MMMM yyyy'}}

Expand Down
19 changes: 8 additions & 11 deletions app/services/challenge.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,19 @@ import moment from 'moment'
// TODO placement logic for challenges can be moved to their corresponding user place directive
// process placement for challenges having winningPlacements array in response
if (Array.isArray(challenge.userDetails.winningPlacements)) {
challenge.highestPlacement = _.min(challenge.userDetails.winningPlacements)
challenge.highestPlacement = _.min(challenge.userDetails.winningPlacements, 'placed').placed
}
// process placement for design challenges
if (challenge.track == 'DESIGN' && challenge.userDetails.submissions && challenge.userDetails.submissions.length > 0) {
challenge.thumbnailId = challenge.userDetails.submissions[0].id

challenge.highestPlacement = _.min(challenge.userDetails.submissions.filter(function(submission) {
return submission.type === CONSTANTS.SUBMISSION_TYPE_CONTEST && submission.placement
}), 'placement').placement
}
if (challenge.track === 'DEVELOP' && challenge.subTrack === 'FIRST_2_FINISH'
&& challenge.userDetails.submissions && challenge.userDetails.submissions.length > 0) {
challenge.highestPlacement = _.min(challenge.userDetails.submissions.filter(function(submission) {
// determines the user status for passing the review for one of the submissions
if (challenge.userDetails.submissions && challenge.userDetails.submissions.length > 0) {
challenge.passedReview = challenge.userDetails.submissions.filter(function(submission) {
return submission.type === CONSTANTS.SUBMISSION_TYPE_CONTEST
&& submission.status === CONSTANTS.STATUS_ACTIVE && submission.placement
}), 'placement').placement
&& (submission.status === CONSTANTS.STATUS_ACTIVE
|| submission.status === CONSTANTS.STATUS_COMPLETED_WITHOUT_WIN)
}).length > 0
}
if (challenge.highestPlacement === 0) {
challenge.highestPlacement = null
Expand All @@ -218,7 +215,7 @@ import moment from 'moment'
}

if (challenge.userDetails.hasUserSubmittedForReview) {
if (!challenge.highestPlacement) {
if (!challenge.passedReview) {
challenge.userStatus = 'PASSED_SCREENING'
} else {
challenge.userStatus = 'PASSED_REVIEW'
Expand Down
58 changes: 42 additions & 16 deletions app/services/challenge.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,16 @@ describe('Challenge Service', function() {
userDetails: {
hasUserSubmittedForReview: true,
roles: ['Submitter'],
winningPlacements: [
{
'submissionId': 12345,
'submitterId': 123456,
'amount': 500.0,
'placed': 1,
'finalScore': 98.0,
'challengeId': 30041345
}
],
submissions: [
{
challengeId: 30041345,
Expand Down Expand Up @@ -479,6 +489,16 @@ describe('Challenge Service', function() {
userDetails: {
hasUserSubmittedForReview: true,
roles: ['Submitter'],
winningPlacements: [
{
'submissionId': 12345,
'submitterId': 123456,
'amount': 500.0,
'placed': 1,
'finalScore': 98.0,
'challengeId': 30041345
}
],
submissions: [
{
challengeId: 30041345,
Expand All @@ -504,8 +524,7 @@ describe('Challenge Service', function() {
status: 'Completed Without Win',
type: 'Checkpoint Submission'
}
],
winningPlacements: [2, 11, 1]
]
}

}
Expand All @@ -528,11 +547,12 @@ describe('Challenge Service', function() {
userDetails: {
hasUserSubmittedForReview: true,
roles: ['Submitter'],
winningPlacements: null,
submissions: [
{
challengeId: 30041345,
id: 12345,
placement: 1,
placement: 5,
score: 98.0,
status: 'Active',
type: 'Contest Submission'
Expand All @@ -553,8 +573,7 @@ describe('Challenge Service', function() {
status: 'Completed Without Win',
type: 'Checkpoint Submission'
}
],
winningPlacements: [0]
]
}

}
Expand All @@ -563,7 +582,7 @@ describe('Challenge Service', function() {
var challenge = challenges[0]
expect(challenge.highestPlacement).not.to.exist
expect(challenge.wonFirst).to.exist.to.false
expect(challenge.userStatus).to.exist.to.equal('PASSED_SCREENING')
expect(challenge.userStatus).to.exist.to.equal('PASSED_REVIEW')
expect(challenge.userHasSubmitterRole).to.exist.to.true
})

Expand All @@ -577,6 +596,16 @@ describe('Challenge Service', function() {
userDetails: {
hasUserSubmittedForReview: true,
roles: ['Submitter'],
winningPlacements: [
{
'submissionId': 12345,
'submitterId': 123456,
'amount': 500.0,
'placed': 1,
'finalScore': 98.0,
'challengeId': 30041345
}
],
submissions: [
{
challengeId: 30041345,
Expand Down Expand Up @@ -624,15 +653,8 @@ describe('Challenge Service', function() {
userDetails: {
hasUserSubmittedForReview: true,
roles: ['Submitter'],
winningPlacements: null,
submissions: [
{
challengeId: 30041345,
id: 12345,
placement: null,
score: 34.0,
status: 'Active',
type: 'Contest Submission'
},
{
challengeId: 30041345,
id: 12346,
Expand Down Expand Up @@ -671,6 +693,7 @@ describe('Challenge Service', function() {
userDetails: {
hasUserSubmittedForReview: true,
roles: ['Submitter'],
winningPlacements: null,
submissions: [
{
challengeId: 30041345,
Expand Down Expand Up @@ -702,7 +725,7 @@ describe('Challenge Service', function() {
]
ChallengeService.processPastChallenges(challenges)
var challenge = challenges[0]
expect(challenge.highestPlacement).to.exist.to.equal(5)
expect(challenge.highestPlacement).not.to.exist.to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the dangling .to is messing anything up or giving a false test pass, but it can be deleted :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Nick!! Fixed it. And I think it was not causing the false test pass. 😁

expect(challenge.wonFirst).to.exist.to.false
expect(challenge.userStatus).to.exist.to.equal('PASSED_REVIEW')
expect(challenge.userHasSubmitterRole).to.exist.to.true
Expand All @@ -718,6 +741,7 @@ describe('Challenge Service', function() {
userDetails: {
hasUserSubmittedForReview: false,
roles: ['Submitter'],
winningPlacements: null,
submissions: []
}
}
Expand All @@ -740,6 +764,7 @@ describe('Challenge Service', function() {
userDetails: {
hasUserSubmittedForReview: false,
roles: ['Submitter'],
winningPlacements: null,
submissions: null
}
}
Expand All @@ -762,6 +787,7 @@ describe('Challenge Service', function() {
userDetails: {
hasUserSubmittedForReview: false,
roles: ['Observer'],
winningPlacements: null,
submissions: []
}
}
Expand All @@ -785,7 +811,7 @@ describe('Challenge Service', function() {
hasUserSubmittedForReview: false,
roles: [],
submissions: [],
winningPlacements: [0]
winningPlacements: null
}
}
]
Expand Down
3 changes: 2 additions & 1 deletion app/topcoder.constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ angular.module('CONSTANTS', []).constant('CONSTANTS', {
'CODING' : 'CODING',
'REGISTERED' : 'REGISTERED',
'SUBMISSION_TYPE_CONTEST': 'Contest Submission',
'STATUS_ACTIVE' : 'Active'
'STATUS_ACTIVE' : 'Active',
'STATUS_COMPLETED_WITHOUT_WIN' : 'Completed Without Win'
})