marty 0.5.16 → 0.5.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ee57ec5bc50741eda9ea8b4cc109221e1cf2e57c
4
- data.tar.gz: 486efeb1bdde157cf0eff2ce7c0f67e5999727ae
3
+ metadata.gz: 3e0cd1fb1ea76e53a48783a66d697d7d7014d2ed
4
+ data.tar.gz: 4f3bc6b7970ed8f8bcb394b28ad4a91f583078bd
5
5
  SHA512:
6
- metadata.gz: 44701d2a49b44b9f433e7b32f79d17d1db6d7ea1af47d660721e8f678278a919bf1f5482d6c6321ee5feef7a7b0dff751f2a50713d968a98c9adc4165091ecf8
7
- data.tar.gz: c16b0685d1a63cd10afd0e3b6b8fefa0336c792bceba6df7946e9ed11a80c5833032728cd866354fe263da42a181d28b03ec11385fe5144ead71cbec16f55a8d
6
+ metadata.gz: 9d0859d91f1b17547f132cef0123b19255f8186839fcbc11e145d716272de3f2b3f749eec155e5f00ff249b4640f2e61ee76cb01f7c2d6b8f37e57cd7637f8bf
7
+ data.tar.gz: 9d05effd3f15b9f08ac668c6ba9cd7bfa6d3bb22eac7351c7cd3726cab51e7da6bea0683080023234683d52d6373735818bc50a96a160f26ddc4535719192361
@@ -25,7 +25,15 @@ class Marty::ReportForm < Marty::Form
25
25
 
26
26
  ######################################################################
27
27
 
28
- def _get_report_engine(params)
28
+ # FIXME: Most of the following functionality should be moved out to
29
+ # a library. It doesn't belong here in a component. These are
30
+ # currently also getting called form the report controller.
31
+
32
+ # FIXME: The usage of session/root_sess should be entirely removed.
33
+ # Instead we should send in :selected_node, :selected_tag_id,
34
+ # :selected_script_name as params.
35
+
36
+ def self.get_report_engine(params, session)
29
37
  d_params = ActiveSupport::JSON.decode(params[:data] || "{}")
30
38
  d_params.each_pair do |k,v|
31
39
  d_params[k] = nil if v.blank? || v == "null"
@@ -39,11 +47,15 @@ class Marty::ReportForm < Marty::Form
39
47
  [engine, d_params]
40
48
  end
41
49
 
42
- def run_eval(params)
43
- engine, d_params = _get_report_engine(params)
50
+ def self.run_eval(params, session)
51
+ node = session[:selected_node]
52
+
53
+ raise "no selected report node" unless String === node
54
+
55
+ engine, d_params = get_report_engine(params, session)
44
56
 
45
57
  begin
46
- engine.evaluate(session[:selected_node], "result", d_params)
58
+ engine.evaluate(node, "result", d_params)
47
59
  rescue => exc
48
60
  Marty::Util.logger.error "run_eval failed: #{exc.backtrace}"
49
61
 
@@ -55,7 +67,7 @@ class Marty::ReportForm < Marty::Form
55
67
  end
56
68
 
57
69
  def export_content(format, title, params={})
58
- data = run_eval(params)
70
+ data = self.class.run_eval(params, session)
59
71
 
60
72
  # hacky: shouldn't have error parsing logic here
61
73
  format = "json" if data.is_a?(Hash) && (data[:error] || data["error"])
@@ -75,7 +87,7 @@ class Marty::ReportForm < Marty::Form
75
87
  endpoint :netzke_submit do |params, this|
76
88
  # We get here when user is asking for a background report
77
89
 
78
- engine, d_params = _get_report_engine(params)
90
+ engine, d_params = self.class.get_report_engine(params, session)
79
91
 
80
92
  roles = engine.
81
93
  evaluate(session[:selected_node], "roles", {}) rescue nil
@@ -100,39 +112,37 @@ class Marty::ReportForm < Marty::Form
100
112
  ######################################################################
101
113
 
102
114
  js_configure do |c|
103
- # FIXME: Can we use POST instead of get:
104
- # http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit
105
- # arman -- I tried this solution. However, with a POST, the
106
- # component doesn't get the session cookie. Therefore, we don't
107
- # have access to the selected script. QQQ: why not just send the
108
- # session cookie in the header?? also see -- using XMLHttpRequest
109
- # http://stackoverflow.com/questions/9516865/how-to-set-a-header-field-on-post-a-form
110
- # http://stackoverflow.com/questions/9713058/sending-post-data-with-a-xmlhttprequest
111
- # Or, perhaps use ExtJS Ajax:
112
- # http://stackoverflow.com/questions/2917581/how-to-post-json-data-with-extjs
115
+ # Find the mount path for the Marty engine. FIXME: this is likely
116
+ # very brittle.
117
+ @@mount_path = Rails.application.routes.routes.detect {
118
+ |r| r.app.app == Marty::Engine
119
+ }.format({})
113
120
 
114
121
  c.on_foreground = <<-JS
115
122
  function() {
116
123
  var values = this.getForm().getValues();
117
- var data = escape(Ext.encode(values));
118
- if (data.length > 4096) {
119
- msg = "There is too much data to run as a foreground report." +\
120
- "<br/>Please run as a background report."
121
- Ext.create('Ext.Window', {
122
- height: 100,
123
- minWidth: 350,
124
- autoWidth: true,
125
- modal: true,
126
- autoScroll: true,
127
- html: msg,
128
- title: "Warning"
129
- }).show();
130
- } else {
131
- // FIXME: this is very hacky since it bypasses Netzke channel.
132
- // This is a security hole wrt to the report role mechanism.
133
- window.location = "/marty/components/#{self.name}." + this.repformat +\
134
- "?data=" + data + "&reptitle=" + this.reptitle;
124
+ var data = Ext.encode(values);
125
+
126
+ var form = document.createElement("form");
127
+ form.setAttribute("method", "post");
128
+ form.setAttribute("action", "#{@@mount_path}/report."+this.repformat);
129
+
130
+ var params = {data: data, reptitle: this.reptitle};
131
+
132
+ for(var key in params) {
133
+ if (params.hasOwnProperty(key)) {
134
+ var hiddenField = document.createElement("input");
135
+ hiddenField.setAttribute("type", "hidden");
136
+ hiddenField.setAttribute("name", key);
137
+ hiddenField.setAttribute("value", params[key]);
138
+
139
+ form.appendChild(hiddenField);
140
+ }
135
141
  }
142
+
143
+ document.body.appendChild(form);
144
+ form.submit();
145
+ document.body.removeChild(form);
136
146
  }
137
147
  JS
138
148
  end
@@ -3,37 +3,11 @@ class Marty::ComponentsController < Marty::ApplicationController
3
3
  # appropriate route needs to be defined.
4
4
  # <base_url>/components/<ComponentCamelCaseName>
5
5
 
6
- # FIXME: what is this??????
7
- # helper Rails.application.routes.url_helpers
8
-
9
6
  def index
10
7
  component = params[:component]
11
8
 
12
9
  return redirect_to root_path unless component
13
10
 
14
- format, req_disposition, title =
15
- params[:format], params[:disposition], params[:reptitle]
16
-
17
- if format && Marty::ContentHandler::GEN_FORMATS.member?(format)
18
- klass = component.constantize
19
-
20
- raise "bad component" unless klass < Netzke::Base
21
-
22
- inst = klass.new
23
- return unless inst.respond_to?(:export_content)
24
-
25
- title ||= component
26
-
27
- res, type, disposition, filename =
28
- inst.export_content(format, title, params)
29
-
30
- return send_data(res,
31
- type: type,
32
- filename: filename,
33
- disposition: req_disposition || disposition,
34
- )
35
- end
36
-
37
11
  cname = component.gsub("::", "_").underscore
38
12
  render layout: true,
39
13
  inline: "<%= netzke :#{cname}, class_name: '#{component}', height: 650 %>"
@@ -0,0 +1,29 @@
1
+ class Marty::ReportController < ActionController::Base
2
+ def index
3
+ format, req_disposition, title =
4
+ params[:format], params[:disposition], params[:reptitle]
5
+
6
+ raise "bad format" unless Marty::ContentHandler::GEN_FORMATS.member?(format)
7
+
8
+ data = Marty::ReportForm.run_eval(params, session)
9
+
10
+ # hacky: shouldn't have error parsing logic here
11
+ format = "json" if data.is_a?(Hash) && (data[:error] || data["error"])
12
+
13
+ # hack for testing -- txt -> csv
14
+ exp_format = format == "txt" ? "csv" : format
15
+
16
+ res, type, disposition, filename =
17
+ Marty::ContentHandler.
18
+ export(data, exp_format, title)
19
+
20
+ # hack for testing -- set content-type
21
+ type = "text/plain" if format == "txt" && type =~ /csv/
22
+
23
+ return send_data(res,
24
+ type: type,
25
+ filename: filename,
26
+ disposition: req_disposition || disposition,
27
+ )
28
+ end
29
+ end
data/config/routes.rb CHANGED
@@ -3,4 +3,5 @@ require 'netzke-core'
3
3
  Marty::Engine.routes.draw do
4
4
  match via: [:get, :post], "rpc/:action(.:format)" => "rpc", as: :rpc
5
5
  get "job/:action" => "job", as: :job
6
+ match via: [:get, :post], "report(.:format)" => "report#index", as: :report
6
7
  end
@@ -43,7 +43,7 @@ class Marty::DataConversion
43
43
  case v.to_s.downcase
44
44
  when "true", "1", "y" then true
45
45
  when "false", "0", "n" then false
46
- else raise "unknown boolean #{v}"
46
+ else raise "unknown boolean: #{v.inspect}"
47
47
  end
48
48
  when :string, :text
49
49
  v
@@ -55,27 +55,25 @@ class Marty::DataConversion
55
55
  v.to_d
56
56
  when :date
57
57
  # Dates are kept as float in Google spreadsheets. Need to
58
- # convert them to dates. FIXME: 'infinity' as a date in
59
- # Rails 3.2 appears to be broken. Setting a date field to
60
- # 'infinity' sets it to nil.
58
+ # convert them to dates.
61
59
  begin
62
60
  v =~ FLOAT_PAT ? EXCEL_START_DATE + v.to_f :
63
61
  Mcfly.is_infinity(v) ? 'infinity' : v.to_date
64
62
  rescue => exc
65
- raise "date conversion failed for #{v}"
63
+ raise "date conversion failed for #{v.inspect}}"
66
64
  end
67
65
  when :datetime
68
66
  begin
69
67
  Mcfly.is_infinity(v) ? 'infinity' : v.to_datetime
70
68
  rescue => exc
71
- raise "datetime conversion failed for #{v}"
69
+ raise "datetime conversion failed for #{v.inspect}}"
72
70
  end
73
71
  when :numrange, :int4range, :int8range
74
72
  v.to_s
75
73
  when :float_array, :json, :jsonb
76
74
  JSON.parse Marty::DataExporter.decode_json(v)
77
75
  else
78
- raise "unknown type #{type} for #{v}"
76
+ raise "unknown type #{type} for #{v.inspect}}"
79
77
  end
80
78
  end
81
79
 
data/lib/marty/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Marty
2
- VERSION = "0.5.16"
2
+ VERSION = "0.5.17"
3
3
  end
@@ -16,6 +16,7 @@ describe 'Jobs Dashboard', type: :feature, js: true, capybara: true do
16
16
  start_dt: Time.now
17
17
 
18
18
  visit "/"
19
+ all 'span', text: 'Sign in'
19
20
  find(ext_button_id('Sign in')).click
20
21
  fill_in 'Login', with: 'marty'
21
22
  fill_in 'Password', with: 'marty'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.16
4
+ version: 0.5.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arman Bostani
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-11-27 00:00:00.000000000 Z
15
+ date: 2015-12-04 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: pg
@@ -355,6 +355,7 @@ files:
355
355
  - app/controllers/marty/application_controller.rb
356
356
  - app/controllers/marty/components_controller.rb
357
357
  - app/controllers/marty/job_controller.rb
358
+ - app/controllers/marty/report_controller.rb
358
359
  - app/controllers/marty/rpc_controller.rb
359
360
  - app/helpers/marty/application_helper.rb
360
361
  - app/helpers/marty/script_set.rb