administrate_ransack 0.1.8 → 0.1.10

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: 5a7c16d4d10426a6a7bb94830b2bbd367d62bbf831ef82f4765113543f36c42c
4
- data.tar.gz: cea19beb75eea4520d151b94fe77ae59c7a52ba57d8deb76024b7f0ac3c8b23f
3
+ metadata.gz: a2dde6b1bd570497e553c4e737f4b48654af8470dfbe733c6e35a3bb74991b6e
4
+ data.tar.gz: e8fcfe208ba7ebc128ccfee07f816da649aa7a8ac0ab35e180e06832af070391
5
5
  SHA512:
6
- metadata.gz: bd68e8ecbd7de43319e8f8d5339f7e89a4f4d1b7538c2ac18fe8ce83ed03562685885b4a952a8342e60ba9298b879d384ef648e6d3cbda44cca08fcbd19eccd1
7
- data.tar.gz: 79e543067086971a5149a919bfad069d9dae57aab5a3f670337f484249fac21a83c216311acd4f95cbedc725a0804d8283b08a9b40d0ed2799e8d5ba4c6525a2
6
+ metadata.gz: 5581bf2209ae91bb8b9b43ffe96be8cecbceadb22d0b0db05755c20443fd6b17ddfcbf70f500442c94c6bf05f4ad31ef3bb9243e3336b9f642b7ac4de4a520b0
7
+ data.tar.gz: cf69dfe636379448c07b703fbf1435f47fdfeb234b15683414215d756132277d8c1b80e7832e8c16fea2fbd1d0ee0e6a904ccde85d43ddcc0409133e6b8da278
data/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
  A plugin for [Administrate](https://github.com/thoughtbot/administrate) to use [Ransack](https://github.com/activerecord-hackery/ransack) for filtering resources.
3
3
 
4
4
  Features:
5
- - add Ransack method via module prepend in controller;
6
- - offer a filters bar based on the resource's attributes;
5
+ - add Ransack search results using module prepend inside an Administrate controller;
6
+ - offer a filters side bar based on the resource's attributes;
7
7
  - customize searchable attributes.
8
8
 
9
9
  ## Installation
@@ -14,8 +14,9 @@ prepend AdministrateRansack::Searchable
14
14
  ```
15
15
  - Add to your resource index view:
16
16
  ```erb
17
- <%= render('administrate_ransack/filters', attribute_types: page.attribute_types) %>
17
+ <%= render('administrate_ransack/filters') %>
18
18
  ```
19
+ - See the Customizations section to change the attributes list
19
20
 
20
21
  ## Usage
21
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`.
@@ -32,11 +33,12 @@ end
32
33
  ```
33
34
 
34
35
  ## Notes
35
- - Administrate Search input works independently from Ransack searches, I suggest to disable it eventually
36
+ - Administrate Search logic works independently from Ransack searches, I suggest to disable it eventually (ex. overriding `show_search_bar?` in the controller)
36
37
  - Ordering by clicking on the headers of the table preserving the Ransack searches requires a change to the headers links, replacing the th links of *_collection* partial with:
37
38
  ```rb
38
39
  sort_link(@ransack_results, attr_name) do
39
- # ...
40
+ # ...
41
+ end
40
42
  ```
41
43
  - Date/time filters use Rails `datetime_field` method which produces a `datetime-local` input field, at the moment this type of element is not broadly supported, a workaround is to include [flatpickr](https://github.com/flatpickr/flatpickr) datetime library.
42
44
  + This gem checks if `flatpickr` function is available in the global scope and applies it to the `datetime-local` filter inputs;
@@ -98,6 +100,25 @@ attribute_labels = {
98
100
  Screenshot:
99
101
  ![screenshot](screenshot.png)
100
102
 
103
+ ## Extra notes
104
+ - If you need to define custom search logics you can skip prepending the module (`AdministrateRansack::Searchable`) and create your own search query in a controller, ex:
105
+ ```ruby
106
+ def scoped_resource
107
+ @ransack_results = super.ransack(params[:q])
108
+ @ransack_results.result(distinct: true)
109
+ end
110
+ ```
111
+ - Sometimes it's easier to create a new ransack field than overriding the search logic, example to search in a `jsonb` field adding to a Post model:
112
+ ```ruby
113
+ ransacker :keywords do
114
+ Arel.sql("posts.metadata ->> 'keywords'")
115
+ end
116
+ ```
117
+ - With this component you can easily link another resource applying some filters, example to add in a tag show page the link to the related posts:
118
+ ```erb
119
+ <%= link_to("Tag's posts", admin_posts_path('q[tags_id_in][]': page.resource.id), class: "button") %>
120
+ ```
121
+
101
122
  ## Do you like it? Star it!
102
123
  If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
103
124
 
@@ -11,6 +11,7 @@
11
11
  <% end %>
12
12
 
13
13
  <% attribute_labels ||= {} %>
14
+ <% attribute_types ||= @dashboard.attribute_types.select { |key, _value| @dashboard.collection_attributes.include?(key) } %>
14
15
  <%= search_form_for [:admin, @ransack_results], html: { 'data-administrate-ransack-filters': '1' } do |f| %>
15
16
  <div class="filters">
16
17
  <% attribute_types.each do |field, type| %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdministrateRansack
4
- VERSION = '0.1.8'
4
+ VERSION = '0.1.10'
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.8
4
+ version: 0.1.10
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-11 00:00:00.000000000 Z
11
+ date: 2021-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate