-
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 6, 2025
1 parent
c7f7307
commit 376840d
Showing
9 changed files
with
2,683 additions
and
92 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
document.addEventListener("DOMContentLoaded", function () { | ||
if (!window.Stimulus) { | ||
window.Stimulus = Stimulus.Application.start(); | ||
} | ||
}); |
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
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.value)}</div>`; | ||
}, | ||
}, | ||
}); | ||
} | ||
|
||
disconnect() { | ||
this.select?.destroy(); | ||
} | ||
}); | ||
} else { | ||
console.error("Stimulus is not loaded yet."); | ||
} | ||
}); | ||
|
26 changes: 0 additions & 26 deletions
26
app/assets/javascripts/trln_argon/controllers/tom_select_controller.js
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
app/assets/javascripts/trln_argon/controllers/tom_select_init.js
This file was deleted.
Oops, something went wrong.
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
113 changes: 57 additions & 56 deletions
113
app/components/trln_argon/multi_select_facet_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 |
---|---|---|
@@ -1,58 +1,59 @@ | ||
module TrlnArgon | ||
# Multi select facet component using TomSelect | ||
class MultiSelectFacetComponent < Blacklight::Component | ||
def initialize(facet_field:, layout: nil) | ||
@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 | ||
# 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 | ||
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
Oops, something went wrong.