Skip to content

Commit

Permalink
Fix multiple files stats for bulk upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Oct 30, 2023
1 parent 3b4059b commit b1ac009
Showing 1 changed file with 29 additions and 24 deletions.
53 changes: 29 additions & 24 deletions app/assets/javascripts/upload.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -300,33 +300,33 @@ bulkCorrectionUpload = (fileInput) ->
null
'/corrections/upload'
'#bulk-uploadButton-button-actual'
(data) =>
(_, dataAll) =>
console.log(dataAll)

data = JSON.parse data.response
console.log(data)
result = (successful: [data])
console.log result
if dataAll.length == 0
console.error('No files uploaded, fatal error')
return

# Disable upload if uploaded (zip)-file is empty
# Temporary fix for ":type option required" error in the
# app/controllers/submissions_controller.rb -> show_correction
if data.metadata.size == 0
fileSizes = dataAll.map((data) => data.metadata.size)
if fileSizes.includes(0)
console.log('empty file encountered during bulk upload')
alert($('#bulk-uploadButton-button-actual').data('tr-failure-empty-file'))
$('#bulk-uploadButton-button-actual').hide()
$(metaData).empty()
return

if result.successful.length > 0
uploaded_files = result.successful.map (file) -> file
console.log uploaded_files
$('#upload-bulk-correction-save').prop('disabled', false)
$(metaData).empty()
.append(fileInput.files.length+ ' ' +$(metaData).data('tr-uploads'))
$(uploadButton).hide()
return
$("#bulk-upload-area").toggle()
# Successfully uploaded
console.log('bulk upload successful')
$('#upload-bulk-correction-save').prop('disabled', false)
$(metaData).empty()
.append(fileInput.files.length+ ' ' +$(metaData).data('tr-uploads'))
$(uploadButton).hide()
null
'upload-bulk-correction-hidden'
false
)
$('#show-bulk-upload-area').on 'click', ->
$(this).hide()
Expand Down Expand Up @@ -370,17 +370,19 @@ directUpload provides an interface to upload (multiple) files to an endpoint
fileInput =document.getElementById(fileInputElement)
fI = $("#"+fileInputElement)
fileInput.style.display = 'none'
result = undefined
merged = undefined
files = []
filez= []


uploadedFiles = []
progressOptimize = 0
$(uploadStatusElement).hide()
uploadButton = $(uploadButtonElement)
$(actualUploadButtonElement).on 'click', (e) ->
# Reset variables
result = undefined
merged = undefined
files = []
filez= []
uploadedFiles = []
progressOptimize = 0
hiddenInput.value = ''

e.preventDefault()
if permissionElement == null || $(permissionElement).is(":checked")
#Upload blob
Expand Down Expand Up @@ -408,8 +410,11 @@ directUpload provides an interface to upload (multiple) files to an endpoint
$(progressBarElement).text(
$(progressBarElement).data 'tr-success'
)
if successCallback != undefined
successCallback(xhr)
if successCallback != undefined
# The second argument is currently only used by the
# bulk upload to get all uploaded files and not just
# the last one.
successCallback(xhr, uploadedFiles2)
hiddenInput.value = JSON.stringify uploadedFiles2
fileInput.value = null
$(progressBarElement)
Expand Down

0 comments on commit b1ac009

Please sign in to comment.