From 581a280b9852e4911b5d018c268b8ee84748e1f6 Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 17 Dec 2024 18:59:06 +0100 Subject: [PATCH] Closes https://github.com/datadryad/dryad-product-roadmap/issues/3325 --- app/assets/stylesheets/scss/_download.scss | 19 ++++-- app/assets/stylesheets/scss/_file-group.scss | 26 +++++++- .../stash_engine/downloads/_download.html.erb | 66 +++++++++++++------ .../downloads/_download_zip.js.erb | 15 +++-- .../stash_engine/landing/_files.html.erb | 19 ++++-- 5 files changed, 106 insertions(+), 39 deletions(-) diff --git a/app/assets/stylesheets/scss/_download.scss b/app/assets/stylesheets/scss/_download.scss index b45147e85..ffc8f8a9c 100644 --- a/app/assets/stylesheets/scss/_download.scss +++ b/app/assets/stylesheets/scss/_download.scss @@ -3,6 +3,10 @@ .o-download { margin-top: $spacing-sm; text-align: right; + + #download-select-label { + font-size: .98rem; margin-left: 1ch; + } } *[class*="o-download__"] { @@ -10,7 +14,6 @@ display: inline-flex; align-items: center; gap: 1ch; - width: 220px; padding: 6px 10px; border: none; background-color: $lighter-blue; @@ -30,8 +33,12 @@ } &:hover { - opacity: 0.85; - } + opacity: 0.85; + } + + &:disabled, &.disabled { + background-color: $lighter-gray; + } } .o-download__files #download_icon::before { @@ -52,9 +59,9 @@ content: '\f1ce'; color: $medium-blue; position: absolute; - top: -3px; left: 0; - -webkit-animation: fa-spin 2s infinite linear; - animation: fa-spin 2s infinite linear; + top: -3px; left: 0; + -webkit-animation: fa-spin 2s infinite linear; + animation: fa-spin 2s infinite linear; } } } diff --git a/app/assets/stylesheets/scss/_file-group.scss b/app/assets/stylesheets/scss/_file-group.scss index 960845e35..9b067e5fa 100644 --- a/app/assets/stylesheets/scss/_file-group.scss +++ b/app/assets/stylesheets/scss/_file-group.scss @@ -11,7 +11,6 @@ } } - } .c-file-group__summary { @@ -64,6 +63,27 @@ margin-left: 1ch; } + #download-select { + margin-left: .75ch; + margin-right: .5ch; + } +} + +.select-file-download, #download-select { + display: none; +} +.large_download { + #download-select { + display: inline-block; + } + .select-file-download { + display: inline-block; + margin-left: .5ch; + } + span.select-file-download { + display: inline-block; + width: 1.4ch; + } } .c-file-group__list { @@ -88,8 +108,8 @@ max-width: 100%; } - span { - flex-basis: calc(100% - 100px); + & > span { + flex-basis: calc(100% - 106px); display: flex; justify-content: space-between; flex-wrap: wrap; diff --git a/app/views/stash_engine/downloads/_download.html.erb b/app/views/stash_engine/downloads/_download.html.erb index 43d17db48..9b39fa3bd 100644 --- a/app/views/stash_engine/downloads/_download.html.erb +++ b/app/views/stash_engine/downloads/_download.html.erb @@ -3,26 +3,52 @@ <% end %> <% worker_scope = request.fullpath.split('/').first(3).join('/') + '/' %> -<% if resource.total_file_size < APP_CONFIG.maximums.zip_size %> -
- <%= form_with url: "#{worker_scope}downloadZip/#{"doi_#{dataset_identifier.identifier}__v#{minimal_date(resource.publication_date.present? && resource.publication_date < Time.now.utc ? resource.publication_date : resource.updated_at)}".gsub(/\.|:|\//, '_')}.zip", method: :post, name: 'download', id: 'zip_download', remote: true do |form| %> -
- - <% end %> -
-
- <% content_for :doc_end do %> - <% params = {resource_id: @resource.id} %> - <% params[:share] = share if share.present? %> - + selectDownloads() + selectForm.addEventListener('change', selectDownloads) <% end %> + const dlbutton = document.getElementById('download_zip_button'); + if ("serviceWorker" in navigator) { + const zip_url = '<%= stash_url_helpers.zip_assembly_info_path(params)%>'; + const scope = '<%= worker_scope %>'; + <%= render partial: 'stash_engine/downloads/download_zip', formats: :js %> + } else { + dlbutton.hidden = true; + document.getElementById('download_resource').classList.remove('large_download'); + } + <% end %> \ No newline at end of file diff --git a/app/views/stash_engine/downloads/_download_zip.js.erb b/app/views/stash_engine/downloads/_download_zip.js.erb index 0b699b42a..533217aca 100644 --- a/app/views/stash_engine/downloads/_download_zip.js.erb +++ b/app/views/stash_engine/downloads/_download_zip.js.erb @@ -9,13 +9,16 @@ navigator.serviceWorker.ready.then(worker => { worker.active.postMessage({type: 'PORT_INITIALIZATION', url: form.action}, [messageChannel.port2]); }); const insertFiles = async (files) => { + const selectForm = document.getElementById('download-select-form').elements for (const f of files) { - for (const k of Object.keys(f)) { - const i = document.createElement('input'); - i.setAttribute('type', 'hidden'); - i.setAttribute('name', k); - i.setAttribute('value', f[k]); - inputs.appendChild(i); + if (selectForm[f.filename].checked) { + for (const k of Object.keys(f)) { + const i = document.createElement('input'); + i.setAttribute('type', 'hidden'); + i.setAttribute('name', k); + i.setAttribute('value', f[k]); + inputs.appendChild(i); + } } } return true; diff --git a/app/views/stash_engine/landing/_files.html.erb b/app/views/stash_engine/landing/_files.html.erb index 4ae86cdd4..ca88655d9 100644 --- a/app/views/stash_engine/landing/_files.html.erb +++ b/app/views/stash_engine/landing/_files.html.erb @@ -14,14 +14,15 @@

Data files

- <% if resources.count.positive? %> + <% if resources.count.positive? %> <% resources.each do |res| %> -
APP_CONFIG.maximums.zip_size) %> open<%end%>> +
id="download_resource"<% end %> class="c-file-group<% if dl_resource == resource && resource.total_file_size > APP_CONFIG.maximums.zip_size %> large_download<% end %>" role="group"<%if res.id === resources.last.id && (res.current_file_uploads.count < 10 || res.total_file_size > APP_CONFIG.maximums.zip_size) %> open<%end%>> <%= formatted_date(res.publication_date.present? && res.publication_date < Time.now.utc ? res.publication_date : res.updated_at) %> version files - <%= filesize(res.total_file_size) %> + <%= filesize(res.total_file_size) %> + <% if dl_resource == resource %>
<% end %>
    <% res.current_file_uploads.each do |fu| %> <% params = {file_id: fu.id} %> @@ -34,10 +35,20 @@
- <%= filesize(fu.upload_file_size) %> +
+ <%= filesize(fu.upload_file_size) %> + <% if dl_resource == resource %> + <% if fu.upload_file_size < APP_CONFIG.maximums.zip_size %> + checked<% end %> aria-label="Select <%= fu.upload_file_name%> for download"> + <% else %> + + <% end %> + <% end %> +
<% end %> + <% if dl_resource == resource %><% end %> <% end %>