Skip to content

Commit

Permalink
Merge pull request #415 from trln/rails-7-hierarchy-fork
Browse files Browse the repository at this point in the history
Blacklight hierarchical facet support in Rails 7
  • Loading branch information
kazymovae authored Feb 26, 2024
2 parents fee295b + 59f5589 commit af8384f
Show file tree
Hide file tree
Showing 24 changed files with 4,631 additions and 8,376 deletions.
15 changes: 4 additions & 11 deletions app/assets/javascripts/trln_argon/location_facet.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Blacklight.onLoad(function() {
var facetLocationWrapper = $('#facet-location_hierarchy_f');

// hide first two facets
facetLocationWrapper.find('.facet_select:contains("' + argonHSL + '")').parent().addClass("d-none");
facetLocationWrapper.find('.facet_select:contains("' + argonLAW + '")').parent().addClass("d-none");
facetLocationWrapper.find('.facet-select:contains("' + argonHSL + '")').closest('li').addClass("d-none");
facetLocationWrapper.find('.facet-select:contains("' + argonLAW + '")').closest('li').addClass("d-none");

// open local institution and expand
facetLocationWrapper.find('.facet_select:contains("' + argonInstitution + '")').parent().addClass("twiddle-open");
facetLocationWrapper.find('.facet_select:contains("' + argonInstitution + '")').parent().children("ul").css("display", "block");
facetLocationWrapper.find('.facet-select:contains("' + argonInstitution + '")').closest('li').addClass("twiddle-open");
facetLocationWrapper.find('.facet-select:contains("' + argonInstitution + '")').closest('li').children("ul.collapse").collapse('show');

// if there are more than 10 results
if ( facetLocationWrapper.find('ul.facet-hierarchy > .twiddle-open > ul > li').length > parseInt(locationFacetLimit) ) {
Expand Down Expand Up @@ -49,11 +49,4 @@ Blacklight.onLoad(function() {

});

// general facet 'onclick' handler; needs some work AJC TODO
$('li.twiddle').on('click', function(t) {
if ( t.target == this ) {
$(this).toggleClass("twiddle-open");
$(this).children("ul").slideToggle();
}
});
});
204 changes: 39 additions & 165 deletions app/assets/stylesheets/trln_argon/trln_argon_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,45 @@ body.blacklight-trln-show {
/* FACETS */
/* =============== */

$hierarchy-facet-expand-icon: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 512'><!--! Font Awesome Free 6.4.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2023 Fonticons, Inc. --><path fill='#{$gray-600}' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M310.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-192 192c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L242.7 256 73.4 86.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l192 192z'/></svg>");

.facet-hierarchy {
ul {
padding-left: 0.5rem;
}

.twiddle-open > .facet-label > a {
font-weight: bold;
}

.twiddle > .toggle-handle {
min-width: 1.1rem;
}

.twiddle > .toggle-handle .toggle-icon {

min-height: 0.8rem;
min-width: 0.8rem;
max-width: 0.8rem;
margin-right: 0.2rem;
margin-top: 0.3rem;
background-size: contain;
background-repeat: no-repeat;

&.closed {
background-image: escape-svg($hierarchy-facet-expand-icon);
}
&.opened {
background-image: escape-svg($hierarchy-facet-expand-icon);
transform: rotate(90deg);
}
}
.more_locations_link, .less_locations_link {
cursor: pointer;
}
}


#checkbox_wrapper_access_type_f { // avalable online
display: flex;
flex-wrap: wrap;
Expand Down Expand Up @@ -676,171 +715,6 @@ div.facet-content { // non-hierarcical facets
}
}

#facet-location_hierarchy_f,
#facet-lcc_callnum_classification_f { // hierarcical facets

ul {
width: 100%;
}

ul.facet-hierarchy {
margin-left: 0;
padding-left: 0;
margin-bottom: 0;

ul {
padding-left: 1em;
padding-top: 0.375em;

ul {
padding-left: 0;
}

}
}

li.h-leaf {
padding-left: 0;
}

li.h-leaf,
li.h-node { // use flexbox for positioning of the hierarchy nodes
display: flex;
flex-wrap: wrap;
margin-top: .5em;
margin-bottom: .5em;
}

li.h-leaf:first-child,
li.h-node:first-child {
margin-top: 0;
}

li.h-leaf:last-child,
li.h-node:last-child {
margin-bottom: 0;
}

li.h-leaf::before {
content: ' '; // needs content to have equal spacing
}

li.h-node::before {
font-family: "FontAwesome";
content: '\f0da';
transform: scaleX(1.5);
}

li.h-node.twiddle-open::before {
font-family: "FontAwesome";
content: '\f0d7';
transform: scaleY(1.5);
}

li.h-leaf::before,
li.h-node::before,
li.h-node.twiddle-open::before {
flex: 0 0 3.5%;
display: block;
color: #929292;
width: 1em;
height: 1em;
font-size: 1em;
margin-top: -0.2em;

@include media-breakpoint-up(sm) {
flex: 0 0 7.5%;
}

@include media-breakpoint-up(xl) {
flex: 0 0 5.5%;
}
}

li.h-node.twiddle-open::before {
flex: 0 0 5%;
margin-top: -0.4em;

@include media-breakpoint-up(sm) {
flex: 0 0 10%;
}

@include media-breakpoint-up(xl) {
flex: 0 0 7.5%;
}
}

a.facet_select,
span.selected {
display: block;
max-width: 100%;
flex: 1 1 60%;
margin-right: 2.5%;
margin-bottom: 0;
line-height: 1.2;


@include media-breakpoint-up(sm) {
flex: 1 1 90%;
margin-right: 0;
}

@include media-breakpoint-up(xl) {
flex: 1 1 50%;
margin-right: 2.5%;
}
}

span.facet-count {
float: none;
display: block;
flex: 0 0 30%;
text-align: right;

@include media-breakpoint-up(sm) {
flex: 1 1 100%;
text-align: left;
margin-left: 10%;
}

@include media-breakpoint-up(xl) {
flex: 0 0 35%;
text-align: right;
margin-left: 0;
}
}

// make open twiddles pretty
li.h-node.twiddle-open {
border-top: 1px solid #eee;
padding-top: 0.5em;
border-bottom: 1px solid #eee;
margin-bottom: 0;
padding-bottom: 0.5em;

> a {
font-weight: bold
}

}

.location-more-toggle-wrapper {
margin-bottom: .5em;
}

}

ul.facet-hierarchy li.h-node.twiddle-open:first-child {
border-top: none !important;
padding-top: 0 !important;
}

ul.facet-hierarchy li.h-node.twiddle-open:last-child {
border-bottom: none !important;
margin-bottom: 0 !important;
}


/* =============== */
/* RESULTS */
/* =============== */
Expand Down
3 changes: 0 additions & 3 deletions app/helpers/hierarchy_helper.rb

This file was deleted.

15 changes: 15 additions & 0 deletions app/presenters/trln_argon/location_facet_item_presenter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module TrlnArgon
class LocationFacetItemPresenter < Blacklight::FacetItemPresenter
# See https://github.com/projectblacklight/blacklight/blob/release-7.x/app/presenters/blacklight/facet_item_presenter.rb

##
# Get the displayable version of a facet's value
#
# @return [String]
def label
TrlnArgon::LookupManager.instance.map([value.split(':').first, 'facet', value.split(':').last].join('.')) || value
end
end
end
3 changes: 0 additions & 3 deletions app/views/blacklight/hierarchy/_facet_hierarchy.html.erb

This file was deleted.

12 changes: 12 additions & 0 deletions lib/generators/trln_argon/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ def verify_blacklight_installed
raise 'Install Blacklight before installing TRLN Argon.'
end

# Load our TRLN fork of the blacklight-hierarchy gem
# TODO: remove in favor of trln_argon.gemspec once our fork is
# published on rubygems
def install_trln_fork_hierarchy
say_status('warning', 'Installing TRLN fork of blacklight-hierarchy', :yellow)

gem 'blacklight-hierarchy', git: 'https://github.com/trln/blacklight-hierarchy', tag: 'v6.3.1'
Bundler.with_clean_env do
run 'bundle install'
end
end

def run_dependency_generators
generate 'blacklight_hierarchy:install'
generate 'blacklight_range_limit:install'
Expand Down
39 changes: 26 additions & 13 deletions lib/trln_argon/controller_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,24 @@ module ControllerOverride
show: true
config.add_home_facet_field TrlnArgon::Fields::LOCATION_HIERARCHY_FACET.to_s,
label: TrlnArgon::Fields::LOCATION_HIERARCHY_FACET.label,
limit: 200,
limit: -1,
sort: 'count',
partial: 'blacklight/hierarchy/facet_hierarchy',
collapse: false,
ex: :rollup,
helper_method: :location_filter_display
# This helper is still needed for the label in constraints
helper_method: :location_filter_display,
component: Blacklight::Hierarchy::FacetFieldListComponent
config.add_home_facet_field TrlnArgon::Fields::RESOURCE_TYPE_FACET.to_s,
label: TrlnArgon::Fields::RESOURCE_TYPE_FACET.label,
limit: true,
collapse: false
config.add_home_facet_field TrlnArgon::Fields::CALL_NUMBER_FACET.to_s,
label: TrlnArgon::Fields::CALL_NUMBER_FACET.label,
limit: 4500,
partial: 'blacklight/hierarchy/facet_hierarchy',
helper_method: :call_number_filter_display
sort: 'alpha',
# This helper is still needed for the label in constraints
helper_method: :call_number_filter_display,
component: Blacklight::Hierarchy::FacetFieldListComponent
config.add_home_facet_field TrlnArgon::Fields::LANGUAGE_FACET.to_s,
label: TrlnArgon::Fields::LANGUAGE_FACET.label,
limit: true
Expand Down Expand Up @@ -192,12 +195,13 @@ module ControllerOverride
advanced_search_component: TrlnArgon::AdvancedSearchFacetFieldComponent
config.add_facet_field TrlnArgon::Fields::LOCATION_HIERARCHY_FACET.to_s,
label: TrlnArgon::Fields::LOCATION_HIERARCHY_FACET.label,
limit: 200,
limit: -1,
sort: 'count',
partial: 'blacklight/hierarchy/facet_hierarchy',
collapse: false,
ex: :rollup,
# This helper is still needed for the label in constraints
helper_method: :location_filter_display,
component: Blacklight::Hierarchy::FacetFieldListComponent,
advanced_search_component: TrlnArgon::AdvancedSearchFacetFieldComponent
config.add_facet_field TrlnArgon::Fields::RESOURCE_TYPE_FACET.to_s,
label: TrlnArgon::Fields::RESOURCE_TYPE_FACET.label,
Expand All @@ -217,8 +221,10 @@ module ControllerOverride
config.add_facet_field TrlnArgon::Fields::CALL_NUMBER_FACET.to_s,
label: TrlnArgon::Fields::CALL_NUMBER_FACET.label,
limit: 4500,
partial: 'blacklight/hierarchy/facet_hierarchy',
sort: 'alpha',
# This helper is still needed for the label in constraints
helper_method: :call_number_filter_display,
component: Blacklight::Hierarchy::FacetFieldListComponent,
advanced_search_component: TrlnArgon::AdvancedSearchFacetFieldComponent
config.add_facet_field TrlnArgon::Fields::LANGUAGE_FACET.to_s,
label: TrlnArgon::Fields::LANGUAGE_FACET.label,
Expand Down Expand Up @@ -257,15 +263,22 @@ module ControllerOverride
limit: true,
advanced_search_component: TrlnArgon::AdvancedSearchFacetFieldComponent

# hierarchical facet configuration
# Hierarchical facet configuration
# See: https://github.com/trln/blacklight-hierarchy/blob/main/README.md
config.facet_display ||= {}
cnf_components = TrlnArgon::Fields::CALL_NUMBER_FACET.to_s.split('_')
lf_components = TrlnArgon::Fields::LOCATION_HIERARCHY_FACET.to_s.split('_')
config.facet_display[:hierarchy] = {
# blacklight-hierarchy requires this mapping;
# prefix + final component (separated by _)
cnf_components[0..-2].join('_') => [[cnf_components[-1]], '|'],
lf_components[0..-2].join('_') => [[lf_components[-1]], ':']
# blacklight-hierarchy gem requires this mapping;
# prefix + final component (separated by _) e.g.,
# 'location_hierarchy' => [['f'], ':']
# TRLN CUSTOMIZATION adds an optional third element to specify
# a custom FacetItemPresenter.
cnf_components[0..-2].join('_') => [[cnf_components[-1]],
'|'],
lf_components[0..-2].join('_') => [[lf_components[-1]],
':',
TrlnArgon::LocationFacetItemPresenter]
}

# solr debug fields to be displayed in the index (search results) view
Expand Down
1 change: 0 additions & 1 deletion lib/trln_argon/engine.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'blacklight'
require 'blacklight_advanced_search'
require 'blacklight-hierarchy'
require 'blacklight_range_limit'
require 'rails_autolink'
require 'library_stdnums'
Expand Down
1 change: 0 additions & 1 deletion lib/trln_argon/view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module TrlnArgon
module ViewHelpers
autoload :BlacklightHelperBehavior, 'trln_argon/view_helpers/blacklight_helper_behavior'
autoload :CatalogHelperBehavior, 'trln_argon/view_helpers/catalog_helper_behavior'
autoload :HierarchyHelper, 'trln_argon/view_helpers/hierarchy_helper'
autoload :TrlnArgonHelper, 'trln_argon/view_helpers/trln_argon_helper'
end
end
Loading

0 comments on commit af8384f

Please sign in to comment.