Module: SnFilterable

Includes:
Filterable
Defined in:
lib/sn_filterable/filterable.rb,
lib/sn_filterable.rb,
lib/sn_filterable/engine.rb,
lib/sn_filterable/railtie.rb,
lib/sn_filterable/version.rb,
app/components/sn_filterable/main_component.rb,
app/components/sn_filterable/chips_component.rb,
app/components/sn_filterable/search_component.rb,
app/components/sn_filterable/category_component.rb,
app/components/sn_filterable/filter_button_component.rb,
app/components/sn_filterable/filter_category_component.rb

Overview

Concern to add sorting and filtering for ActiveRecord models.

The following constants must to be implemented in the base class for filtering and sorting to work:

‘FILTER_SCOPE_MAPPINGS`: A [Hash] that maps a filter’s parameter name to the filter’s scope. The scope’s proc should have a single argument for filtering. Multiple filters will be ANDed when building the full query.

‘ARRAY_FILTER_SCOPES`: An [Array] of filter parameter names that support having multiple values. If multiple filters of the same key are provided, the value’s scope will be ORed when building the filter’s query.

‘SORT_SCOPE_MAPPINGS`: A [Hash] that maps a sorting name to the sorting scope. If the scope is complex preventing automatic reversal, another scope with the suffix ’_reversed’ must be made.

‘DEFAULT_SORT`: Optional, sets the default sort of the items when no sorting parameter is set. Can be either a [String], which returns the sorting name or an [Array], where the first item is the sorting name and the second item is the sort direction (either `:asc` or `:desc`).

See Also:

Defined Under Namespace

Modules: Filterable, FilteredHelper Classes: CategoryComponent, ChipsComponent, Engine, FilterButtonComponent, FilterCategoryComponent, MainComponent, Railtie, SearchComponent

Constant Summary collapse

VERSION =
"3.0.0"

Class Method Summary collapse

Class Method Details

.load_jsObject



14
15
16
# File 'lib/sn_filterable.rb', line 14

def self.load_js
  File.read(File.join(Gem.loaded_specs["sn_filterable"].full_gem_path, "app", "assets", "javascripts", "sn_filtering.js"))
end