-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
184 additions
and
5 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/components/blacklight/hierarchy/facet_field_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<li class="<%= li_class %>" role="treeitem"> | ||
<%= helpers.facet_toggle_button(field_name, id) if subset.any? %> | ||
<% if item.nil? %> | ||
<%= key %> | ||
<% elsif qfacet_selected? %> | ||
<%= render Blacklight::Hierarchy::SelectedQfacetValueComponent.new(field_name: field_name, item: item) %> | ||
<% else %> | ||
<%= render Blacklight::Hierarchy::QfacetValueComponent.new(field_name: field_name, item: item, id: id) %> | ||
<% end %> | ||
|
||
<% unless subset.empty? %> | ||
<ul role=\"group\"> | ||
<% subset.keys.sort.each do |subkey| %> | ||
<%= render self.class.new(field_name: field_name, tree: subset[subkey], key: subkey) %> | ||
<% end %> | ||
</ul> | ||
<% end %> | ||
</li> |
33 changes: 33 additions & 0 deletions
33
app/components/blacklight/hierarchy/facet_field_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Hierarchy | ||
class FacetFieldComponent < ::ViewComponent::Base | ||
def initialize(field_name:, tree:, key:) | ||
@field_name = field_name | ||
@tree = tree | ||
@key = key | ||
@id = SecureRandom.uuid | ||
end | ||
|
||
attr_reader :field_name, :tree, :key, :id | ||
|
||
def subset | ||
@subset ||= tree.reject { |k, _v| !k.is_a?(String) } | ||
end | ||
|
||
def li_class | ||
subset.empty? ? 'h-leaf' : 'h-node' | ||
end | ||
|
||
def item | ||
tree[:_] | ||
end | ||
|
||
def qfacet_selected? | ||
config = helpers.facet_configuration_for_field(field_name) | ||
helpers.search_state.has_facet?(config, value: item.qvalue) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
app/components/blacklight/hierarchy/qfacet_value_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= link_to_unless suppress_link, item.value, path_for_facet, id: id, class: 'facet_select' %> <%= render_facet_count %> |
26 changes: 26 additions & 0 deletions
26
app/components/blacklight/hierarchy/qfacet_value_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Hierarchy | ||
class QfacetValueComponent < ::ViewComponent::Base | ||
def initialize(field_name:, item:, id: nil, suppress_link: false) | ||
@field_name = field_name | ||
@item = item | ||
@id = id | ||
@suppress_link = suppress_link | ||
end | ||
|
||
attr_reader :field_name, :item, :id, :suppress_link | ||
|
||
def path_for_facet | ||
facet_config = helpers.facet_configuration_for_field(field_name) | ||
Blacklight::FacetItemPresenter.new(item.qvalue, facet_config, helpers, field_name).href | ||
end | ||
|
||
def render_facet_count | ||
classes = "facet-count" | ||
content_tag("span", t('blacklight.search.facets.count', number: number_with_delimiter(item.hits)), class: classes) | ||
end | ||
end | ||
end | ||
end |
4 changes: 4 additions & 0 deletions
4
app/components/blacklight/hierarchy/selected_qfacet_value_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<span class="selected"><%= render Blacklight::Hierarchy::QfacetValueComponent.new(field_name: field_name, item: item, suppress_link: true) %></span> | ||
<%= link_to remove_href, class: 'remove' do %> | ||
<span class="glyphicon glyphicon-remove"></span><span class="sr-only">[remove]</span> | ||
<% end %> |
19 changes: 19 additions & 0 deletions
19
app/components/blacklight/hierarchy/selected_qfacet_value_component.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
module Blacklight | ||
module Hierarchy | ||
# Standard display of a SELECTED facet value, no link, special span with class, and 'remove' button. | ||
class SelectedQfacetValueComponent < ::ViewComponent::Base | ||
def initialize(field_name:, item:) | ||
@field_name = field_name | ||
@item = item | ||
end | ||
|
||
attr_reader :field_name, :item | ||
|
||
def remove_href | ||
helpers.search_action_path(helpers.search_state.remove_facet_params(field_name, item.qvalue)) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
HierarchicalFacetItem = Struct.new :qvalue, :value, :hits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters