query_report 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +47 -2
- data/lib/query_report.rb +2 -2
- data/lib/query_report/helper.rb +7 -7
- data/lib/query_report/{record.rb → report.rb} +6 -2
- data/lib/query_report/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# QueryReport
|
2
|
+
The purpose of this gem is to create reports with just the basic query with the built in following features,
|
3
|
+
* Pagination (with Kaminari)
|
4
|
+
* Basic filters (with Ransack)
|
5
|
+
* Custom filter
|
6
|
+
* Export with html, PDF (with Prawn PDF), CSV, JSON
|
2
7
|
|
3
|
-
|
8
|
+
The gem is still in infant stage. So I would just ask you to keep an eye on this for now.
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
@@ -18,7 +23,47 @@ Or install it yourself as:
|
|
18
23
|
|
19
24
|
## Usage
|
20
25
|
|
21
|
-
|
26
|
+
In your controller add,
|
27
|
+
```ruby
|
28
|
+
require 'query_report/helper'
|
29
|
+
```
|
30
|
+
|
31
|
+
And include,
|
32
|
+
```ruby
|
33
|
+
include QueryReport::Helper
|
34
|
+
```
|
35
|
+
|
36
|
+
Then add
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
def invoice
|
40
|
+
query = Invoice.includes(:invoiced_to => {:user => :profile})
|
41
|
+
reporter(query) do
|
42
|
+
scope :unpaid
|
43
|
+
|
44
|
+
filter :invoiced_on, type: :date
|
45
|
+
filter :title, type: :text
|
46
|
+
filter :invoiced_to, type: :user
|
47
|
+
|
48
|
+
column :id, as: 'Invoice#'
|
49
|
+
column :title
|
50
|
+
column 'Invoiced to' do |invoice|
|
51
|
+
invoice.invoiced_to.user.name
|
52
|
+
end
|
53
|
+
column :total_charged, as: 'Charged'
|
54
|
+
column :total_paid, as: 'Paid'
|
55
|
+
|
56
|
+
pie_chart('Charged VS Paid') do
|
57
|
+
add 'Total un paid charge' do |query|
|
58
|
+
query.sum(:total_charged) - query.sum(:total_paid)
|
59
|
+
end
|
60
|
+
add 'Total paid' do |query|
|
61
|
+
query.sum(:total_paid)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
22
67
|
|
23
68
|
## Contributing
|
24
69
|
|
data/lib/query_report.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "query_report/version"
|
2
|
-
require "query_report/
|
2
|
+
require "query_report/report"
|
3
3
|
require 'query_report/chart/pie_chart'
|
4
4
|
require 'query_report/chart/custom_chart'
|
5
5
|
|
@@ -7,7 +7,7 @@ module QueryReport
|
|
7
7
|
autoload :VERSION, 'query_report/version'
|
8
8
|
autoload :Helper, 'query_report/helper'
|
9
9
|
autoload :Views, 'query_report/views'
|
10
|
-
autoload :
|
10
|
+
autoload :Report, 'query_report/report'
|
11
11
|
autoload :Filter, 'query_report/filter'
|
12
12
|
autoload :Column, 'query_report/column'
|
13
13
|
end
|
data/lib/query_report/helper.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require 'query_report/
|
1
|
+
require 'query_report/report'
|
2
2
|
|
3
3
|
module QueryReport
|
4
4
|
module Helper
|
5
5
|
def reporter(query, &block)
|
6
|
-
@
|
7
|
-
@
|
8
|
-
@
|
6
|
+
@report ||= QueryReport::Report.new(params)
|
7
|
+
@report.set_query(query)
|
8
|
+
@report.instance_eval &block
|
9
9
|
render_report
|
10
10
|
end
|
11
11
|
|
12
12
|
def render_report
|
13
13
|
respond_to do |format|
|
14
14
|
format.html { render 'query_report/list' }
|
15
|
-
format.json { render json: @
|
16
|
-
format.csv { send_data generate_csv_for_report(@
|
17
|
-
format.pdf { render_pdf(ReportPdf.new.list(@
|
15
|
+
format.json { render json: @report.records }
|
16
|
+
format.csv { send_data generate_csv_for_report(@report.all_records), :disposition => "attachment;" }
|
17
|
+
format.pdf { render_pdf(ReportPdf.new.list(@report.all_records)) }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -4,8 +4,8 @@ require 'query_report/chart/basic_chart'
|
|
4
4
|
require 'query_report/chart/chart_with_total'
|
5
5
|
|
6
6
|
module QueryReport
|
7
|
-
class
|
8
|
-
attr_accessor :params, :query, :query_without_pagination, :chart,
|
7
|
+
class Report
|
8
|
+
attr_accessor :params, :query, :query_without_pagination, :chart, :charts,
|
9
9
|
:filters, :search, :scopes, :current_scope
|
10
10
|
|
11
11
|
def initialize(params, options={}, &block)
|
@@ -13,6 +13,7 @@ module QueryReport
|
|
13
13
|
@columns = []
|
14
14
|
@filters = []
|
15
15
|
@scopes = []
|
16
|
+
@charts = []
|
16
17
|
@column_separator = options.delete(:separator)
|
17
18
|
@current_scope = @params[:scope] || 'all'
|
18
19
|
@options = options.delete(:options)
|
@@ -70,17 +71,20 @@ module QueryReport
|
|
70
71
|
|
71
72
|
def column_chart(title, columns)
|
72
73
|
@chart = QueryReport::Chart::BasicChart.new(:column, title, columns, all_records)
|
74
|
+
@charts << @chart
|
73
75
|
end
|
74
76
|
|
75
77
|
def compare_with_column_chart(title, x_axis, &block)
|
76
78
|
@chart = QueryReport::Chart::CustomChart.new(:column, title, query_without_pagination)
|
77
79
|
@chart.add_column x_axis
|
78
80
|
@chart.instance_eval &block if block_given?
|
81
|
+
@charts << @chart
|
79
82
|
end
|
80
83
|
|
81
84
|
def pie_chart(title, &block)
|
82
85
|
@chart = QueryReport::Chart::PieChart.new(title, query_without_pagination)
|
83
86
|
@chart.instance_eval &block if block_given?
|
87
|
+
@charts << @chart
|
84
88
|
end
|
85
89
|
|
86
90
|
def pie_chart_on_total(title, columns)
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -67,7 +67,7 @@ files:
|
|
67
67
|
- lib/query_report/column.rb
|
68
68
|
- lib/query_report/filter.rb
|
69
69
|
- lib/query_report/helper.rb
|
70
|
-
- lib/query_report/
|
70
|
+
- lib/query_report/report.rb
|
71
71
|
- lib/query_report/version.rb
|
72
72
|
- query_report.gemspec
|
73
73
|
homepage: https://github.com/ashrafuzzaman/query_report
|