diff --git a/app/components/spotlight/edit_view_links_component.html.erb b/app/components/spotlight/edit_view_links_component.html.erb new file mode 100644 index 000000000..51cb9b974 --- /dev/null +++ b/app/components/spotlight/edit_view_links_component.html.erb @@ -0,0 +1,13 @@ +
+ <% if page.is_a?(Spotlight::HomePage) %> + <%= helpers.exhibit_view_link page, helpers.exhibit_root_path(page.exhibit) %> · + <%= helpers.exhibit_edit_link page, helpers.edit_exhibit_home_page_path(page.exhibit), data: { turbolinks: false, + turbo: false } %> + <% else %> + <%= helpers.exhibit_view_link page %> · + <%= helpers.exhibit_edit_link page, data: { turbolinks: false, turbo: false } %> + <% end %> + <% if delete_link %> + · <%= helpers.exhibit_delete_link page %> + <% end %> +
\ No newline at end of file diff --git a/app/components/spotlight/edit_view_links_component.rb b/app/components/spotlight/edit_view_links_component.rb new file mode 100644 index 000000000..5bbd5f7dd --- /dev/null +++ b/app/components/spotlight/edit_view_links_component.rb @@ -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 diff --git a/app/components/spotlight/solr_document_legacy_embed_component.rb b/app/components/spotlight/solr_document_legacy_embed_component.rb index 543dbeda7..b2b5b1012 100644 --- a/app/components/spotlight/solr_document_legacy_embed_component.rb +++ b/app/components/spotlight/solr_document_legacy_embed_component.rb @@ -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 diff --git a/app/controllers/spotlight/accessibility_controller.rb b/app/controllers/spotlight/accessibility_controller.rb new file mode 100644 index 000000000..bab981841 --- /dev/null +++ b/app/controllers/spotlight/accessibility_controller.rb @@ -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 diff --git a/app/helpers/spotlight/main_app_helpers.rb b/app/helpers/spotlight/main_app_helpers.rb index bcd4c7cc8..3443de02e 100644 --- a/app/helpers/spotlight/main_app_helpers.rb +++ b/app/helpers/spotlight/main_app_helpers.rb @@ -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) diff --git a/app/helpers/spotlight/title_helper.rb b/app/helpers/spotlight/title_helper.rb index 48e637f9e..2e8f064ce 100644 --- a/app/helpers/spotlight/title_helper.rb +++ b/app/helpers/spotlight/title_helper.rb @@ -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 diff --git a/app/models/sir_trevor_rails/block.rb b/app/models/sir_trevor_rails/block.rb index 9e43b2029..60060bec4 100644 --- a/app/models/sir_trevor_rails/block.rb +++ b/app/models/sir_trevor_rails/block.rb @@ -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. diff --git a/app/models/sir_trevor_rails/blocks/solr_documents_block.rb b/app/models/sir_trevor_rails/blocks/solr_documents_block.rb index 71a07fc46..15a615ab1 100644 --- a/app/models/sir_trevor_rails/blocks/solr_documents_block.rb +++ b/app/models/sir_trevor_rails/blocks/solr_documents_block.rb @@ -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? diff --git a/app/models/sir_trevor_rails/blocks/solr_documents_embed_block.rb b/app/models/sir_trevor_rails/blocks/solr_documents_embed_block.rb index f96226881..8e8e407bb 100644 --- a/app/models/sir_trevor_rails/blocks/solr_documents_embed_block.rb +++ b/app/models/sir_trevor_rails/blocks/solr_documents_embed_block.rb @@ -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 diff --git a/app/models/sir_trevor_rails/blocks/uploaded_items_block.rb b/app/models/sir_trevor_rails/blocks/uploaded_items_block.rb index e93ccb32b..05f7153f9 100644 --- a/app/models/sir_trevor_rails/blocks/uploaded_items_block.rb +++ b/app/models/sir_trevor_rails/blocks/uploaded_items_block.rb @@ -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 diff --git a/app/views/spotlight/accessibility/alt_text.html.erb b/app/views/spotlight/accessibility/alt_text.html.erb new file mode 100644 index 000000000..6c9c33115 --- /dev/null +++ b/app/views/spotlight/accessibility/alt_text.html.erb @@ -0,0 +1,53 @@ +<% content_for(:sidebar) do %> + <%= render 'spotlight/shared/exhibit_sidebar' %> +<% end %> + +<%= accessibility_page_title t(:".header") %> + +

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

+ +

+ <%= t(:'.note') %> +

+ + + + + + + + + + <% @pages.each do | page_dict | %> + <% page = page_dict[:page] %> + + + + + + <% end %> + +
+ <%= t :'.table.page_title' %> + + <%= t :'.table.has_alt_text' %> + + <%= t :'.table.can_have_alt_text' %> +
+

+ <%= page.title %> +

+ <%= render Spotlight::EditViewLinksComponent.new(page:, classes:'page-links pt-0') %> +
+ <%= page_dict[:has_alt_text] %> + + <%= page_dict[:can_have_alt_text] %> +
+ +<% unless params[:show_all] || @pages.length < @limit %> + <%= link_to '?show_all=true', class: 'ml-3' do %> + Show all<%= blacklight_icon('chevron_right') %> + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/spotlight/dashboards/_page.html.erb b/app/views/spotlight/dashboards/_page.html.erb index 3f8c7e821..7dc733ccb 100644 --- a/app/views/spotlight/dashboards/_page.html.erb +++ b/app/views/spotlight/dashboards/_page.html.erb @@ -1,15 +1,7 @@

<%= page.title %>

- + <%= render Spotlight::EditViewLinksComponent.new(page:, classes: 'page-links pt-0') %> <%= page.last_edited_by.to_s if page.last_edited_by %> <%= l page.updated_at, format: :long %> diff --git a/app/views/spotlight/feature_pages/_header.html.erb b/app/views/spotlight/feature_pages/_header.html.erb index 4a15c3229..ad3f14a99 100644 --- a/app/views/spotlight/feature_pages/_header.html.erb +++ b/app/views/spotlight/feature_pages/_header.html.erb @@ -11,10 +11,7 @@ <%= p.hidden_field :title, value: page.title , class: 'form-control form-control-sm title-field', data: {:"edit-field-target" => 'true'} %> - + <%= render Spotlight::EditViewLinksComponent.new(page:) %> diff --git a/app/views/spotlight/pages/_page.html.erb b/app/views/spotlight/pages/_page.html.erb index 4e5cb79a9..b6fd303e5 100644 --- a/app/views/spotlight/pages/_page.html.erb +++ b/app/views/spotlight/pages/_page.html.erb @@ -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 %> - + <%= render Spotlight::EditViewLinksComponent.new(page:, delete_link: true) %> <%- if page.feature_page? -%> <%= f.hidden_field :parent_page_id, data: {property: "parent_page"} %> <% end %> diff --git a/app/views/spotlight/shared/_exhibit_sidebar.html.erb b/app/views/spotlight/shared/_exhibit_sidebar.html.erb index 878dc3c5f..2a8664d58 100644 --- a/app/views/spotlight/shared/_exhibit_sidebar.html.erb +++ b/app/views/spotlight/shared/_exhibit_sidebar.html.erb @@ -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) %> <%= render 'spotlight/shared/configuration_sidebar' if can? :update, current_exhibit %> <%= render 'spotlight/shared/curation_sidebar' %> diff --git a/config/locales/spotlight.en.yml b/config/locales/spotlight.en.yml index 1ebfec962..ec5947f3c 100644 --- a/config/locales/spotlight.en.yml +++ b/config/locales/spotlight.en.yml @@ -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, %{has_alt_text} of %{total_alt_items} 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 diff --git a/config/routes.rb b/config/routes.rb index eae0791bb..a2dd0b91b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/views/spotlight/about_pages/index.html.erb_spec.rb b/spec/views/spotlight/about_pages/index.html.erb_spec.rb index 742621003..82ebec9a0 100644 --- a/spec/views/spotlight/about_pages/index.html.erb_spec.rb +++ b/spec/views/spotlight/about_pages/index.html.erb_spec.rb @@ -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) diff --git a/spec/views/spotlight/catalog/admin.html.erb_spec.rb b/spec/views/spotlight/catalog/admin.html.erb_spec.rb index 2c142278e..73401a2ad 100644 --- a/spec/views/spotlight/catalog/admin.html.erb_spec.rb +++ b/spec/views/spotlight/catalog/admin.html.erb_spec.rb @@ -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) diff --git a/spec/views/spotlight/contacts/edit.html.erb_spec.rb b/spec/views/spotlight/contacts/edit.html.erb_spec.rb index c70c2fc43..e2241351d 100644 --- a/spec/views/spotlight/contacts/edit.html.erb_spec.rb +++ b/spec/views/spotlight/contacts/edit.html.erb_spec.rb @@ -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) diff --git a/spec/views/spotlight/dashboards/analytics.html.erb_spec.rb b/spec/views/spotlight/dashboards/analytics.html.erb_spec.rb index 4701c925e..e582c2adf 100644 --- a/spec/views/spotlight/dashboards/analytics.html.erb_spec.rb +++ b/spec/views/spotlight/dashboards/analytics.html.erb_spec.rb @@ -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 diff --git a/spec/views/spotlight/exhibits/edit.html.erb_spec.rb b/spec/views/spotlight/exhibits/edit.html.erb_spec.rb index 790b8e6f1..05d3ecdde 100644 --- a/spec/views/spotlight/exhibits/edit.html.erb_spec.rb +++ b/spec/views/spotlight/exhibits/edit.html.erb_spec.rb @@ -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 ) diff --git a/spec/views/spotlight/job_trackers/show.html.erb_spec.rb b/spec/views/spotlight/job_trackers/show.html.erb_spec.rb index 8e06490a8..62ce462a6 100644 --- a/spec/views/spotlight/job_trackers/show.html.erb_spec.rb +++ b/spec/views/spotlight/job_trackers/show.html.erb_spec.rb @@ -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 diff --git a/spec/views/spotlight/metadata_configurations/edit.html.erb_spec.rb b/spec/views/spotlight/metadata_configurations/edit.html.erb_spec.rb index d197b4af8..93f4e7144 100644 --- a/spec/views/spotlight/metadata_configurations/edit.html.erb_spec.rb +++ b/spec/views/spotlight/metadata_configurations/edit.html.erb_spec.rb @@ -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) diff --git a/spec/views/spotlight/pages/index.html.erb_spec.rb b/spec/views/spotlight/pages/index.html.erb_spec.rb index f562a7cae..a5c3929fa 100644 --- a/spec/views/spotlight/pages/index.html.erb_spec.rb +++ b/spec/views/spotlight/pages/index.html.erb_spec.rb @@ -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) diff --git a/spec/views/spotlight/resources/new.html.erb_spec.rb b/spec/views/spotlight/resources/new.html.erb_spec.rb index bec5d7896..14d8bef5a 100644 --- a/spec/views/spotlight/resources/new.html.erb_spec.rb +++ b/spec/views/spotlight/resources/new.html.erb_spec.rb @@ -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 diff --git a/spec/views/spotlight/roles/index.html.erb_spec.rb b/spec/views/spotlight/roles/index.html.erb_spec.rb index 0b09cc2b6..7e8bf1b20 100644 --- a/spec/views/spotlight/roles/index.html.erb_spec.rb +++ b/spec/views/spotlight/roles/index.html.erb_spec.rb @@ -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 diff --git a/spec/views/spotlight/searches/edit.html.erb_spec.rb b/spec/views/spotlight/searches/edit.html.erb_spec.rb index b82510a6c..fb5904186 100644 --- a/spec/views/spotlight/searches/edit.html.erb_spec.rb +++ b/spec/views/spotlight/searches/edit.html.erb_spec.rb @@ -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) diff --git a/spec/views/spotlight/searches/index.html.erb_spec.rb b/spec/views/spotlight/searches/index.html.erb_spec.rb index ffe3ced91..5ea701505 100644 --- a/spec/views/spotlight/searches/index.html.erb_spec.rb +++ b/spec/views/spotlight/searches/index.html.erb_spec.rb @@ -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 diff --git a/spec/views/spotlight/shared/_exhibit_sidebar.html.erb_spec.rb b/spec/views/spotlight/shared/_exhibit_sidebar.html.erb_spec.rb index ec54aedef..6be7724cf 100644 --- a/spec/views/spotlight/shared/_exhibit_sidebar.html.erb_spec.rb +++ b/spec/views/spotlight/shared/_exhibit_sidebar.html.erb_spec.rb @@ -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 diff --git a/spec/views/spotlight/tags/index.html.erb_spec.rb b/spec/views/spotlight/tags/index.html.erb_spec.rb index 8f7f24fee..d964aa404 100644 --- a/spec/views/spotlight/tags/index.html.erb_spec.rb +++ b/spec/views/spotlight/tags/index.html.erb_spec.rb @@ -11,7 +11,7 @@ allow(view).to receive_messages(exhibit_tag_path: '/tags') allow(view).to receive(:current_exhibit).and_return(exhibit) allow(view).to receive(:url_to_tag_facet, &:first) - allow(view).to receive_messages(update_all_exhibit_tags_path: '/update_all') + allow(view).to receive_messages(update_all_exhibit_tags_path: '/update_all', exhibit_alt_text_path: '/alt-text') allow(view).to receive(:exhibit_path) end