query_report 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
1
  module QueryReport
2
2
  class Filter
3
- attr_reader :column, :type, :comparators, :block, :custom
3
+ attr_reader :params, :column, :type, :comparators, :block, :custom
4
4
 
5
- def initialize(column, options, &block)
5
+ def initialize(params, column, options, &block)
6
+ @params = params
6
7
  @column = column
7
8
  @type = options if options.kind_of? String
8
9
  if options.kind_of? Hash
@@ -27,15 +28,25 @@ module QueryReport
27
28
  end
28
29
  end
29
30
 
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 ''
37
+ end
38
+ hash
39
+ end
40
+
30
41
  private
31
42
  def detect_comparators(type)
32
43
  case type
33
44
  when :date
34
- return {gteq: 'From', lteq: 'To'}
45
+ return {gteq: I18n.t('query_report.filters.from'), lteq: I18n.t('query_report.filters.to')}
35
46
  when :text
36
47
  return {cont: @column.to_s.humanize}
37
48
  end
38
- {eq: 'Equal'}
49
+ {eq: I18n.t('query_report.filters.equal')}
39
50
  end
40
51
  end
41
52
  end
@@ -87,7 +87,15 @@ module QueryReport
87
87
  end
88
88
 
89
89
  def filter(column, options, &block)
90
- @filters << Filter.new(column, options, &block)
90
+ @filters << Filter.new(@params, column, options, &block)
91
+ end
92
+
93
+ def filter_with_values
94
+ hash = {}
95
+ @filters.each do |filter|
96
+ hash.merge!(filter.filter_with_values)
97
+ end
98
+ hash
91
99
  end
92
100
 
93
101
  def column_chart(title, columns)
@@ -1,3 +1,3 @@
1
1
  module QueryReport
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  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.0.7
4
+ version: 0.0.8
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-16 00:00:00.000000000 Z
12
+ date: 2013-04-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ransack