effective_datatables 4.8.16 → 4.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -0
- data/app/assets/javascripts/effective_datatables/bulk_actions.js.coffee +13 -3
- data/app/helpers/effective_datatables_helper.rb +5 -1
- data/app/models/effective/datatable.rb +3 -0
- data/app/models/effective/effective_datatable/cookie.rb +2 -2
- data/app/models/effective/effective_datatable/dsl.rb +2 -0
- data/lib/effective_datatables/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ff0abf72b8f131a02f3ced253e086eae03c145d981e5c266e6cc2c896d811cd
|
4
|
+
data.tar.gz: e51004fc66c9801839e7f26027e07c1764e419b67da580250a313b83b6158be8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94a88b880e49ded7dddbd17fa4fbff3115e266c1fdb5a8550bc7039e14aa7483f73dceedbe6ff60f1ebd3ee8c520c126792970e82345517330ac8962ec1ae856
|
7
|
+
data.tar.gz: d9d8d9257057d8bfca9d38d8be0096b542a4877d452e7b5b33de3743f66d2d7c5cb1e5cf99fec1a8eef3eae15621f30b664f1096000f112ca2bbafe14c71cfbb
|
data/README.md
CHANGED
@@ -197,6 +197,13 @@ class PostsDatatable < Effective::Datatable
|
|
197
197
|
# POSTs to the given url with params[:ids], an Array of ids for all selected rows
|
198
198
|
# These actions are assumed to change the underlying collection
|
199
199
|
bulk_action 'Approve all', bulk_approve_posts_path, data: { confirm: 'Approve all selected posts?' }
|
200
|
+
# GETs to the given url. Pass the ids via cookie, encoded in url, or LocalStorage.
|
201
|
+
# These actions are assumed to redirect the user to some other page.
|
202
|
+
bulk_action 'Action 1 | ids encoded in params', action_1_posts_path, data: { method: :get }
|
203
|
+
|
204
|
+
bulk_action 'Action 2 | ids stored in _ids_ field in local storage', action_2_posts_path, data: { 'payload-mode' => 'local-storage', method: :get }
|
205
|
+
|
206
|
+
bulk_action 'Action 3 | ids stored in _ids_ field in a cookie', action_3_posts_path, data: { 'payload-mode' => 'cookie', method: :get }
|
200
207
|
bulk_action_divider
|
201
208
|
bulk_action 'Destroy all', bulk_destroy_posts_path, data: { confirm: 'Destroy all selected posts?' }
|
202
209
|
end
|
@@ -772,6 +779,12 @@ You can also specify `data-method: :get` to instead make a `GET` request with th
|
|
772
779
|
```ruby
|
773
780
|
bulk_actions do
|
774
781
|
bulk_action 'Approve all', bulk_approve_posts_path, data: { confirm: 'Approve all selected posts?' }
|
782
|
+
|
783
|
+
bulk_action 'Action 1 | ids encoded in params', action_1_posts_path, data: { method: :get }
|
784
|
+
|
785
|
+
bulk_action 'Action 2 | ids stored in _ids_ field in local storage', action_2_posts_path, data: { 'payload-mode' => 'local-storage', method: :get }
|
786
|
+
|
787
|
+
bulk_action 'Action 3 | ids stored in _ids_ field in a cookie', action_3_posts_path, data: { 'payload-mode' => 'cookie', method: :get }
|
775
788
|
end
|
776
789
|
```
|
777
790
|
|
@@ -781,6 +794,9 @@ In your `routes` file:
|
|
781
794
|
resources :posts do
|
782
795
|
collection do
|
783
796
|
post :bulk_approve
|
797
|
+
get :action_1
|
798
|
+
get :action_2
|
799
|
+
get :action_3
|
784
800
|
end
|
785
801
|
end
|
786
802
|
```
|
@@ -799,6 +815,22 @@ def bulk_approve
|
|
799
815
|
render json: { status: 500, message: 'An error occured while approving a post.' }
|
800
816
|
end
|
801
817
|
end
|
818
|
+
|
819
|
+
def action_1
|
820
|
+
@posts = Post.where(id: params[:ids])
|
821
|
+
|
822
|
+
render :some_partial
|
823
|
+
end
|
824
|
+
|
825
|
+
def action_2
|
826
|
+
@posts = Post.where(id: cookies[:ids].split(','))
|
827
|
+
|
828
|
+
render :some_partial
|
829
|
+
end
|
830
|
+
|
831
|
+
def action_3
|
832
|
+
render :some_partial # and get ids via JS: localStorage.getItem('ids');
|
833
|
+
end
|
802
834
|
```
|
803
835
|
|
804
836
|
or if using [effective_resources](https://github.com/code-and-effect/effective_resources):
|
@@ -44,6 +44,8 @@ restoreSelected = ($table, selected) ->
|
|
44
44
|
#### Bulk Action link behaviour
|
45
45
|
$(document).on 'click', '.dataTables_wrapper .buttons-bulk-actions a', (event) ->
|
46
46
|
event.preventDefault() # prevent the click
|
47
|
+
document.cookie = 'ids=; expires = Thu, 01 Jan 1970 00:00:00 GMT'
|
48
|
+
localStorage.removeItem('ids')
|
47
49
|
|
48
50
|
$bulkAction = $(event.currentTarget) # This is a regular <a href=...> tag
|
49
51
|
$wrapper = $bulkAction.closest('.dataTables_wrapper')
|
@@ -54,6 +56,7 @@ $(document).on 'click', '.dataTables_wrapper .buttons-bulk-actions a', (event) -
|
|
54
56
|
url = $bulkAction.attr('href')
|
55
57
|
title = $bulkAction.text()
|
56
58
|
download = $bulkAction.data('bulk-download')
|
59
|
+
payload_mode = $bulkAction.data('payload-mode')
|
57
60
|
token = $table.data('authenticity-token')
|
58
61
|
values = $.map($selected, (input) -> input.getAttribute('value'))
|
59
62
|
method = $bulkAction.data('ajax-method')
|
@@ -61,10 +64,17 @@ $(document).on 'click', '.dataTables_wrapper .buttons-bulk-actions a', (event) -
|
|
61
64
|
return unless url && values
|
62
65
|
|
63
66
|
if method == 'GET'
|
64
|
-
if
|
65
|
-
|
67
|
+
if payload_mode == 'cookie'
|
68
|
+
document.cookie = "ids=#{values}";
|
69
|
+
window.location.assign(url)
|
70
|
+
else if payload_mode == 'local-storage'
|
71
|
+
localStorage.setItem('ids', values);
|
72
|
+
window.location.assign(url)
|
66
73
|
else
|
67
|
-
|
74
|
+
if url.includes('?')
|
75
|
+
window.location.assign(url + '&' + $.param({ids: values}))
|
76
|
+
else
|
77
|
+
window.location.assign(url + '?' + $.param({ids: values}))
|
68
78
|
|
69
79
|
return
|
70
80
|
|
@@ -64,7 +64,7 @@ module EffectiveDatatablesHelper
|
|
64
64
|
}
|
65
65
|
}
|
66
66
|
|
67
|
-
if (charts || filters)
|
67
|
+
retval = if (charts || filters)
|
68
68
|
output = ''.html_safe
|
69
69
|
|
70
70
|
if charts
|
@@ -85,6 +85,10 @@ module EffectiveDatatablesHelper
|
|
85
85
|
locals: { datatable: datatable, effective_datatable_params: effective_datatable_params }
|
86
86
|
)
|
87
87
|
end
|
88
|
+
|
89
|
+
Rails.logger.info(" Rendered datatable #{datatable.class} #{datatable.source_location}")
|
90
|
+
|
91
|
+
retval
|
88
92
|
end
|
89
93
|
|
90
94
|
def render_inline_datatable(datatable)
|
@@ -21,6 +21,9 @@ module Effective
|
|
21
21
|
# The view
|
22
22
|
attr_reader :view
|
23
23
|
|
24
|
+
# Set by DSL so we can track where this datatable is coming from
|
25
|
+
attr_accessor :source_location
|
26
|
+
|
24
27
|
extend Effective::EffectiveDatatable::Dsl
|
25
28
|
|
26
29
|
include Effective::EffectiveDatatable::Attributes
|
@@ -10,7 +10,7 @@ module Effective
|
|
10
10
|
|
11
11
|
def load_cookie!
|
12
12
|
return unless EffectiveDatatables.save_state
|
13
|
-
return unless view.respond_to?(:cookies)
|
13
|
+
return unless (view.cookies rescue false) # Rails 6.1 view doesn't respond_to?(:cookies)
|
14
14
|
|
15
15
|
@dt_cookie = view.cookies.signed['_effective_dt']
|
16
16
|
|
@@ -34,7 +34,7 @@ module Effective
|
|
34
34
|
|
35
35
|
def save_cookie!
|
36
36
|
return unless EffectiveDatatables.save_state
|
37
|
-
return unless view.
|
37
|
+
return unless (view.cookies rescue false)
|
38
38
|
|
39
39
|
@dt_cookie ||= []
|
40
40
|
@dt_cookie << [cookie_key, cookie_payload]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_datatables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: sassc
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|