administrate_ransack 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: faad99daa51ceb91223e79770bc0df8aeb7adae21d76044b510cd7628a8fe323
4
- data.tar.gz: 3b1e7a5f12bc54086a182a72715342c52c79e0bdeef77af03a79bf0f659aa590
3
+ metadata.gz: 88c77d51c97628de19019594f60a310000340c079d4adaf442005c1037da1748
4
+ data.tar.gz: 41055594ee72a4e78c2d201ff04d758839238c122d917362382a8842b860b2a2
5
5
  SHA512:
6
- metadata.gz: bb14807a4275bdc1d62467bca4d30bc3ec9010df4af46516351ad3ec63b9cd863fce18a87dfac75d20d35a785561fea58a254457eadb645d69d9d0163878dd2c
7
- data.tar.gz: e4f7f6c47e66712a9c574ff0394739189a402f33281612113129ec10af6166d85ef5a8d73b0922a5d47e99f245e18ddd961abdec48cb491e525fd4b44110b9d2
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
- - Setup the fields for the filters in the index view:
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
- - Optionally setup the layout for filters as a sidebar:
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
- ## Notes
58
- - 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
79
+ Screenshot:
80
+ ![screenshot](screenshot.png)
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", association.klass.all, :id, label, include_blank: true %>
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", association.klass.all, :id, label do |b| %>
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>
@@ -1,4 +1,6 @@
1
1
  en:
2
2
  administrate_ransack:
3
3
  filters:
4
- clear_filters: Clear filters
4
+ 'clear_filters': Clear filters
5
+ 'no': 'No'
6
+ 'yes': 'Yes'
@@ -4,6 +4,11 @@ require 'ransack'
4
4
 
5
5
  module AdministrateRansack
6
6
  module Searchable
7
+ def index
8
+ @dashboard = dashboard
9
+ super
10
+ end
11
+
7
12
  def scoped_resource
8
13
  @ransack_results = super.ransack(params[:q])
9
14
  @ransack_results.result(distinct: true)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdministrateRansack
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
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.0
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-09-20 00:00:00.000000000 Z
11
+ date: 2020-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate