administrate_ransack 0.1.0 → 0.1.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88c77d51c97628de19019594f60a310000340c079d4adaf442005c1037da1748
|
4
|
+
data.tar.gz: 41055594ee72a4e78c2d201ff04d758839238c122d917362382a8842b860b2a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc773c880ca05607c1af0d11bf15b5bd9a1e6c7bf5a90060f7e49977cdb5f099d379f1617e9b91079c98321847e404c8e3e5cad94d2156ac986a425b95eaf4d4
|
7
|
+
data.tar.gz: 253988df0bb9cb37804da6486b22867dfba2660a8065f38e13a353b549a9c655b300296e38651c1b293cace9bfd6685ed7c6e81f99d1b669b110b3591fb9cdb2
|
data/README.md
CHANGED
@@ -17,8 +17,30 @@ prepend AdministrateRansack::Searchable
|
|
17
17
|
<%= render('administrate_ransack/filters', attribute_types: page.attribute_types) %>
|
18
18
|
```
|
19
19
|
|
20
|
+
## Usage
|
21
|
+
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
|
+
|
23
|
+
Example:
|
24
|
+
```rb
|
25
|
+
class Post < ApplicationRecord
|
26
|
+
scope :admin_scope, -> { where(published: true) }
|
27
|
+
|
28
|
+
def admin_label
|
29
|
+
title.upcase
|
30
|
+
end
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
## Notes
|
35
|
+
- Administrate Search input works independently from Ransack searches, I suggest to disable it eventually
|
36
|
+
- 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
|
+
```rb
|
38
|
+
sort_link(@ransack_results, attr_name) do
|
39
|
+
# ...
|
40
|
+
```
|
41
|
+
|
20
42
|
## Customizations
|
21
|
-
-
|
43
|
+
- Allow only some fields for the filters in the index view:
|
22
44
|
```erb
|
23
45
|
<% attribute_types = {
|
24
46
|
author: Administrate::Field::BelongsTo,
|
@@ -30,7 +52,7 @@ prepend AdministrateRansack::Searchable
|
|
30
52
|
attribute_types: attribute_types
|
31
53
|
) %>
|
32
54
|
```
|
33
|
-
-
|
55
|
+
- Optional basic style to setup the filters as a sidebar:
|
34
56
|
```css
|
35
57
|
.main-content__body {
|
36
58
|
display: inline-block;
|
@@ -54,8 +76,8 @@ prepend AdministrateRansack::Searchable
|
|
54
76
|
}
|
55
77
|
```
|
56
78
|
|
57
|
-
|
58
|
-
|
79
|
+
Screenshot:
|
80
|
+

|
59
81
|
|
60
82
|
## Do you like it? Star it!
|
61
83
|
If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
|
@@ -10,12 +10,13 @@
|
|
10
10
|
<% association = @ransack_results.klass.reflections[field.to_s] %>
|
11
11
|
<% if association %>
|
12
12
|
<% label = association.klass.method_defined?(:admin_label) ? :admin_label : :to_s %>
|
13
|
+
<% collection = association.klass.send(association.klass.respond_to?(:admin_scope) ? :admin_scope : :all) %>
|
13
14
|
<%= f.label field %>
|
14
|
-
<%= f.collection_select "#{field}_id_eq",
|
15
|
+
<%= f.collection_select "#{field}_id_eq", collection, :id, label, include_blank: true %>
|
15
16
|
<% end %>
|
16
17
|
<% when 'Administrate::Field::Boolean' %>
|
17
18
|
<%= f.label field %>
|
18
|
-
<%= f.select "#{field}_eq", [['no', false], ['yes', true]], include_blank: true %>
|
19
|
+
<%= f.select "#{field}_eq", [[t('administrate_ransack.filters.no'), false], [t('administrate_ransack.filters.yes'), true]], include_blank: true %>
|
19
20
|
<% when 'Administrate::Field::Date' %>
|
20
21
|
<%= f.label field %>
|
21
22
|
<%= f.date_field "#{field}_gteq" %>
|
@@ -34,8 +35,9 @@
|
|
34
35
|
<% association = @ransack_results.klass.reflections[field.to_s] %>
|
35
36
|
<% if association %>
|
36
37
|
<% label = association.klass.method_defined?(:admin_label) ? :admin_label : :to_s %>
|
38
|
+
<% collection = association.klass.send(association.klass.respond_to?(:admin_scope) ? :admin_scope : :all) %>
|
37
39
|
<%= f.label field %>
|
38
|
-
<%= f.collection_check_boxes "#{field}_id_in",
|
40
|
+
<%= f.collection_check_boxes "#{field}_id_in", collection, :id, label do |b| %>
|
39
41
|
<%= b.label do %>
|
40
42
|
<%= b.check_box %>
|
41
43
|
<span><%= b.object.send(label) %></span>
|
data/config/locales/en.yml
CHANGED
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: administrate
|