diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 0eec8ff1..fd72eba8 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -268,6 +268,15 @@ def show end end + # This endpoint is used to feed the AJAX call on the Show page for the file list and + # therefore the return JSON must be something that DataTables can use. + def file_list + document = solr_find(params["id"]) + file_list = { data: document.files } + + render json: file_list.to_json + end + # Returns the raw BibTex citation information def bibtex _unused, @document = search_service.fetch(params[:id]) @@ -339,4 +348,15 @@ def pppl_reporting_feed format.json { render json: @documents } end end + + private + + def solr_find(id) + solr_url = Blacklight.default_configuration.connection_config[:url] + solr = RSolr.connect(url: solr_url) + solr_params = { q: "id:#{id}", fl: '*' } + response = solr.get('select', params: solr_params) + solr_doc = response["response"]["docs"][0] + SolrDocument.new(solr_doc) + end end diff --git a/app/models/dataset_file.rb b/app/models/dataset_file.rb index 27936e78..5b3689c6 100644 --- a/app/models/dataset_file.rb +++ b/app/models/dataset_file.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class DatasetFile - attr_accessor :name, :description, :format, :size, :mime_type, :sequence, :handle, :extension, + attr_accessor :name, :description, :format, :size, :display_size, :mime_type, :sequence, :handle, :extension, :source, :download_url, :full_path def self.from_hash(data, data_source) @@ -23,6 +23,7 @@ def self.from_hash_dataspace(data) file.description = hash[:description] file.mime_type = hash[:mime_type] file.size = hash[:size] + file.display_size = ActiveSupport::NumberHelper.number_to_human_size(file.size) file.sequence = (hash[:sequence] || "").to_i # Technically the handle is a property of the dataset item rather than the file (aka bitstream) # but we store it at the file level for convenience. @@ -40,6 +41,7 @@ def self.from_hash_describe(data) file.extension = File.extname(file.name) file.extension = file.extension[1..] if file.extension != "." # drop the leading period file.size = hash[:size] + file.display_size = ActiveSupport::NumberHelper.number_to_human_size(file.size) file.download_url = hash[:url] file end diff --git a/app/views/catalog/_show_documents.html.erb b/app/views/catalog/_show_documents.html.erb index b41f2ae8..67de745d 100644 --- a/app/views/catalog/_show_documents.html.erb +++ b/app/views/catalog/_show_documents.html.erb @@ -13,42 +13,11 @@ - - - <% if @document.data_source == "dataspace" %> - - <% end %> - + + - - <% DatasetFile.sort_file_array(@document.files).each_with_index do |file, ix| %> - - - - <% if @document.data_source == "dataspace" %> - - <% end %> - - - <% end %> - - +
#FilenameDescriptionFilesizeFilenameSize
- <%= ix + 1 %> - - - - <% if @render_links%> - <%= truncate(file.full_path, length: 60) %> - <% else %> - <%= truncate(file.full_path, length: 60) %> - <% end %> - - - <%= file.description %> - - <%= number_to_human_size(file.size) %> -
<% end %> @@ -63,8 +32,45 @@