query_report 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
data/lib/query_report/helper.rb
CHANGED
@@ -2,8 +2,8 @@ require 'query_report/report'
|
|
2
2
|
|
3
3
|
module QueryReport
|
4
4
|
module Helper
|
5
|
-
def reporter(query, &block)
|
6
|
-
@report ||= QueryReport::Report.new(params)
|
5
|
+
def reporter(query, options={}, &block)
|
6
|
+
@report ||= QueryReport::Report.new(params, options)
|
7
7
|
@report.query = query
|
8
8
|
@report.instance_eval &block
|
9
9
|
render_report
|
@@ -11,6 +11,7 @@ module QueryReport
|
|
11
11
|
|
12
12
|
def render_report
|
13
13
|
respond_to do |format|
|
14
|
+
format.js { render 'query_report/list' }
|
14
15
|
format.html { render 'query_report/list' }
|
15
16
|
format.json { render json: @report.records }
|
16
17
|
format.csv { send_data generate_csv_for_report(@report.all_records), :disposition => "attachment;" }
|
data/lib/query_report/report.rb
CHANGED
@@ -4,8 +4,11 @@ require 'query_report/chart/basic_chart'
|
|
4
4
|
require 'query_report/chart/chart_with_total'
|
5
5
|
|
6
6
|
module QueryReport
|
7
|
+
DEFAULT_OPTIONS = {
|
8
|
+
chart_on_pdf: true, paginate: true
|
9
|
+
}
|
7
10
|
class Report
|
8
|
-
attr_accessor :params, :chart, :charts, :filters, :search, :scopes, :current_scope
|
11
|
+
attr_accessor :params, :chart, :charts, :filters, :search, :scopes, :current_scope, :options
|
9
12
|
|
10
13
|
def initialize(params, options={}, &block)
|
11
14
|
@params = params
|
@@ -13,12 +16,19 @@ module QueryReport
|
|
13
16
|
@filters = []
|
14
17
|
@scopes = []
|
15
18
|
@charts = []
|
16
|
-
@column_separator = options.delete(:separator)
|
17
19
|
@current_scope = @params[:scope] || 'all'
|
18
|
-
@options =
|
20
|
+
@options = QueryReport::DEFAULT_OPTIONS.merge options
|
19
21
|
instance_eval &block if block_given?
|
20
22
|
end
|
21
23
|
|
24
|
+
QueryReport::DEFAULT_OPTIONS.each do |option_name, value|
|
25
|
+
if value.class == TrueClass or value.class == FalseClass
|
26
|
+
define_method "#{option_name.to_s}?" do
|
27
|
+
@options[option_name]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
22
32
|
def column(name, options={}, &block)
|
23
33
|
@columns << Column.new(name, options, block)
|
24
34
|
end
|
@@ -70,7 +80,7 @@ module QueryReport
|
|
70
80
|
@charts << @chart
|
71
81
|
end
|
72
82
|
|
73
|
-
def compare_with_column_chart(title, x_axis, &block)
|
83
|
+
def compare_with_column_chart(title, x_axis='', &block)
|
74
84
|
@chart = QueryReport::Chart::CustomChart.new(:column, title, query_without_pagination)
|
75
85
|
@chart.add_column x_axis
|
76
86
|
@chart.instance_eval &block if block_given?
|
@@ -31,19 +31,25 @@ class ReportPdf
|
|
31
31
|
|
32
32
|
def standard
|
33
33
|
pdf_content do
|
34
|
-
@report
|
35
|
-
if chart.respond_to?(:to_blob)
|
36
|
-
blob = chart.to_blob
|
37
|
-
data = StringIO.new(blob)
|
38
|
-
pdf.image(data)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
34
|
+
render_charts_with @report
|
42
35
|
render_table_with(@report.all_records, {font_size: 8, header_font_size: 10})
|
43
36
|
end
|
44
37
|
end
|
45
38
|
|
46
39
|
private
|
40
|
+
def render_charts_with(report)
|
41
|
+
return if report.charts.nil? or !report.chart_on_pdf?
|
42
|
+
report.charts.each do |chart|
|
43
|
+
if chart.respond_to?(:to_blob)
|
44
|
+
blob = chart.to_blob
|
45
|
+
data = StringIO.new(blob)
|
46
|
+
pdf.pad_top(10) do
|
47
|
+
pdf.image(data, :width => 200)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
47
53
|
def table_header_for(table_items, options={})
|
48
54
|
table_items.first.keys
|
49
55
|
end
|
data/lib/query_report/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ransack
|