diff --git a/hyrax/app/assets/javascripts/work_show.js b/hyrax/app/assets/javascripts/work_show.js new file mode 100644 index 0000000000000000000000000000000000000000..4f4a4e8334a74ae41af50898b635466f32555d07 --- /dev/null +++ b/hyrax/app/assets/javascripts/work_show.js @@ -0,0 +1,30 @@ +$(document).on('ready', function() { + var document_id = $('#download-all').data('document-id'); + var intervalId; // Declare intervalId variable in outer scope + + // Function to check if download is ready + function checkDownloadStatus() { + if (document_id) { + $.ajax({ + url: "/download_all/button_ready/" + document_id, + type: 'GET', + dataType: 'json', + success: function(response) { + if (response.is_ready) { + $('#download-all').attr('disabled', false); + clearInterval(intervalId); // Clear the interval + } + }, + error: function(request, error) { + console.error("Request error:", error); + } + }); + } + } + + // Initial check on document ready + checkDownloadStatus(); + + // Set interval to check every 2 minutes (120,000 milliseconds) + intervalId = setInterval(checkDownloadStatus, 120000); +}); diff --git a/hyrax/app/assets/stylesheets/rdms.scss b/hyrax/app/assets/stylesheets/rdms.scss index b8f7406865e8c95aae7aa3e3178ab0dc389ae4bb..98aa5fd00c0d7f2756112c76c91e0ba1c98d314e 100644 --- a/hyrax/app/assets/stylesheets/rdms.scss +++ b/hyrax/app/assets/stylesheets/rdms.scss @@ -135,6 +135,9 @@ form .field-wrapper label[required="required"]::after { justify-content: space-between; } } + #download-all[disabled] { + pointer-events: none; + } } .colection-sidebar, @@ -276,6 +279,11 @@ form .field-wrapper label[required="required"]::after { margin-top: 10px; } +.download_all_waiting_text { + background-color: #d3d3d3; + padding: 10px; +} + .facet-field-heading .crc_dataset_brain_logo { height: 20px; border-radius: 40px; diff --git a/hyrax/app/controllers/download_all_controller.rb b/hyrax/app/controllers/download_all_controller.rb index 73c205e59db287db797a04f1400b5419d8c1b7ff..411915f184eb50cd9eb37e4270ab00d8741bf68d 100644 --- a/hyrax/app/controllers/download_all_controller.rb +++ b/hyrax/app/controllers/download_all_controller.rb @@ -44,6 +44,10 @@ class DownloadAllController < Hyrax::DownloadsController send_file unauthorized_image, status: :unauthorized end + def button_ready + render json: { is_ready: download_all_button_available?(params[:id]) }, status: 200 + end + private def work diff --git a/hyrax/app/helpers/download_helper.rb b/hyrax/app/helpers/download_helper.rb index 85a7c90233bc42c409bd89f5532f25a91a1ea51e..edce3c2c0d74744d2a5e44f7f3434e8c9e931937 100644 --- a/hyrax/app/helpers/download_helper.rb +++ b/hyrax/app/helpers/download_helper.rb @@ -24,7 +24,7 @@ module DownloadHelper def has_zip_file? if work.date_modified.present? - File.exists?(zip_file_path) and local_file_last_modified > (work.date_modified + 1) + File.exists?(zip_file_path) and local_file_last_modified > work.date_modified else File.exists?(zip_file_path) end diff --git a/hyrax/app/helpers/hyrax_helper.rb b/hyrax/app/helpers/hyrax_helper.rb index bfc7b916ece6c1f2a201c42a86b083318bdfa8e2..8acde3a7f92395a8b8098a2a7aae4cb7afa874cf 100644 --- a/hyrax/app/helpers/hyrax_helper.rb +++ b/hyrax/app/helpers/hyrax_helper.rb @@ -137,6 +137,16 @@ module HyraxHelper filtered_data.to_json end + def download_all_button_available?(work_id) + work = ActiveFedora::Base.find(work_id) + s3 = S3StorageService.new + s3.init_client + bucket_name = s3.sanitise_name(work.id) + meta_object = s3.system_metadata_object(bucket_name) + + work.date_modified < DateTime.parse(meta_object.last_modified.to_s) + end + def restricted_file_names?(file_name) parsed_file = YAML.load_file(Rails.root.join('config', 'restricted_files.yml')) parsed_file['restricted_file_names'].map(&:downcase).include?(file_name.downcase) diff --git a/hyrax/app/services/s3_storage_service.rb b/hyrax/app/services/s3_storage_service.rb index 574aae0a777bfe2751f668ae9d7be609893873a7..1773884004fab54fcaa9c1e2ce60e1e13a3e9de5 100644 --- a/hyrax/app/services/s3_storage_service.rb +++ b/hyrax/app/services/s3_storage_service.rb @@ -32,6 +32,10 @@ class S3StorageService buckets end + def system_metadata_object(bucket_name) + @s3_client.get_object(bucket: bucket_name, key: "system_metadata.json") + end + def bucket_exists?(bucket_name) @s3_client.list_buckets.buckets.each do |bucket| return true if bucket.name == bucket_name diff --git a/hyrax/app/views/hyrax/base/_download_all.html.erb b/hyrax/app/views/hyrax/base/_download_all.html.erb index 4e41e8937a3cae9d849f1cdf1a801b642f748430..8c2ed2bf41a01e2aa97c4d086b97fb79fe74d4cb 100644 --- a/hyrax/app/views/hyrax/base/_download_all.html.erb +++ b/hyrax/app/views/hyrax/base/_download_all.html.erb @@ -1,3 +1,3 @@ <div class="download-all"> - <%= link_to t(:'hyrax.download_all'), main_app.download_all_path(presenter.id), id: "download-all",class: "btn btn-default matomo_download" %> + <%= link_to t(:'hyrax.download_all'), main_app.download_all_path(presenter.id), disabled: download_all_button_available?(presenter.id) ? false : true, id: "download-all", class: "btn btn-default matomo_download", data:{ document_id: presenter.id } %> </div> \ No newline at end of file diff --git a/hyrax/config/routes.rb b/hyrax/config/routes.rb index 5ef531afb349f9db4503053e4143929232919a4d..cde0d66422d7aeb9869472458fdd1548659010e7 100644 --- a/hyrax/config/routes.rb +++ b/hyrax/config/routes.rb @@ -40,7 +40,10 @@ Rails.application.routes.draw do resources :solr_documents, only: [:show], path: '/catalog', controller: 'catalog' do concerns :exportable end - resources :download_all, only: :show + + resources :download_all, only: [:show] do + get 'button_ready/:id', :to => "download_all#button_ready", on: :collection + end resources :bookmarks do concerns :exportable