sn_filterable 3.1.2 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/components/sn_filterable/filter_category_component.html.erb +1 -1
- data/app/components/sn_filterable/main_component.html.erb +3 -2
- data/app/components/sn_filterable/main_component.rb +1 -0
- data/lib/models/filtered.rb +9 -2
- data/lib/sn_filterable/filterable.rb +3 -2
- data/lib/sn_filterable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bc47df19eb878cd2185a81c845708e58daa50a4d084a45e56a46e3a37bff2a3
|
4
|
+
data.tar.gz: 38389e482742a8abeb5003c589bf0347ec238870e016eb445e67b273b4f5e32f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e78f6ab61549b24c38fee7b1572251d620a616ffe001dd0e2e7c1a2e9dbf6a38950329d3296c9c7618496bc263893d392315614a449344cd902a97bd8889810f
|
7
|
+
data.tar.gz: fe920cbbac525670491df387d9c9642a0bb55508496e34d181a850b23a4691a18d9841f9f5bc1f4cba301ba5fb295c7bd5834b8c61f25bf5f77ad19f3c5462ee
|
@@ -28,7 +28,7 @@
|
|
28
28
|
<div class="min-w-0 flex-1 flex-grow">
|
29
29
|
<%= content_tag :label,
|
30
30
|
sub_filter[:name],
|
31
|
-
class: "block py-2
|
31
|
+
class: "block pl-3 py-2 text-gray-600 dark:text-gray-400 select-none w-full cursor-pointer",
|
32
32
|
for: "filter-#{@filter[:filter_name]}-#{index}" %>
|
33
33
|
</div>
|
34
34
|
</div>
|
@@ -6,6 +6,7 @@
|
|
6
6
|
"method": "get",
|
7
7
|
"data-turbo-frame": @frame_id,
|
8
8
|
"class": "relative",
|
9
|
+
"aria-label": "Content filters",
|
9
10
|
"@submit": "filtersLoading = true" do %>
|
10
11
|
<% @extra_params.each do |k, v| %>
|
11
12
|
<%= content_tag :input, "", class: "hidden", type: "hidden", value: v, name: k %>
|
@@ -17,7 +18,7 @@
|
|
17
18
|
<% if search? %>
|
18
19
|
<%= search %>
|
19
20
|
<% else %>
|
20
|
-
<div class="col-span-2 col-
|
21
|
+
<div class="col-span-2 xl:col-span-1 col-start-1 h-12 pointer-events-auto">
|
21
22
|
<%= render search_field %>
|
22
23
|
</div>
|
23
24
|
<% end %>
|
@@ -82,7 +83,7 @@
|
|
82
83
|
<%= render SnFilterable::FilterButtonComponent.new(filtered: @filtered, filters: @filters) %>
|
83
84
|
</div>
|
84
85
|
<% if @search_filter_name.present? %>
|
85
|
-
<div class="col-span-2 col-
|
86
|
+
<div class="col-span-2 xl:col-span-1 col-start-1 h-12 pointer-events-none"></div>
|
86
87
|
<% end %>
|
87
88
|
</div>
|
88
89
|
|
data/lib/models/filtered.rb
CHANGED
@@ -7,19 +7,21 @@
|
|
7
7
|
#
|
8
8
|
# @see Filterable
|
9
9
|
class Filtered
|
10
|
-
attr_accessor :items, :queries
|
10
|
+
attr_accessor :items, :queries, :extra_params
|
11
11
|
|
12
12
|
# @param [Class] model_class The class of the ActiveRecord::Base subclass
|
13
13
|
# @param [ActiveRecord::Relation] items The items sorted and filtered by [Filterable]
|
14
14
|
# @param [Hash] queries A hash of the sorting / filtering parameters
|
15
15
|
# @param [Symbol] sort_name The current sorting name
|
16
16
|
# @param [Boolean] sort_reversed True when the current sorting order is reversed
|
17
|
-
|
17
|
+
# @param [Hash] extra_params Optional hash of additional parameters to include in URLs
|
18
|
+
def initialize(model_class, items, queries, sort_name, sort_reversed, extra_params = {})
|
18
19
|
@model_class = model_class
|
19
20
|
@items = items
|
20
21
|
@queries = queries
|
21
22
|
@sort_name = sort_name
|
22
23
|
@sort_reversed = sort_reversed
|
24
|
+
@extra_params = extra_params || {}
|
23
25
|
end
|
24
26
|
|
25
27
|
# Returns if any filters are active
|
@@ -162,6 +164,11 @@ class Filtered
|
|
162
164
|
uri = URI.parse(url)
|
163
165
|
query = Rack::Utils.parse_nested_query(uri.query).deep_merge(@queries.deep_dup)
|
164
166
|
|
167
|
+
# Add extra_params to the URL
|
168
|
+
@extra_params.each do |key, value|
|
169
|
+
query[key.to_s] = value
|
170
|
+
end if @extra_params.present?
|
171
|
+
|
165
172
|
yield(query) if block_given?
|
166
173
|
|
167
174
|
uri.query = Rack::Utils.build_nested_query(query)
|
@@ -26,8 +26,9 @@ module SnFilterable
|
|
26
26
|
# @param [ActiveRecord::Relation] items Optional, the items to scope from the model
|
27
27
|
# @param [String, Array, nil] default_sort Optional, similar to the `DEFAULT_SORT` constant, sets the default sort of 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`). Will take precedence over the `DEFAULT_SORT` constant.
|
28
28
|
# @param [Boolean] pagination_enabled Optional, toggles pagination
|
29
|
+
# @param [Hash] extra_params Optional, allows for custom query parameters to be included in URLs
|
29
30
|
# @return [Filtered] the filtered and sorted items
|
30
|
-
def filter(params:, items: where(nil), default_sort: nil, pagination_enabled: true)
|
31
|
+
def filter(params:, items: where(nil), default_sort: nil, pagination_enabled: true, extra_params: {})
|
31
32
|
filter_params = filter_params(params)
|
32
33
|
sort_params = sort_params(params)
|
33
34
|
other_params = other_params(params, items)
|
@@ -35,7 +36,7 @@ module SnFilterable
|
|
35
36
|
items = perform_filter(items, filter_params)
|
36
37
|
items = items.page(other_params[:page]).per(other_params[:per]) if pagination_enabled
|
37
38
|
|
38
|
-
Filtered.new(self, items, generate_url_queries(filter_params, sort_params, other_params), sort_name, reverse_order)
|
39
|
+
Filtered.new(self, items, generate_url_queries(filter_params, sort_params, other_params), sort_name, reverse_order, extra_params)
|
39
40
|
end
|
40
41
|
|
41
42
|
private
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sn_filterable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IBM Skills Network
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-28 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: heroicon
|