Skip to content

Commit

Permalink
Updated the code to display empty file names and empty folders on the…
Browse files Browse the repository at this point in the history
… file list.

This prevents the issue where the file count displayed to the user does not match the number of files on the list.

Co-authored-by: Robert-Anthony Lee-Faison <leefaisonr@users.noreply.github.com>
  • Loading branch information
hectorcorrea and leefaisonr committed Jun 3, 2024
1 parent 7056cdd commit 4fd3ebd
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app/models/s3_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class S3File
include Rails.application.routes.url_helpers
include ActionView::Helpers::NumberHelper

attr_accessor :safe_id, :filename, :last_modified, :size, :checksum, :url, :filename_display, :last_modified_display, :display_size
attr_accessor :safe_id, :filename, :last_modified, :size, :checksum, :url, :filename_display, :last_modified_display, :display_size, :is_folder
alias key filename
alias id filename

Expand All @@ -29,6 +29,7 @@ def initialize(filename:, last_modified:, size:, checksum:, work:, filename_disp
@checksum = checksum.delete('"')
@url = url || work_download_path(work, filename:)
@work = work
@is_folder = filename.ends_with?("/")
end

def created_at
Expand Down
3 changes: 2 additions & 1 deletion app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ def file_list
"last_modified_display": s3_file.last_modified_display,
"size": s3_file.size,
"display_size": s3_file.display_size,
"url": s3_file.url
"url": s3_file.url,
"is_folder": s3_file.is_folder
}
end
files_info
Expand Down
4 changes: 3 additions & 1 deletion app/services/s3_query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def publish_files(current_user)
source_bucket = S3QueryService.pre_curation_config[:bucket]
target_bucket = S3QueryService.post_curation_config[:bucket]
empty_files = client_s3_empty_files(reload: true, bucket_name: source_bucket)
# See TODO below
# Do not move the empty files, however, ensure that it is noted that the
# presence of empty files is specified in the provenance log.
unless empty_files.empty?
Expand Down Expand Up @@ -368,7 +369,8 @@ def parse_objects(resp, ignore_directories: true)
resp_hash = resp.to_h
response_objects = resp_hash[:contents]
response_objects&.each do |object|
next if object[:size] == 0 && ignore_directories
# TODO: Revisit this, we might need this logic
# next if object[:size] == 0 && ignore_directories
s3_file = S3File.new(work: model, filename: object[:key], last_modified: object[:last_modified], size: object[:size], checksum: object[:etag])
objects << s3_file
end
Expand Down
41 changes: 27 additions & 14 deletions app/views/works/_s3_resources.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,28 @@
// On edit mode, file is marked to be deleted display strikethrough
html = `<span><s>${row.filename_display.substring(1)}</s></span>`;
} else {
// Display as a hyperlink with the download icon
// (Note: Interpolation in the client is interpreted after the server-side Ruby builds the download path)
let downloadUrl;
if (work) {
downloadUrl = `<%= @work_decorator.download_path %>?filename=${data}`;
if (row.size == 0) {
// Display the filename as text (i.e. not a hyperlink)
html = `<span>
<i class="bi bi-dash-square"></i>
${row.filename_display}
</span>`;
} else {
downloadUrl = '<%= root_path %>';
}
var encodedUrl = window.encodeURI(downloadUrl);
// Display as a hyperlink with the download icon
// (Note: Interpolation in the client is interpreted after the server-side Ruby builds the download path)
let downloadUrl;
if (work) {
downloadUrl = `<%= @work_decorator.download_path %>?filename=${data}`;
} else {
downloadUrl = '<%= root_path %>';
}
var encodedUrl = window.encodeURI(downloadUrl);

html = `<span>
<i class="bi bi-file-arrow-down"></i>
<a href="${encodedUrl}" target="_blank">${row.filename_display}</a>
</span>`;
html = `<span>
<i class="bi bi-file-arrow-down"></i>
<a href="${encodedUrl}" target="_blank">${row.filename_display}</a>
</span>`;
}
}
return html;
}
Expand Down Expand Up @@ -137,8 +145,13 @@
render: function (data, type, row) {
// size
if (type == "display") {
// human readable (e.g. 34 KB)
return row.display_size;
if (row.is_folder === true) {
// display no size for folders
return "";
} else {
// human readable (e.g. 34 KB)
return row.display_size;
}
}
// raw bytes
return row.size;
Expand Down

0 comments on commit 4fd3ebd

Please sign in to comment.