Skip to content

Commit

Permalink
add alt-text dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
dnoneill committed Nov 15, 2024
1 parent f978b64 commit 53f1300
Show file tree
Hide file tree
Showing 31 changed files with 183 additions and 26 deletions.
13 changes: 13 additions & 0 deletions app/components/spotlight/edit_view_links_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="<%= classes %>">
<% if page.is_a?(Spotlight::HomePage) %>
<%= helpers.exhibit_view_link page, helpers.exhibit_root_path(page.exhibit) %> &middot;
<%= helpers.exhibit_edit_link page, helpers.edit_exhibit_home_page_path(page.exhibit), data: { turbolinks: false,
turbo: false } %>
<% else %>
<%= helpers.exhibit_view_link page %> &middot;
<%= helpers.exhibit_edit_link page, data: { turbolinks: false, turbo: false } %>
<% end %>
<% if delete_link %>
&middot; <%= helpers.exhibit_delete_link page %>
<% end %>
</div>
16 changes: 16 additions & 0 deletions app/components/spotlight/edit_view_links_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Spotlight
# Allows component addition to exhibit navbar
class EditViewLinksComponent < ViewComponent::Base
attr_reader :page, :classes, :delete_link

def initialize(page:, classes: 'page-links', delete_link: false)
super

@page = page
@classes = classes
@delete_link = delete_link
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(*args, block: nil, **kwargs)
end

def before_render
set_slot(:embed, nil, block_context: block_context) unless embed
set_slot(:embed, nil, block_context:) unless embed

super
end
Expand Down
49 changes: 49 additions & 0 deletions app/controllers/spotlight/accessibility_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

module Spotlight
##
# Exhibit dashboard controller
class AccessibilityController < Spotlight::ApplicationController
before_action :authenticate_user!
load_and_authorize_resource :exhibit, class: Spotlight::Exhibit
helper_method :get_alt_info

include Spotlight::Base
include Spotlight::SearchHelper

def alt_text
authorize! :curate, @exhibit

@limit = 5
pages_with_alt = @exhibit.pages.select { |elem| elem.content.any?(&:alt_text?) }
pages = params[:show_all] ? pages_with_alt : pages_with_alt.first(@limit)
@pages = pages.map { |page| get_alt_info(page) }
@has_alt_text = @pages.sum { |page| page[:has_alt_text] }
@total_alt_items = @pages.sum { |page| page[:can_have_alt_text] }

attach_dashboard_breadcrumbs
end

def get_alt_info(page)
can_have_alt_text = 0
has_alt_text = 0
page.content.each do |content|
content.item&.each_value do |item|
next if item['alt_text_backup'].nil?

can_have_alt_text += 1
has_alt_text += 1 if item['alt_text'].present? || item['decorative'].present?
end
end
{ can_have_alt_text:, has_alt_text:, page: }
end

protected

def attach_dashboard_breadcrumbs
add_breadcrumb(t(:'spotlight.exhibits.breadcrumb', title: @exhibit.title), @exhibit)
add_breadcrumb(t(:'spotlight.accessibility.header'), exhibit_dashboard_path(@exhibit))
add_breadcrumb(t(:'spotlight.accessibility.alt_text.header'), exhibit_alt_text_path(@exhibit))
end
end
end
2 changes: 1 addition & 1 deletion app/helpers/spotlight/main_app_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def link_back_to_catalog(opts = { label: nil })

# Expecting to upstream this override in https://github.com/projectblacklight/blacklight/pull/3343/files
def document_presenter(document, view_config: nil, **kwargs)
(view_config&.document_presenter_class || document_presenter_class(document)).new(document, self, view_config: view_config, **kwargs)
(view_config&.document_presenter_class || document_presenter_class(document)).new(document, self, view_config:, **kwargs)
end

def document_presenter_class(_document)
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/spotlight/title_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def curation_page_title(title = nil)
page_title t(:'spotlight.curation.header'), title
end

def accessibility_page_title(title = nil)
page_title t(:'spotlight.accessibility.header'), title
end

def configuration_page_title(title = nil)
page_title t(:'spotlight.configuration.header'), title
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/sir_trevor_rails/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def format
send(:[], :format).present? ? send(:[], :format).to_sym : DEFAULT_FORMAT
end

def alt_text?
false
end

# Sets a list of custom block types to speed up lookup at runtime.
def self.custom_block_types
# You can define your custom block types directly here or in your engine config.
Expand Down
4 changes: 4 additions & 0 deletions app/models/sir_trevor_rails/blocks/solr_documents_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def with_solr_helper(solr_helper)
@solr_helper = solr_helper
end

def alt_text?
true
end

def each_document
return to_enum(:each_document) unless block_given?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module Blocks
##
# Embed documents (using a special blacklight view configuration) and text block
class SolrDocumentsEmbedBlock < SirTrevorRails::Blocks::SolrDocumentsBlock
def alt_text?
false
end
end
end
end
4 changes: 4 additions & 0 deletions app/models/sir_trevor_rails/blocks/uploaded_items_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def files
(item || {}).map { |_, file| file }.select { |file| file[:display].to_s == 'true' }
end

def alt_text?
true
end

def zpr_link?
zpr_link == 'true'
end
Expand Down
53 changes: 53 additions & 0 deletions app/views/spotlight/accessibility/alt_text.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<% content_for(:sidebar) do %>
<%= render 'spotlight/shared/exhibit_sidebar' %>
<% end %>
<%= accessibility_page_title t(:".header") %>

<p>
<%= t(:'.total_items', has_alt_text: @has_alt_text, total_alt_items: @total_alt_items).html_safe %>
</p>

<p>
<%= t(:'.note') %>
</p>
<table class="table table-striped">
<thead>
<tr class="d-flex">
<th class="col-6">
<%= t :'.table.page_title' %>
</th>
<th class="col-3">
<%= t :'.table.has_alt_text' %>
</th>
<th class="col-3">
<%= t :'.table.can_have_alt_text' %>
</th>
</tr>
</thead>
<tbody>
<% @pages.each do | page_dict | %>
<% page = page_dict[:page] %>
<tr class="d-flex">
<td class="col-6">
<h4 class="h5 mb-0">
<%= page.title %>
</h4>
<%= render Spotlight::EditViewLinksComponent.new(page:, classes:'page-links pt-0') %>
</td>
<td class="col-3">
<%= page_dict[:has_alt_text] %>
</td>
<td class="col-3">
<%= page_dict[:can_have_alt_text] %>
</td>
</tr>
<% end %>
</tbody>
</table>

<% unless params[:show_all] || @pages.length < @limit %>
<%= link_to '?show_all=true', class: 'ml-3' do %>
Show all<%= blacklight_icon('chevron_right') %>
<% end %>
<% end %>
10 changes: 1 addition & 9 deletions app/views/spotlight/dashboards/_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
<tr class="d-flex">
<td class="col-6">
<h4 class="h5 mb-0"><%= page.title %></h4>
<div class="page-links pt-0">
<% if page.is_a?(Spotlight::HomePage) %>
<%= link_to action_default_value(page, :view), current_exhibit %> &middot;
<%= exhibit_edit_link page, edit_exhibit_home_page_path(page.exhibit), data: { turbolinks: false, turbo: false } %>
<% else %>
<%= exhibit_view_link page %> &middot;
<%= exhibit_edit_link page, data: { turbolinks: false, turbo: false } %>
<% end %>
</div>
<%= render Spotlight::EditViewLinksComponent.new(page:, classes: 'page-links pt-0') %>
</td>
<td class="col-4"><%= page.last_edited_by.to_s if page.last_edited_by %></td>
<td class="col-2"><%= l page.updated_at, format: :long %></td>
Expand Down
5 changes: 1 addition & 4 deletions app/views/spotlight/feature_pages/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
<%= p.hidden_field :title, value: page.title , class: 'form-control form-control-sm title-field', data: {:"edit-field-target" => 'true'} %>
</h3>
</div>
<div class="page-links">
<%= exhibit_view_link page, exhibit_root_path(page.exhibit) %> &middot;
<%= exhibit_edit_link page, edit_exhibit_home_page_path(page.exhibit), data: { turbolinks: false } %>
</div>
<%= render Spotlight::EditViewLinksComponent.new(page:) %>
</div>
</div>
</div>
Expand Down
6 changes: 1 addition & 5 deletions app/views/spotlight/pages/_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
<% page = f.object %>
<%= render layout: 'spotlight/shared/dd3_item', locals: { id: page.id.to_s, field: f, label: page.title, label_method: :title, enabled_method: :published } do |_, section| %>
<% case section when :additional_options %>
<div class="page-links">
<%= exhibit_view_link page %> &middot;
<%= exhibit_edit_link page, data: { turbolinks: false, turbo: false } %> &middot;
<%= exhibit_delete_link page %>
</div>
<%= render Spotlight::EditViewLinksComponent.new(page:, delete_link: true) %>
<%- if page.feature_page? -%>
<%= f.hidden_field :parent_page_id, data: {property: "parent_page"} %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions app/views/spotlight/shared/_exhibit_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<% if current_exhibit.analytics_provider&.enabled? %>
<%= nav_link t(:'spotlight.curation.sidebar.analytics'), spotlight.analytics_exhibit_dashboard_path(current_exhibit) %>
<% end %>
<%= nav_link t(:'spotlight.accessibility.header'), exhibit_alt_text_path(@exhibit) %>
</ul>
<%= render 'spotlight/shared/configuration_sidebar' if can? :update, current_exhibit %>
<%= render 'spotlight/shared/curation_sidebar' %>
10 changes: 10 additions & 0 deletions config/locales/spotlight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ en:
instructions: Enter details for each librarian, curator or other contact person for this exhibit. Select the contacts you want to be show in the sidebar of the about pages. Drag and drop contacts to specify the order in which they are shown in the sidebar.
page_options:
published: Publish
accessibility:
alt_text:
header: Alternative text
note: Items displayed via Item Embed are excluded from these totals, as it not currently possible to add alt text using this widget.
table:
can_have_alt_text: Total items on page
has_alt_text: Items with alt text
page_title: Page title
total_items: Of the items displayed via spotlight's widgets, <b>%{has_alt_text} of %{total_alt_items}</b> have entered alt text (or a checked decorative box).
header: Accessibility
admin_users:
create:
error: There was a problem adding the user as an exhibits adminstrator
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
get :analytics
end

get '/accessibility/alt-text', to: 'accessibility#alt_text', as: 'alt_text'

resources :resources do
collection do
get :monitor
Expand Down
1 change: 1 addition & 0 deletions spec/views/spotlight/about_pages/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
allow(view).to receive(:page_collection_name).and_return(:about_pages)
allow(view).to receive(:update_all_exhibit_about_pages_path).and_return('/exhibit/about/update_all')
allow(view).to receive(:exhibit_contacts_path).and_return('/exhibit/1/contacts')
allow(view).to receive(:exhibit_alt_text_path).and_return('/exhibit/1/alt-text')
allow(view).to receive(:nestable_data_attributes).and_return('data-behavior="nestable"')
allow(exhibit).to receive_messages(contacts:)
assign(:page, Spotlight::AboutPage.new)
Expand Down
1 change: 1 addition & 0 deletions spec/views/spotlight/catalog/admin.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
allow(view).to receive(:spotlight_page_path_for).and_return(nil)
allow(view).to receive(:current_exhibit).and_return(exhibit)
allow(view).to receive(:new_exhibit_resource_path).and_return('')
allow(view).to receive(:exhibit_alt_text_path).and_return('')
allow(view).to receive(:reindex_all_exhibit_resources_path).and_return('')
allow(view).to receive(:monitor_exhibit_resources_path).and_return('')
assign(:exhibit, exhibit)
Expand Down
1 change: 1 addition & 0 deletions spec/views/spotlight/contacts/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
before do
allow(view).to receive(:exhibit_contacts_path).and_return('/exhibit/1/contacts')
allow(view).to receive(:exhibit_about_pages_path).and_return('/exhibit/admin/about')
allow(view).to receive(:exhibit_alt_text_path).and_return('/exhibit/1/alt-text')
allow(view).to receive(:contact_images_path).and_return('/contact_images')
assign(:contact, contact)
assign(:exhibit, exhibit)
Expand Down
3 changes: 2 additions & 1 deletion spec/views/spotlight/dashboards/analytics.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
allow(current_exhibit).to receive(:page_analytics).and_return(data)
allow(current_exhibit).to receive(:analytics).and_return(data)
allow(current_exhibit).to receive(:analytics_provider).and_return(double(Spotlight::Analytics::Ga, enabled?: enabled))
allow(view).to receive_messages(current_exhibit:, exhibit_root_path: '/some/path', analytics_exhibit_dashboard_path: '/some/path')
allow(view).to receive_messages(current_exhibit:, exhibit_root_path: '/some/path', analytics_exhibit_dashboard_path: '/some/path',
exhibit_alt_text_path: '/alt-text')
end

context 'without a configured analytics integration' do
Expand Down
1 change: 1 addition & 0 deletions spec/views/spotlight/exhibits/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_exhibit_path: '/',
exhibit_filters_path: '/',
exhibit_languages_path: '/',
exhibit_alt_text_path: '/',
add_exhibit_language_dropdown_options: [],
default_language?: true
)
Expand Down
2 changes: 1 addition & 1 deletion spec/views/spotlight/job_trackers/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
assign(:exhibit, exhibit)
assign(:job_tracker, job_tracker)

allow(view).to receive_messages(current_exhibit: exhibit)
allow(view).to receive_messages(current_exhibit: exhibit, exhibit_alt_text_path: '')
end

it 'displays the type of job' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
current_exhibit: exhibit,
blacklight_config: exhibit.blacklight_configuration.blacklight_config,
available_view_fields: { some_view_type: 1, another_view_type: 2 },
exhibit_alt_text_path: '/',
select_deselect_action: nil
)
allow(controller).to receive(:enabled_in_spotlight_view_type_configuration?).and_return(true)
Expand Down
1 change: 1 addition & 0 deletions spec/views/spotlight/pages/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

before do
allow(view).to receive(:page_collection_name).and_return(:feature_pages)
allow(view).to receive(:exhibit_alt_text_path).and_return('/')
allow(view).to receive(:update_all_exhibit_feature_pages_path).and_return('/exhibit/features/update_all')
assign(:page, Spotlight::FeaturePage.new)
assign(:exhibit, exhibit)
Expand Down
2 changes: 1 addition & 1 deletion spec/views/spotlight/resources/new.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
before do
allow(view).to receive_messages(blacklight_config:)
allow(view).to receive(:current_exhibit).and_return(exhibit)
allow(view).to receive_messages(current_page?: true)
allow(view).to receive_messages(current_page?: true, exhibit_alt_text_path: '')
stub_template 'spotlight/shared/_curation_sidebar.html.erb' => ''
end

Expand Down
1 change: 1 addition & 0 deletions spec/views/spotlight/roles/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

before do
assign(:exhibit, exhibit)
allow(view).to receive(:exhibit_alt_text_path).and_return('/')
allow(view).to receive(:current_exhibit).and_return(exhibit)
allow(exhibit).to receive(:roles).and_return roles
end
Expand Down
1 change: 1 addition & 0 deletions spec/views/spotlight/searches/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
allow(view).to receive(:featured_images_path).and_return('/featured_images')
allow(view).to receive(:exhibit_search_path).and_return('/search')
allow(view).to receive(:exhibit_searches_path).and_return('/searches')
allow(view).to receive(:exhibit_alt_text_path).and_return('/alt-text')
allow(view).to receive(:blacklight_config).and_return(blacklight_config)
allow(controller).to receive(:search_state_class).and_return(Blacklight::SearchState)

Expand Down
2 changes: 1 addition & 1 deletion spec/views/spotlight/searches/index.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
let(:exhibit) { stub_model(Spotlight::Exhibit) }

before do
allow(view).to receive_messages(update_all_exhibit_searches_path: '/')
allow(view).to receive_messages(update_all_exhibit_searches_path: '/', exhibit_alt_text_path: '/')
allow(view).to receive(:current_exhibit).and_return(exhibit)
assign(:exhibit, exhibit)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
let(:current_exhibit) { FactoryBot.create(:exhibit) }

before do
allow(view).to receive_messages(current_exhibit:, exhibit_root_path: '/some/path')
allow(view).to receive_messages(current_exhibit:, exhibit_root_path: '/some/path', exhibit_alt_text_path: '/some/path')
end

context 'with a configured analytics integration' do
Expand Down
Loading

0 comments on commit 53f1300

Please sign in to comment.