From 581a280b9852e4911b5d018c268b8ee84748e1f6 Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 17 Dec 2024 18:59:06 +0100 Subject: [PATCH 1/3] 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 %>
From dae51f4ac52ef62df1adb6a4f1eeab3a4a1010c8 Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 17 Dec 2024 19:23:05 +0100 Subject: [PATCH 2/3] variable name fix --- app/views/stash_engine/landing/_files.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/stash_engine/landing/_files.html.erb b/app/views/stash_engine/landing/_files.html.erb index ca88655d9..efa21da69 100644 --- a/app/views/stash_engine/landing/_files.html.erb +++ b/app/views/stash_engine/landing/_files.html.erb @@ -17,12 +17,12 @@ <% if resources.count.positive? %> <% resources.each do |res| %> -
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%>> +
id="download_resource"<% end %> class="c-file-group<% if dl_resource == res && res.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) %> - <% if dl_resource == resource %>
<% end %> + <% if dl_resource == res %><% end %>
    <% res.current_file_uploads.each do |fu| %> <% params = {file_id: fu.id} %> @@ -37,9 +37,9 @@
    <%= filesize(fu.upload_file_size) %> - <% if dl_resource == resource %> + <% if dl_resource == res %> <% if fu.upload_file_size < APP_CONFIG.maximums.zip_size %> - checked<% end %> aria-label="Select <%= fu.upload_file_name%> for download"> + checked<% end %> aria-label="Select <%= fu.upload_file_name%> for download"> <% else %> <% end %> @@ -48,7 +48,7 @@ <% end %>
- <% if dl_resource == resource %>
<% end %> + <% if dl_resource == res %><% end %>
<% end %>
From 8771df410b31e4c1a5eaa9fdedb6a6345aa11f4d Mon Sep 17 00:00:00 2001 From: Audrey Hamelers Date: Tue, 17 Dec 2024 19:39:19 +0100 Subject: [PATCH 3/3] aria accessibility adjustments --- app/assets/stylesheets/scss/_file-group.scss | 26 +++++++------------ .../stash_engine/landing/_files.html.erb | 8 +++--- 2 files changed, 13 insertions(+), 21 deletions(-) diff --git a/app/assets/stylesheets/scss/_file-group.scss b/app/assets/stylesheets/scss/_file-group.scss index 9b067e5fa..542341f6b 100644 --- a/app/assets/stylesheets/scss/_file-group.scss +++ b/app/assets/stylesheets/scss/_file-group.scss @@ -69,23 +69,6 @@ } } -.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 { list-style-type: none; font-size: .98rem; @@ -124,4 +107,13 @@ display: inline-block; } } + + .select-file-download { + display: inline-block; + margin-left: .5ch; + } + span.select-file-download { + display: inline-block; + width: 1.4ch; + } } diff --git a/app/views/stash_engine/landing/_files.html.erb b/app/views/stash_engine/landing/_files.html.erb index efa21da69..7bd284020 100644 --- a/app/views/stash_engine/landing/_files.html.erb +++ b/app/views/stash_engine/landing/_files.html.erb @@ -17,12 +17,12 @@ <% if resources.count.positive? %> <% resources.each do |res| %> -
id="download_resource"<% end %> class="c-file-group<% if dl_resource == res && res.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%>> +
id="download_resource"<% end %> class="c-file-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 == res && res.total_file_size > APP_CONFIG.maximums.zip_size %><% end %> - <% if dl_resource == res %>
<% end %> + <% if dl_resource == res %> APP_CONFIG.maximums.zip_size %>aria-labelledby="download-select-label"<% end %>><% end %>
    <% res.current_file_uploads.each do |fu| %> <% params = {file_id: fu.id} %> @@ -39,7 +39,7 @@ <%= filesize(fu.upload_file_size) %> <% if dl_resource == res %> <% if fu.upload_file_size < APP_CONFIG.maximums.zip_size %> - checked<% end %> aria-label="Select <%= fu.upload_file_name%> for download"> + checked hidden <% end %>aria-label="Select <%= fu.upload_file_name%> for download"> <% else %> <% end %>