Skip to content

Commit

Permalink
Added "Latest Download" link to inventory download modal (#1123)
Browse files Browse the repository at this point in the history
* Added latest download link to controller, added link to modal

* Added a test to the modal
  • Loading branch information
kelynch authored Dec 12, 2024
1 parent a37a477 commit b7b5b92
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/_projects.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,8 @@
}

}

.latest-download-link {
margin: 1em 0em 1em 0em;
display: block;
}
2 changes: 2 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def show

@project_purpose = @project_metadata[:project_purpose]


respond_to do |format|
format.html do
@project = ProjectShowPresenter.new(project)
Expand Down Expand Up @@ -176,6 +177,7 @@ def contents
add_breadcrumb("Contents", project_contents_path)
project

@latest_completed_download = current_user.user_requests.where(project_id: @project.id, state: "completed").order(:completion_time).last
@storage_usage = project.storage_usage(session_id: current_user.mediaflux_session)
@storage_capacity = project.storage_capacity(session_id: current_user.mediaflux_session)

Expand Down
1 change: 1 addition & 0 deletions app/views/projects/_latest_download_link.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= link_to("Download latest report - generated #{time_ago_in_words(@latest_completed_download.completion_time)} ago", project_file_list_download_path(@latest_completed_download.id, target: "_blank")) %>
2 changes: 2 additions & 0 deletions app/views/projects/contents.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
</div>
<div class="modal-body">
This will generate a list of <%= @num_files %> files and their attributes in a downloadable CSV. Do you wish to continue?

<span class="latest-download-link"><%= render partial: "latest_download_link", locals: { project: @project } if @latest_completed_download %></span>
</div>
<div class="modal-footer">
<button type="button" id="request-list-contents" class="btn btn-success" data-list-contents-path="<%= project_list_contents_path %>" >Yes</button>
Expand Down
22 changes: 22 additions & 0 deletions spec/system/project_show_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,28 @@
find("a.paginate_button", text: 3).click
expect(page).to have_content(last_file.name)
end

context "when downloads do not exist" do
it "does not include a link to the latest download in the download modal" do
sign_in sponsor_user
visit "/projects/#{project.id}/contents"
click_on("Download Complete List")
expect(page).not_to have_content("Download latest")
end
end

context "when downloads exist" do
before do
FileInventoryRequest.create!(user_id: sponsor_user.id, project_id: project.id, job_id: 123, state: UserRequest::COMPLETED,
request_details: { project_title: project.title }, completion_time: 1.day.ago)
end
it "includes a link to the latest download in the download modal" do
sign_in sponsor_user
visit "/projects/#{project.id}/contents"
click_on("Download Complete List")
expect(page).to have_content("Download latest")
end
end
end

context "system administrator" do
Expand Down

0 comments on commit b7b5b92

Please sign in to comment.