effective_datatables 4.7.19 → 4.8.2

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: 618838ca90e9046e4cbd0bb0e7d7a5e73f00b07e58733a81ac07a0a7976524da
4
- data.tar.gz: 8e1c0545b02af85a0c4270f4ab70c1ac1e81b1d3b7ff9438f7562a42e71e661b
3
+ metadata.gz: feffe8acf84566b07ea4c44e130b42b0870287978d1f009af25e1d81da8131db
4
+ data.tar.gz: 223d61e7e3ab0cea75eae0a10660a009cd4894dfb1d256d18fd1fc37f1c164c7
5
5
  SHA512:
6
- metadata.gz: 9a33841f4c1923cfea7b9b28c767df80ca6454c5fe6174a7169ba902a3df3eb60c6437381a9b8b130ef6769f3276f4d35d83744eade5201ec164b819dd7f909e
7
- data.tar.gz: 40f39a4bdc1f0cb9b078be9332c60ece434b85cd31932604592f811c92b12cffd0944bfc1cb397bdc80ef41f1f307de929337e61438e4fe3e6c9a6e5ead4fc5e
6
+ metadata.gz: 505cb075ee12d78a3617eb3f81a8a6c62b31ddf1d443370a3348b5f9c46f1f24ff89fae59ceba428c74c5ecb2afc6da1f16e45b1ad1bb00c1d69b7c3fa118fa1
7
+ data.tar.gz: 21330062f4a3f3dd010a272166cb5a8113eeb6e65a6ad8ff1a89ad831f7252bfa37cdd1273097e800cffc2f496f83b00ad832dfa2e5a99890136a4237bb3a0c5
data/README.md CHANGED
@@ -879,6 +879,10 @@ Create a [Google Chart](https://developers.google.com/chart/interactive/docs/qui
879
879
 
880
880
  No javascript required. Just use the `chart do ... end` block and return an Array of Arrays.
881
881
 
882
+ The first collection, `collection` is the raw results as returned from the `collection do` block.
883
+
884
+ The second collection, `searched_collection` is the results after the table's search columns have been applied, but irregardless of pagination.
885
+
882
886
  ```ruby
883
887
  charts do
884
888
  chart :breakfast, 'BarChart' do |collection|
@@ -894,6 +898,18 @@ charts do
894
898
  [date.strftime('%F'), posts.length]
895
899
  end
896
900
  end
901
+
902
+ chart :posts_per_user, 'ColumnChart' do |collection, searched_collection|
903
+ measured_posts = if search.present?
904
+ ["Posts with #{search.map { |k, v| k.to_s + ' ' + v.to_s }.join(',')}", searched_collection.length]
905
+ else
906
+ ['All Posts', collection.length]
907
+ end
908
+
909
+ [['Posts', 'Count'], measured_posts] +
910
+ searched_collection.group_by(&:user).map { |user, posts| [user.last_name, posts.length] }
911
+ end
912
+
897
913
  end
898
914
  ```
899
915
 
@@ -131,7 +131,7 @@ initializeDataTables = (target) ->
131
131
  if typeof(google) != 'undefined' && typeof(google.visualization) != 'undefined'
132
132
  $.each charts, (name, data) =>
133
133
  $(".effective-datatables-chart[data-name='#{name}']").each (_, obj) =>
134
- chart = new google.visualization[data['type']](obj)
134
+ chart = new google.visualization[data['as']](obj)
135
135
  chart.draw(google.visualization.arrayToDataTable(data['data']), data['options'])
136
136
 
137
137
  # Appends the search html, stored in the column definitions, into each column header
@@ -169,7 +169,15 @@ initializeDataTables = (target) ->
169
169
  return if $input.is(':invalid')
170
170
 
171
171
  table = $input.closest('table.dataTable')
172
- table.DataTable().column("#{$input.data('column-name')}:name").search($input.val()).draw()
172
+
173
+ value = $input.val()
174
+
175
+ if value.startsWith('"') && value.endsWith('"')
176
+ value = value.substring(1, value.length-1)
177
+ else
178
+ value = $.trim(value)
179
+
180
+ table.DataTable().column("#{$input.data('column-name')}:name").search(value).draw()
173
181
 
174
182
  if reorder
175
183
  init_options['rowReorder'] = { selector: 'td.col-_reorder', snapX: true, dataSrc: datatable.data('reorder-index') }
@@ -1,11 +1,32 @@
1
1
  $(document).on 'click', '.dataTables_wrapper a.buttons-reset-search', (event) ->
2
2
  event.preventDefault() # prevent the click
3
3
 
4
+ # Reset the HTML
4
5
  $table = $(event.currentTarget).closest('.dataTables_wrapper').find('table.dataTable').first()
5
6
  $thead = $table.children('thead').first()
6
7
 
7
- $thead.find('input').val('').removeAttr('checked').removeAttr('selected')
8
+ # Reset all inputs
8
9
  $thead.find('select').val('').trigger('change.select2')
9
10
 
10
- $table.DataTable().search('').columns().search('').draw()
11
+ $inputs = $thead.find('input')
12
+ $inputs.val('').removeAttr('checked').removeAttr('selected')
13
+
14
+ # Reset delayedChange
15
+ $.each $inputs, (input) =>
16
+ $input = $(input)
17
+ if ($input.delayedChange.oldVal)
18
+ $input.delayedChange.oldVal = undefined
19
+
20
+ # Reset the datatable
21
+ datatable = $table.DataTable()
22
+
23
+ # Reset search
24
+ datatable.search('').columns().search('')
25
+
26
+ # Reset to default visibility
27
+ $.each $table.data('default-visibility'), (index, visible) =>
28
+ datatable.column(index).visible(visible, false)
29
+
30
+ # Don't pass up the click
31
+ false
11
32
 
@@ -18,7 +18,6 @@
18
18
  clearTimeout(timer);
19
19
  timer = setTimeout(function() {
20
20
  var newVal = element.val();
21
- newVal = $.trim(newVal);
22
21
  if (element.delayedChange.oldVal != newVal) {
23
22
  element.delayedChange.oldVal = newVal;
24
23
  o.onChange.call(this, element);
@@ -162,9 +162,7 @@ div.dataTables_scrollFoot > .dataTables_scrollFootInner > table {
162
162
  text-align: center;
163
163
  }
164
164
  }
165
- table.dataTable.table-sm > thead > tr > th {
166
- padding-right: 20px;
167
- }
165
+
168
166
  table.dataTable.table-sm .sorting:before,
169
167
  table.dataTable.table-sm .sorting_asc:before,
170
168
  table.dataTable.table-sm .sorting_desc:before {
@@ -44,6 +44,7 @@ module EffectiveDatatablesHelper
44
44
  'authenticity-token' => form_authenticity_token,
45
45
  'bulk-actions' => datatable_bulk_actions(datatable),
46
46
  'columns' => datatable_columns(datatable),
47
+ 'default-visibility' => datatable.default_visibility.to_json,
47
48
  'display-length' => datatable.display_length,
48
49
  'display-order' => datatable_display_order(datatable),
49
50
  'display-records' => datatable.to_json[:recordsFiltered],
@@ -149,6 +149,8 @@ module EffectiveDatatablesPrivateHelper
149
149
  elsif as == :boolean
150
150
  collection ||= [true, false].map { |value| [t("effective_datatables.boolean_#{value}"), value] }
151
151
  form.public_send(:select, name, collection, options) # boolean
152
+ elsif as == :string
153
+ form.public_send(:text_field, name, options)
152
154
  elsif form.respond_to?(as)
153
155
  form.public_send(as, name, options) # check_box, text_area
154
156
  else
@@ -33,7 +33,7 @@ module Effective
33
33
  include Effective::EffectiveDatatable::Resource
34
34
  include Effective::EffectiveDatatable::State
35
35
 
36
- def initialize(view = nil, attributes = nil)
36
+ def initialize(view = nil, attributes = nil)
37
37
  (attributes = view; view = nil) if view.kind_of?(Hash)
38
38
 
39
39
  @attributes = (attributes || {})
@@ -49,6 +49,7 @@ module Effective
49
49
 
50
50
  raise 'expected a hash of arguments' unless @attributes.kind_of?(Hash)
51
51
  raise 'collection is defined as a method. Please use the collection do ... end syntax.' unless collection.nil?
52
+
52
53
  self.view = view if view
53
54
  end
54
55
 
@@ -170,6 +171,10 @@ module Effective
170
171
  @fallback_effective_resource ||= Effective::Resource.new('', namespace: controller_namespace)
171
172
  end
172
173
 
174
+ def default_visibility
175
+ columns.values.inject({}) { |h, col| h[col[:index]] = col[:visible]; h }
176
+ end
177
+
173
178
  private
174
179
 
175
180
  def column_tool
@@ -36,6 +36,9 @@ module Effective
36
36
  # Apply value ordering
37
37
  col = value_tool.order(col)
38
38
 
39
+ # Charts too
40
+ @charts_data = chart(collection, col) if _charts.present?
41
+
39
42
  # Apply pagination
40
43
  col = col.kind_of?(Array) ? value_tool.paginate(col) : column_tool.paginate(col)
41
44
 
@@ -48,9 +51,6 @@ module Effective
48
51
  # Compute aggregate data
49
52
  @aggregates_data = aggregate(col) if _aggregates.present?
50
53
 
51
- # Charts too
52
- @charts_data = chart(col) if _charts.present?
53
-
54
54
  # Format all results
55
55
  format(col)
56
56
 
@@ -161,11 +161,11 @@ module Effective
161
161
  end || BLANK
162
162
  end
163
163
 
164
- def chart(collection)
164
+ def chart(collection, searched_collection)
165
165
  _charts.inject({}) do |retval, (name, chart)|
166
166
  retval[name] = {
167
167
  as: chart[:as],
168
- data: dsl_tool.instance_exec(collection, &chart[:compute]),
168
+ data: dsl_tool.instance_exec(collection, searched_collection, &chart[:compute]),
169
169
  name: chart[:name],
170
170
  options: chart[:options]
171
171
  }
@@ -20,7 +20,7 @@ module Effective
20
20
  elsif value != nil
21
21
  Effective::Attribute.new(value).type
22
22
  end
23
- ) || :text
23
+ ) || :string
24
24
 
25
25
  datatable._filters[name.to_sym] = {
26
26
  value: value,
@@ -91,6 +91,8 @@ module Effective
91
91
  opts[:sql_column] = :effective_addresses
92
92
  when :effective_roles
93
93
  opts[:sql_column] = :effective_roles
94
+ when :active_storage
95
+ opts[:sql_column] = :active_storage
94
96
  when :string # This is the fallback
95
97
  # Anything that doesn't belong to the model or the sql table, we assume is a SELECT SUM|AVG|RANK() as fancy
96
98
  opts[:sql_as_column] = true if (effective_resource.table && effective_resource.column(name).blank?)
@@ -137,6 +139,10 @@ module Effective
137
139
  opts[:partial] ||= '/effective/datatables/resource_column'
138
140
  end
139
141
 
142
+ if opts[:as] == :active_storage
143
+ opts[:partial] ||= '/effective/datatables/active_storage_column'
144
+ end
145
+
140
146
  opts[:col_class] = [
141
147
  "col-#{opts[:as]}",
142
148
  "col-#{name.to_s.parameterize}",
@@ -198,7 +198,7 @@ module Effective
198
198
  def parse_filter_value(filter, value)
199
199
  return filter[:parse].call(value) if filter[:parse]
200
200
  return nil if value.blank? && !filter[:required]
201
- Effective::Attribute.new(filter[:value]).parse(value, name: filter[:name])
201
+ Effective::Attribute.new(filter[:as] || filter[:value] || :string).parse(value, name: filter[:name])
202
202
  end
203
203
 
204
204
  def cookie_state_params
@@ -0,0 +1,4 @@
1
+ - Array(resource.public_send(column[:name])).each do |file|
2
+ .col-resource_item
3
+ - title = [file.content_type, number_to_human_size(file.byte_size)].map(&:presence).compact
4
+ = link_to(file.filename, url_for(file), title: title, target: '_blank')
@@ -35,7 +35,7 @@ EffectiveDatatables.setup do |config|
35
35
  config.save_state = true
36
36
 
37
37
  # Configure the _effective_dt cookie.
38
- config.cookie_max_size = 2000 # String size. Final byte size is about 1.5 times bigger, after rails signs it
38
+ config.cookie_max_size = 1500 # String size. Final byte size is about 1.5 times bigger, after rails signs it
39
39
  config.cookie_domain = :all # Should usually be :all
40
40
  config.cookie_tld_length = nil # Leave nil to autodetect, or set to probably 2
41
41
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.7.19'.freeze
2
+ VERSION = '4.8.2'.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.7.19
4
+ version: 4.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-03 00:00:00.000000000 Z
11
+ date: 2020-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -153,6 +153,7 @@ files:
153
153
  - app/models/effective/effective_datatable/params.rb
154
154
  - app/models/effective/effective_datatable/resource.rb
155
155
  - app/models/effective/effective_datatable/state.rb
156
+ - app/views/effective/datatables/_active_storage_column.html.haml
156
157
  - app/views/effective/datatables/_bulk_actions_column.html.haml
157
158
  - app/views/effective/datatables/_bulk_actions_dropdown.html.haml
158
159
  - app/views/effective/datatables/_chart.html.haml
@@ -177,7 +178,7 @@ homepage: https://github.com/code-and-effect/effective_datatables
177
178
  licenses:
178
179
  - MIT
179
180
  metadata: {}
180
- post_install_message:
181
+ post_install_message:
181
182
  rdoc_options: []
182
183
  require_paths:
183
184
  - lib
@@ -192,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
193
  - !ruby/object:Gem::Version
193
194
  version: '0'
194
195
  requirements: []
195
- rubygems_version: 3.0.3
196
- signing_key:
196
+ rubygems_version: 3.1.2
197
+ signing_key:
197
198
  specification_version: 4
198
199
  summary: Uniquely powerful server-side searching, sorting and filtering of any ActiveRecord
199
200
  or Array collection as well as post-rendered content displayed as a frontend jQuery