Skip to content
This repository has been archived by the owner on Nov 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #765 from psu-stewardship/sul-accessibility
Browse files Browse the repository at this point in the history
Making the single-use links more accessible, ref #738
  • Loading branch information
carolyncole authored Apr 17, 2017
2 parents d3a3d23 + 0063155 commit e5fedee
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/views/curation_concerns/file_sets/_show_actions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="form-actions">
<% if Sufia.config.analytics %>
<%= link_to "Analytics", @presenter.stats_path, id: 'stats', class: 'btn btn-default' %>
<% end %>
<% if Sufia.config.citations %>
<%= link_to "Citations", sufia.citations_work_path(@presenter), id: 'citations', class: 'btn btn-default' %>
<% end %>
<% if @presenter.editor? %>
<%= link_to "Edit This #{@presenter.human_readable_type}", edit_polymorphic_path([main_app, @presenter]),
class: 'btn btn-default' %>
<%= link_to "Delete This #{@presenter.human_readable_type}", [main_app, @presenter],
class: 'btn btn-danger', data: { confirm: "Delete this #{@presenter.human_readable_type}?" },
method: :delete %>
<%# Overrides Sufia to remove single-use links button %>
<% end %>

<%= render 'social_media' %>
</div>

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%# Overrides Sufia to provide better accessibility %>
<% single_use_links.each do |presenter| %>
<tr scope="row">
<td>
<%= t('sufia.single_use_links.expiration_message', link: presenter.short_key,
time: presenter.human_readable_expiration) %>

<button class="btn btn-xs btn-default copy-single-use-link"
data-clipboard-text="<%= curation_concerns.send(presenter.url_helper, presenter.downloadKey) %>"
data-toggle="tooltip" data-placement="bottom"
title="<%= t('curation_concerns.single_use_links.copy.tooltip') %>"
aria-label="<%= t('sufia.single_use_links.accessibility.copy', link: presenter.short_key) %>">
<%= t('curation_concerns.single_use_links.copy.button', link: presenter.short_key) %>
</button>

<%= link_to t('curation_concerns.single_use_links.delete'),
curation_concerns.delete_single_use_link_path(params[:id], presenter),
class: 'btn btn-xs btn-danger delete-single-use-link',
aria: { label: t('sufia.single_use_links.accessibility.delete', link: presenter.short_key) } %>
</td>
</tr>
<% end %>
23 changes: 23 additions & 0 deletions app/views/curation_concerns/file_sets/_single_use_links.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<%# Overrides Sufia to provide better accessibility %>
<h3><%= t('curation_concerns.single_use_links.title') %></h3>

<table class="table table-striped table-condensed <%= dom_class(presenter) %> single-use-links" aria-live="assertive">
<caption>
Listing of current single-use links to this file
</caption>
<tbody data-url="<%= curation_concerns.generated_single_use_links_path(presenter) %>">
<% if presenter.single_use_links.present? %>
<%= render 'single_use_link_rows', single_use_links: presenter.single_use_links %>
<% else %>
<tr class="sr-only" scope="row">
<td><%= t('sufia.single_use_links.accessibility.no_links') %></td>
</tr>
<% end %>
</tbody>
</table>

<div class="form_actions">
<%= link_to t('sufia.single_use_links.button'),
curation_concerns.generate_download_single_use_link_path(presenter),
class: 'btn btn-default generate-single-use-link' %>
</div>
8 changes: 8 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ en:
add_new_works:
label: "Add new works"
desc: "Add new works to this Collection"
single_use_links:
button: "Create Single-Use Link"
expiration_message: "Link id %{link} expires %{time}"
accessibility:
no_links: "No links present. To create a new link, click Create Single-Use Link"
copy: "Copy link id %{link} to clipboard"
delete: "Delete link id %{link}"


hydra:
metadata_help:
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/single_use_links.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true
FactoryGirl.define do
factory :single_use_link do
itemId 'fs-id'
path '/downloads/1234'
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true
require 'rails_helper'

describe "curation_concerns/file_sets/_single_use_links.html.erb" do
let(:user) { create(:user) }
let(:solr_doc) { SolrDocument.new(build(:file_set, id: "1234").to_solr) }
let(:ability) { Ability.new(user) }
let(:presenter) { FileSetPresenter.new(solr_doc, ability) }

context "when no links are present" do
before { render "curation_concerns/file_sets/single_use_links", presenter: presenter }
it "renders accessible text" do
expect(rendered).to have_content("No links present. To create a new link, click Create Single-Use Link")
end
end

context "when links are present" do
let(:sul_presenter) { CurationConcerns::SingleUseLinkPresenter.new(create(:single_use_link)) }
let(:page) { Capybara::Node::Simple.new(rendered) }
let(:copy_button) { page.find('button.copy-single-use-link')['aria-label'] }
let(:delete_link) { page.find('a.delete-single-use-link')['aria-label'] }

before do
controller.params = { id: "fs-id" }
allow(presenter).to receive(:single_use_links).and_return([sul_presenter])
render "curation_concerns/file_sets/single_use_links", presenter: presenter
end

it "renders accessible actions" do
expect(page).to have_content("Link id #{sul_presenter.short_key} expires in 23 hours")
expect(copy_button).to eq("Copy link id #{sul_presenter.short_key} to clipboard")
expect(delete_link).to eq("Delete link id #{sul_presenter.short_key}")
end
end
end

0 comments on commit e5fedee

Please sign in to comment.