simple_drilldown 0.3.4 → 0.3.5

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: edb4a7a11169686c1934a597adf694bcf0698324f51e1b0f3f1d50fd1c22eb5f
4
- data.tar.gz: 39555fb5382aad0a9d4e0a5542c697a90115baf295b5b4ba618662b0dda7ef38
3
+ metadata.gz: 388fda7e00b8742770fafabfe6742b0fa910bd6055ba7dc8dfe323c46a2bca74
4
+ data.tar.gz: a765fbd6f39829ecf2ac58c40b44e48095f502530f30a26b75e3d6fed0513538
5
5
  SHA512:
6
- metadata.gz: ca37f8f77a901ba524e062066a91daad4df326870656387d847acd79f3f06494208a5d6923a9aea96d1c66a171b35453a38788e0df7604aa2f6b6eb9b87ca8bd
7
- data.tar.gz: e7d83e533b1b4862cc37d7adcf7c0491e9a8f250cbf2d5695a6cc8a8be48043917e02c5a4976f550ef0a90a000d959cb729f703cf95d307633b4ee7c18bbe591
6
+ metadata.gz: 49e848195ec11d171b4968f5645d15805241acb3dfed17a9df221204324d320e238dd70c23234c506282f279afeabcd01277340417a35d5dc3495c1ecbf59305
7
+ data.tar.gz: dfa6461733db75343fb7c8b4199c08b83bfa49fb22e9a8babadba6ec30a5aa8b9317c91701e817b6635736438aff4e83923d50bfc22a6f61f733a0bd4cb38b46
@@ -0,0 +1,62 @@
1
+ <%
2
+ data =
3
+ case @dimensions.size
4
+ when 0
5
+ { @result[:value] => @result[:count] }
6
+ when 1
7
+ @result[:rows].map { |r| [@dimensions[0][:label_method] ? @dimensions[0][:label_method].call(r[:value]) : r[:value], r[:count]] }
8
+ when 2
9
+ @result[:rows].map do |r|
10
+ {
11
+ name: r[:value],
12
+ data: r[:rows].map { |r2| [r2[:value], r2[:count]] }
13
+ }
14
+ end
15
+ when 3
16
+ end
17
+ %>
18
+
19
+ <%
20
+ case @search.display_type
21
+ when SimpleDrilldown::Search::DisplayType::PIE
22
+ %>
23
+ <%= pie_chart data, height: '24rem' %>
24
+ <% when SimpleDrilldown::Search::DisplayType::BAR %>
25
+ <%= column_chart data, height: '24rem' %>
26
+ <% when SimpleDrilldown::Search::DisplayType::LINE %>
27
+ <%= line_chart data, height: '24rem' %>
28
+ <% else %>
29
+ <div id="drilldown_area">
30
+ <h2><%= caption %></h2>
31
+ <h3><%= subcaption %></h3>
32
+ <br/>
33
+ </div>
34
+ <% end %>
35
+
36
+ <div id="drilldown_search_area" style="margin-left: auto; margin-right: auto; text-align: center">
37
+ <% (0..2).each do |i|
38
+ options = [['', '']]
39
+ options << [@dimensions[i][:pretty_name], @dimensions[i][:url_param_name]] if @dimensions[i]
40
+ options += @remaining_dimensions.keys.map { |name| [@dimension_defs[name][:pretty_name], name] } %>
41
+ <%= t(i == 0 ? :group_by : :then_by) %>:
42
+ <%= form.select 'dimensions', options, { :selected => @search.dimensions && @search.dimensions[i] },
43
+ { :onChange => 'form.submit()', :name => 'search[dimensions][]', :id => "search_dimensions_#{i}" } %>
44
+ <% end %>
45
+
46
+ <br/>
47
+ <%= t :chart_type %>
48
+ <%= form.radio_button 'display_type', SimpleDrilldown::Search::DisplayType::BAR, { :onChange => 'form.submit()' } %>
49
+ <%= form.label :display_type_bar, t(:bar) %>
50
+ <%= form.radio_button 'display_type', SimpleDrilldown::Search::DisplayType::PIE, { :disabled => @search.dimensions.size >= 2, :onChange => 'form.submit()' } %>
51
+ <%= form.label :display_type_pie, t(:pie) %>
52
+ <%= form.radio_button 'display_type', SimpleDrilldown::Search::DisplayType::LINE, { :onChange => 'form.submit()' } %>
53
+ <%= form.label :display_type_line, t(:line) %>
54
+ <%= form.radio_button 'display_type', SimpleDrilldown::Search::DisplayType::NONE, { :onChange => 'form.submit()' } %>
55
+ <%= form.label :display_type_none, t(:none) %>
56
+
57
+ <%= form.check_box :order_by_value, { :onChange => 'form.submit()' } %>
58
+ <%= form.label :order_by_value, t(:order_by_value) %>
59
+
60
+ <%= form.check_box :list, { :onChange => 'form.submit()' } %>
61
+ <%= form.label :list, t(:list) %>
62
+ </div>
@@ -1,18 +1,18 @@
1
1
  <% if new_row -%>
2
- <tr class="<%= cycle("odd", "even", :name => "dim#{dimension}") %>">
3
- <% ((dimension + 1)..(@dimensions.size)).each { |i| cycle("odd", "even", :name => "dim#{i}") if current_cycle("dim#{i}") != current_cycle("dim#{dimension}") } -%>
2
+ <tr class="<%= cycle("odd", "even", :name => "dim#{dimension}") %>">
3
+ <% ((dimension + 1)..(@dimensions.size)).each { |i| cycle("odd", "even", :name => "dim#{i}") if current_cycle("dim#{i}") != current_cycle("dim#{dimension}") } -%>
4
4
  <% end -%>
5
5
  <% if dimension > 0 %>
6
- <td valign="top" rowspan="<%= result[:nodes] %>">
7
- <%= link_to value_label(dimension - 1, result[:value]), @search.drill_down(@dimensions, *[headers[1..-1], result].flatten.map { |h| h[:value] }).url_options %>
8
- </td>
6
+ <td valign="top" rowspan="<%= result[:nodes] %>">
7
+ <%= link_to value_label(dimension - 1, result[:value]), @search.drill_down(@dimensions, *[headers[1..-1], result].flatten.map { |h| h[:value] }).url_options %>
8
+ </td>
9
9
  <% end %>
10
10
  <% if with_results %>
11
- <td align="right">
12
- <%= result[:count] %>
13
- <% if parent_result && @search.percent %>
14
- (<%= 100 * result[:count] / parent_result[:count] %>%)
15
- <% end %>
16
- </td>
17
- </tr>
11
+ <td align="right">
12
+ <%= result[:count] %>
13
+ <% if parent_result && @search.percent %>
14
+ (<%= 100 * result[:count] / parent_result[:count] %>%)
15
+ <% end %>
16
+ </td>
17
+ </tr>
18
18
  <% end %>
@@ -27,14 +27,15 @@ class <%= class_name %>DrilldownController < DrilldownController
27
27
  # field :comments, attr_method: ->(post) { post.comments.count }
28
28
 
29
29
  dimension :calendar_date, 'DATE(<%= plural_name %>.created_at)', interval: true
30
- dimension :day_of_month, "date_part('day', <%= plural_name %>.created_at)"
31
- dimension :day_of_week, "CASE WHEN date_part('dow', <%= plural_name %>.created_at) = 0 THEN 7 ELSE date_part('dow', <%= plural_name %>.created_at) END",
32
- label_method: ->(day_no) { Date::DAYNAMES[day_no.to_i % 7] }
33
- dimension :hour_of_day, "date_part('hour', <%= plural_name %>.created_at)"
34
- dimension :month, "date_part('month', <%= plural_name %>.created_at)",
30
+ dimension :day_of_month, "date_part('day', <%= plural_name %>.created_at)::int"
31
+ dimension :day_of_week, <<~SQL, label_method: ->(day_no) { Date::DAYNAMES[day_no.to_i % 7] }
32
+ CASE WHEN date_part('dow', <%= plural_name %>.created_at) = 0 THEN 7 ELSE date_part('dow', <%= plural_name %>.created_at)::int END
33
+ SQL
34
+ dimension :hour_of_day, "date_part('hour', <%= plural_name %>.created_at)::int"
35
+ dimension :month, "date_part('month', <%= plural_name %>.created_at)::int",
35
36
  label_method: ->(month_no) { Date::MONTHNAMES[month_no.to_i] }
36
- dimension :week, "date_part('week', <%= plural_name %>.created_at)"
37
- dimension :year, "date_part('year', <%= plural_name %>.created_at)"
37
+ dimension :week, "date_part('week', <%= plural_name %>.created_at)::int"
38
+ dimension :year, "date_part('year', <%= plural_name %>.created_at)::varchar"
38
39
 
39
40
  # dimension :comments, 'SELECT count(*) FROM comments c WHERE c.<%= singular_name %>_id = <%= plural_name %>.id'
40
41
  # dimension :user, 'users.name', includes: :user
@@ -1,67 +1,64 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleDrilldown
4
+ # View helper for SimpleDrilldown
2
5
  module DrilldownHelper
3
6
  def value_label(dimension_index, value)
4
- return nil if @dimensions[dimension_index].nil?
5
- h(@dimensions[dimension_index][:label_method] ?
6
- @dimensions[dimension_index][:label_method].call(value) :
7
- value)
7
+ dimension = @dimensions[dimension_index]
8
+ return nil if dimension.nil?
9
+
10
+ h(dimension[:label_method] ? dimension[:label_method].call(value) : value)
8
11
  end
9
12
 
10
13
  def caption
11
- result = @search.title ? @search.title : "#{@target_class} #{t(@search.select_value.downcase)}" +
12
- ((@dimensions && @dimensions.any?) ? ' by ' + @dimensions.map { |d| d[:pretty_name] }.join(' and ') : '')
14
+ result = @search.title || "#{@target_class} #{t(@search.select_value.downcase)}" +
15
+ (@dimensions && @dimensions.any? ? ' by ' + @dimensions.map { |d| d[:pretty_name] }.join(' and ') : '')
13
16
  result.gsub('$date', [*@search.filter[:calendar_date]].uniq.join(' - '))
14
17
  end
15
18
 
16
19
  def subcaption
17
- @search.title ? '' : @filter_text && @filter_text.size > 0 ? "for #{@filter_text}" : ''
20
+ @search.title || @filter_text.blank? ? '' : "for #{@filter_text}"
18
21
  end
19
22
 
20
23
  def summary_row(result, parent_result = nil, dimension = 0, headers = [], new_row = true)
21
- html = render(:partial => '/drilldown/summary_row', :locals => { :result => result, :parent_result => parent_result, :new_row => new_row, :dimension => dimension, :headers => headers, :with_results => !result[:rows] })
24
+ html = render(partial: '/drilldown/summary_row', locals: { result: result, parent_result: parent_result, new_row: new_row, dimension: dimension, headers: headers, with_results: !result[:rows] })
22
25
  if result[:rows]
23
- sub_headers = headers + [{ :value => result[:value], :display_row_count => result[:nodes] + result[:row_count] * (@search.list ? 1 : 0) }]
24
- significant_rows = result[:rows].select { |r| r[:row_count] != 0 }
26
+ sub_headers = headers + [{ value: result[:value], display_row_count: result[:nodes] + result[:row_count] * (@search.list ? 1 : 0) }]
27
+ significant_rows = result[:rows].reject { |r| r[:row_count].zero? }
25
28
  significant_rows.each_with_index do |r, i|
26
- html << summary_row(r, result, dimension + 1, sub_headers, i > 0)
29
+ html << summary_row(r, result, dimension + 1, sub_headers, i.positive?)
27
30
  end
28
31
  elsif @search.list
29
- html << render(:partial => '/drilldown/record_list', :locals => { :result => result })
30
- end
31
- if dimension < @dimensions.size
32
- html << render(:partial => '/drilldown/summary_total_row', :locals => { :result => result, :parent_result => parent_result, :headers => headers.dup, :dimension => dimension })
32
+ html << render(partial: '/drilldown/record_list', locals: { result: result })
33
33
  end
34
+ html << render(partial: '/drilldown/summary_total_row', locals: { result: result, parent_result: parent_result, headers: headers.dup, dimension: dimension }) if dimension < @dimensions.size
34
35
 
35
36
  html
36
37
  end
37
38
 
38
39
  def excel_summary_row(result, parent_result = nil, dimension = 0, headers = [])
39
- xml = ''
40
+ xml = +''
40
41
  if result[:rows]
41
- significant_rows = result[:rows].select { |r| r[:row_count] != 0 }
42
+ significant_rows = result[:rows].reject { |r| r[:row_count].zero? }
42
43
  significant_rows.each_with_index do |r, i|
43
- if i == 0
44
- if dimension == 0
45
- sub_headers = headers
46
- else
47
- sub_headers = headers + [{ :value => result[:value], :display_row_count => result[:nodes] + result[:row_count] * (@search.list ? 1 : 0) }]
48
- end
49
- else
50
- sub_headers = [] # [{:value => result[:value], :row_count => result[:row_count]}]
51
- end
44
+ sub_headers = if i.zero?
45
+ if dimension.zero?
46
+ headers
47
+ else
48
+ headers + [{ value: result[:value], display_row_count: result[:nodes] + result[:row_count] * (@search.list ? 1 : 0) }]
49
+ end
50
+ else
51
+ [] # [{:value => result[:value], :row_count => result[:row_count]}]
52
+ end
52
53
  xml << excel_summary_row(r, result, dimension + 1, sub_headers)
53
54
  end
54
55
  else
55
- xml << render(:partial => '/drilldown/excel_summary_row', :locals => { :result => result, :parent_result => parent_result, :headers => headers.dup, :dimension => dimension })
56
+ xml << render(partial: '/drilldown/excel_summary_row', locals: { result: result, parent_result: parent_result, headers: headers.dup, dimension: dimension })
56
57
 
57
- if @search.list
58
- xml << render(:partial => '/drilldown/excel_record_list', :locals => { :result => result })
59
- end
58
+ xml << render(partial: '/drilldown/excel_record_list', locals: { result: result }) if @search.list
60
59
  end
61
60
 
62
- if dimension < @dimensions.size
63
- xml << render(:partial => '/drilldown/excel_summary_total_row', :locals => { :result => result, :headers => headers.dup, :dimension => dimension })
64
- end
61
+ xml << render(partial: '/drilldown/excel_summary_total_row', locals: { result: result, headers: headers.dup, dimension: dimension }) if dimension < @dimensions.size
65
62
  xml
66
63
  end
67
64
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleDrilldown
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_drilldown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uwe Kubosch
@@ -90,7 +90,7 @@ files:
90
90
  - app/jobs/simple_drilldown/application_job.rb
91
91
  - app/mailers/simple_drilldown/application_mailer.rb
92
92
  - app/models/simple_drilldown/application_record.rb
93
- - app/views/drilldown/_chart.html.slim
93
+ - app/views/drilldown/_chart.html.erb
94
94
  - app/views/drilldown/_excel_record_list.builder
95
95
  - app/views/drilldown/_excel_row.builder
96
96
  - app/views/drilldown/_excel_row_header.builder
@@ -1,52 +0,0 @@
1
- ruby:
2
- data =
3
- case @dimensions.size
4
- when 0
5
- { @result[:value] => @result[:count] }
6
- when 1
7
- @result[:rows].map { |r| [ @dimensions[0][:label_method] ? @dimensions[0][:label_method].call(r[:value]) : r[:value], r[:count] ] }
8
- when 2
9
- @result[:rows].map do |r|
10
- {
11
- name: r[:value],
12
- data: r[:rows].map { |r2| [r2[:value], r2[:count]] }
13
- }
14
- end
15
- when 3
16
- end
17
- - case @search.display_type
18
- - when SimpleDrilldown::Search::DisplayType::PIE
19
- = pie_chart data, height: '24rem'
20
- - when SimpleDrilldown::Search::DisplayType::BAR
21
- = column_chart data, height: '24rem'
22
- - when SimpleDrilldown::Search::DisplayType::LINE
23
- = line_chart data, height: '24rem'
24
- - else
25
- #drilldown_area
26
- h2 = caption
27
- h3 = subcaption
28
- br
29
- #drilldown_search_area style="margin-left: auto; margin-right: auto; text-align: center"
30
- - (0..2).each do |i|
31
- - options = [['', '']]
32
- - options << [@dimensions[i][:pretty_name], @dimensions[i][:url_param_name]] if @dimensions[i]
33
- - options += @remaining_dimensions.keys.map { |name| [@dimension_defs[name][:pretty_name], name] }
34
- | #{t(i == 0 ? :group_by : :then_by)}:
35
- = form.select 'dimensions', options, { :selected => @search.dimensions && @search.dimensions[i] }, \
36
- { :onChange => 'form.submit()', :name => 'search[dimensions][]', :id => "search_dimensions_#{i}" }
37
- br
38
- = t :chart_type
39
- = form.radio_button 'display_type', SimpleDrilldown::Search::DisplayType::BAR, { :onChange => 'form.submit()' }
40
- = form.label :display_type_bar, t(:bar)
41
- = form.radio_button 'display_type', SimpleDrilldown::Search::DisplayType::PIE, { :disabled => @search.dimensions.size >= 2, :onChange => 'form.submit()' }
42
- = form.label :display_type_pie, t(:pie)
43
- = form.radio_button 'display_type', SimpleDrilldown::Search::DisplayType::LINE, { :onChange => 'form.submit()' }
44
- = form.label :display_type_line, t(:line)
45
- = form.radio_button 'display_type', SimpleDrilldown::Search::DisplayType::NONE, { :onChange => 'form.submit()' }
46
- = form.label :display_type_none, t(:none)
47
-
48
- = form.check_box :order_by_value, { :onChange => 'form.submit()' }
49
- = form.label :order_by_value, t(:order_by_value)
50
-
51
- = form.check_box :list, { :onChange => 'form.submit()' }
52
- = form.label :list, t(:list)