administrate_ransack 0.3.0 → 0.3.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: 07d7f30c351a3488f7eb7f2ba5c21ed52d1a935fc895070026af20209883d48f
4
- data.tar.gz: 07b89a2beba6bdf5d6c59f17c100c70c7a90d73f85b3260715ba4b1641d566b4
3
+ metadata.gz: 53f9b7117bb0a7ddf959ed0d6e6e054e781cbb50904e076ecba27790f221d2c0
4
+ data.tar.gz: dbc0c054f730be1b2b6479e8fa4e72a55d0adf0d9f1f46c3143606700289e9ae
5
5
  SHA512:
6
- metadata.gz: c87a21c626b2553f8659740e785c5a7f893b35d021dc483d70d75ada047b729f8a04fcafaf95236f8dae55f25f61fc95a558580ae89bd68d68f520892ff303ee
7
- data.tar.gz: a7040f799122eb75d22e1af2d24c86a84c51c5da6001219cf8ba67fa861b59f2a772fae3a13cfeb9cbaa4e1d3517c754e241723993bc5603ee68f23f409ec74c
6
+ metadata.gz: bd13d31b54c05bacbc172eb81871044ab80e9fe1f5182fcdb20e7c4ef96245e3f95be05753abd5b7e7f5cd99367545530b992242d1845b6d4e9dea592d40862f
7
+ data.tar.gz: 0befebe036ae09c3336bfd214ae904acb6bfc773d4fe16dbdb89ed5248d36d921616e4b526a7e9c1bbfd430106f3830588be79786d67d64b55b19782bb5da9ec
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
- # Administrate Ransack [![Gem Version](https://badge.fury.io/rb/administrate_ransack.svg)](https://badge.fury.io/rb/administrate_ransack) [![Specs](https://github.com/blocknotes/administrate_ransack/actions/workflows/specs.yml/badge.svg)](https://github.com/blocknotes/administrate_ransack/actions/workflows/specs.yml)
1
+ # Administrate Ransack
2
+ [![gem version](https://badge.fury.io/rb/administrate_ransack.svg)](https://badge.fury.io/rb/administrate_ransack)
3
+ [![gem downloads](https://badgen.net/rubygems/dt/administrate_ransack)](https://rubygems.org/gems/administrate_ransack)
4
+ [![linters](https://github.com/blocknotes/administrate_ransack/actions/workflows/linters.yml/badge.svg)](https://github.com/blocknotes/administrate_ransack/actions/workflows/linters.yml)
5
+ [![specs](https://github.com/blocknotes/administrate_ransack/actions/workflows/specs.yml/badge.svg)](https://github.com/blocknotes/administrate_ransack/actions/workflows/specs.yml)
2
6
 
3
7
  A plugin for [Administrate](https://github.com/thoughtbot/administrate) to use [Ransack](https://github.com/activerecord-hackery/ransack) for filtering resources.
4
8
 
@@ -26,6 +30,7 @@ prepend AdministrateRansack::Searchable
26
30
  + `attribute_labels`: hash used to override the field labels, ex. `{ title: "The title" }`
27
31
  + `attribute_types`: hash used to specify the filter fields, ex. `{ title: Administrate::Field::String }`
28
32
  + `search_path`: the path to use for searching (form URL)
33
+ + `namespace`: the namespace used by Administrate, ex. `:supervisor`
29
34
  - 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:
30
35
 
31
36
  ```rb
@@ -106,7 +111,11 @@ attribute_labels = {
106
111
  ```erb
107
112
  <%= render('administrate_ransack/filters', attribute_types: @dashboard.class::RANSACK_TYPES) %>
108
113
  ```
114
+
115
+ ## Sample styles
116
+
109
117
  - Some basic style to setup the filters as a sidebar (see the screenshot below):
118
+
110
119
  ```css
111
120
  .main-content__body {
112
121
  display: inline-block;
@@ -131,7 +140,38 @@ attribute_labels = {
131
140
  ```
132
141
 
133
142
  Screenshot:
134
- ![screenshot](screenshot.png)
143
+ ![screenshot](extra/screenshot.png)
144
+
145
+ - Alternative styles for an horizontal search bar:
146
+
147
+ ```css
148
+ [data-administrate-ransack-filters] {
149
+ border: 1px solid #ddd;
150
+ padding: 10px;
151
+ text-align: center;
152
+ }
153
+
154
+ [data-administrate-ransack-filters] .filters {
155
+ display: inline-block;
156
+ }
157
+
158
+ [data-administrate-ransack-filters] .filter, [data-administrate-ransack-filters] .filter > label {
159
+ display: inline-block;
160
+ }
161
+
162
+ [data-administrate-ransack-filters] .filter > input {
163
+ display: inline-block;
164
+ width: auto;
165
+ }
166
+
167
+ [data-administrate-ransack-filters] .filters-buttons {
168
+ display: inline-block;
169
+ margin-left: 20px;
170
+ }
171
+ ```
172
+
173
+ Screenshot:
174
+ ![screenshot2](extra/screenshot2.png)
135
175
 
136
176
  ## Extra notes
137
177
 
@@ -162,6 +202,7 @@ Or consider offering me a coffee, it's a small thing but it is greatly appreciat
162
202
  ## Contributors
163
203
 
164
204
  - [Mattia Roccoberton](https://blocknot.es/): author
205
+ - The good guys that opened issues and pull requests from time to time
165
206
 
166
207
  ## License
167
208
 
@@ -14,13 +14,14 @@
14
14
  attribute_labels ||= {}
15
15
  attribute_types ||= @dashboard.attribute_types.select { |key, _value| @dashboard.collection_attributes.include?(key) }
16
16
  form_options = { html: { 'data-administrate-ransack-filters': '1' } }
17
+ namespace = local_assigns[:namespace] || :admin
17
18
  if local_assigns.has_key?(:search_path)
18
19
  form_path = @ransack_results
19
20
  form_options[:url] = search_path
20
21
  clear_filters_path = search_path
21
22
  else
22
- form_path = [:admin, @ransack_results]
23
- clear_filters_path = url_for(url_for([:admin, @ransack_results.klass]))
23
+ form_path = [namespace, @ransack_results]
24
+ clear_filters_path = url_for(url_for([namespace, @ransack_results.klass]))
24
25
  end
25
26
  %>
26
27
 
@@ -1,6 +1,6 @@
1
1
  <%= form.label(label) %>
2
2
  <% if model.ransackable_scopes.include?(field) %>
3
- <%= form.date_field(field) %>
3
+ <%= form.date_field(field, value: form.object.send(field)) %>
4
4
  <% else %>
5
5
  <%= form.date_field("#{field}_gteq") %>
6
6
  <%= form.date_field("#{field}_lteq") %>
@@ -1,6 +1,6 @@
1
1
  <%= form.label(label) %>
2
2
  <% if model.ransackable_scopes.include?(field) %>
3
- <%= form.datetime_field(field) %>
3
+ <%= form.datetime_field(field, value: form.object.send(field)) %>
4
4
  <% else %>
5
5
  <%= form.datetime_field("#{field}_gteq") %>
6
6
  <%= form.datetime_field("#{field}_lteq") %>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdministrateRansack
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.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.3.0
4
+ version: 0.3.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: 2021-05-19 00:00:00.000000000 Z
11
+ date: 2021-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate