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

Commit bc605e9

Browse files
author
vikasrohit
authored
Merge pull request #856 from appirio-tech/feature/submission-bughunt-fixes
Issue#847, "Drag and Drop your zip file here" must remove from the "Preview Image" section
2 parents a1b41ab + 50f29d1 commit bc605e9

File tree

6 files changed

+69
-57
lines changed

6 files changed

+69
-57
lines changed

app/directives/tc-fp-file-input/tc-fp-file-input.directive.js

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ import _ from 'lodash'
3131
if (scope.fieldId.indexOf('ZIP') > -1) {
3232
scope.filePath += _.join([userId, scope.fieldId, (new Date()).valueOf()], '-') + '.zip'
3333
}
34+
var dragAreaClasses = 'tc-fp-file-drag-drop'
3435
// set extensions
3536
if (scope.fieldId.indexOf('ZIP') > -1) {
3637
scope.extensions = '.zip'
3738
} else if (scope.fieldId.indexOf('DESIGN_COVER') > -1) {
3839
scope.extensions = '.png,.jpeg,.jpg,.bmp'
40+
dragAreaClasses += ' tc-fp-file-drag-drop-image'
3941
}
4042

4143
// set default services
@@ -59,7 +61,7 @@ import _ from 'lodash'
5961
input.setAttribute('data-fp-maxSize', scope.maxSize)
6062
input.setAttribute('data-fp-services', scope.fpServices)
6163
input.setAttribute('data-fp-button-class', 'tc-btn')
62-
input.setAttribute('data-fp-drag-class', 'tc-fp-file-drag-drop')
64+
input.setAttribute('data-fp-drag-class', dragAreaClasses)
6365
input.setAttribute('data-fp-multiple', false)
6466
input.setAttribute('data-fp-extensions', scope.extensions)
6567
input.setAttribute('data-fp-store-location', 's3')
@@ -70,18 +72,28 @@ import _ from 'lodash'
7072

7173
scope.onSuccess = function(event) {
7274
var fpFile = event.fpfile
73-
var _file = {
74-
name: scope.filename || fpFile.filename,
75-
container: fpFile.container || scope.fpContainer,
76-
path: fpFile.key,
77-
size: fpFile.size,
78-
mimetype: fpFile.mimetype
75+
if (fpFile) {
76+
element.addClass('file-uploaded')
77+
var _file = {
78+
name: scope.filename || fpFile.filename,
79+
container: fpFile.container || scope.fpContainer,
80+
path: fpFile.key,
81+
size: fpFile.size,
82+
mimetype: fpFile.mimetype
83+
}
84+
scope.ngModel = _file
85+
scope.setFileReference({
86+
file: _file,
87+
fieldId: scope.fieldId
88+
})
89+
} else {
90+
element.removeClass('file-uploaded')
91+
scope.ngModel = null
92+
scope.setFileReference({
93+
file: null,
94+
fieldId: scope.fieldId
95+
})
7996
}
80-
scope.ngModel = _file
81-
scope.setFileReference({
82-
file: _file,
83-
fieldId: scope.fieldId
84-
})
8597
}
8698
}
8799
}

app/services/submissions.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import angular from 'angular'
2323
function startSubmission(body, progressCallback) {
2424
return api.all('submissions').customPOST(body)
2525
.then(function(response) {
26-
//progressCallback.call(progressCallback, 'PREPARE', 100)
26+
progressCallback.call(progressCallback, 'PREPARE', 100)
2727
// uploadSubmissionFileToS3(response, response.data.files, files, progressCallback)
2828
processSubmission(response, progressCallback)
2929
})

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

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import _ from 'lodash'
1212
if (!challengeToSubmitTo.challenge) { return }
1313

1414
var vm = this
15-
var fileUploadProgress = {}
1615
vm.urlRegEx = new RegExp(/^(http(s?):\/\/)?(www\.)?[a-zA-Z0-9\.\-\_]+(\.[a-zA-Z]{2,3})+(\/[a-zA-Z0-9\_\-\s\.\/\?\%\#\&\=]*)?$/)
1716
vm.rankRegEx = new RegExp(/^[1-9]\d*$/)
1817
vm.comments = ''
1918
vm.uploadProgress = 0
20-
vm.uploading = false
2119
vm.preparing = false
2220
vm.finishing = false
21+
vm.finished = false
2322
vm.showProgress = false
2423
vm.errorInUpload = false
2524
vm.formFonts = {}
@@ -77,21 +76,25 @@ import _ from 'lodash'
7776
}
7877

7978
function setFileReference(file, fieldId) {
80-
var fileObject = {
81-
name: file.name,
82-
type: fieldId,
83-
status: 'STAGED',
84-
stagedFileContainer: file.container,
85-
stagedFilePath: file.path,
86-
size: file.size,
87-
mediaType: file.mimetype
79+
var fileObject = null
80+
if (file) {
81+
fileObject = {
82+
name: file.name,
83+
type: fieldId,
84+
status: 'STAGED',
85+
stagedFileContainer: file.container,
86+
stagedFilePath: file.path,
87+
size: file.size,
88+
mediaType: file.mimetype
89+
}
8890
}
8991

9092
// If user changes a file input's file, update the file details
9193
var isFound = vm.submissionsBody.data.files.reduce(function(isFound, file, i, filesArray) {
9294
if (isFound) { return true }
9395

94-
if (file.type === fileObject.type) {
96+
if (file && file.type === fieldId) {
97+
// when file is removed, it would set correspding file as null
9598
filesArray[i] = fileObject
9699
return true
97100
}
@@ -100,19 +103,18 @@ import _ from 'lodash'
100103
}, false)
101104

102105
// Add new files to the list
103-
if (!isFound) {
106+
if (!isFound && fileObject) {
104107
vm.submissionsBody.data.files.push(fileObject)
105108
}
106109
}
107110

108111
function uploadSubmission() {
109112
vm.errorInUpload = false
110113
vm.uploadProgress = 0
111-
vm.fileUploadProgress = {}
112114
vm.showProgress = true
113115
vm.preparing = true
114-
vm.uploading = false
115116
vm.finishing = false
117+
vm.finished = false
116118
vm.submissionsBody.data.submitterComments = vm.comments
117119
vm.submissionsBody.data.submitterRank = vm.submissionForm.submitterRank
118120

@@ -164,41 +166,16 @@ import _ from 'lodash'
164166
// we are concerned only for completion of the phase
165167
if (args === 100) {
166168
vm.preparing = false
167-
vm.uploading = true
168-
logger.debug('Prepared for upload.')
169-
}
170-
} else if (phase === 'UPLOAD') {
171-
// if args is object, this update is about XHRRequest's upload progress
172-
if (typeof args === 'object') {
173-
var requestId = args.file
174-
var progress = args.progress
175-
if (!fileUploadProgress[requestId] || fileUploadProgress[requestId] < progress) {
176-
fileUploadProgress[requestId] = progress
177-
}
178-
var total = 0, count = 0
179-
for(var requestIdKey in fileUploadProgress) {
180-
var prog = fileUploadProgress[requestIdKey]
181-
total += prog
182-
count++
183-
}
184-
vm.uploadProgress = total / count
185-
186-
// initiate digest cycle because this event (xhr event) is caused outside angular
187-
$scope.$apply()
188-
} else { // typeof args === 'number', mainly used a s fallback to mark completion of the UPLOAD phase
189-
vm.uploadProgress = args
190-
}
191-
192-
// start next phase when UPLOAD is done
193-
if (vm.uploadProgress == 100) {
194-
logger.debug('Uploaded files.')
195-
vm.uploading = false
196169
vm.finishing = true
170+
logger.debug('Prepared for upload.')
197171
}
198172
} else if (phase === 'FINISH') {
199173
// we are concerned only for completion of the phase
200174
if (args === 100) {
201175
logger.debug('Finished upload.')
176+
vm.preparing = false
177+
vm.finishing = false
178+
vm.finished = true
202179
}
203180
} else {
204181
// assume it to be error condition

app/submissions/submit-design-files/submit-design-files.jade

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,13 @@ modal.transition(show="vm.showProgress", background-click-close="false", style="
170170

171171
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.
172172

173-
progress-bar.upload-progress__progress-bar(completed="vm.uploadProgress", message="of 3 files uploaded")
173+
//- progress-bar.upload-progress__progress-bar(completed="vm.uploadProgress", message="of 3 files uploaded")
174174
175175
.upload-progress__preparing(ng-show="vm.preparing && !vm.errorInUpload") #[span Preparing...]
176176
.upload-progress__finishing(ng-show="vm.finishing && !vm.errorInUpload")
177+
p Finishing...
178+
179+
.upload-progress__finished(ng-show="vm.finished && !vm.errorInUpload")
177180
p Finished!
178181

179182
.upload-progess__links

assets/css/directives/tc-fp-file-input.directive.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ tc-fp-file-input {
4545
top: 0;
4646
height: 190px;
4747
width: 240px;
48+
position: relative;
49+
50+
> span {
51+
position: absolute;
52+
top: 0px;
53+
right: 0px;
54+
}
4855
}
4956

5057
.tc-fp-file-drag-drop::after {
@@ -57,4 +64,15 @@ tc-fp-file-input {
5764
left: 50%;
5865
transform: translateX(-50%)
5966
}
67+
68+
.tc-fp-file-drag-drop-image::after {
69+
content: 'Drag and Drop your PNG or JPG file here';
70+
}
71+
72+
&.file-uploaded {
73+
.tc-file-field__input::after,
74+
.tc-fp-file-drag-drop::after {
75+
content: '';
76+
}
77+
}
6078
}

assets/css/submissions/submit-file.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,14 @@ modal {
168168

169169
.upload-progress__preparing,
170170
.upload-progress__finishing,
171+
.upload-progress__finished,
171172
.upload-progress__error {
172173
@include font-with-weight('Sofia Pro', 500);
173174
font-size: 12px;
174175
line-height: 14px;
175176
color: $accent-gray-dark;
176177
text-align: center;
178+
margin-top: 40px;
177179
}
178180

179181
.upload-progress__error {

0 commit comments

Comments
 (0)