From 0fff432dc0c0ba0159f760532a36e83bfa17aa42 Mon Sep 17 00:00:00 2001 From: LaRita Robinson Date: Mon, 20 Jun 2022 15:23:19 -0400 Subject: [PATCH] Accessibility changes Adds: * ability to add alternate text for images added via Appearance admin menu. * use of alternate text for main page logo * use of alternate text via title attribute for main page banner image * missing reindex jobs (referenced when adding default images) * default logo view (pulled up from hyrax) to allow use of alt text --- app/controllers/sites_controller.rb | 17 ++++++ app/forms/hyrax/forms/admin/appearance.rb | 53 +++++++++++++++++-- app/helpers/hyrax_helper.rb | 6 +++ app/jobs/reindex_admin_sets_job.rb | 7 +++ app/jobs/reindex_collections_job.rb | 10 ++++ app/jobs/reindex_works_job.rb | 9 ++++ app/views/_logo.html.erb | 2 +- .../appearances/_banner_image_form.html.erb | 4 +- .../appearances/_default_images_form.html.erb | 2 + .../_directory_image_form.html.erb | 4 +- .../appearances/_logo_image_form.html.erb | 4 +- app/views/layouts/homepage.html.erb | 21 ++++++++ .../themes/cultural_repository/_logo.html.erb | 2 +- .../layouts/homepage.html.erb | 3 +- .../institutional_repository/_logo.html.erb | 2 +- .../layouts/homepage.html.erb | 3 +- .../layouts/homepage.html.erb | 3 +- config/locales/simple_form.en.yml | 2 +- spec/controllers/sites_controller_spec.rb | 30 +++++++++++ spec/helpers/hyrax_helper_spec.rb | 24 +++++++++ 20 files changed, 193 insertions(+), 15 deletions(-) create mode 100644 app/jobs/reindex_admin_sets_job.rb create mode 100644 app/jobs/reindex_collections_job.rb create mode 100644 app/jobs/reindex_works_job.rb create mode 100644 app/views/layouts/homepage.html.erb diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index a586507bd..dd90273f9 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -8,6 +8,7 @@ class SitesController < ApplicationController def update # FIXME: Pull these strings out to i18n locale if @site.update(update_params) + remove_appearance_text(update_params) redirect_to hyrax.admin_appearance_path, notice: 'The appearance was successfully updated.' else redirect_to hyrax.admin_appearance_path, flash: { error: 'Updating the appearance was unsuccessful.' } @@ -33,4 +34,20 @@ def update_params def site_theme_params params.require(:site).permit(:home_theme, :search_theme, :show_theme) end + + REMOVE_TEXT_MAPS = { + "remove_logo_image" => "logo_image_text", + "remove_banner_image" => "banner_image_text", + "remove_directory_image" => "directory_image_text", + "remove_default_collection_image" => "default_collection_image_text", + "remove_default_work_image" => "default_work_image_text" + }.freeze + + def remove_appearance_text(update_params) + image_text_keys = update_params.keys + image_text_keys.each do |image_text_key| + block = ContentBlock.find_by(name: REMOVE_TEXT_MAPS[image_text_key]) + block.delete if block&.value.present? + end + end end diff --git a/app/forms/hyrax/forms/admin/appearance.rb b/app/forms/hyrax/forms/admin/appearance.rb index 9a1c1068b..a1d84b349 100644 --- a/app/forms/hyrax/forms/admin/appearance.rb +++ b/app/forms/hyrax/forms/admin/appearance.rb @@ -79,6 +79,31 @@ def persisted? true end + # The alt text for the logo image + def logo_image_text + block_for('logo_image_text') + end + + # The alt text for the banner image + def banner_image_text + block_for('banner_image_text') + end + + # The alt text for the directory image + def directory_image_text + block_for('directory_image_text') + end + + # The alt text for the default_collection image + def default_collection_image_text + block_for('default_collection_image_text') + end + + # The alt text for the default_work image + def default_work_image_text + block_for('default_work_image_text') + end + # The font for the body copy def body_font block_for('body_font') @@ -287,20 +312,33 @@ def default_image_attributes # @return [Array] a list of fields that are related to the banner def self.banner_fields - [:banner_image] + %i[ + banner_image banner_label + ] end - # @return [Array] a list of fields that are related to the banner + # @return [Array] a list of fields that are related to the logo def self.logo_fields - [:logo_image] + %i[ + logo_image logo_label + ] end + # @return [Array] a list of fields that are related to the directory def self.directory_fields - [:directory_image] + %i[ + directory_image directory_image_label + ] end + # @return [Array] a list of fields that are related to default works & collections def self.default_image_fields - %i[default_collection_image default_work_image] + %i[ + default_collection_image + default_work_image + default_collection_label + default_work_label + ] end # Persist the form values @@ -337,6 +375,11 @@ def self.customization_params searchbar_text_color searchbar_text_hover_color custom_css_block + logo_image_text + banner_image_text + directory_image_text + default_collection_image_text + default_work_image_text ] end diff --git a/app/helpers/hyrax_helper.rb b/app/helpers/hyrax_helper.rb index 6ca473c0e..23341d4ae 100644 --- a/app/helpers/hyrax_helper.rb +++ b/app/helpers/hyrax_helper.rb @@ -25,6 +25,12 @@ def logo_image Site.instance.logo_image? ? Site.instance.logo_image.url : false end + def block_for(name:) + block = ContentBlock.find_by(name: name) + has_value = block&.value.present? + has_value ? block.value : false + end + def directory_image Site.instance.directory_image? ? Site.instance.directory_image.url : false end diff --git a/app/jobs/reindex_admin_sets_job.rb b/app/jobs/reindex_admin_sets_job.rb new file mode 100644 index 000000000..c1a68e4b9 --- /dev/null +++ b/app/jobs/reindex_admin_sets_job.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class ReindexAdminSetsJob < ApplicationJob + def perform + AdminSet.find_each(&:update_index) + end +end diff --git a/app/jobs/reindex_collections_job.rb b/app/jobs/reindex_collections_job.rb new file mode 100644 index 000000000..4f266b67d --- /dev/null +++ b/app/jobs/reindex_collections_job.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class ReindexCollectionsJob < ApplicationJob + def perform + Collection.find_each do |collection| + collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX + collection.update_index + end + end +end diff --git a/app/jobs/reindex_works_job.rb b/app/jobs/reindex_works_job.rb new file mode 100644 index 000000000..6aee04ba6 --- /dev/null +++ b/app/jobs/reindex_works_job.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class ReindexWorksJob < ApplicationJob + def perform + Hyrax.config.registered_curation_concern_types.each do |work_type| + work_type.constantize.find_each(&:update_index) + end + end +end diff --git a/app/views/_logo.html.erb b/app/views/_logo.html.erb index 133e033f0..841216770 100644 --- a/app/views/_logo.html.erb +++ b/app/views/_logo.html.erb @@ -1,7 +1,7 @@ <% if logo_image %> <% else %>