-
Notifications
You must be signed in to change notification settings - Fork 3
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
Genia Kazymova
committed
Feb 7, 2025
1 parent
366f5aa
commit 745cf0b
Showing
17 changed files
with
7,743 additions
and
1,886 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1 +1 @@ | ||
3.0.1 | ||
3.0.2 |
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 was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
app/assets/javascripts/trln_argon/controllers/multi_select_controller.js
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,27 @@ | ||
document.addEventListener("DOMContentLoaded", function () { | ||
if (window.Stimulus) { | ||
// Only register the controller if Stimulus is loaded | ||
const application = window.Stimulus.Application.start(); | ||
|
||
application.register("multi-select", class extends Stimulus.Controller { | ||
static values = { plugins: Array }; | ||
|
||
connect() { | ||
this.select = new TomSelect(this.element, { | ||
plugins: this.pluginsValue, | ||
render: { | ||
item: function (data, escape) { | ||
return `<div>${escape(data.text)}</div>`; | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
disconnect() { | ||
this.select?.destroy(); | ||
} | ||
}); | ||
} else { | ||
console.error("Stimulus is not loaded yet."); | ||
} | ||
}); |
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
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
16 changes: 16 additions & 0 deletions
16
app/components/trln_argon/multi_select_facet_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,16 @@ | ||
<%= render(@layout.new(facet_field: @facet_field)) do |component| %> | ||
<% component.with_label do %> | ||
<%= @facet_field.label %> | ||
<% end %> | ||
<% component.with_body do %> | ||
<div class="facet-multi-select"> | ||
<select <%= tag.attributes(select_attributes.merge(placeholder: t('blacklight_advanced_search.form.placeholder'))) %>> | ||
<% presenters.each do |presenter| %> | ||
<option <%= tag.attributes(option_attributes(presenter: presenter)) %>> | ||
<%= "#{presenter.label} (#{number_with_delimiter(presenter.hits)})" %> | ||
</option> | ||
<% end %> | ||
</select> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module TrlnArgon | ||
# Multi select facet component using TomSelect | ||
class MultiSelectFacetComponent < Blacklight::Component | ||
def initialize(facet_field:, layout: nil) | ||
super() | ||
@facet_field = facet_field | ||
@layout = layout == false ? FacetFieldNoLayoutComponent : Blacklight::FacetFieldComponent | ||
end | ||
|
||
# @return [Boolean] whether to render the component | ||
def render? | ||
presenters.any? | ||
end | ||
|
||
# @return [Array<Blacklight::FacetFieldPresenter>] array of facet field presenters | ||
def presenters | ||
return [] unless @facet_field.paginator | ||
|
||
return to_enum(:presenters) unless block_given? | ||
|
||
@facet_field.paginator.items.each do |item| | ||
yield @facet_field.facet_field | ||
.item_presenter | ||
.new(item, @facet_field.facet_field, helpers, @facet_field.key, @facet_field.search_state) | ||
end | ||
end | ||
|
||
# @return [Hash] HTML attributes for the select element | ||
def select_attributes | ||
{ | ||
class: "#{@facet_field.key}-select", | ||
name: "f_inclusive[#{@facet_field.key}][]", | ||
placeholder: I18n.t('facets.advanced_search.placeholder'), | ||
multiple: true, | ||
data: { | ||
controller: 'multi-select', | ||
multi_select_plugins_value: select_plugins.to_json | ||
} | ||
} | ||
end | ||
|
||
# @return [Hash] HTML attributes for the option elements within the select element | ||
def option_attributes(presenter:) | ||
{ | ||
value: presenter.value, | ||
selected: presenter.selected? ? 'selected' : nil | ||
} | ||
end | ||
|
||
# TomSelect functionality can be expanded with plugins. `checkbox_options` | ||
# allow us to use the existing advanced search facet logic by using checkboxes. | ||
# More plugins can be found here: https://tom-select.js.org/plugins/ | ||
# | ||
# @return [Array<String>] array of TomSelect plugins | ||
def select_plugins | ||
%w[checkbox_options caret_position input_autogrow clear_button] | ||
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
Oops, something went wrong.