Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get and update submission status in page #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -314,7 +314,8 @@ import _ from 'lodash'
'application/octet-stream',
'application/x-compress',
'application/x-compressed',
'multipart/x-zip'
'multipart/x-zip',
'application/x-download'
],
jpeg: [
'image/jpeg',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import angular from 'angular'
getPresignedURL: getPresignedURL,
uploadSubmissionFileToS3: uploadSubmissionFileToS3,
updateSubmissionStatus: updateSubmissionStatus,
recordCompletedSubmission: recordCompletedSubmission
recordCompletedSubmission: recordCompletedSubmission,
getSubmissionStatus: getSubmissionStatus
}

return service
Expand Down Expand Up @@ -127,13 +128,25 @@ import angular from 'angular'
.then(function(response) {
logger.info('Successfully made file record. Beginning processing')

progressCallback.call(progressCallback, 'FINISH', 100)
progressCallback.call(progressCallback, 'FINISH', {progress: 100, submissionId: response.id})
})
.catch(function(err) {
logger.error('Could not start processing', err)

progressCallback.call(progressCallback, 'ERROR', err)
})
}

function getSubmissionStatus(submissionId, progressCallback) {
return api.one('submissions', submissionId).get()
.then(function(response) {
logger.info('Got submission status: ' + response.status)
progressCallback.call(progressCallback, 'STATUS', {status: response.status})
})
.catch(function(err) {
logger.error('Could not get submission status', err)
progressCallback.call(progressCallback, 'ERROR', err)
})
}
}
})()
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import _ from 'lodash'

angular.module('tc.submissions').controller('SubmitDesignFilesController', SubmitDesignFilesController)

SubmitDesignFilesController.$inject = ['$scope','$window', '$stateParams', 'logger', 'UserService', 'SubmissionsService', 'challengeToSubmitTo']
SubmitDesignFilesController.$inject = ['$scope','$window', '$interval', '$stateParams', 'logger', 'UserService', 'SubmissionsService', 'challengeToSubmitTo', 'CONSTANTS']

function SubmitDesignFilesController($scope, $window, $stateParams, logger, UserService, SubmissionsService, challengeToSubmitTo) {
function SubmitDesignFilesController($scope, $window, $interval, $stateParams, logger, UserService, SubmissionsService, challengeToSubmitTo, CONSTANTS) {
if (!challengeToSubmitTo.challenge) { return }

var vm = this
Expand Down Expand Up @@ -38,6 +38,11 @@ import _ from 'lodash'
stockArts: [],
hasAgreedToTerms: false
}
vm.submissionId = null
vm.submissionStatus = null
vm.errorInSubmissionStatus = false
vm.stopSubmissionStatusPoll = null


var userId = parseInt(UserService.getUserIdentity().userId)

Expand All @@ -64,6 +69,7 @@ import _ from 'lodash'
vm.setRankTo1 = setRankTo1
vm.setFileReference = setFileReference
vm.uploadSubmission = uploadSubmission
vm.updateSubmissionStatus = updateSubmissionStatus
vm.refreshPage = refreshPage
vm.cancelRetry = cancelRetry

Expand Down Expand Up @@ -203,9 +209,16 @@ import _ from 'lodash'
vm.finishing = true
}
} else if (phase === 'FINISH') {
// we are concerned only for completion of the phase
if (args === 100) {
if (typeof args === 'object' && args.progress === 100) {
logger.debug('Finished upload.')
// start polling submission state
vm.submissionId = args.submissionId
vm.stopSubmissionStatusPoll = $interval(updateSubmissionStatus, CONSTANTS.SUBMISSION_STATUS_POLL_INTERVAL)
updateSubmissionStatus()
} else {
if (args === 100) {
logger.debug('Finished upload.')
}
}
} else {
// assume it to be error condition
Expand All @@ -214,6 +227,28 @@ import _ from 'lodash'
}
}

function updateSubmissionStatus() {
SubmissionsService.getSubmissionStatus(vm.submissionId, function(result, args) {
if (result === 'STATUS') {
vm.submissionStatus = args.status
if (args.status === 'SUBMITTED' || args.status === 'ERROR') {
$interval.cancel(vm.stopSubmissionStatusPoll)
vm.stopSubmissionStatusPoll = undefined
}
if (args.status === 'ERROR') {
vm.errorInSubmissionStatus = true
}
} else {
// Assume error
logger.debug('Error Condition: Get submission status')
vm.submissionStatus = 'ERROR'
vm.errorInSubmissionStatus = true
$interval.cancel(vm.stopSubmissionStatusPoll)
vm.stopSubmissionStatusPoll = undefined
}
})
}

function refreshPage() {
$window.location.reload(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,25 @@ modal.transition(show="vm.showProgress", background-click-close="false", style="

img.upload-progress__image(src=require("../../../assets/images/skills/id-180.svg"), ng-hide="vm.errorInUpload")
img.upload-progress__image--error(src=require("../../../assets/images/robot-embarresed.svg"), ng-show="vm.errorInUpload")
img.submission-status__image--error(src=require("../../../assets/images/robot-embarresed.svg"), ng-show="vm.errorInSubmissionStatusPoll")

p.upload-progress__message(ng-hide="vm.errorInUpload") Hey, your work is AWESOME! Please don’t close the window while the upload is in progress, or you’ll lose all files!

p.upload-progress__message--error(ng-show="vm.errorInUpload") Oh, that’s embarrassing! One of the files couldn’t be uploaded, I’m so sorry.
p.submission-status__message--error(ng-show="vm.errorInSubmissionStatusPoll") An error occurred processing your submission, please contact support

progress-bar.upload-progress__progress-bar(completed="vm.uploadProgress", message="of 3 files uploaded")

.upload-progress__preparing(ng-show="vm.preparing && !vm.errorInUpload") #[span Preparing...]
.upload-progress__finishing(ng-show="vm.finishing && !vm.errorInUpload")
p Finished!
p Upload Finished!
.submission-status__pending(ng-show="vm.submissionStatus === 'PROCESS_PENDING' && !vm.errorInSubmissionStatusPoll")
p Submission waiting to be processed
.submission-status__processing(ng-show="vm.submissionStatus === 'PROCESSING' && !vm.errorInSubmissionStatusPoll")
p Submission processing
.submission-status__submitted(ng-show="vm.submissionStatus === 'SUBMITTED' && !vm.errorInSubmissionStatusPoll")
p Submission processing completed successfully


.upload-progess__links
a.tc-btn.tc-btn-s(ng-href="https://www.{{DOMAIN}}/challenge-details/{{submissions.challengeId}}/?type={{submissions.track}}") Back to the challenge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('Submit Design Files Controller', function() {
}

var submissionsService = {
getPresignedURL: function() {}
getPresignedURL: function() {},
getSubmissionStatus: function() {}
}

var mockWindow = {
Expand All @@ -28,6 +29,10 @@ describe('Submit Design Files Controller', function() {
}
}

var mockInterval = {
cancel: function() {}
}

beforeEach(function() {
bard.appModule('tc.submissions')
bard.inject(this, '$controller', '$rootScope')
Expand All @@ -43,7 +48,8 @@ describe('Submit Design Files Controller', function() {
UserService: userService,
challengeToSubmitTo: mockChallenge,
SubmissionsService: submissionsService,
$window: mockWindow
$window: mockWindow,
$interval: mockInterval
})
vm = controller
})
Expand Down Expand Up @@ -268,6 +274,59 @@ describe('Submit Design Files Controller', function() {
})
})

describe('updateSubmissionStatus', function() {
var args = {status: 'PROCESSING', result: 'STATUS'}
var mockAPICall = sinon.stub(submissionsService, 'getSubmissionStatus', function(id, cb) {
cb(args.result, {status: args.status})
})
var mockIntervalCancelCall = sinon.spy(mockInterval, 'cancel')

it('calls the submissions service', function() {
vm.submissionId = 1
scope.$digest()
vm.updateSubmissionStatus()
scope.$digest()

expect(mockAPICall).calledOnce
})

it('sets the submission status', function() {
vm.submissionId = 1
scope.$digest()
vm.updateSubmissionStatus()
scope.$digest()
expect(vm.submissionStatus).to.equal('PROCESSING')
})

it('resets the polling timer on SUBMITTED status', function() {
args.status = 'SUBMITTED'
vm.submissionId = 1
scope.$digest()
vm.updateSubmissionStatus()
scope.$digest()
expect(vm.submissionStatus).to.equal('SUBMITTED')
expect(mockIntervalCancelCall).calledOnce
})

it('handles ERROR status', function() {
args.status = 'ERROR'
vm.submissionId = 1
scope.$digest()
vm.updateSubmissionStatus()
scope.$digest()
expect(vm.submissionStatus).to.equal('ERROR')
expect(vm.errorInSubmissionStatus).to.equal(true)
args.status = null
args.result = 'ERROR'
vm.submissionId = 1
scope.$digest()
vm.updateSubmissionStatus()
scope.$digest()
expect(vm.submissionStatus).to.equal('ERROR')
expect(vm.errorInSubmissionStatus).to.equal(true)
})
})

describe('refreshPage', function() {
it('reloads the page', function() {
var mockRefresh = sinon.spy(mockWindow.location, 'reload')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ angular.module('CONSTANTS', []).constant('CONSTANTS', {
'MAILCHIMP_NL_DESIGN' : process.env.MAILCHIMP_NL_DESIGN,
'MAILCHIMP_NL_DATA' : process.env.MAILCHIMP_NL_DATA,

'SUBMISSION_STATUS_POLL_INTERVAL': process.env.SUBMISSION_STATUS_POLL_INTERVAL,

'NEW_CHALLENGES_URL' : 'https://www.topcoder.com/challenges/develop/upcoming/',
'SWIFT_PROGRAM_ID' : 3445,
'UPCOMING_SRMS_URL' : 'https://www.topcoder.com/challenges/data/upcoming/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ modal {
}

.upload-progress__image,
.upload-progress__image--error {
.upload-progress__image--error,
.submission-status__image--error {
margin-top: 30px;
}

.upload-progress__message,
.upload-progress__message--error {
.upload-progress__message--error,
.submission-status__message--error {
@include font-with-weight('Merriweather Sans', 400);
font-size: 15px;
line-height: 19px;
Expand All @@ -154,7 +156,10 @@ modal {

.upload-progress__preparing,
.upload-progress__finishing,
.upload-progress__error {
.upload-progress__error,
.submission-status__pending,
.submission-status__processing,
.submission-status__submitted {
@include font-with-weight('Sofia Pro', 500);
font-size: 12px;
line-height: 14px;
Expand Down