simple_drilldown 0.9.10 → 0.10.2

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
  SHA256:
3
- metadata.gz: 20b3fbd48f5942a10b5ffa459c1c9c900f8275d800eb52819945a7aacda37440
4
- data.tar.gz: cf384149ace94850f19310210d4cc0a278b7dde606753afbe5e43dfd5600e88d
3
+ metadata.gz: 4d8d435e92abad75f581cab051616487b405d0e399591c2223d40c15679631ba
4
+ data.tar.gz: b1576d561bc76f1b9f32055ffdb078c608ecb6888754659f67c2c33b3ed2c2fc
5
5
  SHA512:
6
- metadata.gz: c9e55d9444a72c13d3fde5ac7b58f60941299ae15d45fdcfda1dd0b4db385df99b5fbdf36570131328f007da3896a33d0caa26c411c0295cf499279bda5a3e22
7
- data.tar.gz: f0f6794cd72544eca752af71dcaae8f153de7674424e0eebe7f99f34f453edf1f32caf1fa6b198f41d9b49948d0a7513b5940a9c9177014e77d08ea08d84a6bb
6
+ metadata.gz: e60320131e2ecacb83020b4f26d1c1e890cb4f569687a41b237f39dece5b19a6aa04e34ad596fc9eb03ebd9fa9fa347ef72e9adf54212df688e028dbc4f5ef8d
7
+ data.tar.gz: e6bfc5405cb576cf76367529ebec4c8080d8eeda6ebfa2021f4b9b18981ffab24eec385af90b40b3c94a5b7eb3edbb5f98ca946e62758ae80ef3c5929d3b7b2b
@@ -6,7 +6,7 @@
6
6
  </style>
7
7
 
8
8
  <% @transaction_fields.each do | field | %>
9
- <%=form.label "fields[#{field}]", t(field, default: :"attributes.#{field}"), :class => "field_label" %>
10
- <%=form.check_box :fields, :id => "search_fields[#{field}]", :name => "search[fields][#{field}]", :checked => @search.fields.include?(field) %>
9
+ <%=form.label "fields[#{field}]", t(field, default: [:"attributes.#{field}", field.humanize]), class: "field_label" %>
10
+ <%=form.check_box :fields, id: "search_fields[#{field}]", name: "search[fields][#{field}]", checked: @search.fields.include?(field) %>
11
11
  <br/>
12
12
  <% end %>
@@ -1,7 +1,7 @@
1
1
  <thead>
2
2
  <tr>
3
3
  <% @search.fields.each do |field| %>
4
- <th><%= t field, default: :"attributes.#{field}" %></th>
4
+ <th><%= t field, default: [:"attributes.#{field}", field.humanize] %></th>
5
5
  <% end %>
6
6
  <th>
7
7
  <%= render 'drilldown/export_links', records: records %>
@@ -4,7 +4,7 @@ xml.chart(
4
4
  xAxisName: (@dimensions[0][:pretty_name] || 'Elections').gsub("'", ''), palette: '2',
5
5
  caption: caption, subcaption: subcaption,
6
6
  showNames: '1',
7
- showValues: @result[:rows].size > 15 || @result[:rows][0] && @result[:rows][0][:rows].size > 4 ? 0 : 1,
7
+ showValues: @result[:rows].size > 15 || (@result[:rows][0] && @result[:rows][0][:rows].size > 4) ? 0 : 1,
8
8
  decimals: '0',
9
9
  numberPrefix: '', clustered: '0', exeTime: '1.5', showPlotBorder: '0', zGapPlot: '30',
10
10
  zDepth: '90', divLineEffect: 'emboss', startAngX: '10', endAngX: '18', startAngY: '-10',
@@ -5,7 +5,7 @@ xml.chart(
5
5
  caption: caption, subcaption: subcaption,
6
6
  showNames: '1',
7
7
  showValues:
8
- @result[:rows].size > 15 || @result[:rows][0] && @result[:rows][0][:rows].size > 4 ? 0 : 1,
8
+ @result[:rows].size > 15 || (@result[:rows][0] && @result[:rows][0][:rows].size > 4) ? 0 : 1,
9
9
  decimals: '0',
10
10
  numberPrefix: '', clustered: '0', exeTime: '1.5', showPlotBorder: '0', zGapPlot: '30',
11
11
  zDepth: '90', divLineEffect: 'emboss', startAngX: '10', endAngX: '18', startAngY: '-10',
@@ -11,7 +11,7 @@ def excel_summary_row_xlsx(sheet, result, parent_result = nil, dimension = 0, he
11
11
  else
12
12
  headers + [{
13
13
  value: result[:value],
14
- display_row_count: result[:nodes] + result[:row_count] * (@search.list ? 1 : 0)
14
+ display_row_count: result[:nodes] + (result[:row_count] * (@search.list ? 1 : 0))
15
15
  }]
16
16
  end
17
17
  else
@@ -36,9 +36,7 @@ module SimpleDrilldown
36
36
  # No default target class found
37
37
  end
38
38
  end
39
- return unless base.c_target_class.try :paranoid?
40
-
41
- base.c_base_condition = "#{base.c_target_class.table_name}.deleted_at IS NULL"
39
+ base.update_base_condition
42
40
  end
43
41
 
44
42
  def base_condition(base_condition)
@@ -63,6 +61,7 @@ module SimpleDrilldown
63
61
 
64
62
  def target_class(target_class)
65
63
  self.c_target_class = target_class
64
+ update_base_condition
66
65
  end
67
66
 
68
67
  def select(select)
@@ -148,25 +147,18 @@ module SimpleDrilldown
148
147
 
149
148
  def legal_values_for(field, preserve_filter = false)
150
149
  lambda do |search|
151
- my_filter = search.filter.dup
152
- my_filter.delete(field.to_s) unless preserve_filter
153
- filter_conditions, _t, includes = make_conditions(my_filter)
150
+ filter = search.filter.dup
151
+ filter.delete(field.to_s) unless preserve_filter
152
+ filter_conditions, _t, includes = make_conditions(filter)
154
153
  dimension_def = c_dimension_defs[field.to_s]
155
154
  result_sets = dimension_def[:queries].map do |query|
156
- if query[:includes]
157
- if query[:includes].is_a?(Array)
158
- includes += query[:includes]
159
- else
160
- includes << query[:includes]
161
- end
162
- includes.uniq!
163
- end
155
+ includes = merge_includes(includes, query[:includes]) if query[:includes]
164
156
  rows_query = c_target_class.unscoped.where(c_base_condition)
165
157
  .select("#{query[:select]} AS value")
166
158
  .joins(make_join([], c_target_class.name.underscore.to_sym, includes))
167
159
  .order('value')
168
160
  .group(:value)
169
- # rows_query = rows_query.without_deleted if c_target_class.try :paranoid?
161
+ rows_query = rows_query.without_deleted if c_target_class.try :paranoid?
170
162
  rows_query = rows_query.where(filter_conditions) if filter_conditions
171
163
  rows_query = rows_query.where(query[:where]) if query[:where]
172
164
  rows = rows_query.to_a
@@ -275,8 +267,8 @@ module SimpleDrilldown
275
267
  fk_col = ass.options[:foreign_key] || "#{model}_id"
276
268
  sql = +"LEFT JOIN #{include_table} #{include_alias} ON #{include_alias}.#{fk_col} = #{model_table}.id"
277
269
  sql << " AND #{include_alias}.deleted_at IS NULL" if ass.klass.paranoid?
278
- if ass.scope && (ass_order = ScopeHolder.new(ass.scope).to_s)
279
- ass_order = ass_order.sub(/ DESC\s*$/i, '')
270
+ if ass.scope && (base_ass_order = ScopeHolder.new(ass.scope).to_s)
271
+ /^(?<ass_order>\S*)(?<ass_order_desc>\s+DESC)?/i =~ base_ass_order
280
272
  ass_order_prefixed = ass_order.dup
281
273
  ActiveRecord::Base.connection.columns(include_table).map(&:name).each do |cname|
282
274
  ass_order_prefixed.gsub!(/\b#{cname}\b/, "#{include_alias}.#{cname}")
@@ -284,10 +276,10 @@ module SimpleDrilldown
284
276
  paranoid_clause = 'AND t2.deleted_at IS NULL' if ass.klass.paranoid?
285
277
  # FIXME(uwe): Should we add "where" from the ScopeHolder here as well?
286
278
  # Ref: SimpleDrilldown::Changes#changes_for
287
- min_query = <<~SQL
288
- SELECT MIN(#{ass_order}) FROM #{include_table} t2 WHERE t2.#{fk_col} = #{model_table}.id #{paranoid_clause}
279
+ aggregate_query = <<~SQL
280
+ SELECT #{ass_order_desc ? :MAX : :MIN}(#{ass_order}) FROM #{include_table} t2 WHERE t2.#{fk_col} = #{model_table}.id #{paranoid_clause}
289
281
  SQL
290
- sql << " AND #{ass_order_prefixed} = (#{min_query})"
282
+ sql << " AND #{ass_order_prefixed} = (#{aggregate_query})"
291
283
  end
292
284
  sql
293
285
  else
@@ -301,6 +293,51 @@ module SimpleDrilldown
301
293
  raise "Unknown join class: #{include.inspect}"
302
294
  end
303
295
  end
296
+
297
+ def merge_includes(*args)
298
+ hash = hash_includes(*args)
299
+ result = hash.dup.map do |k, v|
300
+ if v.blank?
301
+ hash.delete(k)
302
+ k
303
+ end
304
+ end.compact
305
+ result << hash unless hash.blank?
306
+ case result.size
307
+ when 0
308
+ nil
309
+ when 1
310
+ result[0]
311
+ else
312
+ result
313
+ end
314
+ end
315
+
316
+ def hash_includes(*args)
317
+ args.inject({}) do |h, inc|
318
+ case inc
319
+ when Array
320
+ inc.each do |v|
321
+ h = hash_includes(h, v)
322
+ end
323
+ when Hash
324
+ inc.each do |k, v|
325
+ h[k] = merge_includes(h[k], v)
326
+ end
327
+ when NilClass, FalseClass
328
+ # Leave as it is
329
+ when String, Symbol
330
+ h[inc] ||= []
331
+ else
332
+ raise "Unknown include type: #{inc.inspect}"
333
+ end
334
+ h
335
+ end
336
+ end
337
+
338
+ def update_base_condition
339
+ self.c_base_condition = "#{c_target_class.table_name}.deleted_at IS NULL" if c_target_class.try :paranoid?
340
+ end
304
341
  end
305
342
 
306
343
  def initialize
@@ -535,18 +572,18 @@ module SimpleDrilldown
535
572
  def populate_list(conditions, includes, result, values)
536
573
  return result[:rows].each { |r| populate_list(conditions, includes, r, values + [r[:value]]) } if result[:rows]
537
574
 
538
- list_includes = merge_includes(includes, c_list_includes)
575
+ list_includes = self.class.merge_includes(includes, c_list_includes)
539
576
  @search.fields.each do |field|
540
577
  field_def = c_fields[field.to_sym]
541
578
  raise "Field definition missing for: #{field.inspect}" unless field_def
542
579
 
543
580
  field_includes = field_def[:include]
544
- list_includes = merge_includes(list_includes, field_includes) if field_includes
581
+ list_includes = self.class.merge_includes(list_includes, field_includes) if field_includes
545
582
  end
546
583
  if @search.list_change_times
547
584
  @history_fields.each do |f|
548
585
  if @search.fields.include? f
549
- list_includes = merge_includes(list_includes, assignment: { order: :"#{f}_changes" })
586
+ list_includes = self.class.merge_includes(list_includes, assignment: { order: :"#{f}_changes" })
550
587
  end
551
588
  end
552
589
  end
@@ -557,47 +594,6 @@ module SimpleDrilldown
557
594
  result[:records] = base_query.to_a
558
595
  end
559
596
 
560
- def merge_includes(*args)
561
- hash = hash_includes(*args)
562
- result = hash.dup.map do |k, v|
563
- if v.blank?
564
- hash.delete(k)
565
- k
566
- end
567
- end.compact
568
- result << hash unless hash.blank?
569
- case result.size
570
- when 0
571
- nil
572
- when 1
573
- result[0]
574
- else
575
- result
576
- end
577
- end
578
-
579
- def hash_includes(*args)
580
- args.inject({}) do |h, inc|
581
- case inc
582
- when Array
583
- inc.each do |v|
584
- h = hash_includes(h, v)
585
- end
586
- when Hash
587
- inc.each do |k, v|
588
- h[k] = merge_includes(h[k], v)
589
- end
590
- when NilClass, FalseClass
591
- # Leave as it is
592
- when String, Symbol
593
- h[inc] ||= []
594
- else
595
- raise "Unknown include type: #{inc.inspect}"
596
- end
597
- h
598
- end
599
- end
600
-
601
597
  def list_conditions(conditions, values)
602
598
  conditions ||= ['']
603
599
 
@@ -31,7 +31,7 @@ module SimpleDrilldown
31
31
  if result[:rows]
32
32
  sub_headers = headers + [{
33
33
  value: result[:value],
34
- display_row_count: result[:nodes] + result[:row_count] * (@search.list ? 1 : 0)
34
+ display_row_count: result[:nodes] + (result[:row_count] * (@search.list ? 1 : 0))
35
35
  }]
36
36
  significant_rows = result[:rows].reject { |r| r[:row_count].zero? }
37
37
  significant_rows.each_with_index do |r, i|
@@ -62,7 +62,7 @@ module SimpleDrilldown
62
62
  else
63
63
  headers + [{
64
64
  value: result[:value],
65
- display_row_count: result[:nodes] + result[:row_count] * (@search.list ? 1 : 0)
65
+ display_row_count: result[:nodes] + (result[:row_count] * (@search.list ? 1 : 0))
66
66
  }]
67
67
  end
68
68
  else
@@ -47,7 +47,7 @@ module SimpleDrilldown
47
47
  attributes = attributes_or_search
48
48
  @default_fields = default_fields
49
49
  @default_select_value = default_select_value
50
- @dimensions = attributes && attributes[:dimensions] || []
50
+ @dimensions = (attributes && attributes[:dimensions]) || []
51
51
  @dimensions.delete_if(&:empty?)
52
52
  @filter = attributes && attributes[:filter] ? attributes[:filter] : {}
53
53
  @filter.keys.dup.each { |k| @filter[k] = Array(@filter[k]) }
@@ -1,3 +1,3 @@
1
1
  module SimpleDrilldown
2
- VERSION = '0.9.10'
2
+ VERSION = '0.10.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_drilldown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.10
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uwe Kubosch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-16 00:00:00.000000000 Z
11
+ date: 2021-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caxlsx_rails
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  - !ruby/object:Gem::Version
171
171
  version: '0'
172
172
  requirements: []
173
- rubygems_version: 3.2.15
173
+ rubygems_version: 3.2.22
174
174
  signing_key:
175
175
  specification_version: 4
176
176
  summary: Simple data warehouse and drilldown.