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

Commit 00ed688

Browse files
committed
Merge pull request #689 from appirio-tech/develop-submission
Add develop submission pages
2 parents b905bc0 + 132c8f4 commit 00ed688

File tree

5 files changed

+455
-6
lines changed

5 files changed

+455
-6
lines changed

app/index.jade

+1-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ html
156156
script(src='../bower_components/react/react.js')
157157
script(src='../bower_components/react/react-dom.js')
158158
script(src='../bower_components/classnames/index.js')
159-
script(src='../bower_components/classnames/bind.js')
160-
script(src='../bower_components/classnames/dedupe.js')
161159
script(src='../bower_components/react-input-autosize/dist/react-input-autosize.min.js')
162160
script(src='../bower_components/react-select/dist/react-select.min.js')
163161
script(src='../bower_components/ngReact/ngReact.js')
@@ -336,6 +334,7 @@ html
336334
script(src="submissions/submissions.controller.js")
337335
script(src="submissions/submissions.routes.js")
338336
script(src="submissions/submit-design-files/submit-design-files.controller.js")
337+
script(src="submissions/submit-develop-files/submit-develop-files.controller.js")
339338
script(src="topcoder.constants.js")
340339
script(src="topcoder.controller.js")
341340
script(src="topcoder.interceptors.js")

app/submissions/submit-design-files/submit-design-files.controller.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,8 @@
163163
SubmissionsService.getPresignedURL(vm.submissionsBody, files, updateProgress);
164164
}
165165

166-
/*
167-
* Callback for updating submission upload process. It looks for different phases e.g. PREPARE, UPLOAD, FINISH
168-
* of the submission upload and updates the progress UI accordingly.
169-
*/
166+
// Callback for updating submission upload process. It looks for different phases e.g. PREPARE, UPLOAD, FINISH
167+
// of the submission upload and updates the progress UI accordingly.
170168
function updateProgress(phase, args) {
171169
// for PREPARE phase
172170
if (phase === 'PREPARE') {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
(function () {
2+
'use strict';
3+
4+
angular.module('tc.submissions').controller('SubmitDevelopFilesController', SubmitDevelopFilesController);
5+
6+
SubmitDevelopFilesController.$inject = ['$scope','$window', '$stateParams', '$log', 'UserService', 'SubmissionsService', 'challengeToSubmitTo'];
7+
8+
function SubmitDevelopFilesController($scope, $window, $stateParams, $log, UserService, SubmissionsService, challengeToSubmitTo) {
9+
var vm = this;
10+
$log = $log.getInstance('SubmitDevelopFilesController');
11+
var files = {};
12+
var fileUploadProgress = {};
13+
vm.comments = '';
14+
vm.uploadProgress = 0;
15+
vm.uploading = false;
16+
vm.preparing = false;
17+
vm.finishing = false;
18+
vm.showProgress = false;
19+
vm.errorInUpload = false;
20+
vm.submissionForm = {
21+
files: [],
22+
23+
// use develop name
24+
sourceZip: null,
25+
26+
submitterComments: '',
27+
hasAgreedToTerms: false
28+
};
29+
30+
var userId = parseInt(UserService.getUserIdentity().userId);
31+
32+
vm.submissionsBody = {
33+
reference: {
34+
type: 'CHALLENGE',
35+
id: $stateParams.challengeId,
36+
phaseType: challengeToSubmitTo.phaseType,
37+
phaseId: challengeToSubmitTo.phaseId
38+
},
39+
userId: userId,
40+
data: {
41+
method: challengeToSubmitTo.challenge.track.toUpperCase() + '_CHALLENGE_ZIP_FILE',
42+
43+
// Can delete below since they are processed and added later?
44+
files: [],
45+
submitterComments: '',
46+
}
47+
};
48+
49+
vm.setFileReference = setFileReference;
50+
vm.uploadSubmission = uploadSubmission;
51+
vm.refreshPage = refreshPage;
52+
vm.cancelRetry = cancelRetry;
53+
54+
activate();
55+
56+
function activate() {}
57+
58+
function setFileReference(file, fieldId) {
59+
// Can clean up since fileValue on tcFileInput has file reference?
60+
files[fieldId] = file;
61+
62+
var fileObject = {
63+
name: file.name,
64+
type: fieldId,
65+
status: 'PENDING'
66+
};
67+
68+
// TODO: Refactor or develop
69+
switch(fieldId) {
70+
case 'SUBMISSION_ZIP':
71+
fileObject.mediaType = 'application/octet-stream';
72+
break;
73+
case 'SOURCE_ZIP':
74+
fileObject.mediaType = 'application/octet-stream';
75+
break;
76+
default:
77+
fileObject.mediaType = file.type;
78+
}
79+
80+
// If user changes a file input's file, update the file details
81+
var isFound = vm.submissionsBody.data.files.reduce(function(isFound, file, i, filesArray) {
82+
if (isFound) { return true; }
83+
84+
if (file.type === fileObject.type) {
85+
filesArray[i] = fileObject;
86+
return true;
87+
}
88+
89+
return false;
90+
}, false);
91+
92+
// Add new files to the list
93+
if (!isFound) {
94+
vm.submissionsBody.data.files.push(fileObject);
95+
}
96+
}
97+
98+
function uploadSubmission() {
99+
vm.errorInUpload = false;
100+
vm.uploadProgress = 0;
101+
vm.fileUploadProgress = {};
102+
vm.showProgress = true;
103+
vm.preparing = true;
104+
vm.uploading = false;
105+
vm.finishing = false;
106+
vm.submissionsBody.data.submitterComments = vm.comments;
107+
108+
$log.debug('Body for request: ', vm.submissionsBody);
109+
SubmissionsService.getPresignedURL(vm.submissionsBody, files, updateProgress);
110+
}
111+
112+
// Callback for updating submission upload process. It looks for different phases e.g. PREPARE, UPLOAD, FINISH
113+
// of the submission upload and updates the progress UI accordingly.
114+
function updateProgress(phase, args) {
115+
// for PREPARE phase
116+
if (phase === 'PREPARE') {
117+
// we are concerned only for completion of the phase
118+
if (args === 100) {
119+
vm.preparing = false;
120+
vm.uploading = true;
121+
$log.debug('Prepared for upload.');
122+
}
123+
} else if (phase === 'UPLOAD') {
124+
// if args is object, this update is about XHRRequest's upload progress
125+
if (typeof args === 'object') {
126+
var requestId = args.file;
127+
var progress = args.progress;
128+
if (!fileUploadProgress[requestId] || fileUploadProgress[requestId] < progress) {
129+
fileUploadProgress[requestId] = progress;
130+
}
131+
var total = 0, count = 0;
132+
for(var requestId in fileUploadProgress) {
133+
var prog = fileUploadProgress[requestId];
134+
total += prog;
135+
count++;
136+
}
137+
vm.uploadProgress = total / count;
138+
139+
// initiate digest cycle because this event (xhr event) is caused outside angular
140+
$scope.$apply();
141+
} else { // typeof args === 'number', mainly used a s fallback to mark completion of the UPLOAD phase
142+
vm.uploadProgress = args;
143+
}
144+
145+
// start next phase when UPLOAD is done
146+
if (vm.uploadProgress == 100) {
147+
$log.debug('Uploaded files.');
148+
vm.uploading = false;
149+
vm.finishing = true;
150+
}
151+
} else if (phase === 'FINISH') {
152+
// we are concerned only for completion of the phase
153+
if (args === 100) {
154+
$log.debug('Finished upload.');
155+
}
156+
} else {
157+
// assume it to be error condition
158+
$log.debug("Error Condition: " + phase);
159+
vm.errorInUpload = true;
160+
}
161+
}
162+
163+
function refreshPage() {
164+
$window.location.reload(true);
165+
}
166+
167+
function cancelRetry() {
168+
vm.showProgress = false;
169+
}
170+
}
171+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
.mobile-redirect
2+
.mobile-redirect__title File upload is not available for mobile
3+
4+
.mobile-redirect__body
5+
p Our team is working hard on new features, and file upload currently only works on the web. Please open this page on your desktop if you want to create a submission.
6+
7+
a(ng-href="http://help.{{DOMAIN}}/design/submitting-to-a-design-challenge/formatting-your-submission-for-design-challenges/") TODO: same link as below for help on formatting submission
8+
9+
a.tc-btn.tc-btn-s(ng-href="https://www.{{DOMAIN}}/challenge-details/{{submissions.challengeId}}/?type={{submissions.track}}") Back to Challenge Details
10+
11+
.panel-body
12+
form.form-blocks(name="submissionForm", role="form", ng-submit="submissionForm.$valid && vm.uploadSubmission()", novalidate)
13+
.form-block.flex
14+
.form-block__instructions
15+
.form-block__title Files
16+
17+
.form-block__text
18+
p Need text from PMs.
19+
20+
p Need text from PMs.
21+
22+
p Need text from PMs.
23+
24+
a(ng-href="http://help.{{DOMAIN}}/design/submitting-to-a-design-challenge/formatting-your-submission-for-design-challenges/") Need link from PMs
25+
26+
.form-block__fields
27+
.fieldset
28+
tc-file-input.tc-file-field(
29+
label-text="Preview Image",
30+
field-id="DESIGN_COVER",
31+
button-text="Add File",
32+
file-type="jpg,jpeg,png"
33+
placeholder="Image file as .jpg or .png",
34+
mandatory="true",
35+
set-file-reference="vm.setFileReference(file, fieldId)",
36+
ng-model="vm.submissionForm.designCover"
37+
)
38+
39+
.tc-error-messages(
40+
ng-show="submissionForm['DESIGN_COVER'].$touched && submissionForm['DESIGN_COVER'].$invalid",
41+
ng-messages="submissionForm['DESIGN_COVER'].$error"
42+
)
43+
p(ng-message="filesize") File size may not exceed 500MB.
44+
45+
p(ng-message="required") This is not the correct file format. Please select a .jpg or .png file.
46+
47+
.panel-footer
48+
p Submitting your files means you hereby agree to the #[a(ng-href="https://www.{{DOMAIN}}/community/how-it-works/terms/", target="_blank") Topcoder terms of use] and to the extent your uploaded file wins a Topcoder Competition, you hereby assign, grant, and transfer to Topcoder all rights in and title to the Winning Submission (as further described in the terms of use).
49+
50+
p.tc-error-messages(ng-show="vm.submissionForm.hasAgreedToTerms && submissionForm.$invalid") There are outstanding problems with this page. You must fix them before you can upload your submission.
51+
52+
.checkbox.flex.center
53+
input(type="checkbox", ng-model="vm.submissionForm.hasAgreedToTerms", id="agree-to-terms", required)
54+
55+
label(for="agree-to-terms") I understand and agree
56+
57+
button.tc-btn.tc-btn-secondary(type="submit", ng-disabled="submissionForm.$invalid") Submit
58+
59+
modal.transition(show="vm.showProgress", background-click-close="false", style="background-color:white;")
60+
.upload-progress(ng-class="{'upload-progress--error': vm.errorInUpload}")
61+
.upload-progress__title
62+
p Uploading submission for
63+
64+
p.upload-progress-title__challenge-name [Challenge name]
65+
66+
img.upload-progress__image(src="/images/robot.svg", ng-hide="vm.errorInUpload")
67+
img.upload-progress__image--error(src="/images/robot-embarresed.svg", ng-show="vm.errorInUpload")
68+
69+
p.upload-progress__message(ng-hide="vm.errorInUpload") Hey, your work is AWESOME! Please don’t close the window while I’m working or you’ll loose all files!
70+
71+
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.
72+
73+
progress-bar.upload-progress__progress-bar(completed="vm.uploadProgress", message="of 3 files uploaded")
74+
75+
.upload-progress__preparing(ng-show="vm.preparing && !vm.errorInUpload") #[span Preparing...]
76+
.upload-progress__finishing(ng-show="vm.finishing && !vm.errorInUpload")
77+
p Finished!
78+
79+
.upload-progess__links
80+
a.tc-btn.tc-btn-s(ng-href="https://www.{{DOMAIN}}/challenge-details/{{submissions.challengeId}}/?type={{submissions.track}}") Back to the challenge
81+
82+
a.tc-btn.tc-btn-s.tc-btn-ghost(ng-click="vm.refreshPage()") Submit another
83+
84+
85+
.upload-progress__error(ng-show="vm.errorInUpload") #[span File upload failed]
86+
87+
.upload-progress__error-action(ng-show="vm.errorInUpload")
88+
button.tc-btn.tc-btn-s.tc-btn-ghost(type="button", ng-click="vm.cancelRetry()") Cancel
89+
90+
button.tc-btn.tc-btn-s.tc-btn-secondary(type="button", ng-click="submissionForm.$valid && vm.uploadSubmission()") Try Again

0 commit comments

Comments
 (0)