active_list 6.9.4 → 6.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b860bd10a1b420c93a9c97b1b80b98b350928b1
4
- data.tar.gz: abf875e4b6fea99f161ed9cf39507cf6c7d33358
3
+ metadata.gz: 5baaa0da5fd9dd52b02bc136ea12da6ebe1ae498
4
+ data.tar.gz: b4b7bb336a78617923273ff0fae085552a7d8669
5
5
  SHA512:
6
- metadata.gz: ec7e678f2f037d0bd2539a541300a11dc6a7a4e2428d98b7bca6a1bb89d2b83f35cdbeecd5758f5e746c40a6f4de164372f3dadd4363e20f4e53bd9c6623d554
7
- data.tar.gz: 7dd686f77a080a88027a2f82792744e0d53f0e96f07a9fdd57e4847dcb0fbb74914ce2584eb2cb4bb4f52fc404061a2b0a0d06772962df798ca6ce0ebbb7a88d
6
+ metadata.gz: f8bc42dfee4953d3a2b3d260e8afd18ef54a5fd66bb8e4976e5a155897b4c0f1dfa4381f2736f463b0fd8b1270c382342401d63f2059c0048bcc0ab52f2d35a7
7
+ data.tar.gz: e03b4bc03ddfd5f31d5c4a1b90c98920d62021a9f1f9c4ef44feafc234299a6d7e2c0e85231533751de7db6f1f71d0bb62e6dc0bc5685c5f73e42daacfa5b750
@@ -70,7 +70,7 @@ module ActiveList
70
70
  code = "# encoding: utf-8\n"
71
71
  code << "def #{view_method_name}(options={}, &block)\n"
72
72
  code << session_initialization_code.dig
73
- code << renderer.build_table_code.dig
73
+ code << "#{renderer.build_table_code}(options).dig\n"
74
74
  code << "end\n"
75
75
  # code.split("\n").each_with_index{|l, x| puts((x+1).to_s.rjust(4)+": "+l)}
76
76
  unless ::Rails.env.production?
@@ -17,6 +17,7 @@ module ActiveList
17
17
  query_code = class_name.to_s
18
18
  query_code << scope_code if scope_code
19
19
  query_code << ".select(#{select_code})" if select_code
20
+ query_code << ".from(#{from_code})" if from_code
20
21
  query_code << ".where(#{conditions_code})" unless @table.options[:conditions].blank?
21
22
  query_code << ".joins(#{@table.options[:joins].inspect})" unless @table.options[:joins].blank?
22
23
  unless includes_reflections.empty?
@@ -26,8 +27,15 @@ module ActiveList
26
27
  end
27
28
 
28
29
  code = ''
29
- code << "#{var_name(:count)} = #{query_code}.count\n"
30
+ code << "#{query_code}\n"
30
31
 
32
+ code << if @table.options[:count].present?
33
+ "#{var_name(:count)} = #{query_code}.count(#{@table.options[:count].inspect})\n"
34
+ else
35
+ "#{var_name(:count)} = #{query_code}.count\n"
36
+ end
37
+
38
+ query_code << ".group(#{@table.options[:group].inspect})" unless @table.options[:group].blank?
31
39
  query_code << ".reorder(#{var_name(:order)})"
32
40
 
33
41
  if paginate
@@ -111,13 +119,31 @@ module ActiveList
111
119
  code
112
120
  end
113
121
 
122
+ def from_code
123
+ return nil unless @table.options[:from]
124
+ from = @table.options[:from]
125
+ code = ''
126
+ code << '(' + from.gsub(/\s*\n\s*/, ';') + ')'
127
+ code
128
+ end
129
+
114
130
  def select_code
115
131
  return nil unless @table.options[:distinct] || @table.options[:select]
116
132
  code = ''
117
133
  code << 'DISTINCT ' if @table.options[:distinct]
118
- code << "#{@table.model.table_name}.*"
119
134
  if @table.options[:select]
120
- code << @table.options[:select].collect { |k, v| ", #{k[0].to_s + '.' + k[1].to_s} AS #{v}" }.join
135
+ # code << @table.options[:select].collect { |k, v| ", #{k[0].to_s + '.' + k[1].to_s} AS #{v}" }.join
136
+ code << @table.options[:select].collect do |k, v|
137
+ c = if k.is_a? Array
138
+ k[0].to_s + '.' + k[1].to_s
139
+ else
140
+ k
141
+ end
142
+ c += " AS #{v}" unless v.blank?
143
+ c
144
+ end.join(', ')
145
+ else
146
+ code << "#{@table.model.table_name}.*"
121
147
  end
122
148
  ("'" + code + "'").c
123
149
  end
@@ -34,7 +34,7 @@ module ActiveList
34
34
  code
35
35
  end
36
36
 
37
- def build_table_code
37
+ def build_table_code(options = {})
38
38
  record = 'r'
39
39
 
40
40
  # colgroup = columns_definition_code
@@ -51,6 +51,7 @@ module ActiveList
51
51
  code << "if #{var_name(:count)} > 0\n"
52
52
  code << " #{generator.records_variable_name}.each do |#{record}|\n"
53
53
  code << " #{var_name(:attrs)} = {id: 'r' + #{record}.id.to_s}\n"
54
+ code << " #{var_name(:attrs)}['data-' + options[:data].gsub('_', '-')] = #{record}.send(options[:data]) if options[:data]\n"
54
55
  if table.options[:line_class]
55
56
  code << " #{var_name(:attrs)}[:class] = (#{recordify!(table.options[:line_class], record)}).to_s\n"
56
57
  code << " #{var_name(:attrs)}[:class] << ' focus' if params['#{table.name}-id'].to_i == #{record}.id\n"
@@ -179,7 +180,7 @@ module ActiveList
179
180
  currency = :currency if currency.is_a?(TrueClass)
180
181
  # currency = "#{record}.#{currency}".c if currency.is_a?(Symbol)
181
182
  currency = "#{column.record_expr(record)}.#{currency}".c if currency.is_a?(Symbol)
182
- value_code = "(#{value_code}.nil? ? '' : #{value_code}.l(currency: #{currency.inspect}))"
183
+ value_code = "(#{value_code}.nil? || #{value_code}.zero? ? ('#{column.options[:default]}'.present? ? '#{column.options[:default]}' : '') : #{value_code}.l(currency: #{currency.inspect}))"
183
184
  elsif column.datatype == :decimal
184
185
  value_code = "(#{value_code}.nil? ? '' : #{value_code}.l)"
185
186
  elsif column.enumerize?
@@ -1,3 +1,3 @@
1
1
  module ActiveList
2
- VERSION = '6.9.4'.freeze
2
+ VERSION = '6.10.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.9.4
4
+ version: 6.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brice Texier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-06 00:00:00.000000000 Z
11
+ date: 2019-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -228,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  version: '0'
229
229
  requirements: []
230
230
  rubyforge_project:
231
- rubygems_version: 2.5.2
231
+ rubygems_version: 2.6.14
232
232
  signing_key:
233
233
  specification_version: 4
234
234
  summary: Simple interactive tables for Rails app