rgviz-rails 0.54 → 0.55

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,17 +20,19 @@ module Rgviz
20
20
  tqx = Rgviz::Tqx.parse(tqx)
21
21
 
22
22
  begin
23
- if model.is_a? Class and model < ActiveRecord::Base
24
- executor = Rgviz::Executor.new model
25
- elsif model.respond_to? :execute
26
- executor = model
27
- else
28
- raise "The argument to render :rgviz => ... must extend from ActiveRecord::Base or respond to execute"
29
- end
30
23
  options = {}
31
24
  options[:conditions] = conditions if conditions
32
25
  options[:extensions] = extensions if extensions
33
- table = executor.execute query, options
26
+
27
+ table = if model.is_a?(Class) && model < ActiveRecord::Base
28
+ Rgviz::Executor.new(model).execute query, options
29
+ elsif model.respond_to? :execute
30
+ model.execute query, options
31
+ elsif model.is_a? Rgviz::Table
32
+ model
33
+ else
34
+ raise "The argument to render :rgviz => ... must extend from ActiveRecord::Base, respond to execute or be an Rgviz::Table"
35
+ end
34
36
 
35
37
  yield table if block_given?
36
38
 
@@ -19,6 +19,7 @@ module Rgviz
19
19
  html = options[:html] || {}
20
20
  hidden = options[:hidden]
21
21
  extensions = options[:extensions]
22
+ conditions = options[:conditions]
22
23
 
23
24
  rgviz_events, google_events = events.partition{|x| x[0].to_s.start_with? 'rgviz'}
24
25
  rgviz_events = rgviz_events.inject(Hash.new){|h, y| h[y[0]] = y[1]; h}
@@ -79,7 +80,8 @@ module Rgviz
79
80
  raise "Must specify a :kind" unless kind
80
81
  raise "Must specify a :url" unless url
81
82
 
82
- url = url_for url
83
+ custom_executor = (url.is_a?(Class) and url < ActiveRecord::Base) || url.respond_to?(:execute) || url.is_a?(Rgviz::Table)
84
+ url = url_for url unless custom_executor
83
85
 
84
86
  # Parse the query
85
87
  query = Parser.parse query, :extensions => extensions
@@ -167,21 +169,41 @@ module Rgviz
167
169
 
168
170
  # And define the callback
169
171
  out << "function #{callback}(#{params.join(', ')}) {\n"
170
- out << " #{rgviz_events[:rgviz_start]}('#{id}');\n" if rgviz_events[:rgviz_start]
172
+ out << " #{rgviz_events[:rgviz_start]}('#{id}');\n" if rgviz_events[:rgviz_start]
173
+ unless custom_executor
171
174
  out << " var query = new google.visualization.Query('#{url}');\n"
172
175
  out << " #{query_builder}\n"
173
176
  out << " alert(#{query_builder_var});\n" if debug
174
177
  out << " query.setQuery(#{query_builder_var});\n"
175
178
  out << " query.send(function(response) {\n"
176
- out << " rgviz_#{id} = new google.visualization.#{kind}(document.getElementById('#{id}'));\n"
177
- google_events.each do |name, handler|
178
- out << " google.visualization.events.addListener(rgviz_#{id}, '#{name}', #{handler});\n"
179
- end
180
- out << " rgviz_#{id}_data = response.getDataTable();\n"
181
- out << " #{rgviz_events[:rgviz_before_draw]}(rgviz_#{id}, rgviz_#{id}_data);\n" if rgviz_events[:rgviz_before_draw]
182
- out << " rgviz_#{id}.draw(rgviz_#{id}_data, #{opts});\n"
183
- out << " #{rgviz_events[:rgviz_end]}('#{id}');\n" if rgviz_events[:rgviz_end]
184
- out << " });\n"
179
+ end
180
+ out << " rgviz_#{id} = new google.visualization.#{kind}(document.getElementById('#{id}'));\n"
181
+ google_events.each do |name, handler|
182
+ out << " google.visualization.events.addListener(rgviz_#{id}, '#{name}', #{handler});\n"
183
+ end
184
+
185
+ if custom_executor
186
+ executor_options = {}
187
+ executor_options[:conditions] = conditions if conditions
188
+ executor_options[:extensions] = extensions if extensions
189
+
190
+ table = if url.is_a?(Class) and url < ActiveRecord::Base
191
+ Rgviz::Executor.new(url).execute(query, executor_options)
192
+ elsif url.respond_to?(:execute)
193
+ url.execute(query, executor_options)
194
+ else
195
+ url
196
+ end
197
+ out << " rgviz_#{id}_data = new google.visualization.DataTable(#{table.to_json});\n"
198
+ else
199
+ out << " rgviz_#{id}_data = response.getDataTable();\n"
200
+ end
201
+ out << " #{rgviz_events[:rgviz_before_draw]}(rgviz_#{id}, rgviz_#{id}_data);\n" if rgviz_events[:rgviz_before_draw]
202
+ out << " rgviz_#{id}.draw(rgviz_#{id}_data, #{opts});\n"
203
+ out << " #{rgviz_events[:rgviz_end]}('#{id}');\n" if rgviz_events[:rgviz_end]
204
+ unless custom_executor
205
+ out << "});\n"
206
+ end
185
207
  out << "}\n"
186
208
 
187
209
  out << "</script>\n"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgviz-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.54'
4
+ version: '0.55'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rgviz
16
- requirement: &70276898913000 !ruby/object:Gem::Requirement
16
+ requirement: &70295143977060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70276898913000
24
+ version_requirements: *70295143977060
25
25
  description:
26
26
  email: aborenszweig@manas.com.ar
27
27
  executables: []