Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TD-1337 restore local filter #436

Merged
merged 4 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/components/trln_argon/search/sidebar_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<% # TRLN override of BL8 sidebar component %>
<%= render 'catalog/local_filter',
local_button_id: 'toggle-local-btn-top',
trln_button_id: 'toggle-trln-btn-top' %>

<search>
<% facet_group_names.each do |groupname| %>
<% fields = facet_fields_in_group(groupname) %>
<%= render group_component_class.new(id: groupname, fields: fields, response: response) do |component| %>
<% component.with_body do %>
<%= render Blacklight::FacetComponent.with_collection(fields, response: response) %>
<% end %>
<% end %>
<% end %>
</search>
18 changes: 18 additions & 0 deletions app/components/trln_argon/search/sidebar_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

module TrlnArgon
module Search
class SidebarComponent < Blacklight::Search::SidebarComponent
def initialize(blacklight_config:, response:, view_config:)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove lines 6-15 here, which will spare us from having to reconcile this code frequently against upstream Blacklight to make sure it matches.

super(blacklight_config: blacklight_config, response: response, view_config: view_config)
@blacklight_config = blacklight_config
@response = response
@group_component_class = view_config.facet_group_component || Blacklight::Response::FacetGroupComponent
end

attr_reader :group_component_class, :response

delegate :facet_group_names, :facet_fields_in_group, to: :@blacklight_config
end
end
end
83 changes: 43 additions & 40 deletions app/views/catalog/_local_filter.html.erb
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
<h2 class="local-filter-heading" id="<%= local_filter_id %>"><%= t("trln_argon.local_filter.showing_results") %></h2>

<% query_state = query_state_from_search_state(search_state) %>
<% query_state.delete('page') %>
<% query_state.fetch('f', {}).delete(TrlnArgon::Fields::LOCATION_HIERARCHY_FACET.to_s) %>

<div class="toggle toggle-local">

<%= button_tag( type: "button",
id: local_button_id,
class: "btn btn-md #{local_search_button_class}",
title: "#{t("trln_argon.local_filter.search_verb")} #{t("trln_argon.local_filter.searching_local", local_institution_name: institution_long_name)}",
onclick: "window.location='#{search_catalog_path(query_state)}'"
) do %>
<span class="visually-hidden">icon</span><span class="icon-wrapper"></span>
<% end %>

<%= label_tag( local_button_id,
t("trln_argon.local_filter.searching_local", local_institution_name: institution_long_name),
class: "#{local_search_button_label_class}",
data: { count_only_path: trln_argon.catalog_count_only_path(query_state) }) %>

<% inst = TrlnArgon::Engine.configuration.local_institution_code %>
<% instname = TrlnArgon::LookupManager.instance.map("#{inst}.facet.#{inst}") %>

<div id="location-data"
data-argon-institution="<%= instname %>"
data-argon-hsl="<%= TrlnArgon::LookupManager.instance.map('hsl.facet.hsl') %>"
data-argon-law="<%= TrlnArgon::LookupManager.instance.map('law.facet.law') %>"
data-location-facet-limit="<%= TrlnArgon::Engine.configuration.number_of_location_facets %>">
</div>


<div class="toggle toggle-trln">

<%= button_tag( type: "button",
id: trln_button_id,
class: "btn btn-md #{trln_search_button_class}",
title: "#{t("trln_argon.local_filter.search_verb")} #{t("trln_argon.local_filter.searching_trln")}",
onclick: "window.location='#{search_trln_path(query_state)}'"
) do %>
<span class="visually-hidden">icon</span><span class="icon-wrapper"></span>
<% end %>

<%= label_tag( trln_button_id,
"#{t("trln_argon.local_filter.searching_trln")}",
class: "#{trln_search_button_label_class}",
data: { count_only_path: trln_argon.trln_count_only_path(query_state) }) %>

</div>
<div id="trln-toggle" class="sidenav facets top-panel-heading">
<div id="viewAllResults" class="clearfix" role="navigation" aria-label="Searching (context)">
<h2 class="local-filter-heading" id="localFilterLabelFacets">
<%= t("trln_argon.local_filter.showing_results") %>
</h2>

<% query_state = query_state_from_search_state(search_state) %>
<% query_state.delete('page') %>
<% query_state.fetch('f', {}).delete(TrlnArgon::Fields::LOCATION_HIERARCHY_FACET.to_s) %>

<div class="toggle toggle-local">
<%= button_tag(type: "button", id: local_button_id, class: "btn btn-md #{local_search_button_class}",
title: "#{t('trln_argon.local_filter.search_verb')} #{t('trln_argon.local_filter.searching_local', local_institution_name: institution_long_name)}",
onclick: "window.location='#{search_catalog_path(query_state)}'") do %>
<span class="sr-only">icon</span><span class="icon-wrapper"></span>
<% end %>

<%= label_tag(local_button_id, t('trln_argon.local_filter.searching_local', local_institution_name: institution_long_name),
class: "#{local_search_button_label_class}",
data: { count_only_path: trln_argon.catalog_count_only_path(query_state) }) %>
</div>

<div class="toggle toggle-trln">
<%= button_tag(type: "button", id: trln_button_id, class: "btn btn-md #{trln_search_button_class}",
title: "#{t('trln_argon.local_filter.search_verb')} #{t('trln_argon.local_filter.searching_trln')}",
onclick: "window.location='#{search_trln_path(query_state)}'") do %>
<span class="sr-only">icon</span><span class="icon-wrapper"></span>
<% end %>

<%= label_tag(trln_button_id, t('trln_argon.local_filter.searching_trln'),
class: "#{trln_search_button_label_class}",
data: { count_only_path: trln_argon.trln_count_only_path(query_state) }) %>
</div>
</div>
</div>
20 changes: 0 additions & 20 deletions app/views/catalog/_search_sidebar.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion config/initializers/blacklight_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Blacklight
class Configuration
extend ActiveSupport::Autoload

eager_autoload do
autoload :HomeFacetField
autoload :ShowSubHeaderField
Expand Down
10 changes: 5 additions & 5 deletions lib/generators/trln_argon/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ def inject_javascript_include
say_status('info', '==============================', :magenta)
say_status('info', 'Injecting TRLN Argon JS assets', :magenta)
say_status('info', '==============================', :magenta)
if File.exist?('app/assets/javascripts/application.js')
return if IO.read('app/assets/javascripts/application.js').include?('trln_argon')
insert_into_file 'app/assets/javascripts/application.js', after: '//= require blacklight/blacklight' do
"\n//= require trln_argon/trln_argon\n"
end
return unless File.exist?('app/assets/javascripts/application.js')
return if IO.read('app/assets/javascripts/application.js').include?('trln_argon')

insert_into_file 'app/assets/javascripts/application.js', after: '//= require blacklight/blacklight' do
"\n//= require trln_argon/trln_argon\n"
end
end

Expand Down
3 changes: 3 additions & 0 deletions lib/trln_argon/controller_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ module ControllerOverride
config.search_builder_class = DefaultLocalSearchBuilder
config.default_per_page = 20

# Sets the sidebar component for the index view in the TrlnArgon configuration.
config.index.sidebar_component = TrlnArgon::Search::SidebarComponent

# Use Solr search requestHandler for search requests
config.http_method = :get
config.solr_path = :select
Expand Down
Loading