query_report 0.1.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/{LICENSE.txt → MIT-LICENSE} +2 -4
- data/README.md +32 -53
- data/Rakefile +50 -0
- data/app/helpers/query_report_filter_helper.rb +22 -0
- data/app/helpers/query_report_helper.rb +31 -0
- data/app/views/query_report/_charts.html.erb +10 -0
- data/app/views/query_report/_search.html.erb +8 -0
- data/app/views/query_report/list.html.erb +19 -38
- data/config/locales/query_report.yml +7 -0
- data/config/routes.rb +2 -0
- data/db/schema.rb +34 -0
- data/lib/query_report.rb +22 -15
- data/lib/query_report/chart/chart_base.rb +60 -0
- data/lib/query_report/chart/chart_column.rb +12 -0
- data/lib/query_report/chart/column_chart.rb +40 -0
- data/lib/query_report/chart/pie_chart.rb +22 -25
- data/lib/query_report/chart/themes.rb +18 -114
- data/lib/query_report/column.rb +29 -18
- data/lib/query_report/config.rb +6 -0
- data/lib/query_report/engine.rb +4 -0
- data/lib/query_report/errors.rb +4 -0
- data/lib/query_report/filter.rb +110 -31
- data/lib/query_report/helper.rb +19 -3
- data/lib/query_report/paginate.rb +13 -0
- data/lib/query_report/record.rb +46 -0
- data/lib/query_report/report.rb +19 -102
- data/lib/query_report/report_pdf.rb +68 -84
- data/lib/query_report/version.rb +1 -1
- data/lib/tasks/query_report_tasks.rake +4 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/javascripts/invoices.js +2 -0
- data/test/dummy/app/assets/javascripts/users.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/invoices.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/assets/stylesheets/users.css +4 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/invoices_controller.rb +114 -0
- data/test/dummy/app/controllers/users_controller.rb +91 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/invoices_helper.rb +2 -0
- data/test/dummy/app/helpers/users_helper.rb +2 -0
- data/test/dummy/app/models/invoice.rb +3 -0
- data/test/dummy/app/models/pdf_report_template.rb +24 -0
- data/test/dummy/app/models/user.rb +3 -0
- data/test/dummy/app/views/invoices/_form.html.erb +33 -0
- data/test/dummy/app/views/invoices/edit.html.erb +6 -0
- data/test/dummy/app/views/invoices/index.html.erb +29 -0
- data/test/dummy/app/views/invoices/new.html.erb +5 -0
- data/test/dummy/app/views/invoices/show.html.erb +25 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/users/_form.html.erb +33 -0
- data/test/dummy/app/views/users/edit.html.erb +6 -0
- data/test/dummy/app/views/users/index.html.erb +29 -0
- data/test/dummy/app/views/users/new.html.erb +5 -0
- data/test/dummy/app/views/users/show.html.erb +25 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +60 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/query_report.rb +3 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +10 -0
- data/test/dummy/config/routes.rb +64 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130622120853_create_users.rb +12 -0
- data/test/dummy/db/migrate/20130630132513_create_invoices.rb +12 -0
- data/test/dummy/db/schema.rb +34 -0
- data/test/dummy/db/seed.rb +4 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +30613 -0
- data/test/dummy/log/test.log +28 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/fixtures/invoices.yml +13 -0
- data/test/dummy/test/functional/invoices_controller_test.rb +49 -0
- data/test/dummy/test/unit/helpers/invoices_helper_test.rb +4 -0
- data/test/dummy/test/unit/invoice_test.rb +7 -0
- data/test/dummy/tmp/cache/assets/C8C/B80/sprockets%2F371bf96e99717688ed7313a0c53f4212 +0 -0
- data/test/dummy/tmp/cache/assets/CA9/F20/sprockets%2F00ff4f84806dd8834ab35f800a082640 +0 -0
- data/test/dummy/tmp/cache/assets/CAA/620/sprockets%2F87b209c0c9da28094a8d5581a21262c6 +0 -0
- data/test/dummy/tmp/cache/assets/CB5/B70/sprockets%2Fa769d915e72b1c8c0614793b54d02c86 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/CD8/B70/sprockets%2F4050a4e5062ab95c9f32e9b6940821ea +0 -0
- data/test/dummy/tmp/cache/assets/CF0/1D0/sprockets%2F6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/D46/650/sprockets%2Ff56253b5f374fff1a33fbbc9881c9124 +0 -0
- data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/D54/B90/sprockets%2F90719d7bdca76469cd487928f710decb +0 -0
- data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/D67/B60/sprockets%2F5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
- data/test/dummy/tmp/cache/assets/D7C/990/sprockets%2F302f7d851fcdb17936f8096bfb967cab +0 -0
- data/test/dummy/tmp/cache/assets/D7F/AF0/sprockets%2Fa7deca9af827ab462635389b96c7da39 +0 -0
- data/test/dummy/tmp/cache/assets/DA3/AC0/sprockets%2F797d3e5f21daaf5c046cc6ec4830e95b +0 -0
- data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/DFC/6F0/sprockets%2F2c45c36e4d7c7bfaeb826eeba29a09d2 +0 -0
- data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/E0E/8A0/sprockets%2Fbecd48a9cf2ece858e433d7dcf0554f6 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_5awpjfhldzcfjkeiia3p +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_a7ev5lal7xp2xzjj2n9p +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_c5lzifpf785aic4t3cm8 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_etmdhvrbbmdadc7oyw8q +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_m0kxxiow6jlfcjulu02t +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_m2ow1xy7c6tw0f4fj2co +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_mitzsa7y0lvka04il6an +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_ujpdek4jfp8flbqp7fi3 +0 -0
- data/test/dummy/tmp/miniprofiler/mp_timers_wbiyljqrnox89js4m0at +0 -0
- data/test/dummy/tmp/miniprofiler/mp_views_127.0.0.1 +1 -0
- data/test/test_helper.rb +15 -0
- metadata +380 -24
- data/.gitignore +0 -18
- data/Gemfile +0 -10
- data/README.rdoc +0 -3
- data/app/views/query_report/_custom_filters.html.erb +0 -7
- data/lib/query_report/chart/basic_chart.rb +0 -41
- data/lib/query_report/chart/custom_chart.rb +0 -55
- data/lib/query_report/row.rb +0 -11
- data/query_report.gemspec +0 -31
data/{LICENSE.txt → MIT-LICENSE}
RENAMED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
2
|
-
|
|
3
|
-
MIT License
|
|
1
|
+
Copyright 2013 YOURNAME
|
|
4
2
|
|
|
5
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
4
|
a copy of this software and associated documentation files (the
|
|
@@ -19,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
19
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
19
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
|
@@ -1,74 +1,53 @@
|
|
|
1
|
-
|
|
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
|
|
1
|
+
[Query report](http://ashrafuzzaman.github.io/query_report/) By [Ashrafuzzaman](http://www.ashrafuzzaman.com).
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
Query report is a reporting tool, which does the following:
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
* Generate paginated HTML view with filters, defined columns with sorting
|
|
6
|
+
* Generate PDF, CSV, JSON
|
|
7
|
+
* Provide feature to define re usable custom filter
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
As built in filter I have used [ransack](https://github.com/ernie/ransack) and pagination with [kaminari](https://github.com/amatsuda/kaminari)
|
|
13
10
|
|
|
14
|
-
|
|
11
|
+
## The purpose
|
|
12
|
+
The purpose of this gem is to produce consistent reports quickly and manage them easily. Because all we need to
|
|
13
|
+
concentrate in a report is the query and filter.
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
## Getting started
|
|
16
|
+
Query report is tested with Rails 3. You can add it to your Gemfile with:
|
|
17
17
|
|
|
18
|
-
$ bundle
|
|
19
|
-
|
|
20
|
-
Or install it yourself as:
|
|
21
|
-
|
|
22
|
-
$ gem install query_report
|
|
23
|
-
|
|
24
|
-
## Usage
|
|
25
|
-
|
|
26
|
-
In your controller add,
|
|
27
18
|
```ruby
|
|
28
|
-
|
|
19
|
+
gem 'query_report'
|
|
29
20
|
```
|
|
30
21
|
|
|
31
|
-
|
|
32
|
-
```ruby
|
|
33
|
-
include QueryReport::Helper
|
|
34
|
-
```
|
|
22
|
+
Run the bundle command to install it.
|
|
35
23
|
|
|
36
|
-
|
|
24
|
+
Here is a sample controller which uses query report. And that is all you need, query report will generate all the view for you.
|
|
37
25
|
|
|
38
26
|
```ruby
|
|
39
|
-
|
|
40
|
-
query = Invoice.includes(:invoiced_to => {:user => :profile})
|
|
41
|
-
reporter(query) do
|
|
42
|
-
scope :unpaid
|
|
27
|
+
require 'query_report/helper' #need to require the helper
|
|
43
28
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
filter :invoiced_to, type: :user
|
|
29
|
+
class InvoicesController < ApplicationController
|
|
30
|
+
include QueryReport::Helper #need to include it
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
|
|
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'
|
|
32
|
+
def index
|
|
33
|
+
@invoices = Invoice.scoped
|
|
55
34
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
35
|
+
reporter(@invoices) do
|
|
36
|
+
filter :title, type: :text
|
|
37
|
+
filter :created_at, type: :date, default: [5.months.ago.to_date.to_s(:db),
|
|
38
|
+
1.months.from_now.to_date.to_s(:db)]
|
|
39
|
+
filter :paid, type: :boolean, default: false
|
|
40
|
+
|
|
41
|
+
column :title do |invoice|
|
|
42
|
+
link_to invoice.title, invoice
|
|
62
43
|
end
|
|
44
|
+
column :total_paid
|
|
45
|
+
column :total_charged
|
|
46
|
+
column :paid
|
|
63
47
|
end
|
|
64
48
|
end
|
|
65
49
|
end
|
|
66
50
|
```
|
|
67
51
|
|
|
68
|
-
##
|
|
69
|
-
|
|
70
|
-
1. Fork it
|
|
71
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
72
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
73
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
|
74
|
-
5. Create new Pull Request
|
|
52
|
+
## License
|
|
53
|
+
MIT License. Copyright © 2013 [Ashrafuzzaman](http://www.ashrafuzzaman.com). See MIT-LICENSE for further details.
|
data/Rakefile
CHANGED
|
@@ -1 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
begin
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
6
|
+
end
|
|
7
|
+
begin
|
|
8
|
+
require 'rdoc/task'
|
|
9
|
+
rescue LoadError
|
|
10
|
+
require 'rdoc/rdoc'
|
|
11
|
+
require 'rake/rdoctask'
|
|
12
|
+
RDoc::Task = Rake::RDocTask
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
17
|
+
rdoc.title = 'QueryReport'
|
|
18
|
+
rdoc.options << '--line-numbers'
|
|
19
|
+
rdoc.rdoc_files.include('README.md')
|
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
|
24
|
+
load 'rails/tasks/engine.rake'
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Bundler::GemHelper.install_tasks
|
|
29
|
+
|
|
30
|
+
#require 'rake/testtask'
|
|
31
|
+
#
|
|
32
|
+
#Rake::TestTask.new(:test) do |t|
|
|
33
|
+
# t.libs << 'lib'
|
|
34
|
+
# t.libs << 'test'
|
|
35
|
+
# t.pattern = 'test/**/*_test.rb'
|
|
36
|
+
# t.verbose = false
|
|
37
|
+
#end
|
|
38
|
+
#
|
|
39
|
+
#
|
|
40
|
+
#task :default => :test
|
|
41
|
+
|
|
42
|
+
|
|
1
43
|
require "bundler/gem_tasks"
|
|
44
|
+
require "rspec/core/rake_task"
|
|
45
|
+
|
|
46
|
+
RSpec::Core::RakeTask.new
|
|
47
|
+
|
|
48
|
+
task :default => :spec
|
|
49
|
+
task :test => :spec
|
|
50
|
+
|
|
51
|
+
task :default => :test
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module QueryReportFilterHelper
|
|
2
|
+
def query_report_text_filter(name, value, options={})
|
|
3
|
+
text_field_tag name, value, options
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def query_report_date_filter(name, value, options={})
|
|
7
|
+
text_field_tag name, value, options.merge(type: :date)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def query_report_boolean_filter(name, value, options={})
|
|
11
|
+
concat(label_tag options[:placeholder])
|
|
12
|
+
select_tag name, options_for_select([['', ''], ['true', 'true'], ['false', 'false']], value)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def link_to_download_report_pdf
|
|
16
|
+
link_to t('views.links.pdf'), export_report_url_with_format('pdf'), :target => "_blank"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def link_to_download_report_csv
|
|
20
|
+
link_to t('views.links.csv'), export_report_url_with_format('csv'), :target => "_blank"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'query_report/errors'
|
|
2
|
+
|
|
3
|
+
module QueryReportHelper
|
|
4
|
+
def query_report_render_filter(filter, comparator)
|
|
5
|
+
hint = comparator.name
|
|
6
|
+
#search_key = comparator.search_key
|
|
7
|
+
search_tag_name = comparator.search_tag_name #"#{filter.params_key}[#{search_key}]"
|
|
8
|
+
value = comparator.param_value #params[filter.params_key] ? params[filter.params_key][comparator.search_key] : comparator.default
|
|
9
|
+
|
|
10
|
+
method_name = :"query_report_#{filter.type.to_s}_filter"
|
|
11
|
+
if main_app.respond_to? method_name
|
|
12
|
+
main_app.send method_name, search_tag_name, value, :placeholder => hint
|
|
13
|
+
elsif self.respond_to? method_name
|
|
14
|
+
self.send method_name, search_tag_name, value, :placeholder => hint
|
|
15
|
+
else
|
|
16
|
+
raise QueryReport::FilterNotDefined, "#{filter.type.to_s} filter is not defined"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def export_report_url_with_format(format)
|
|
21
|
+
url = request.url
|
|
22
|
+
if url.match(/(\.\w*\?)/)
|
|
23
|
+
url = url.gsub(/(\?)/, ".#{format}?")
|
|
24
|
+
elsif url.match(/(\?)/)
|
|
25
|
+
url = url.gsub(/(\?)/, ".#{format}?")
|
|
26
|
+
else
|
|
27
|
+
url = "#{url}.#{format}"
|
|
28
|
+
end
|
|
29
|
+
url.gsub(/format=(\w*)/, 'format=#{format}')
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<div class="row-fluid">
|
|
2
|
+
<% report.charts.each_with_index do |chart, i| %>
|
|
3
|
+
<% chart_id = "chart#{i}" %>
|
|
4
|
+
<div class="span6">
|
|
5
|
+
<div id="<%= chart_id %>" style="text-align: center;"></div>
|
|
6
|
+
</div>
|
|
7
|
+
<%= render_chart(chart.prepare_visualr, chart_id) %>
|
|
8
|
+
<% end %>
|
|
9
|
+
<div class="clearfix"></div>
|
|
10
|
+
</div>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<%= search_form_for report.search, :url => url_for, :html => {:method => :get, :class => 'form-inline'} do |f| %>
|
|
2
|
+
<% report.filters.each do |filter| %>
|
|
3
|
+
<% filter.comparators.each do |comparator| %>
|
|
4
|
+
<%= query_report_render_filter(filter, comparator) %>
|
|
5
|
+
<% end %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<%= f.submit 'Search', :class => 'btn btn-blue' %>
|
|
8
|
+
<% end %>
|
|
@@ -1,55 +1,36 @@
|
|
|
1
|
-
<%=
|
|
2
|
-
<% @record.filters.each do |filter| %>
|
|
3
|
-
<% if filter.class.supported_types.include?(filter.type) %>
|
|
4
|
-
<% filter.comparators.each do |key, hint| %>
|
|
5
|
-
<% search_key = "#{filter.column}_#{key}" %>
|
|
6
|
-
<% if filter.date? %>
|
|
7
|
-
<%= f.date_field search_key, :placeholder => hint %>
|
|
8
|
-
<% elsif filter.text? %>
|
|
9
|
-
<%= f.text_field search_key, placeholder: hint %>
|
|
10
|
-
<% end %>
|
|
11
|
-
<% end %>
|
|
12
|
-
<% else %>
|
|
13
|
-
<%= render :partial => "query_report/custom_filters", locals: {f: f, filter: filter} %>
|
|
14
|
-
<% end %>
|
|
15
|
-
<% end %>
|
|
16
|
-
|
|
17
|
-
<%= f.submit 'Search', :class => 'btn' %>
|
|
18
|
-
<% end %>
|
|
19
|
-
|
|
1
|
+
<%= render :partial => "query_report/search", locals: {report: @report} %>
|
|
20
2
|
<br/>
|
|
3
|
+
|
|
21
4
|
<%= link_to_download_report_pdf %>
|
|
22
5
|
<%= link_to_download_report_csv %>
|
|
23
|
-
<br/>
|
|
24
|
-
<br/>
|
|
25
|
-
|
|
26
|
-
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
|
27
|
-
<div id='chart' style="margin-left:auto;margin-right:auto;width:600px;"></div>
|
|
28
|
-
<%= render_chart(@record.chart.prepare, 'chart') if @record.chart %>
|
|
29
6
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<%=
|
|
33
|
-
<% @record.scopes.each do |scope| %>
|
|
34
|
-
<%= link_to_with_scope(scope, @record.current_scope) %>
|
|
35
|
-
<% end %>
|
|
7
|
+
<% if @report.has_chart? and @report.enable_chart? and @report.chart_on_web? %>
|
|
8
|
+
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
|
|
9
|
+
<%= render :partial => "query_report/charts", locals: {report: @report} %>
|
|
36
10
|
<% end %>
|
|
11
|
+
|
|
37
12
|
<br/>
|
|
13
|
+
<%# if @report.scopes.size > 0 %>
|
|
14
|
+
<%#= link_to_with_scope('all', @report.current_scope) %>
|
|
15
|
+
<%# @report.scopes.each do |scope| %>
|
|
16
|
+
<%#= link_to_with_scope(scope, @report.current_scope) %>
|
|
17
|
+
<%# end %>
|
|
18
|
+
<%# end %>
|
|
38
19
|
<br/>
|
|
39
20
|
|
|
40
|
-
<% if @
|
|
21
|
+
<% if @report.records.size > 0 %>
|
|
41
22
|
<table class="table table-bordered table-striped">
|
|
42
23
|
<thead>
|
|
43
|
-
<% @
|
|
44
|
-
<th><%= column.
|
|
24
|
+
<% @report.columns.each do |column| %>
|
|
25
|
+
<th><%= sort_link(@report.search, column.name) %></th>
|
|
45
26
|
<% end %>
|
|
46
27
|
</thead>
|
|
47
28
|
|
|
48
29
|
<tbody>
|
|
49
|
-
<% @
|
|
30
|
+
<% @report.records.each do |record| %>
|
|
50
31
|
<tr>
|
|
51
|
-
<% @
|
|
52
|
-
<td><%= record[column] %></td>
|
|
32
|
+
<% @report.columns.each do |column| %>
|
|
33
|
+
<td><%= record[column.humanize] %></td>
|
|
53
34
|
<% end %>
|
|
54
35
|
</tr>
|
|
55
36
|
<% end %>
|
|
@@ -59,4 +40,4 @@
|
|
|
59
40
|
<p>No record found</p>
|
|
60
41
|
<% end %>
|
|
61
42
|
|
|
62
|
-
<%= paginate @report.
|
|
43
|
+
<%= paginate @report.paginated_query if @report.paginate? %>
|
data/config/routes.rb
ADDED
data/db/schema.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
|
5
|
+
#
|
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
|
7
|
+
# database schema. If you need to create the application database on another
|
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
|
11
|
+
#
|
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
|
13
|
+
|
|
14
|
+
ActiveRecord::Schema.define(:version => 20130630132513) do
|
|
15
|
+
|
|
16
|
+
create_table "invoices", :force => true do |t|
|
|
17
|
+
t.string "title"
|
|
18
|
+
t.float "total_paid"
|
|
19
|
+
t.float "total_charged"
|
|
20
|
+
t.boolean "paid"
|
|
21
|
+
t.datetime "created_at", :null => false
|
|
22
|
+
t.datetime "updated_at", :null => false
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
create_table "users", :force => true do |t|
|
|
26
|
+
t.string "name"
|
|
27
|
+
t.string "email"
|
|
28
|
+
t.boolean "single"
|
|
29
|
+
t.date "dob"
|
|
30
|
+
t.datetime "created_at", :null => false
|
|
31
|
+
t.datetime "updated_at", :null => false
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
data/lib/query_report.rb
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
|
-
require
|
|
2
|
-
require 'query_report/report'
|
|
3
|
-
require 'query_report/chart/pie_chart'
|
|
4
|
-
require 'query_report/chart/custom_chart'
|
|
1
|
+
require "query_report/engine"
|
|
5
2
|
|
|
6
3
|
module QueryReport
|
|
7
|
-
|
|
8
|
-
#autoload :Helper, 'query_report/helper'
|
|
9
|
-
#autoload :Views, 'query_report/views'
|
|
10
|
-
#autoload :Report, 'query_report/report'
|
|
11
|
-
#autoload :Filter, 'query_report/filter'
|
|
12
|
-
#autoload :Column, 'query_report/column'
|
|
4
|
+
autoload :Configuration, "query_report/config"
|
|
13
5
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
def self.configure(&block)
|
|
7
|
+
yield @config ||= QueryReport::Configuration.new
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.config
|
|
11
|
+
@config
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
configure do |config|
|
|
15
|
+
config.pdf_options = {
|
|
16
|
+
template_class: nil,
|
|
17
|
+
color: '000000',
|
|
18
|
+
font_size: 12,
|
|
19
|
+
table: {
|
|
20
|
+
row: {odd_bg_color: "DDDDDD", even_bg_color: "FFFFFF"},
|
|
21
|
+
header: {bg_color: 'AAAAAA', font_size: 12}
|
|
22
|
+
},
|
|
23
|
+
chart: { height: 160, width: 200 }
|
|
24
|
+
}
|
|
25
|
+
end
|
|
19
26
|
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'query_report/chart/chart_column'
|
|
2
|
+
require 'query_report/chart/themes'
|
|
3
|
+
|
|
4
|
+
module QueryReport
|
|
5
|
+
module Chart
|
|
6
|
+
class ChartBase
|
|
7
|
+
attr_reader :title, :options, :columns, :data
|
|
8
|
+
|
|
9
|
+
def initialize(title, query, options={})
|
|
10
|
+
@title = title
|
|
11
|
+
@query = query
|
|
12
|
+
@options = {:width => 500, :height => 240}.merge(options)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def add(column_title, &block)
|
|
16
|
+
val = block.call(@query)
|
|
17
|
+
@columns ||= []
|
|
18
|
+
@columns << QueryReport::Chart::Column.new(column_title, val.kind_of?(String) ? :string : :number)
|
|
19
|
+
@data ||= []
|
|
20
|
+
@data << val
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def prepare_visualr(type)
|
|
24
|
+
@data_table = GoogleVisualr::DataTable.new
|
|
25
|
+
|
|
26
|
+
##### Adding column header #####
|
|
27
|
+
@data_table.new_column('string', '') if type == :column
|
|
28
|
+
@columns.each do |col|
|
|
29
|
+
@data_table.new_column(col.type.to_s, col.title)
|
|
30
|
+
end
|
|
31
|
+
##### Adding column header #####
|
|
32
|
+
|
|
33
|
+
##### Adding value #####
|
|
34
|
+
chart_row_data = type == :column ? [''] + @data : @data
|
|
35
|
+
@data_table.add_row(chart_row_data)
|
|
36
|
+
##### Adding value #####
|
|
37
|
+
|
|
38
|
+
options = {:title => title, backgroundColor: 'transparent'}.merge(@options)
|
|
39
|
+
chart_type = "#{type}_chart".classify
|
|
40
|
+
chart_type = "GoogleVisualr::Interactive::#{chart_type}".constantize
|
|
41
|
+
ap @data_table.as_json
|
|
42
|
+
chart_type.new(@data_table, options)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def to_blob(type)
|
|
46
|
+
chart_type = type.to_s.classify
|
|
47
|
+
chart_type = "Gruff::#{chart_type}".constantize
|
|
48
|
+
|
|
49
|
+
@gruff = chart_type.new(@options[:width])
|
|
50
|
+
@gruff.title = title
|
|
51
|
+
@gruff.theme = QueryReport::Chart::Themes::GOOGLE_CHART
|
|
52
|
+
@data.each_with_index do |value, i|
|
|
53
|
+
@gruff.data(@columns[i].title, value)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
@gruff.to_blob
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|