effective_datatables 4.39.1 → 4.39.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: 92dbd778d7e5b63be5dfedb7137193290c21da8d1b119d7ff92e5c06474dc032
4
- data.tar.gz: f044c7be5c129b36c2f437f7e7acca2fa2cecc1d1aec5e101dfa86e7debbd2d5
3
+ metadata.gz: 12e01bd82fc2bf197109050265f20948617f7b0e57fac56c9d83cdf0469fd080
4
+ data.tar.gz: 043e49461b97e3d496b5556e4c14da0ce72249a6b03108bf66482c003f0e5d54
5
5
  SHA512:
6
- metadata.gz: 79f406c3eb58b786a935addd180a35c9fec5638277aea6f5280fda9f649ec714c07bb9a15fba9e45aadcdff7a7cf128f3d01a651a8af6e70b66f388b35e32097
7
- data.tar.gz: ba94caf90dca5d5f69bf38c6297e5f523cea245b14b17707783a6a3d56f8c41acdeab0bd56da8475efc17e7bb5300ff1883cfa023a2fdb846e7720e5ccb0d85a
6
+ metadata.gz: 7a8c9b8745fcb7a477bff5ab7bc9699303a28edd8d616845f852fe949205c910b6e6e2bc453f7bd6e76105488b9e35cebbf9c42de7d4ca506eaf62777501b2a9
7
+ data.tar.gz: 77cc02b1405a176616ab8780e1afc21ad14f54244ccaadf4aa6575178b73c3bab28e51c4b506ffa1a6f1cf1f9a8263c2cfd2bfec823df352078c8a2c98ad2524
@@ -67,18 +67,19 @@ module Effective
67
67
  EffectiveDatatables.authorize!(self, :update, @resource)
68
68
 
69
69
  attribute = @datatable.columns[:_reorder][:reorder]
70
+ column = @resource.class.arel_table[attribute]
70
71
  old_index = params[:reorder][:old].to_i
71
72
  new_index = params[:reorder][:new].to_i
72
73
 
73
74
  @resource.class.transaction do
74
75
  if new_index > old_index
75
- @datatable.collection.where("#{attribute} > ? AND #{attribute} <= ?", old_index, new_index).update_all("#{attribute} = #{attribute} - 1")
76
+ @datatable.collection.where(column.gt(old_index).and(column.lteq(new_index))).update_all(attribute => column - 1)
76
77
  @resource.update_column(attribute, new_index)
77
78
  @resource.touch
78
79
  end
79
80
 
80
81
  if old_index > new_index
81
- @datatable.collection.where("#{attribute} >= ? AND #{attribute} < ?", new_index, old_index).update_all("#{attribute} = #{attribute} + 1")
82
+ @datatable.collection.where(column.gteq(new_index).and(column.lt(old_index))).update_all(attribute => column + 1)
82
83
  @resource.update_column(attribute, new_index)
83
84
  @resource.touch
84
85
  end
@@ -88,7 +89,7 @@ module Effective
88
89
  rescue Effective::AccessDenied => e
89
90
  render(status: :unauthorized, body: 'Access Denied')
90
91
  rescue Exception => e
91
- render(status: :error, body: 'Unexpected Error')
92
+ render(status: :internal_server_error, body: 'Unexpected Error')
92
93
  end
93
94
 
94
95
  end
@@ -44,8 +44,12 @@ module Effective
44
44
  def order_column(collection, direction, column, sql_column)
45
45
  Rails.logger.info "COLUMN TOOL: order_column #{column.to_s} #{direction} #{sql_column}" if EffectiveDatatables.debug
46
46
 
47
- if column[:sql_as_column]
48
- collection.order(Arel.sql("#{sql_column} #{datatable.effective_resource.sql_direction(direction)}"))
47
+ if column[:as] == :reorder && sql_column == column[:reorder]
48
+ attribute = collection.arel_table[column[:reorder]]
49
+ collection.order(direction.to_s.downcase == 'desc' ? attribute.desc : attribute.asc)
50
+ elsif column[:sql_as_column]
51
+ expression = Arel.sql(sql_column.to_s)
52
+ collection.order(direction.to_s.downcase == 'desc' ? expression.desc : expression.asc)
49
53
  else
50
54
  Effective::Resource.new(collection)
51
55
  .order(column[:name], direction, as: column[:as], sort: column[:sort], sql_column: column[:sql_column], limit: datatable.limit)
@@ -99,12 +103,7 @@ module Effective
99
103
  when Hash
100
104
  count.size # This represents the number of displayed datatable rows, not the sum all groups (which might be more)
101
105
  else
102
- if collection.klass.connection.respond_to?(:unprepared_statement)
103
- collection_sql = collection.klass.connection.unprepared_statement { collection.to_sql }
104
- (collection.klass.connection.exec_query("SELECT COUNT(*) FROM (#{collection_sql}) AS datatables_total_count").rows[0][0] rescue 1)
105
- else
106
- (collection.klass.connection.exec_query("SELECT COUNT(*) FROM (#{collection.to_sql}) AS datatables_total_count").rows[0][0] rescue 1)
107
- end.to_i
106
+ (collection.klass.unscoped.from(collection, :datatables_total_count).count(:all) rescue 1).to_i
108
107
  end
109
108
  end
110
109
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.39.1'.freeze
2
+ VERSION = '4.39.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.39.1
4
+ version: 4.39.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect