diff --git a/app/assets/javascripts/sitewide/drag_n_drop.js b/app/assets/javascripts/sitewide/drag_n_drop.js
index 6b49f8a20..fe9976776 100644
--- a/app/assets/javascripts/sitewide/drag_n_drop.js
+++ b/app/assets/javascripts/sitewide/drag_n_drop.js
@@ -464,15 +464,8 @@
const form = $(ev.target.form);
const url = form.find('#drag-n-drop-assets').data('directUploadUrl');
const numberOfFiles = droppedFiles.length;
-
- let resultNames = [];
-
- $.each($('input[rel="results[name]"]'), function() {
- resultNames.push($(this).val());
- });
-
- resultNames.reverse();
var counter = 0;
+
for (let i = 0; i < numberOfFiles; i += 1) {
let upload = new ActiveStorage.DirectUpload(droppedFiles[i], url);
@@ -480,7 +473,7 @@
if (error) {
// Handle the error
} else {
- fd.append('results_names[' + i + ']', resultNames[i]);
+ fd.append('results_names[' + i + ']', $('input[name="results[name][' + i + ']"]').val());
fd.append('results_files[' + i + '][signed_blob_id]', blob.signed_id);
counter += 1;
if (counter === numberOfFiles) {
@@ -521,7 +514,7 @@
${I18n.t('assets.drag_n_drop.file_label')}
@@ -530,7 +523,7 @@
+ rel="results[name]" name="results[name][${i}]">
@@ -555,7 +548,7 @@
}
}
- function removeItemHandler(id, callback) {
+ function removeItemHandler(id) {
$('[data-item-id="' + id + '"]').off('click').on('click', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
@@ -564,7 +557,7 @@
let index = $el.data('item-id');
totalSize -= parseInt(droppedFiles[index].size, 10);
droppedFiles.splice(index, 1);
- callback();
+ $el.closest('.panel-result-attachment-new').remove();
});
}
@@ -582,7 +575,7 @@
.after(uploadedAssetPreview(droppedFiles[i], i))
.promise()
.done(function() {
- removeItemHandler(i, listItems);
+ removeItemHandler(i);
});
}
validateTotalSize();
@@ -594,7 +587,7 @@
fileMaxSizeMb = GLOBAL_CONSTANTS.FILE_MAX_SIZE_MB;
fileMaxSize = fileMaxSizeMb * 1024 * 1024;
for (let i = 0; i < files.length; i += 1) {
- droppedFiles.push(files[i]);
+ droppedFiles.unshift(files[i]);
}
listItems();
}
diff --git a/app/controllers/result_assets_controller.rb b/app/controllers/result_assets_controller.rb
index 2967afb13..9bb7d10fc 100644
--- a/app/controllers/result_assets_controller.rb
+++ b/app/controllers/result_assets_controller.rb
@@ -175,12 +175,12 @@ class ResultAssetsController < ApplicationController
results = []
ActiveRecord::Base.transaction do
- params[:results_files].values.each_with_index do |file, index|
+ params[:results_files].each do |index, file|
asset = Asset.create!(created_by: current_user, last_modified_by: current_user, team: current_team)
asset.file.attach(file[:signed_blob_id])
result = Result.create!(user: current_user,
my_module: @my_module,
- name: params[:results_names][index.to_s],
+ name: params[:results_names][index],
asset: asset,
last_modified_by: current_user)
results << result