administrate_ransack 0.1.10 → 0.1.12

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: a2dde6b1bd570497e553c4e737f4b48654af8470dfbe733c6e35a3bb74991b6e
4
- data.tar.gz: e8fcfe208ba7ebc128ccfee07f816da649aa7a8ac0ab35e180e06832af070391
3
+ metadata.gz: 1be017567c90bc3b625f7db95063c8f79ec3176191d0ac8c97b2a720574d32da
4
+ data.tar.gz: c8ca5c07a2ce1e560d394736173db107a9b8a1177854bac626eb6c296e901f95
5
5
  SHA512:
6
- metadata.gz: 5581bf2209ae91bb8b9b43ffe96be8cecbceadb22d0b0db05755c20443fd6b17ddfcbf70f500442c94c6bf05f4ad31ef3bb9243e3336b9f642b7ac4de4a520b0
7
- data.tar.gz: cf69dfe636379448c07b703fbf1435f47fdfeb234b15683414215d756132277d8c1b80e7832e8c16fea2fbd1d0ee0e6a904ccde85d43ddcc0409133e6b8da278
6
+ metadata.gz: 97465a3a36becda93904588d3505376b76481d35cb5f710788568f578a476c43c7dc2ff49a7f7d3b733e1f42c6988c5182a69bd1eb0660f193b013a6d1b9dbc9
7
+ data.tar.gz: dc13be2b62e76b562169e1646b627d7d2c5e410b3625c37aa1982470ed33d052e382098de2fbca904207caf69a94ed144c4e7d2c7bfcf4605c9e57b0ee11d08b
data/README.md CHANGED
@@ -19,9 +19,12 @@ prepend AdministrateRansack::Searchable
19
19
  - See the Customizations section to change the attributes list
20
20
 
21
21
  ## Usage
22
- For associations (has many/belongs to) the label used can be customized adding an `admin_label` method to the target model which returns a string while the collection can by filtered with `admin_scope`.
22
+ - The filters partial accepts some optional parameters:
23
+ + `attribute_labels`: hash used to override the field labels, ex. `{ title: "The title" }`
24
+ + `attribute_types`: hash used to specify the filter fields, ex. `{ title: Administrate::Field::String }`
25
+ + `search_path`: the path to use for searching (form URL)
26
+ - For associations (has many/belongs to) the label used can be customized adding an `admin_label` method to the target model which returns a string while the collection can by filtered with `admin_scope`. Example:
23
27
 
24
- Example:
25
28
  ```rb
26
29
  class Post < ApplicationRecord
27
30
  scope :admin_scope, -> { where(published: true) }
@@ -54,9 +57,10 @@ end
54
57
  ```
55
58
 
56
59
  ## Customizations
57
- - Allow only some fields for the filters in the index view:
60
+ - Sample with different options provided:
58
61
  ```erb
59
62
  <%
63
+ # In alternative prepare an hash in the dashboard like RANSACK_TYPES = {}
60
64
  attribute_types = {
61
65
  title: Administrate::Field::String,
62
66
  author: Administrate::Field::BelongsTo,
@@ -70,9 +74,14 @@ attribute_labels = {
70
74
  <%= render(
71
75
  'administrate_ransack/filters',
72
76
  attribute_types: attribute_types,
73
- attribute_labels: attribute_labels
77
+ attribute_labels: attribute_labels,
78
+ search_path: admin_root_path
74
79
  ) %>
75
80
  ```
81
+ - An alternative is to prepare some hashes constants in the dashboard (ex. `RANSACK_TYPES`) and then:
82
+ ```erb
83
+ <%= render('administrate_ransack/filters', attribute_types: @dashboard.class::RANSACK_TYPES) %>
84
+ ```
76
85
  - Optional basic style to setup the filters as a sidebar:
77
86
  ```css
78
87
  .main-content__body {
@@ -10,9 +10,18 @@
10
10
  </script>
11
11
  <% end %>
12
12
 
13
- <% attribute_labels ||= {} %>
14
- <% attribute_types ||= @dashboard.attribute_types.select { |key, _value| @dashboard.collection_attributes.include?(key) } %>
15
- <%= search_form_for [:admin, @ransack_results], html: { 'data-administrate-ransack-filters': '1' } do |f| %>
13
+ <%
14
+ attribute_labels ||= {}
15
+ attribute_types ||= @dashboard.attribute_types.select { |key, _value| @dashboard.collection_attributes.include?(key) }
16
+ form_options = { html: { 'data-administrate-ransack-filters': '1' } }
17
+ if local_assigns.has_key?(:search_path)
18
+ form_path = @ransack_results
19
+ form_options[:url] = search_path
20
+ else
21
+ form_path = [:admin, @ransack_results]
22
+ end
23
+ %>
24
+ <%= search_form_for form_path, form_options do |f| %>
16
25
  <div class="filters">
17
26
  <% attribute_types.each do |field, type| %>
18
27
  <% next if field == :id %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdministrateRansack
4
- VERSION = '0.1.10'
4
+ VERSION = '0.1.12'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate_ransack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-17 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0'
229
229
  requirements: []
230
- rubygems_version: 3.0.3
230
+ rubygems_version: 3.1.4
231
231
  signing_key:
232
232
  specification_version: 4
233
233
  summary: Administrate Ransack plugin