From bd269c54b7977979c5b3922c85c05316a20ab3ad Mon Sep 17 00:00:00 2001 From: Steve Taylor Date: Fri, 6 Dec 2024 11:09:28 -0800 Subject: [PATCH 1/3] Move role/name facet off blacklight-hierarchy --- .../name_roles_facet_hierarchy_component.rb | 41 +++++++++++++++++++ app/controllers/catalog_controller.rb | 12 ++---- app/presenters/role_facet_item_presenter.rb | 11 ++++- 3 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 app/components/blacklight/name_roles_facet_hierarchy_component.rb diff --git a/app/components/blacklight/name_roles_facet_hierarchy_component.rb b/app/components/blacklight/name_roles_facet_hierarchy_component.rb new file mode 100644 index 000000000..6ed78af51 --- /dev/null +++ b/app/components/blacklight/name_roles_facet_hierarchy_component.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Blacklight + # Display the creators/contributors by role facet in a tree hierarchy + class NameRolesFacetHierarchyComponent < Blacklight::FacetFieldListComponent + def facet_item_presenters + facet_item_tree_hierarchy.map do |item| + facet_item_presenter(item) + end + end + + def facet_items(wrapping_element: :li, **item_args) + facet_item_component_class.with_collection( + facet_item_presenters, + wrapping_element:, + suppress_link: true, + **item_args + ) + end + + # Solr data is in the form of role|name. Either can be empty. + # E.g., ["Collector|", "Defendant|Becker, Friedrich", "|Wagner, Richard, 1813-1883"] + def facet_item_tree_hierarchy(delimiter: facet_config.delimiter || '|') + roles = {} + + @facet_field.paginator.items.each do |item| + role, name = item.value.split(delimiter) + next if role.blank? || name.blank? + + roles[role] ||= Blacklight::Solr::Response::Facets::FacetItem.new( + value: role, + hits: nil, + items: [] + ) + roles[role].items << item if name.present? + end + + roles.values + end + end +end diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index e8665ea68..d49673833 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -187,8 +187,10 @@ class CatalogController < ApplicationController config.add_facet_field 'pub_year_tisim', label: 'Date Range', range: { chart_js: false, slider_js: false } config.add_facet_field 'language', label: 'Language', limit: true config.add_facet_field 'name_ssim', label: 'Creators/Contributors', limit: true - config.add_facet_field 'name_roles_ssim', label: 'Creators/Contributors by role', limit: -1, - component: Blacklight::Hierarchy::FacetFieldListComponent, + config.add_facet_field 'name_roles_ssim', label: 'Creators/Contributors by role', limit: -1, sort: :index, + collapsing: true, multiple: true, + component: Blacklight::NameRolesFacetHierarchyComponent, + item_component: Blacklight::FacetItemPivotComponent, item_presenter: RoleFacetItemPresenter config.add_facet_field 'author_person_facet', label: 'Author', limit: true # includes Collectors config.add_facet_field 'author_no_collector_ssim', label: 'Author (no Collectors)', limit: true @@ -218,12 +220,6 @@ class CatalogController < ApplicationController # handler defaults, or have no facets. config.add_facet_fields_to_solr_request! - config.facet_display = { - hierarchy: { - 'name_roles' => [['ssim'], '|'] - } - } - # Solr fields to be displayed in the search results and the show (single result) views # The ordering of the field names is the order of the display diff --git a/app/presenters/role_facet_item_presenter.rb b/app/presenters/role_facet_item_presenter.rb index 7fb0dd07e..37d9ea733 100644 --- a/app/presenters/role_facet_item_presenter.rb +++ b/app/presenters/role_facet_item_presenter.rb @@ -1,8 +1,15 @@ # frozen_string_literal: true # Format role hierarchy for display -class RoleFacetItemPresenter < Blacklight::FacetItemPresenter +class RoleFacetItemPresenter < Blacklight::FacetItemPivotPresenter def label - super.split('|', 2).join(': ') + role, name = value.split('|', 2) + return role if name.blank? + + name + end + + def constraint_label + value.split('|', 2).join(': ') end end From db5956c5ed9e44ae3d958632eb9487efb1a2867a Mon Sep 17 00:00:00 2001 From: Steve Taylor Date: Fri, 6 Dec 2024 11:15:14 -0800 Subject: [PATCH 2/3] Remove blacklight-hierarchy --- Gemfile | 1 - Gemfile.lock | 5 ----- app/assets/javascripts/application.js | 1 - app/assets/javascripts/blacklight_hierarchy.js | 9 --------- app/assets/stylesheets/base.scss | 1 - 5 files changed, 17 deletions(-) delete mode 100644 app/assets/javascripts/blacklight_hierarchy.js diff --git a/Gemfile b/Gemfile index 8c034c998..36519ed67 100644 --- a/Gemfile +++ b/Gemfile @@ -92,7 +92,6 @@ gem 'bootstrap_form', '~> 5.4' gem 'blacklight', '~> 8.0' gem 'blacklight-gallery', '~> 4.4' gem 'blacklight_heatmaps', '~> 1.3.0' -gem 'blacklight-hierarchy' gem 'blacklight-spotlight', '~> 4.4', '>= 4.4.0' gem 'twitter-typeahead-rails', '0.11.1.pre.corejavascript' gem 'blacklight_advanced_search' diff --git a/Gemfile.lock b/Gemfile.lock index 1b357f985..347dcea7b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -114,10 +114,6 @@ GEM blacklight-gallery (4.6.1) blacklight (>= 7.17, < 9) rails (>= 6.1, < 8) - blacklight-hierarchy (6.4.0) - blacklight (>= 7.18, < 9) - deprecation - rails (>= 6.1, < 7.3) blacklight-oembed (1.2.0) blacklight (>= 7.25, < 9) rails @@ -904,7 +900,6 @@ DEPENDENCIES bibtex-ruby blacklight (~> 8.0) blacklight-gallery (~> 4.4) - blacklight-hierarchy blacklight-oembed (~> 1.0) blacklight-spotlight (~> 4.4, >= 4.4.0) blacklight_advanced_search diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index a8f5db5e0..fed595d7c 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -28,7 +28,6 @@ //= require cited_documents //= require blacklight_gallery //= require blacklight_heatmaps -//= require blacklight_hierarchy //= require blacklight_oembed //= require full_text_collapse //= require index_status_typeahead diff --git a/app/assets/javascripts/blacklight_hierarchy.js b/app/assets/javascripts/blacklight_hierarchy.js deleted file mode 100644 index 3cf7ca25d..000000000 --- a/app/assets/javascripts/blacklight_hierarchy.js +++ /dev/null @@ -1,9 +0,0 @@ -//= require blacklight/hierarchy/hierarchy - -// If you use Stimulus in your application you can remove the line above and require -// blacklight_hierarchy_controller instead: -// -// import BlacklightHierarchyController from 'blacklight-hierarchy/app/assets/javascripts/blacklight/hierarchy/blacklight_hierarchy_controller' -// import { Application } from '@hotwired/stimulus' -// const application = Application.start() -// application.register("b-h-collapsible", BlacklightHierarchyController) diff --git a/app/assets/stylesheets/base.scss b/app/assets/stylesheets/base.scss index a357f6006..c026eb044 100644 --- a/app/assets/stylesheets/base.scss +++ b/app/assets/stylesheets/base.scss @@ -9,7 +9,6 @@ @import "sir-trevor/main"; @import "openseadragon"; @import "blacklight"; -@import "blacklight/hierarchy/hierarchy"; @import "blacklight_gallery"; @import "spotlight"; @import "sul_theme"; From b5c29c99c90d3b04c9545d2bd12379c3bfa083e5 Mon Sep 17 00:00:00 2001 From: Steve Taylor Date: Mon, 9 Dec 2024 08:16:19 -0800 Subject: [PATCH 3/3] Move roles facet out of Blacklight namespace --- .../name_roles_facet_hierarchy_component.rb | 41 ------------------- .../name_roles_facet_hierarchy_component.rb | 39 ++++++++++++++++++ app/controllers/catalog_controller.rb | 2 +- 3 files changed, 40 insertions(+), 42 deletions(-) delete mode 100644 app/components/blacklight/name_roles_facet_hierarchy_component.rb create mode 100644 app/components/name_roles_facet_hierarchy_component.rb diff --git a/app/components/blacklight/name_roles_facet_hierarchy_component.rb b/app/components/blacklight/name_roles_facet_hierarchy_component.rb deleted file mode 100644 index 6ed78af51..000000000 --- a/app/components/blacklight/name_roles_facet_hierarchy_component.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -module Blacklight - # Display the creators/contributors by role facet in a tree hierarchy - class NameRolesFacetHierarchyComponent < Blacklight::FacetFieldListComponent - def facet_item_presenters - facet_item_tree_hierarchy.map do |item| - facet_item_presenter(item) - end - end - - def facet_items(wrapping_element: :li, **item_args) - facet_item_component_class.with_collection( - facet_item_presenters, - wrapping_element:, - suppress_link: true, - **item_args - ) - end - - # Solr data is in the form of role|name. Either can be empty. - # E.g., ["Collector|", "Defendant|Becker, Friedrich", "|Wagner, Richard, 1813-1883"] - def facet_item_tree_hierarchy(delimiter: facet_config.delimiter || '|') - roles = {} - - @facet_field.paginator.items.each do |item| - role, name = item.value.split(delimiter) - next if role.blank? || name.blank? - - roles[role] ||= Blacklight::Solr::Response::Facets::FacetItem.new( - value: role, - hits: nil, - items: [] - ) - roles[role].items << item if name.present? - end - - roles.values - end - end -end diff --git a/app/components/name_roles_facet_hierarchy_component.rb b/app/components/name_roles_facet_hierarchy_component.rb new file mode 100644 index 000000000..e8ed8deb5 --- /dev/null +++ b/app/components/name_roles_facet_hierarchy_component.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +# Display the creators/contributors by role facet in a tree hierarchy +class NameRolesFacetHierarchyComponent < Blacklight::FacetFieldListComponent + def facet_item_presenters + facet_item_tree_hierarchy.map do |item| + facet_item_presenter(item) + end + end + + def facet_items(wrapping_element: :li, **item_args) + facet_item_component_class.with_collection( + facet_item_presenters, + wrapping_element:, + suppress_link: true, + **item_args + ) + end + + # Solr data is in the form of role|name. Either can be empty. + # E.g., ["Collector|", "Defendant|Becker, Friedrich", "|Wagner, Richard, 1813-1883"] + def facet_item_tree_hierarchy(delimiter: facet_config.delimiter || '|') + roles = {} + + @facet_field.paginator.items.each do |item| + role, name = item.value.split(delimiter) + next if role.blank? || name.blank? + + roles[role] ||= Blacklight::Solr::Response::Facets::FacetItem.new( + value: role, + hits: nil, + items: [] + ) + roles[role].items << item if name.present? + end + + roles.values + end +end diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index d49673833..a8db7208e 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -189,7 +189,7 @@ class CatalogController < ApplicationController config.add_facet_field 'name_ssim', label: 'Creators/Contributors', limit: true config.add_facet_field 'name_roles_ssim', label: 'Creators/Contributors by role', limit: -1, sort: :index, collapsing: true, multiple: true, - component: Blacklight::NameRolesFacetHierarchyComponent, + component: NameRolesFacetHierarchyComponent, item_component: Blacklight::FacetItemPivotComponent, item_presenter: RoleFacetItemPresenter config.add_facet_field 'author_person_facet', label: 'Author', limit: true # includes Collectors