Skip to content

Commit

Permalink
Merge pull request #2680 from sul-dlss/remove-blacklight-hierarchy
Browse files Browse the repository at this point in the history
Remove blacklight hierarchy
  • Loading branch information
corylown authored Dec 9, 2024
2 parents 6a68e57 + b5c29c9 commit d491484
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 27 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 0 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -908,7 +904,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
Expand Down
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions app/assets/javascripts/blacklight_hierarchy.js

This file was deleted.

1 change: 0 additions & 1 deletion app/assets/stylesheets/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
@import "sir-trevor/main";
@import "openseadragon";
@import "blacklight";
@import "blacklight/hierarchy/hierarchy";
@import "blacklight_gallery";
@import "spotlight";
@import "sul_theme";
Expand Down
39 changes: 39 additions & 0 deletions app/components/name_roles_facet_hierarchy_component.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 4 additions & 8 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,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: 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
Expand Down Expand Up @@ -221,12 +223,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

Expand Down
11 changes: 9 additions & 2 deletions app/presenters/role_facet_item_presenter.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d491484

Please sign in to comment.