effective_datatables 4.10.0 → 4.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -0
  3. data/app/controllers/effective/datatables_controller.rb +2 -0
  4. data/app/helpers/effective_datatables_controller_helper.rb +2 -0
  5. data/app/helpers/effective_datatables_helper.rb +3 -0
  6. data/app/helpers/effective_datatables_private_helper.rb +11 -9
  7. data/app/models/effective/datatable.rb +3 -1
  8. data/app/models/effective/datatable_column.rb +2 -0
  9. data/app/models/effective/datatable_column_tool.rb +2 -0
  10. data/app/models/effective/datatable_dsl_tool.rb +2 -0
  11. data/app/models/effective/datatable_value_tool.rb +2 -0
  12. data/app/models/effective/effective_datatable/attributes.rb +20 -0
  13. data/app/models/effective/effective_datatable/collection.rb +3 -1
  14. data/app/models/effective/effective_datatable/compute.rb +2 -0
  15. data/app/models/effective/effective_datatable/cookie.rb +2 -0
  16. data/app/models/effective/effective_datatable/csv.rb +2 -0
  17. data/app/models/effective/effective_datatable/dsl/bulk_actions.rb +2 -0
  18. data/app/models/effective/effective_datatable/dsl/charts.rb +2 -0
  19. data/app/models/effective/effective_datatable/dsl/datatable.rb +2 -0
  20. data/app/models/effective/effective_datatable/dsl/filters.rb +2 -0
  21. data/app/models/effective/effective_datatable/dsl.rb +5 -3
  22. data/app/models/effective/effective_datatable/format.rb +6 -0
  23. data/app/models/effective/effective_datatable/hooks.rb +2 -0
  24. data/app/models/effective/effective_datatable/params.rb +2 -0
  25. data/app/models/effective/effective_datatable/resource.rb +2 -0
  26. data/app/models/effective/effective_datatable/state.rb +3 -1
  27. data/lib/effective_datatables/version.rb +1 -1
  28. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 173cdec1d403c8203a7f3d3701104a76d7fd8fb04843c4989180b351b5096264
4
- data.tar.gz: 70da4dcc029e6f7ac2a2f0d7f896734c4036eea227dfd5ecb6354f1efa59f531
3
+ metadata.gz: c52636b5c1ed7d99254c4a3ffeac60a3e85edb190ca2321783f75ad6a5824298
4
+ data.tar.gz: 6c7681d656c2903bb55601b0168bf9973c17dee21f0118030dcb534e83d3ade7
5
5
  SHA512:
6
- metadata.gz: 474ead17fcde2196a4bdf06cdfa02c9d23e1dc4345126d79bcdf4fa3aa9785a358cce6d54a062862f17ec33c618a908db703a1eaa94e847a87df42dfe738b816
7
- data.tar.gz: 55570bbe0d91f0bcdb24d818368a3a4dce9be6ffc0d7a99327121d8204df62a56b6eecc61a1bbbb6bb89b1feff5e4ea6d293497bb571ffff640331f14076d8b2
6
+ metadata.gz: 1e792d9737426b30211fd7e0810f8021d404149be1b47587c49799fa0090e41529a52a2736d07a7a8b593d8d325d325f00f2613372c40eb7cf08ee7759f553a7
7
+ data.tar.gz: 21da5721c55fe36fe9c232cc045e8b6f1ba72a13d7f275e03ed1dc8c7eac952f4d13cbcf9b4b081ddc05b70e508cc6ecf61d35259e17f1c65089d956b9457c52
data/README.md CHANGED
@@ -605,6 +605,12 @@ Any `data-remote` actions will be hijacked and performed as inline ajax by datat
605
605
 
606
606
  If you'd like to opt-out of this behavior, use `actions_col(inline: false)` or add `data-inline: false` to your action link.
607
607
 
608
+ If the automatic actions_col aren't being displayed, try setting the namespace directly when calling the table
609
+
610
+ ```
611
+ MyApp::UsersTable.new(namespace: :my_app)
612
+ ```
613
+
608
614
  ## length
609
615
 
610
616
  Sets the default number of rows per page. Valid lengths are `5`, `10`, `25`, `50`, `100`, `250`, `500`, `:all`
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'csv'
2
4
 
3
5
  module Effective
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # These are expected to be called by a developer. They are part of the datatables DSL.
2
4
  module EffectiveDatatablesControllerHelper
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # These are expected to be called by a developer. They are part of the datatables DSL.
2
4
  module EffectiveDatatablesHelper
3
5
  def render_datatable(datatable, input_js: {}, buttons: true, charts: true, download: nil, entries: true, filters: true, inline: false, namespace: nil, pagination: true, search: true, simple: false, sort: true)
@@ -60,6 +62,7 @@ module EffectiveDatatablesHelper
60
62
  'inline' => inline.to_s,
61
63
  'language' => EffectiveDatatables.language(I18n.locale),
62
64
  'options' => input_js.to_json,
65
+ 'reorder' => datatable.reorder?.to_s,
63
66
  'reorder-index' => (datatable.columns[:_reorder][:index] if datatable.reorder?).to_s,
64
67
  'simple' => simple.to_s,
65
68
  'spinner' => icon('spinner'), # effective_bootstrap
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # These aren't expected to be called by a developer. They are internal methods.
2
4
  module EffectiveDatatablesPrivateHelper
3
5
 
@@ -33,7 +35,7 @@ module EffectiveDatatablesPrivateHelper
33
35
  action = { action: :new, class: ['btn', column[:btn_class].presence].compact.join(' '), 'data-remote': true }
34
36
 
35
37
  if column[:actions][:new].kind_of?(Hash) # This might be active_record_array_collection?
36
- action.merge!(column[:actions][:new])
38
+ actions = action.merge(column[:actions][:new])
37
39
 
38
40
  effective_resource = (datatable.effective_resource || datatable.fallback_effective_resource)
39
41
  klass = (column[:actions][:new][:klass] || effective_resource&.klass || datatable.collection_class)
@@ -67,13 +69,13 @@ module EffectiveDatatablesPrivateHelper
67
69
  return if opts[:search] == false
68
70
 
69
71
  # Build the search
70
- @_effective_datatables_form_builder || effective_form_with(scope: :datatable_search, url: '#') { |f| @_effective_datatables_form_builder = f }
72
+ @_effective_datatables_form_builder || effective_form_with(scope: 'datatable_search', url: '#') { |f| @_effective_datatables_form_builder = f }
71
73
  form = @_effective_datatables_form_builder
72
74
 
73
75
  collection = opts[:search].delete(:collection)
74
76
  value = datatable.state[:search][name]
75
77
 
76
- options = opts[:search].merge!(
78
+ options = opts[:search].merge(
77
79
  name: nil,
78
80
  feedback: false,
79
81
  label: false,
@@ -87,20 +89,20 @@ module EffectiveDatatablesPrivateHelper
87
89
  when :string, :text, :number
88
90
  form.text_field name, options
89
91
  when :date, :datetime
90
- form.date_field name, options.reverse_merge!(
92
+ form.date_field name, options.reverse_merge(
91
93
  date_linked: false, prepend: false, input_js: { useStrict: true, keepInvalid: true }
92
94
  )
93
95
  when :time
94
- form.time_field name, options.reverse_merge!(
96
+ form.time_field name, options.reverse_merge(
95
97
  date_linked: false, prepend: false, input_js: { useStrict: false, keepInvalid: true }
96
98
  )
97
99
  when :select, :boolean
98
- options[:input_js] = (options[:input_js] || {}).reverse_merge!(placeholder: '')
100
+ options[:input_js] = (options[:input_js] || {}).reverse_merge(placeholder: '')
99
101
 
100
102
  form.select name, collection, options
101
103
  when :bulk_actions
102
104
  options[:data]['role'] = 'bulk-actions'
103
- form.check_box name, options.merge!(label: ' ')
105
+ form.check_box name, options.merge(label: ' ')
104
106
  end
105
107
  end
106
108
 
@@ -130,7 +132,7 @@ module EffectiveDatatablesPrivateHelper
130
132
  placeholder: (opts[:label] || name.to_s.titleize),
131
133
  value: value,
132
134
  wrapper: { class: 'form-group col-auto'}
133
- }.merge!(opts.except(:as, :collection, :parse, :value))
135
+ }.merge(opts.except(:as, :collection, :parse, :value))
134
136
 
135
137
  options[:name] = '' unless datatable._filters_form_required?
136
138
 
@@ -162,7 +164,7 @@ module EffectiveDatatablesPrivateHelper
162
164
  label: false,
163
165
  required: false,
164
166
  wrapper: { class: 'form-group col-auto'}
165
- }.merge!(opts.except(:checked, :value))
167
+ }.merge(opts.except(:checked, :value))
166
168
 
167
169
  form.radios :scope, collection, options
168
170
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  class Datatable
3
5
  attr_reader :attributes # Anything that we initialize our table with. That's it. Can't be changed by state.
@@ -40,7 +42,7 @@ module Effective
40
42
  def initialize(view = nil, attributes = nil)
41
43
  (attributes = view; view = nil) if view.kind_of?(Hash)
42
44
 
43
- @attributes = (attributes || {})
45
+ @attributes = initial_attributes(attributes)
44
46
  @state = initial_state
45
47
 
46
48
  @_aggregates = {}
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # In practice this is just a regular hash with the aggregate, format, search, sort do syntax that saves a block
2
4
  module Effective
3
5
  class DatatableColumn
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  class DatatableColumnTool
3
5
  attr_reader :datatable
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
 
3
5
  class DatatableDslTool
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  # The collection is an Array of Arrays
3
5
  class DatatableValueTool
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Attributes
@@ -15,6 +17,24 @@ module Effective
15
17
  @attributes[:namespace] ||= view.controller_path.split('/')[0...-1].join('/')
16
18
  end
17
19
 
20
+ # Polymorphic shorthand attributes.
21
+ # If you pass resource: User(1), it sets resource_id: 1, resource_type: 'User'
22
+ def initial_attributes(attributes)
23
+ return {} if attributes.blank?
24
+
25
+ resources = attributes.select { |k, v| v.kind_of?(ActiveRecord::Base) }
26
+ return attributes if resources.blank?
27
+
28
+ retval = attributes.except(*resources.keys)
29
+
30
+ resources.each do |k, resource|
31
+ retval["#{k}_id".to_sym] = resource.id
32
+ retval["#{k}_type".to_sym] = resource.class.name
33
+ end
34
+
35
+ retval
36
+ end
37
+
18
38
  end
19
39
  end
20
40
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Collection
@@ -34,7 +36,7 @@ module Effective
34
36
  raise 'No collection defined. Please add a collection with collection do ... end' if collection.nil?
35
37
 
36
38
  @collection_class = (collection.respond_to?(:klass) ? collection.klass : self.class)
37
-
39
+
38
40
  @active_record_collection = (collection.ancestors.include?(ActiveRecord::Base) rescue false)
39
41
  @active_record_array_collection = collection.kind_of?(Array) && collection.present? && collection.first.kind_of?(ActiveRecord::Base)
40
42
  @array_collection = collection.kind_of?(Array) && (collection.blank? || collection.first.kind_of?(Array))
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Compute
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Cookie
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'csv'
2
4
 
3
5
  module Effective
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Dsl
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Dsl
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Dsl
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Dsl
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Dsl
@@ -11,11 +13,11 @@ module Effective
11
13
  end
12
14
 
13
15
  def collection(apply_belongs_to: true, apply_scope: true, &block)
14
- define_method('initialize_collection') {
16
+ define_method('initialize_collection') {
15
17
  self._collection_apply_belongs_to = apply_belongs_to
16
18
  self._collection_apply_scope = apply_scope
17
-
18
- self._collection = dsl_tool.instance_exec(&block)
19
+
20
+ self._collection = dsl_tool.instance_exec(&block)
19
21
  }
20
22
  end
21
23
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Format
@@ -93,6 +95,10 @@ module Effective
93
95
  return value if value.kind_of?(String)
94
96
  end
95
97
 
98
+ if value.kind_of?(Array) && column[:as] == :string
99
+ return value.map { |v| view.content_tag(:div, format_column(v, column, csv: csv), class: 'col-resource_item') }.join.html_safe
100
+ end
101
+
96
102
  case column[:as]
97
103
  when :actions
98
104
  raise("please use actions_col instead of col(#{name}, as: :actions)")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Hooks
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Params
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module Resource
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Effective
2
4
  module EffectiveDatatable
3
5
  module State
@@ -98,7 +100,7 @@ module Effective
98
100
  load_cookie_state! if cookie.present? && cookie[:params] == cookie_state_params
99
101
  load_filter_params!
100
102
  end
101
-
103
+
102
104
  fill_empty_filters!
103
105
  end
104
106
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.10.0'.freeze
2
+ VERSION = '4.10.4'.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.10.0
4
+ version: 4.10.4
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-12-08 00:00:00.000000000 Z
11
+ date: 2022-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails