simple_drilldown 0.9.3 → 0.9.8

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: 787eb533d80540491493c1fb623d8358b72974059b007a838fe3f41c39f2314c
4
- data.tar.gz: 284a49c988fe530ac7e64840ba2162c5afb4424217570905618f7595d2328d2b
3
+ metadata.gz: fb72497b4b3d1137bcba13a86c51f4547aa83200a6ef6cfd4940cc26da5dd431
4
+ data.tar.gz: e487608abefd17185ef9319e304a2489439a4053121f9c540639317e981141a1
5
5
  SHA512:
6
- metadata.gz: b381290a734b9b701d4d33c86fb21e9ac7a6e9ccf5cae8b4c0263bccc5d80e8e155262cd916f6373d40b53732a1272c2d1c3b7bf8733b3d1d1744bbe7e797850
7
- data.tar.gz: cc8569627e64cc18618d26f8e0036d22cfd79b31c6e5ad4752db8fe663c0f9053fb6fff3376e526e20e6d562379156c57d604992b85e076486cee9e7fd5342e2
6
+ metadata.gz: 23afcd4a1e3498d316ae6e8d48788fb93e982bbb5982a0e2c5b33277a30c4f14cf23f04c42bcda6fee0d8aec4242644f1e248340088f9cd473bf95f90582687a
7
+ data.tar.gz: a841a7dbfffbd22401acddea431d934cbd72d5ed82f8eca35816210230df1becb8d0bfd5ec60dd97f9af7c0f3db904eb4cd8342e82e731339730ff3cfb389e90
@@ -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
 
@@ -68,10 +84,10 @@
68
84
  <%= javascript_tag do %>
69
85
  $('#chart-1').on('click', function(e){
70
86
  chart = Chartkick.charts['chart-1'].getChartObject();
71
- firstPoint = chart.getElementsAtEvent(e)[0]
87
+ firstPoint = chart.getElementsAtEventForMode(e, 'nearest', { intersect: true }, false)[0]
72
88
  if (firstPoint) {
73
- label = chart.data.labels[firstPoint._index];
74
- value = chart.data.datasets[firstPoint._datasetIndex].data[firstPoint._index];
89
+ label = chart.data.labels[firstPoint.index];
90
+ value = chart.data.datasets[firstPoint.datasetIndex].data[firstPoint._index];
75
91
  console.log("Label: " + label + ", Value: " + value);
76
92
  new_location = window.location.toString();
77
93
  new_location = new_location.replace(/#.*$/, '');
@@ -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>
@@ -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.3'
2
+ VERSION = '0.9.8'
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.3
4
+ version: 0.9.8
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-20 00:00:00.000000000 Z
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caxlsx_rails