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 +4 -4
- data/README.md +26 -5
- data/app/views/administrate_ransack/_filters.html.erb +1 -0
- data/lib/administrate_ransack/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: a2dde6b1bd570497e553c4e737f4b48654af8470dfbe733c6e35a3bb74991b6e
|
4
|
+
data.tar.gz: e8fcfe208ba7ebc128ccfee07f816da649aa7a8ac0ab35e180e06832af070391
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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'
|
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
|
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
|

|
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| %>
|
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.
|
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
|
+
date: 2021-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: administrate
|