simple_drilldown 0.9.4 → 0.9.9

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: a9258ecdeb91deb6d4a17a1a23e28f1e0e9cbf243588d9f40e057f93f16c0892
4
- data.tar.gz: 5a6e71f4400c9259fe90a04420372adfd29982bede1aec6968d06050c44de9cf
3
+ metadata.gz: 8e0ff048ca6aef6cfe9f4e3ccc63eb22f7a303c53612bff80afffff62bc4fbc1
4
+ data.tar.gz: fa462127353656e4f3ace83e97ac3c91065a3f0aa1b8a1a32c9429ab755c27ea
5
5
  SHA512:
6
- metadata.gz: c84bcd765bdb3a7fd29a67a2401849ca065505ec888b0691f6a3b3b79cd94ad5db7a8a28a12b575f6ab6675e328209e7aaa0c13b43c52f65fe227312efaf2e41
7
- data.tar.gz: b87a85a90e3843d4deed1aa9725e914622073e77cfdf02db5e771912bd457812a846298f171d4673ee9d6cdcf9154bd661c6a2cd651231503de227fef1422f52
6
+ metadata.gz: 8c4fa801f0dadea11dc6821a750be32af77574f89d28500f867ac5224a45cf0533392630781ebf502e8a9d7726b0f463d3fe178ebab6193275e6024b27042a6f
7
+ data.tar.gz: a820957b4d377ede56478ed6d46bc4622cf43738f5f14601fedff63af6eb4db54fe228e68b35036341f5332c4acd53e591175f436e7267cda980d5e832c225df
@@ -19,7 +19,6 @@ th.header {
19
19
  td {
20
20
  border: 1px solid #dfded2;
21
21
  padding: 2px;
22
- font-size: 10px;
23
22
  }
24
23
 
25
24
  td.numeric {
@@ -2,14 +2,14 @@
2
2
  data =
3
3
  case @dimensions.size
4
4
  when 0
5
- { @result[:value] => @result[:count] }
5
+ { @result[:value] => @result[@search.select_value] }
6
6
  when 1
7
- @result[:rows].map { |r| [@dimensions[0][:label_method] ? @dimensions[0][:label_method].call(r[:value]) : r[:value], r[:count]] }
7
+ @result[:rows].map { |r| [@dimensions[0][:label_method] ? @dimensions[0][:label_method].call(r[:value]) : r[:value], r[@search.select_value]] }
8
8
  when 2
9
9
  @result[:rows].map do |r|
10
10
  {
11
11
  name: r[:value],
12
- data: r[:rows].map { |r2| [r2[:value], r2[:count]] }
12
+ data: r[:rows].map { |r2| [r2[:value], r2[@search.select_value]] }
13
13
  }
14
14
  end
15
15
  when 3
@@ -56,6 +56,22 @@
56
56
  <%= form.radio_button 'display_type', SimpleDrilldown::Search::DisplayType::NONE, { :onChange => 'form.submit()' } %>
57
57
  <%= form.label :display_type_none, t(:none) %>
58
58
 
59
+ <% if controller.c_summary_fields.present? && @search.display_type != SimpleDrilldown::Search::DisplayType::NONE %>
60
+ <div class="text-center">
61
+ <label style="margin-bottom:0;margin-right:1em" for="search_select_value">Value: </label>
62
+ <div class="form-check form-check-inline">
63
+ <%= form.radio_button :select_value, SimpleDrilldown::Search::SelectValue::COUNT, class: "form-check-input", onChange: 'form.submit()' %>
64
+ <label class="form-check-label mr-3" for="search_select_value_count"><%= t(:count) %></label>
65
+ </div>
66
+ <% controller.c_summary_fields.each do |field| %>
67
+ <div class="form-check form-check-inline">
68
+ <%= form.radio_button :select_value, field, class: "form-check-input", onChange: 'form.submit()' %>
69
+ <label class="form-check-label mr-3" for="search_select_value_<%= field %>"><%= t(:field, default: field.to_s.titleize) %></label>
70
+ </div>
71
+ <% end %>
72
+ </div>
73
+ <% end %>
74
+
59
75
  <%= form.check_box :order_by_value, { :onChange => 'form.submit()' } %>
60
76
  <%= form.label :order_by_value, t(:order_by_value) %>
61
77
 
@@ -1,3 +1,4 @@
1
+ <% row_class = dimension > 0 && @dimensions[dimension - 1]&.[](:row_class)&.call(result[:value]) %>
1
2
  <% if new_row -%>
2
3
  <tr class="<%= cycle("odd", "even", :name => "dim#{dimension}") %>">
3
4
  <% ((dimension + 1)..(@dimensions.size)).each { |i| cycle("odd", "even", :name => "dim#{i}") if current_cycle("dim#{i}") != current_cycle("dim#{dimension}") } -%>
@@ -14,5 +15,13 @@
14
15
  (<%= 100 * result[:count] / parent_result[:count] %>%)
15
16
  <% end %>
16
17
  </td>
18
+ <% controller.c_summary_fields.each do |summary_field| %>
19
+ <td class="<%=row_class%>" align="right">
20
+ <%= result[summary_field] %>
21
+ <% if @search.percent && parent_result && parent_result[summary_field] > 0 %>
22
+ (<%= 100 * result[summary_field] / parent_result[summary_field] %>%)
23
+ <% end %>
24
+ </td>
25
+ <% end %>
17
26
  </tr>
18
27
  <% end %>
@@ -1,14 +1,16 @@
1
- <table id="drilldown-summary-table" class="table table-condensed table-bordered">
2
- <thead>
3
- <tr>
4
- <% @dimensions.each do |d| %>
5
- <th><%= h d[:pretty_name] %></th>
6
- <% end %>
7
- <th><%= t controller.c_target_class.table_name.capitalize %></th>
8
- <%= controller.c_summary_fields.map { |l| "<th>#{t(l)}</th>" }.join("\n").html_safe %>
9
- </tr>
10
- </thead>
11
- <tbody>
12
- <%= summary_row(@result) %>
13
- </tbody>
14
- </table>
1
+ <div class="table-responsive">
2
+ <table id="drilldown-summary-table" class="table table-sm table-bordered">
3
+ <thead>
4
+ <tr>
5
+ <% @dimensions.each do |d| %>
6
+ <th><%= h d[:pretty_name] %></th>
7
+ <% end %>
8
+ <th><%= t controller.c_target_class.table_name.capitalize %></th>
9
+ <%= controller.c_summary_fields.map { |l| "<th>#{t(l)}</th>" }.join("\n").html_safe %>
10
+ </tr>
11
+ </thead>
12
+ <tbody>
13
+ <%= summary_row(@result) %>
14
+ </tbody>
15
+ </table>
16
+ </div>
@@ -1,4 +1,12 @@
1
1
  <tr class="summary">
2
2
  <td colspan="<%= @dimensions.size - dimension %>"></td>
3
3
  <td align="right"><%= result[:count] %></td>
4
+ <% controller.c_summary_fields.each do |summary_field| %>
5
+ <td align="right">
6
+ <%= result[summary_field] %>
7
+ <% if @search.percent && parent_result && parent_result[summary_field] > 0 %>
8
+ (<%= 100 * result[summary_field] / parent_result[summary_field] %>%)
9
+ <% end %>
10
+ </td>
11
+ <% end %>
4
12
  </tr>
@@ -12,6 +12,15 @@ class <%= class_name %>DrilldownController < SimpleDrilldown::Controller
12
12
  # How should we count the reords?
13
13
  # select 'count(*) as count'
14
14
 
15
+ # Multiple select values:
16
+ # select <<~SQL
17
+ # COUNT(*) as count,
18
+ # sum(hours) as hours,
19
+ # sum(billable_hours) as billable_hours
20
+ # SQL
21
+ # summary_fields :hours, :billable_hours
22
+ # default_select_value :billable_hours
23
+
15
24
  # When selecting records, what relations should be included for optimization?
16
25
  # Other relations can be included for specific dimensions and fields.
17
26
  # base_includes :user, :comments # TODO(uwe): Read relations from schema?
@@ -58,7 +58,7 @@ module SimpleDrilldown
58
58
  end
59
59
 
60
60
  def default_select_value(default_select_value)
61
- self.c_default_select_value = default_select_value
61
+ self.c_default_select_value = default_select_value.to_sym
62
62
  end
63
63
 
64
64
  def target_class(target_class)
@@ -85,7 +85,15 @@ module SimpleDrilldown
85
85
  self.c_summary_fields = summary_fields.flatten
86
86
  end
87
87
 
88
- def dimension(name, select_expression = name, options = {})
88
+ def dimension(name, select_expression = name.to_s, options = {})
89
+ if select_expression.is_a?(Hash)
90
+ unless options.blank?
91
+ raise "select_expression should be a string: #{select_expression.class}, options: #{options.inspect}"
92
+ end
93
+
94
+ options = select_expression
95
+ select_expression = name.to_s
96
+ end
89
97
  interval = options.delete(:interval)
90
98
  label_method = options.delete(:label_method)
91
99
  legal_values = options.delete(:legal_values) || legal_values_for(name)
@@ -327,16 +335,7 @@ module SimpleDrilldown
327
335
  includes.flatten!
328
336
  includes.keep_if(&:present?).uniq!
329
337
  if @search.order_by_value && @dimensions.size <= 1
330
- order = case @search.select_value
331
- when Search::SelectValue::VOLUME
332
- 'volume DESC'
333
- when Search::SelectValue::VOLUME_COMPENSATED
334
- 'volume_compensated DESC'
335
- when Search::SelectValue::COUNT
336
- 'count DESC'
337
- else
338
- 'count DESC'
339
- end
338
+ order = "#{c_summary_fields.find { |f| f == @search.select_value } || 'count'} DESC"
340
339
  else
341
340
  order = (1..@dimensions.size).map { |i| "value#{i}" }.join(',')
342
341
  order = nil if order.empty?
@@ -89,7 +89,8 @@ module SimpleDrilldown
89
89
  private
90
90
 
91
91
  def caption_txt
92
- "#{controller.c_target_class} #{I18n.t(@search.select_value.downcase)}" +
92
+ "#{controller.c_target_class} #{I18n.t(@search.select_value.downcase,
93
+ default: @search.select_value.to_s.titleize)}" +
93
94
  (@dimensions && @dimensions.any? ? " by #{@dimensions.map { |d| d[:pretty_name] }.join(' and ')}" : '')
94
95
  end
95
96
  end
@@ -14,9 +14,7 @@ module SimpleDrilldown
14
14
  end
15
15
 
16
16
  module SelectValue
17
- COUNT = 'COUNT'
18
- VOLUME = 'VOLUME'
19
- VOLUME_COMPENSATED = 'VOLUME_COMPENSATED'
17
+ COUNT = :count
20
18
  end
21
19
 
22
20
  attr_reader :dimensions, :display_type, :fields, :filter, :list_change_times, :order_by_value,
@@ -62,7 +60,7 @@ module SimpleDrilldown
62
60
  @display_type = DisplayType::BAR if @dimensions.size >= 2 && @display_type == DisplayType::PIE
63
61
 
64
62
  @order_by_value = attributes && (attributes[:order_by_value] == '1')
65
- @select_value = attributes&.dig(:select_value).present? ? attributes[:select_value] : @default_select_value
63
+ @select_value = attributes&.dig(:select_value).presence&.to_sym || @default_select_value
66
64
  @list = attributes&.[](:list) == '1'
67
65
  @percent = attributes&.[](:percent) == '1'
68
66
  @list_change_times = attributes&.[](:list_change_times) == '1'
@@ -1,3 +1,3 @@
1
1
  module SimpleDrilldown
2
- VERSION = '0.9.4'
2
+ VERSION = '0.9.9'
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.4
4
+ version: 0.9.9
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-05-21 00:00:00.000000000 Z
11
+ date: 2021-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caxlsx_rails