diff --git a/app/controllers/submissions_download_controller.rb b/app/controllers/submissions_download_controller.rb
index 26ebdf51..93f90027 100644
--- a/app/controllers/submissions_download_controller.rb
+++ b/app/controllers/submissions_download_controller.rb
@@ -8,6 +8,15 @@ class SubmissionsDownloadController < ApplicationController
Submissions::GenerateResultAttachments.call(submitter) if submitter.documents.blank?
- render json: submitter.documents.map { |e| helpers.rails_blob_url(e) }
+ original_documents = submitter.submission.template.documents.preload(:blob)
+ is_more_than_two_images = original_documents.count(&:image?) > 1
+
+ urls = submitter.documents.preload(:blob).filter_map do |attachment|
+ next if is_more_than_two_images && original_documents.find { |a| a.uuid == attachment.uuid }&.image?
+
+ helpers.rails_blob_url(attachment)
+ end
+
+ render json: urls
end
end
diff --git a/app/javascript/elements/download_button.js b/app/javascript/elements/download_button.js
index a51138e7..2e81a176 100644
--- a/app/javascript/elements/download_button.js
+++ b/app/javascript/elements/download_button.js
@@ -18,20 +18,27 @@ export default targetable(class extends HTMLElement {
this.toggleState()
fetch(this.dataset.src).then((response) => response.json()).then((urls) => {
- urls.forEach((url) => {
- fetch(url).then(async (resp) => {
- const blobUrl = URL.createObjectURL(await resp.blob())
- const link = document.createElement('a')
+ const fileRequests = urls.map((url) => {
+ return () => {
+ return fetch(url).then(async (resp) => {
+ const blobUrl = URL.createObjectURL(await resp.blob())
+ const link = document.createElement('a')
- link.href = blobUrl
- link.setAttribute('download', resp.headers.get('content-disposition').split('"')[1])
+ link.href = blobUrl
+ link.setAttribute('download', decodeURI(resp.headers.get('content-disposition').split('"')[1]))
- link.click()
+ link.click()
- URL.revokeObjectURL(url)
- })
+ URL.revokeObjectURL(url)
+ })
+ }
})
- }).finally(() => {
+
+ fileRequests.reduce(
+ (prevPromise, request) => prevPromise.then(() => request()),
+ Promise.resolve()
+ )
+
this.toggleState()
})
}
diff --git a/app/javascript/submission_form/completed.vue b/app/javascript/submission_form/completed.vue
index a619efb6..1969be30 100644
--- a/app/javascript/submission_form/completed.vue
+++ b/app/javascript/submission_form/completed.vue
@@ -90,20 +90,27 @@ export default {
this.isDownloading = true
fetch(`/submitters/${this.submitterSlug}/download`).then((response) => response.json()).then((urls) => {
- urls.forEach((url) => {
- fetch(url).then(async (resp) => {
- const blobUrl = URL.createObjectURL(await resp.blob())
- const link = document.createElement('a')
+ const fileRequests = urls.map((url) => {
+ return () => {
+ return fetch(url).then(async (resp) => {
+ const blobUrl = URL.createObjectURL(await resp.blob())
+ const link = document.createElement('a')
- link.href = blobUrl
- link.setAttribute('download', resp.headers.get('content-disposition').split('"')[1])
+ link.href = blobUrl
+ link.setAttribute('download', decodeURI(resp.headers.get('content-disposition').split('"')[1]))
- link.click()
+ link.click()
- URL.revokeObjectURL(url)
- })
+ URL.revokeObjectURL(url)
+ })
+ }
})
- }).finally(() => {
+
+ fileRequests.reduce(
+ (prevPromise, request) => prevPromise.then(() => request()),
+ Promise.resolve()
+ )
+
this.isDownloading = false
})
}
diff --git a/app/javascript/submission_form/form.vue b/app/javascript/submission_form/form.vue
index e1b666d7..1851d7aa 100644
--- a/app/javascript/submission_form/form.vue
+++ b/app/javascript/submission_form/form.vue
@@ -191,7 +191,7 @@
:field="currentField"
:attachments-index="attachmentsIndex"
:submitter-slug="submitterSlug"
- @attached="attachments.push($event)"
+ @attached="[attachments.push($event), $refs.areas.scrollIntoField(currentField)]"
/>