Skip to content
Snippets Groups Projects
Commit d2a81dde authored by Anusha Ranganathan's avatar Anusha Ranganathan
Browse files

Merge branch 'bug_fix/393-download-for-small-experiments-not-working' into 'develop'

Fixes for small experiment download issue

Closes FDM/rdm-system/antleaf-projectmanagement#393

See merge request !311
parents f05c41ef ecdb1459
No related branches found
Tags v1.0-beta4
1 merge request!311Fixes for small experiment download issue
Pipeline #15309 passed
$(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);
});
......@@ -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;
......
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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
......
<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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment