administrate_ransack 0.1.6 → 0.1.8

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: a078f88d2e79c5adbdc16067e6e89f596070d78bac034679683f4df009e726e1
4
- data.tar.gz: 404b723fb74cc7bd4bc2906ed1519afbca0e3f826cddc1ca7a8f6dfa31c19533
3
+ metadata.gz: 5a7c16d4d10426a6a7bb94830b2bbd367d62bbf831ef82f4765113543f36c42c
4
+ data.tar.gz: cea19beb75eea4520d151b94fe77ae59c7a52ba57d8deb76024b7f0ac3c8b23f
5
5
  SHA512:
6
- metadata.gz: 1f61aa1ad07e32e11817999360dd28b99b0172d4c9b42eeff3241412681c0f78c31396cbe2f1c64b7a32692b8cb400269ed30a0e2e793e23492dfc0a7973bba4
7
- data.tar.gz: dcbdcfccf39362122f7c4c745210e56d1023015050c48249c997df3fc0adb1de54ed612cb69bb0c7015ca973c19d3630cd27e290022c32e2316bfe6308518bee
6
+ metadata.gz: bd68e8ecbd7de43319e8f8d5339f7e89a4f4d1b7538c2ac18fe8ce83ed03562685885b4a952a8342e60ba9298b879d384ef648e6d3cbda44cca08fcbd19eccd1
7
+ data.tar.gz: 79e543067086971a5149a919bfad069d9dae57aab5a3f670337f484249fac21a83c216311acd4f95cbedc725a0804d8283b08a9b40d0ed2799e8d5ba4c6525a2
data/README.md CHANGED
@@ -38,6 +38,18 @@ end
38
38
  sort_link(@ransack_results, attr_name) do
39
39
  # ...
40
40
  ```
41
+ - 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
+ + This gem checks if `flatpickr` function is available in the global scope and applies it to the `datetime-local` filter inputs;
43
+ + you can include the library using your application assets or via CDN, ex. adding to **app/views/layouts/admin/application.html.erb**:
44
+ ```html
45
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr@4.5.7/dist/flatpickr.min.css">
46
+ <script src="https://cdn.jsdelivr.net/npm/flatpickr@4.5.7/dist/flatpickr.min.js"></script>
47
+
48
+ <script>
49
+ // optionally change the flatpikr options:
50
+ window.flatpickr_filters_options = { dateFormat: "Y-m-d" };
51
+ </script>
52
+ ```
41
53
 
42
54
  ## Customizations
43
55
  - Allow only some fields for the filters in the index view:
@@ -1,3 +1,15 @@
1
+ <% content_for :javascript do %>
2
+ <script>
3
+ document.addEventListener('DOMContentLoaded', (_event) => {
4
+ if(typeof window.flatpickr === 'function') {
5
+ var options = window.flatpickr_filters_options;
6
+ if(typeof options !== 'object') options = { enableTime: true };
7
+ window.flatpickr('.filter [type="datetime-local"]', options);
8
+ }
9
+ });
10
+ </script>
11
+ <% end %>
12
+
1
13
  <% attribute_labels ||= {} %>
2
14
  <%= search_form_for [:admin, @ransack_results], html: { 'data-administrate-ransack-filters': '1' } do |f| %>
3
15
  <div class="filters">
@@ -12,32 +24,32 @@
12
24
  <% if association %>
13
25
  <% label = association.klass.method_defined?(:admin_label) ? :admin_label : :to_s %>
14
26
  <% collection = association.klass.send(association.klass.respond_to?(:admin_scope) ? :admin_scope : :all) %>
15
- <%= f.label (attribute_labels.include?(field) ? attribute_labels[field] : field) %>
27
+ <%= f.label(attribute_labels.include?(field) ? attribute_labels[field] : field) %>
16
28
  <%= f.collection_select "#{field}_id_eq", collection, :id, label, include_blank: true %>
17
29
  <% end %>
18
30
  <% when 'Administrate::Field::Boolean' %>
19
- <%= f.label (attribute_labels.include?(field) ? attribute_labels[field] : field) %>
31
+ <%= f.label(attribute_labels.include?(field) ? attribute_labels[field] : field) %>
20
32
  <%= f.select "#{field}_eq", [[t('administrate_ransack.filters.no'), false], [t('administrate_ransack.filters.yes'), true]], include_blank: true %>
21
33
  <% when 'Administrate::Field::Date' %>
22
- <%= f.label (attribute_labels.include?(field) ? attribute_labels[field] : field) %>
34
+ <%= f.label(attribute_labels.include?(field) ? attribute_labels[field] : field) %>
23
35
  <%= f.date_field "#{field}_gteq" %>
24
36
  <%= f.date_field "#{field}_lteq" %>
25
37
  <% when 'Administrate::Field::DateTime' %>
26
- <%= f.label (attribute_labels.include?(field) ? attribute_labels[field] : field) %>
38
+ <%= f.label(attribute_labels.include?(field) ? attribute_labels[field] : field) %>
27
39
  <%= f.datetime_field "#{field}_gteq" %>
28
40
  <%= f.datetime_field "#{field}_lteq" %>
29
41
  <% when 'Administrate::Field::Email', 'Administrate::Field::String', 'Administrate::Field::Text' %>
30
- <%= f.label (attribute_labels.include?(field) ? attribute_labels[field] : field) %>
42
+ <%= f.label(attribute_labels.include?(field) ? attribute_labels[field] : field) %>
31
43
  <%= f.search_field "#{field}_cont" %>
32
44
  <% when 'Administrate::Field::Number' %>
33
- <%= f.label (attribute_labels.include?(field) ? attribute_labels[field] : field) %>
45
+ <%= f.label(attribute_labels.include?(field) ? attribute_labels[field] : field) %>
34
46
  <%= f.number_field "#{field}_eq" %>
35
47
  <% when 'Administrate::Field::HasMany' %>
36
48
  <% association = @ransack_results.klass.reflections[field.to_s] %>
37
49
  <% if association %>
38
50
  <% label = association.klass.method_defined?(:admin_label) ? :admin_label : :to_s %>
39
51
  <% collection = association.klass.send(association.klass.respond_to?(:admin_scope) ? :admin_scope : :all) %>
40
- <%= f.label (attribute_labels.include?(field) ? attribute_labels[field] : field) %>
52
+ <%= f.label(attribute_labels.include?(field) ? attribute_labels[field] : field) %>
41
53
  <%= f.collection_check_boxes "#{field}_id_in", collection, :id, label do |b| %>
42
54
  <%= b.label do %>
43
55
  <%= b.check_box %>
@@ -46,12 +58,13 @@
46
58
  <% end %>
47
59
  <% end %>
48
60
  <% when 'Administrate::Field::Select' %>
49
- <%= f.label (attribute_labels.include?(field) ? attribute_labels[field] : field) %>
61
+ <%= f.label(attribute_labels.include?(field) ? attribute_labels[field] : field) %>
50
62
  <%= f.select "#{field}_eq", type.options[:collection], include_blank: true %>
63
+ <% else %>
64
+ <!-- unsupported Field::HasOne -->
65
+ <!-- unsupported Field::Polymorphic -->
66
+ <!-- unsupported Field::Password -->
51
67
  <% end %>
52
- <%# unsupported Field::HasOne %>
53
- <%# unsupported Field::Polymorphic %>
54
- <%# unsupported Field::Password %>
55
68
  </div>
56
69
  <% end %>
57
70
  </div>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdministrateRansack
4
- VERSION = '0.1.6'
4
+ VERSION = '0.1.8'
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.6
4
+ version: 0.1.8
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-03-24 00:00:00.000000000 Z
11
+ date: 2021-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate
@@ -227,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0'
229
229
  requirements: []
230
- rubygems_version: 3.1.4
230
+ rubygems_version: 3.0.3
231
231
  signing_key:
232
232
  specification_version: 4
233
233
  summary: Administrate Ransack plugin