effective_datatables 4.8.16 → 4.9.3

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: cb1dc8f3ac21b885c37e56552192568b059350efcdcd7bd79784d87d91a4bee3
4
- data.tar.gz: 46094ee0a00e9246b8dde73c2c9ab4f531c84a287f2cd7db7da467cc0dab6d92
3
+ metadata.gz: 4ff0abf72b8f131a02f3ced253e086eae03c145d981e5c266e6cc2c896d811cd
4
+ data.tar.gz: e51004fc66c9801839e7f26027e07c1764e419b67da580250a313b83b6158be8
5
5
  SHA512:
6
- metadata.gz: 51f91cf414121df572748ce03da5732b53011ad113db667b95284276f9ec628ec12ff0f8f614567ab88c770f9fa674059c6b8ca9a1ab1a5701e4dd8dbd509c2f
7
- data.tar.gz: 1fbacd63b25ba9ba0556ccfec605a07ff5a3c6e5ddfc8da6dc723e66bfc4a72cb0d9c97d796a4acdb419e7fa5d1a2c8b8ec760bb4df77dbcee9b79708fce235d
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 url.includes('?')
65
- window.location.assign(url + '&' + $.param({ids: values}))
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
- window.location.assign(url + '?' + $.param({ids: values}))
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.respond_to?(:cookies)
37
+ return unless (view.cookies rescue false)
38
38
 
39
39
  @dt_cookie ||= []
40
40
  @dt_cookie << [cookie_key, cookie_payload]
@@ -24,6 +24,8 @@ module Effective
24
24
  dsl_tool.in_datatables_do_block = true
25
25
  dsl_tool.instance_exec(&block)
26
26
  dsl_tool.in_datatables_do_block = false
27
+
28
+ self.source_location = block.source_location.first if block.respond_to?(:source_location)
27
29
  end
28
30
  end
29
31
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.8.16'.freeze
2
+ VERSION = '4.9.3'.freeze
3
3
  end
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.8.16
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-02-22 00:00:00.000000000 Z
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: sass
70
+ name: sassc
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="