Skip to content

Commit

Permalink
Show files in S3 on dataset show page
Browse files Browse the repository at this point in the history
Also: Add configuration so we do not update ARK url unless we explicitly
say we're ready.
  • Loading branch information
bess committed Apr 28, 2022
1 parent dd6e31c commit c95316a
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ To create a tagged release use the [steps in the RDSS handbook](https://github.c
An early stages Entity-Relationship Diagram (ERD) is available in [this Google Doc](https://docs.google.com/drawings/d/1q2sfj8rrcNVgqQPK5uT_t79A9SYqncinh3HbnCSGMyQ/edit).

### Sample Data
Sample data available here: https://docs.google.com/document/d/18ZkBldqWxIIR1UA6qMY87RnGFTKU9HG3EJzodzzFf2A/edit#heading=h.cj3zec9ihjhc
Sample data available here: https://docs.google.com/document/d/18ZkBldqWxIIR1UA6qMY87RnGFTKU9HG3EJzodzzFf2A/edit
14 changes: 9 additions & 5 deletions app/models/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ class Dataset < ApplicationRecord
end

after_save do |ds|
if ds.ark.present?
# Ensure that the ARK metadata is updated for the new URL
if ark_object.target != ds.url
ark_object.target = ds.url
ark_object.save!
# We only want to update the ark url under certain conditions.
# Set this value in config/update_ark_url.yml
if Rails.configuration.update_ark_url
if ds.ark.present?
# Ensure that the ARK metadata is updated for the new URL
if ark_object.target != ds.url
ark_object.target = ds.url
ark_object.save!
end
end
end
end
Expand Down
73 changes: 52 additions & 21 deletions app/views/datasets/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,32 +1,63 @@
<h1><%= @dataset.title %></h1>

<div>
<p>DOI: <%= link_to(@dataset.doi, @dataset.doi) %></p>
<p>ARK: <%= link_to(@dataset.ark, @dataset.ark_url) %></p>
<p>Created by: <%= @dataset.created_by_user.uid %></p>
<p>Collection: <%= @dataset.collection_title %></p>
</div>

<!-- TODO: Move this logic to a helper -->
<div>
<table id="files-table">
<table id="files-table" class="table">
<thead>
<tr>
<th scope="col" nowrap="nowrap"><span>Filename</span></th>
<th scope="col"><span>Last Modified</span></th>
<th scope="col" nowrap="nowrap"><span>Filesize</span></th>
</tr>
</thead>

<% if @files %>
<% @files.each do |file| %>
<%= file.filename %>
<% end %>
<% else %>
<p>No files in S3</p>
<% end %>
</table>
</div>

<section class="files-section">
<div class="lux">
<div class="card">
<div class="files card-body">

<!-- Only render file download table if there are files in DataSpace -->

<% if @files && @files.empty? %>
<p>No files in S3</p>
<% else %>
<table id="files-table" class="table">
<thead>
<tr>
<th scope="col" nowrap="nowrap"><span>#</span></th>
<th scope="col" nowrap="nowrap"><span>Filename</span></th>
<th scope="col"><span>Last Modified</span></th>
<th scope="col" nowrap="nowrap"><span>Filesize</span></th>
</tr>
</thead>
<tbody>
<% @files&.each_with_index do |file, ix| %>
<tr class="files">
<th scope="row">
<span><span><%= ix + 1 %></span></span>
</th>
<td>
<span>
<i class="bi bi-file-arrow-down"></i>
<a href="<%= file.filename %>" class="documents-file-link" target="_blank" title="<%= file.filename %>"><%= truncate(file.filename, length: 80) %></a>
</span>
</td>
<td>
<span><%= file.last_modified %></span>
</td>
<td>
<span><span><%= number_to_human_size(file.size) %></span></span>
</td>
</tr>
<% end %>
</tbody>
<tfoot></tfoot>
</table>
<% end %>

<!-- End of file download table -->

</div>
</div>
</div>
</section>

<div>
<%= link_to("Edit", edit_dataset_path(@dataset), class: "btn btn-primary") %>
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/load_update_ark_url.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true
module PdcDescribe
class Application < Rails::Application
config.update_ark_url = config_for(:update_ark_url)
end
end
9 changes: 9 additions & 0 deletions config/update_ark_url.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
production:
false
staging:
false
development:
false
test:
false
2 changes: 1 addition & 1 deletion spec/factories/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
factory :dataset do
factory :shakespeare_and_company_dataset do
doi { "https://doi.org/10.34770/pe9w-x904" }
ark { "http://arks.princeton.edu/ark:/88435/dsp01zc77st047" }
ark { "ark:/88435/dsp01zc77st047" }
work { FactoryBot.create(:shakespeare_and_company_work) }
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/models/dataset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
subject(:data_set) { described_class.create_skeleton("test title", user.id, collection.id) }

context "and when the ARK is valid" do
around do |example|
Rails.configuration.update_ark_url = true
example.run
Rails.configuration.update_ark_url = false
end

before do
# stub_request(:get, "https://ezid.cdlib.org/id/#{ezid}").to_return(status: 200, body: response_body)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/system/view_data_in_s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@

expect(page).to have_content file1.filename
expect(page).to have_content file1.last_modified
expect(page).to have_content file1.size
expect(page).to have_content "10.5 KB"

expect(page).to have_content file2.filename
expect(page).to have_content file2.last_modified
expect(page).to have_content file2.size
expect(page).to have_content "12.4 KB"
end
end
end

0 comments on commit c95316a

Please sign in to comment.