From b1ac0096d5659e90d4795ff14e9a54aecfd61332 Mon Sep 17 00:00:00 2001 From: Splines Date: Mon, 30 Oct 2023 23:03:37 +0100 Subject: [PATCH] Fix multiple files stats for bulk upload --- app/assets/javascripts/upload.coffee | 53 +++++++++++++++------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/upload.coffee b/app/assets/javascripts/upload.coffee index 1c3a456dc..3eb804d23 100644 --- a/app/assets/javascripts/upload.coffee +++ b/app/assets/javascripts/upload.coffee @@ -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() @@ -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 @@ -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)