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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 189899fbf9e20cc4383ea9429c84278c0e7f231dc5d315a35193d6232f696758
4
- data.tar.gz: b35afd8d7a0bef95d8567d7e66bf53de969e494b8cbc2b39f894405d9d2e059c
3
+ metadata.gz: 0bc47df19eb878cd2185a81c845708e58daa50a4d084a45e56a46e3a37bff2a3
4
+ data.tar.gz: 38389e482742a8abeb5003c589bf0347ec238870e016eb445e67b273b4f5e32f
5
5
  SHA512:
6
- metadata.gz: 512c8c66a5fcbd99c1d93a4161b02da557a007d3912162954a155c43deb3015fbb698757fb6f895eb553a03a17441403dd2b5551f74ffb48ce4cbb5c3a4c4c5c
7
- data.tar.gz: dc13d05d8e747b99155d0ade9fd98f1adad2e0051c2c1e52e5905d4314c03a50a43f44f4d9428a05ca62f35e39bf72a51793e80bcb2f1c8ebe44f16325e6995c
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 pr-4 text-gray-600 dark:text-gray-400 select-none w-full cursor-pointer",
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-start-2 md:ml-48 lg:ml-64 h-12 pointer-events-auto">
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-start-2 md:ml-64 h-12 pointer-events-none"></div>
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
 
@@ -34,6 +34,7 @@ module SnFilterable
34
34
  @show_sidebar = show_sidebar
35
35
  @update_url_on_submit = update_url_on_submit
36
36
  @extra_params = extra_params
37
+ @filtered.extra_params = extra_params if extra_params.present?
37
38
  end
38
39
 
39
40
  def search_field
@@ -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
- def initialize(model_class, items, queries, sort_name, sort_reversed)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SnFilterable
4
- VERSION = "3.1.2"
4
+ VERSION = "3.1.4"
5
5
  end
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.2
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-04 00:00:00.000000000 Z
10
+ date: 2025-03-28 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: heroicon