Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,41 @@
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
# Bundler config
/.bundle

# Ignore the default SQLite database.
# SQLite database files
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
# Logs and temp files
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep
dump.rdb
vendor/*.csv

# Ignore Byebug command history file.
# Byebug history
.byebug_history

# Test coverage output
coverage/*

##Mac OS
# macOS files
.DS_Store

# Cursor/VS Code settings
# Editor and IDE settings
.vscode/settings.json
.idea/

# Application files to ingore
# Application files to ignore
fits.log
vendor/*.csv
dump.rdb

# Ignore dotenv config files
# Local dotenv config files
.env.development.local
.env.test.local
.env.production.local

# Ignore compiled assets
# Compiled assets
public/**
.idea/
56 changes: 56 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,60 @@
# frozen_string_literal: true

module ApplicationHelper
def thumbnail_alt_text_for(record)
label = thumbnail_label_for(record)
type = thumbnail_type_for(record)

return "#{type} thumbnail: #{label}" if type.present? && label.present?
return "Thumbnail for #{label}" if label.present?
return "#{type} thumbnail" if type.present?

'Thumbnail'
end

private

def thumbnail_label_for(record)
[title_or_label_value(record), title_value(record), to_s_value(record)]
.map { |value| normalized_thumbnail_label(value) }
.find(&:present?)
end

def thumbnail_type_for(record)
return record.human_readable_type.to_s.strip if record.respond_to?(:human_readable_type) && record.human_readable_type.present?

nil
end

def normalized_thumbnail_label(value)
value = extract_first_label_value(value)
label = value.to_s.strip
return nil if label.blank? || label.casecmp('null').zero?

label
end

def title_or_label_value(record)
return unless record.respond_to?(:title_or_label)

record.title_or_label
end

def title_value(record)
return unless record.respond_to?(:title) && record.title.present?

record.title.is_a?(Array) ? record.title.first : record.title
end

def to_s_value(record)
return unless record.respond_to?(:to_s)

record.to_s
end

def extract_first_label_value(value)
return value.first if value.respond_to?(:first) && !value.is_a?(String)

value
end
end
12 changes: 12 additions & 0 deletions app/helpers/catalog_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module CatalogHelper
include Blacklight::CatalogHelperBehavior

def render_thumbnail_tag(document, image_options = {}, url_options = {})
options = image_options.to_h.symbolize_keys
options[:alt] = thumbnail_alt_text_for(document) if options[:alt].blank?

super(document, options, url_options)
end
end
5 changes: 5 additions & 0 deletions app/views/catalog/_thumbnail_default.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%- if has_thumbnail?(document) && tn = render_thumbnail_tag(document, {}, tabindex: -1, counter: document_counter_with_offset(document_counter)) %>
<div class="document-thumbnail">
<%= tn %>
</div>
<%- end %>
7 changes: 7 additions & 0 deletions app/views/hyrax/collections/_media_display.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if presenter.thumbnail_path %>
<%= image_tag presenter.thumbnail_path,
class: "representative-media",
alt: thumbnail_alt_text_for(presenter) %>
<% else %>
<span class="<%= Hyrax::ModelIcon.css_class_for(Collection) %> collection-icon-search" aria-hidden="true"></span>
<% end %>
73 changes: 73 additions & 0 deletions app/views/hyrax/dashboard/collections/_list_collections.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<% # used by All and Managed Collections tabs %>
<% id = collection_presenter.id %>
<tr id="document_<%= id %>"
data-id="<%= id %>"
data-colls-hash="<%= collection_presenter.available_parent_collections(scope: controller) %>"
data-post-url="<%= hyrax.dashboard_create_nest_collection_within_path(id) %>"
data-post-delete-url="<%= is_admin_set ? hyrax.admin_admin_set_path(id) : hyrax.dashboard_collection_path(id) %>">

<td>
<% if collection_presenter.allow_batch? %>
<input type="checkbox" name="batch_document_ids[]" id="batch_document_<%= id %>" value="<%= id %>" class="batch_document_selector"
data-hasaccess="<%= (can?(:edit, collection_presenter.solr_document)) %>" />
<% else %>
<input type="checkbox" class="disabled" disabled=true />
<% end %>
</td>
<td>
<div class="thumbnail-title-wrapper">
<div class="thumbnail-wrapper">
<% if (collection_presenter.thumbnail_path == nil) %>
<span class="<%= Hyrax::ModelIcon.css_class_for(Collection) %> collection-icon-small"></span>
<% else %>
<%= image_tag(collection_presenter.thumbnail_path, alt: thumbnail_alt_text_for(collection_presenter)) %>
<% end %>
</div>
<%= link_to collection_presenter.show_path do %>
<span class="sr-only"><%= t("hyrax.dashboard.my.sr.show_label") %> </span>
<%= collection_presenter.title_or_label %>
<% end %>

<%# Expand arrow %>
<a href="#" class="small show-more" title="Click for more details">
<i id="expand_<%= id %>" class="glyphicon glyphicon-chevron-right" aria-hidden="true"></i>
<span class="sr-only"> <%= "#{t("hyrax.dashboard.my.sr.detail_label")} #{collection_presenter.title_or_label}" %></span>
</a>
</div>

<%# Collection details %>
<div id="detail_<%= id %>">
<div class="expanded-details">
<p>
<strong><%= t("hyrax.dashboard.my.collection_list.description") %></strong>
<br /><%= collection_presenter.description&.first %>
</p>
<p>
<strong><%= t("hyrax.dashboard.my.collection_list.edit_access") %></strong>
<br />
<% if collection_presenter.edit_groups.present? %>
<%= t("hyrax.dashboard.my.collection_list.groups") %> <%= collection_presenter.edit_groups.join(', ') %>
<br />
<% end %>
<%= t("hyrax.dashboard.my.collection_list.users") %> <%= collection_presenter.edit_people.join(', ') %>
</p>
</div>
</div>
</td>
<% if !current_ability.admin? %>
<td><%= collection_presenter.managed_access %></td>
<% end %>
<td class="collection_type">
<%= collection_presenter.collection_type_badge %>
</td>
<td><%= collection_presenter.permission_badge %> </td>
<td><%= collection_presenter.total_viewable_items %></td>
<td class="date"><%= collection_presenter.modified_date.try(:to_formatted_s, :standard) %> </td>
<td>
<% if collection_presenter.solr_document.admin_set? %>
<%= render '/hyrax/my/admin_set_action_menu', admin_set_presenter: collection_presenter %>
<% else %>
<%= render '/hyrax/my/collection_action_menu', collection_presenter: collection_presenter %>
<% end %>
</td>
</tr>
3 changes: 1 addition & 2 deletions app/views/hyrax/homepage/_featured_collections.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<div class="center-block main row featured-thumb featured-collection">
<%= link_to collection_path(featured_collection.collection_id) do %>
<%= image_tag collection.to_solr["thumbnail_path_ss"],
alt: "Thumbnail for featured collection: #{collection.title.first}",
role: "presentation" %>
alt: thumbnail_alt_text_for(collection) %>
<% end %>
</div>
<% end %>
Expand Down
72 changes: 72 additions & 0 deletions app/views/hyrax/my/collections/_list_collections.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<% # used by Your Collections tab %>
<% id = collection_presenter.id %>
<%# Data attributes referenced by the javascript for submitting nested forms. %>
<tr id="document_<%= id %>"
data-source="my"
data-id="<%= id %>"
data-colls-hash="<%= collection_presenter.available_parent_collections(scope: controller) %>"
data-post-url="<%= hyrax.dashboard_create_nest_collection_within_path(id) %>"
data-post-delete-url="<%= is_admin_set ? hyrax.admin_admin_set_path(id) : hyrax.dashboard_collection_path(id) %>">

<td>
<% if collection_presenter.allow_batch? %>
<input type="checkbox" name="batch_document_ids[]" id="batch_document_<%= id %>" value="<%= id %>" class="batch_document_selector"
data-hasaccess="<%= (can?(:edit, collection_presenter.solr_document)) %>" />
<% else %>
<input type="checkbox" class="disabled" disabled=true />
<% end %>
</td>
<td>
<div class="thumbnail-title-wrapper">
<div class="thumbnail-wrapper">
<% if (collection_presenter.thumbnail_path == nil) %>
<span class="<%= Hyrax::ModelIcon.css_class_for(Collection) %> collection-icon-small"></span>
<% else %>
<%= image_tag(collection_presenter.thumbnail_path, alt: thumbnail_alt_text_for(collection_presenter)) %>
<% end %>
</div>
<%= link_to collection_presenter.show_path, id: "src_copy_link#{id}" do %>
<span class="sr-only"><%= t("hyrax.dashboard.my.sr.show_label") %></span>
<%= collection_presenter.title_or_label %>
<% end %>

<%# Expand arrow %>
<a href="#" class="small show-more" title="Click for more details">
<i id="expand_<%= id %>" class="glyphicon glyphicon-chevron-right" aria-hidden="true"></i>
<span class="sr-only"> <%= "#{t("hyrax.dashboard.my.sr.detail_label")} #{collection_presenter.title_or_label}" %></span>
</a>
</div>

<%# Collection details %>
<div id="detail_<%= id %>">
<div class="expanded-details">
<p>
<strong><%= t("hyrax.dashboard.my.collection_list.description") %></strong>
<br /><%= collection_presenter.description&.first %>
</p>
<p>
<strong><%= t("hyrax.dashboard.my.collection_list.edit_access") %></strong>
<br />
<% if collection_presenter.edit_groups.present? %>
<%= t("hyrax.dashboard.my.collection_list.groups") %> <%= collection_presenter.edit_groups.join(', ') %>
<br />
<% end %>
<%= t("hyrax.dashboard.my.collection_list.users") %> <%= collection_presenter.edit_people.join(', ') %>
</p>
</div>
</div>
</td>
<td class="collection_type">
<%= collection_presenter.collection_type_badge %>
</td>
<td><%= collection_presenter.permission_badge %></td>
<td><%= collection_presenter.total_viewable_items %></td>
<td class="date"><%= collection_presenter.modified_date.try(:to_formatted_s, :standard) %> </td>
<td>
<% if collection_presenter.solr_document.admin_set? %>
<%= render '/hyrax/my/admin_set_action_menu', admin_set_presenter: collection_presenter %>
<% else %>
<%= render 'hyrax/my/collection_action_menu', collection_presenter: collection_presenter %>
<% end %>
</td>
</tr>
25 changes: 25 additions & 0 deletions app/views/hyrax/users/_contributions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="tab-pane active" id="contributions">
<% if presenter.trophies.count > 0 %>
<table>
<% presenter.trophies.each do |t| %>
<tr id="trophyrow_<%= t.id %>" class='highlighted-works'>
<td>
<%= link_to [main_app, t] do %>
<%= image_tag t.thumbnail_path, width: 90, alt: thumbnail_alt_text_for(t) %>
<% end %>
</td>
<td>
<%= link_to t.to_s, [main_app, t] %>
<% if presenter.current_user? %>
<%= display_trophy_link current_user, t.id, class: 'glyphicon glyphicon-star', data: { removerow: true } do %>
<i class='trophy-on glyphicon glyphicon-remove'></i>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</table>
<% else %>
<%= presenter.name %> has no highlighted works.
<% end %>
</div>
3 changes: 2 additions & 1 deletion spec/features/featured_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
visit hyrax.dashboard_collection_path(collection)
click_link("Feature")
visit '/'
expect(page).to have_css("img[alt='Thumbnail for featured collection: #{collection.title.first}")
expected_alt = ApplicationController.helpers.thumbnail_alt_text_for(collection)
expect(page).to have_css("img[alt='#{expected_alt}']")
end
end
end
53 changes: 53 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe ApplicationHelper, type: :helper do
describe '#thumbnail_alt_text_for' do
it 'uses the first value when title_or_label is relation-like' do
relation_like_label = double('ActiveTriples::Relation', first: 'Collection Title 2')
record = instance_double(
'Record',
title_or_label: relation_like_label,
title: ['Collection Title 2'],
human_readable_type: 'Collection',
to_s: relation_like_label.to_s
)

alt_text = helper.thumbnail_alt_text_for(record)

expect(alt_text).to eq('Collection thumbnail: Collection Title 2')
expect(alt_text).not_to include('ActiveTriples::Relation')
end

it 'returns a non-nil alt text when title is missing' do
record = instance_double(
'Record',
title_or_label: nil,
title: nil,
human_readable_type: 'Collection',
to_s: ''
)

alt_text = helper.thumbnail_alt_text_for(record)

expect(alt_text).to be_present
expect(alt_text).to eq('Collection thumbnail')
end

it 'does not render a null label in alt text' do
record = instance_double(
'Record',
title_or_label: 'null',
title: ['null'],
human_readable_type: 'Collection',
to_s: 'null'
)

alt_text = helper.thumbnail_alt_text_for(record)

expect(alt_text).to eq('Collection thumbnail')
expect(alt_text.downcase).not_to include('null')
end
end
end
Loading
Loading