query_report 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in query_report.gemspec
4
4
  gemspec
5
+
6
+ group :development do
7
+ gem 'jquery-rails'
8
+ gem 'bullet'
9
+ gem 'rack-mini-profiler'
10
+ end
data/lib/query_report.rb CHANGED
@@ -1,13 +1,19 @@
1
- require "query_report/version"
2
- require "query_report/report"
1
+ require 'query_report/version'
2
+ require 'query_report/report'
3
3
  require 'query_report/chart/pie_chart'
4
4
  require 'query_report/chart/custom_chart'
5
5
 
6
6
  module QueryReport
7
- autoload :VERSION, 'query_report/version'
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'
7
+ #autoload :VERSION, 'query_report/version'
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'
13
+
14
+ #mattr_accessor :chart_on_pdf
15
+ #self.chart_on_pdf = true
16
+ #
17
+ #mattr_accessor :paginate
18
+ #self.paginate = true
13
19
  end
@@ -1,17 +1,32 @@
1
1
  module QueryReport
2
- class Column
3
- attr_reader :name, :options, :type, :data
2
+ module ColumnModule
3
+ def column(name, options={}, &block)
4
+ options.merge!(model_name: model_name)
5
+ @columns << Column.new(name, options, block)
6
+ end
4
7
 
5
- def initialize(name, options={}, block = nil)
6
- @name = name
7
- @options = options
8
- @type = (options.kind_of?(Hash) ? options[:type] : options) || 'string'
9
- @data = block || name.to_sym
8
+ def columns
9
+ @columns
10
10
  end
11
11
 
12
- def humanize
13
- options[:as] || name.to_s.humanize
12
+ def column_names
13
+ @column_names ||= (@columns||[]).collect(&:humanize)
14
14
  end
15
- end
16
15
 
16
+ class Column
17
+ attr_reader :name, :options, :type, :data
18
+
19
+ def initialize(name, options={}, block = nil)
20
+ @name = name
21
+ @options = options
22
+ @type = (options.kind_of?(Hash) ? options[:type] : options) || 'string'
23
+ @data = block || name.to_sym
24
+ end
25
+
26
+ def humanize
27
+ options[:as] || I18n.t("activerecord.models.#{options[:model_name]}.#{name}", :default => name.to_s.humanize)
28
+ end
29
+ end
30
+
31
+ end
17
32
  end
@@ -1,52 +1,66 @@
1
1
  module QueryReport
2
- class Filter
3
- attr_reader :params, :column, :type, :comparators, :block, :custom
4
-
5
- def initialize(params, column, options, &block)
6
- @params = params
7
- @column = column
8
- @type = options if options.kind_of? String
9
- if options.kind_of? Hash
10
- @type = options[:type]
11
- @comparators = options[:comp] || detect_comparators(@type)
12
- end
13
- @block = block
14
- @custom = @block ? true : false
2
+ module FilterModule
3
+ def filter(column, options, &block)
4
+ @filters << Filter.new(@params, column, options, &block)
15
5
  end
16
6
 
17
- def self.supported_types
18
- [:date, :text]
7
+ def filter_with_values
8
+ hash = {}
9
+ @filters.each do |filter|
10
+ hash.merge!(filter.filter_with_values)
11
+ end
12
+ hash
19
13
  end
20
14
 
21
- def keys
22
- @keys ||= (@comparators || {}).keys.map { |comp| "#{column.to_s}_#{comp}" }
23
- end
15
+ class Filter
16
+ attr_reader :params, :column, :type, :comparators, :block, :custom
24
17
 
25
- supported_types.each do |supported_type|
26
- define_method("#{supported_type.to_s}?") do
27
- @type == supported_type
18
+ def initialize(params, column, options, &block)
19
+ @params = params
20
+ @column = column
21
+ @type = options if options.kind_of? String
22
+ if options.kind_of? Hash
23
+ @type = options[:type]
24
+ @comparators = options[:comp] || detect_comparators(@type)
25
+ end
26
+ @block = block
27
+ @custom = @block ? true : false
28
28
  end
29
- end
30
29
 
31
- def filter_with_values
32
- hash = {}
33
- @comparators.each do |key, filter_name|
34
- [key, filter_name]
35
- param_key = "#{column.to_s}_#{key.to_s}"
36
- hash[filter_name] = @params['q'][param_key] || @params['custom_search'][param_key] rescue ''
30
+ def self.supported_types
31
+ [:date, :text]
32
+ end
33
+
34
+ def keys
35
+ @keys ||= (@comparators || {}).keys.map { |comp| "#{column.to_s}_#{comp}" }
36
+ end
37
+
38
+ supported_types.each do |supported_type|
39
+ define_method("#{supported_type.to_s}?") do
40
+ @type == supported_type
41
+ end
42
+ end
43
+
44
+ def filter_with_values
45
+ hash = {}
46
+ @comparators.each do |key, filter_name|
47
+ [key, filter_name]
48
+ param_key = "#{column.to_s}_#{key.to_s}"
49
+ hash[filter_name] = @params['q'][param_key] || @params['custom_search'][param_key] rescue ''
50
+ end
51
+ hash
37
52
  end
38
- hash
39
- end
40
53
 
41
- private
42
- def detect_comparators(type)
43
- case type
44
- when :date
45
- return {gteq: I18n.t('query_report.filters.from'), lteq: I18n.t('query_report.filters.to')}
46
- when :text
47
- return {cont: @column.to_s.humanize}
54
+ private
55
+ def detect_comparators(type)
56
+ case type
57
+ when :date
58
+ return {gteq: I18n.t('query_report.filters.from'), lteq: I18n.t('query_report.filters.to')}
59
+ when :text
60
+ return {cont: @column.to_s.humanize}
61
+ end
62
+ {eq: I18n.t('query_report.filters.equal')}
48
63
  end
49
- {eq: I18n.t('query_report.filters.equal')}
50
64
  end
51
65
  end
52
66
  end
@@ -1,24 +1,20 @@
1
1
  require 'query_report/filter'
2
2
  require 'query_report/column'
3
- require 'query_report/chart/basic_chart'
4
- require 'query_report/chart/chart_with_total'
5
3
 
6
4
  module QueryReport
7
5
  DEFAULT_OPTIONS = {
8
6
  chart_on_pdf: true, paginate: true
9
7
  }
8
+
10
9
  class Report
11
- include ActionView::Helpers
10
+ include QueryReport::ColumnModule
11
+ include QueryReport::FilterModule
12
12
 
13
13
  attr_accessor :params, :template, :chart, :charts, :filters, :scopes, :current_scope, :options
14
14
 
15
15
  def initialize(params, template, options={}, &block)
16
- @params = params
17
- @template = template
18
- @columns = []
19
- @filters = []
20
- @scopes = []
21
- @charts = []
16
+ @params, @template = params, template
17
+ @columns, @filters, @scopes, @charts = [], [], [], []
22
18
  @current_scope = @params[:scope] || 'all'
23
19
  @options = QueryReport::DEFAULT_OPTIONS.merge options
24
20
  instance_eval &block if block_given?
@@ -34,35 +30,15 @@ module QueryReport
34
30
 
35
31
  # to support the helper methods
36
32
  def method_missing(meth, *args, &block)
37
- #if Rails.application.routes.url_helpers.respond_to?(meth)
38
- # Rails.application.routes.url_helpers.send(meth, *args)
39
- #elsif ActionController::Base.helpers.respond_to?(meth)
40
- # ActionController::Base.helpers.send(meth, *args)
41
- #else
42
- # super # You *must* call super if you don't handle the
43
- # # method, otherwise you'll mess up Ruby's method
44
- # # lookup.
45
- #end
46
-
47
33
  if @template.respond_to?(meth)
48
34
  @template.send(meth, *args)
49
35
  else
50
- super # You *must* call super if you don't handle the
51
- # method, otherwise you'll mess up Ruby's method
52
- # lookup.
36
+ super
53
37
  end
54
38
  end
55
39
 
56
- def column(name, options={}, &block)
57
- @columns << Column.new(name, options, block)
58
- end
59
-
60
- def columns
61
- @columns
62
- end
63
-
64
- def column_names
65
- @column_names ||= (@columns||[]).collect(&:humanize)
40
+ def model_name
41
+ query.table.name.singularize
66
42
  end
67
43
 
68
44
  def query=(query)
@@ -95,21 +71,14 @@ module QueryReport
95
71
  end
96
72
  end
97
73
 
98
- def filter(column, options, &block)
99
- @filters << Filter.new(@params, column, options, &block)
100
- end
101
-
102
- def filter_with_values
103
- hash = {}
104
- @filters.each do |filter|
105
- hash.merge!(filter.filter_with_values)
106
- end
107
- hash
74
+ def scope(scope)
75
+ @scopes << scope
76
+ @scopes = @scopes.uniq
108
77
  end
109
78
 
110
- def column_chart(title, columns)
111
- @chart = QueryReport::Chart::BasicChart.new(:column, title, columns, all_records)
112
- @charts << @chart
79
+ def search
80
+ apply_filters_and_pagination
81
+ @search
113
82
  end
114
83
 
115
84
  def compare_with_column_chart(title, x_axis='', &block)
@@ -125,20 +94,6 @@ module QueryReport
125
94
  @charts << @chart
126
95
  end
127
96
 
128
- def pie_chart_on_total(title, columns)
129
- @chart = QueryReport::Chart::ChartWithTotal.new(:pie, title, columns, all_records, {:is3D => true})
130
- end
131
-
132
- def scope(scope)
133
- @scopes << scope
134
- @scopes = @scopes.uniq
135
- end
136
-
137
- def search
138
- apply_filters_and_pagination
139
- @search
140
- end
141
-
142
97
  private
143
98
  def apply_filters_and_pagination
144
99
  return if @applied_filters_and_pagination
@@ -1,3 +1,3 @@
1
1
  module QueryReport
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/query_report.gemspec CHANGED
@@ -17,8 +17,15 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib", "app"]
19
19
 
20
+ gem.add_dependency "rails", "~> 3.2.13"
20
21
  gem.add_dependency 'ransack'
21
22
  gem.add_dependency 'google_visualr', '>= 2.1'
22
23
  gem.add_dependency 'rmagick'
23
24
  gem.add_dependency 'gruff'
25
+ gem.add_dependency 'kaminari'
26
+
27
+ gem.add_development_dependency "sqlite3"
28
+ gem.add_development_dependency "jquery-rails"
29
+ gem.add_development_dependency "bullet"
30
+ gem.add_development_dependency "rack-mini-profiler"
24
31
  end
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.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-05-12 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.13
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 3.2.13
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: ransack
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +91,86 @@ dependencies:
75
91
  - - ! '>='
76
92
  - !ruby/object:Gem::Version
77
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: kaminari
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: sqlite3
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: jquery-rails
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: bullet
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: rack-mini-profiler
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
78
174
  description: This is a gem to help you to structure common reports of you application
79
175
  just by writing in the controller
80
176
  email:
@@ -93,7 +189,6 @@ files:
93
189
  - app/views/query_report/list.html.erb
94
190
  - lib/query_report.rb
95
191
  - lib/query_report/chart/basic_chart.rb
96
- - lib/query_report/chart/chart_with_total.rb
97
192
  - lib/query_report/chart/custom_chart.rb
98
193
  - lib/query_report/chart/pie_chart.rb
99
194
  - lib/query_report/chart/themes.rb
@@ -1,82 +0,0 @@
1
- module QueryReport
2
- module Chart
3
- class ChartWithTotal
4
- attr_reader :title, :columns, :type, :data, :options
5
-
6
- def initialize(type, name, columns, data, options={})
7
- @type = type
8
- @name = name
9
- @columns = []
10
- columns.each do |column|
11
- @columns << QueryReport::Column.new(column, 'number')
12
- end
13
- @data = data
14
- @options = options
15
- end
16
-
17
- def prepare
18
- data_table = GoogleVisualr::DataTable.new
19
- columns.each do |column|
20
- data_table.new_column(column.type, column.name)
21
- end
22
-
23
- row = []
24
- columns.each do |column|
25
- total = 0
26
- @data.each do |r|
27
- total += r[column].to_f
28
- end
29
- row << total
30
- end
31
-
32
- data_table.add_row(row)
33
-
34
- opts = {:width => 400, :height => 240, :title => title}.merge(options)
35
-
36
- chart_type = "#{type}_chart".classify
37
- chart_type = "GoogleVisualr::Interactive::#{chart_type}".constantize
38
- chart_type.new(data_table, opts)
39
- end
40
- end
41
- end
42
-
43
- #class ColumnChartWithTotal
44
- # attr_reader :title, :columns, :type, :data, :options
45
- #
46
- # def initialize(type, name, columns, data, options={})
47
- # @type = type
48
- # @name = name
49
- # @columns = []
50
- # columns.each do |column|
51
- # @columns << Report::Column.new(column, 'number')
52
- # end
53
- # @data = data
54
- # @options = options
55
- # end
56
- #
57
- # def prepare
58
- # data_table = GoogleVisualr::DataTable.new
59
- # columns.each do |column|
60
- # data_table.new_column(column.type, column.name)
61
- # end
62
- #
63
- # row = []
64
- # columns.each do |column|
65
- # total = 0
66
- # @data.each do |r|
67
- # total += r[column].to_f
68
- # end
69
- # row << total
70
- # end
71
- #
72
- # data_table.add_row(row)
73
- #
74
- # opts = {:width => 400, :height => 240, :title => title}.merge(options)
75
- #
76
- # chart_type = "#{type}_chart".classify
77
- # chart_type = "GoogleVisualr::Interactive::#{chart_type}".constantize
78
- # chart_type.new(data_table, opts)
79
- # end
80
- #end
81
-
82
- end