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 +4 -4
- data/app/assets/stylesheets/simple_drilldown/application.css +0 -1
- data/app/views/drilldown/_chart.html.erb +22 -6
- data/app/views/drilldown/_summary_row.html.erb +9 -0
- data/app/views/drilldown/_summary_table.html.erb +16 -14
- data/lib/generators/drilldown_controller/templates/drilldown_controller.rb.erb +9 -0
- data/lib/simple_drilldown/controller.rb +11 -12
- data/lib/simple_drilldown/helper.rb +2 -1
- data/lib/simple_drilldown/search.rb +2 -4
- data/lib/simple_drilldown/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb72497b4b3d1137bcba13a86c51f4547aa83200a6ef6cfd4940cc26da5dd431
|
4
|
+
data.tar.gz: e487608abefd17185ef9319e304a2489439a4053121f9c540639317e981141a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23afcd4a1e3498d316ae6e8d48788fb93e982bbb5982a0e2c5b33277a30c4f14cf23f04c42bcda6fee0d8aec4242644f1e248340088f9cd473bf95f90582687a
|
7
|
+
data.tar.gz: a841a7dbfffbd22401acddea431d934cbd72d5ed82f8eca35816210230df1becb8d0bfd5ec60dd97f9af7c0f3db904eb4cd8342e82e731339730ff3cfb389e90
|
@@ -2,14 +2,14 @@
|
|
2
2
|
data =
|
3
3
|
case @dimensions.size
|
4
4
|
when 0
|
5
|
-
{ @result[:value] => @result[
|
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[
|
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[
|
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.
|
87
|
+
firstPoint = chart.getElementsAtEventForMode(e, 'nearest', { intersect: true }, false)[0]
|
72
88
|
if (firstPoint) {
|
73
|
-
label = chart.data.labels[firstPoint.
|
74
|
-
value = chart.data.datasets[firstPoint.
|
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
|
-
<
|
2
|
-
<
|
3
|
-
<
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
</
|
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 =
|
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 =
|
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).
|
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'
|
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
|
+
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-
|
11
|
+
date: 2021-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: caxlsx_rails
|