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 +4 -4
- data/app/components/marty/report_form.rb +44 -34
- data/app/controllers/marty/components_controller.rb +0 -26
- data/app/controllers/marty/report_controller.rb +29 -0
- data/config/routes.rb +1 -0
- data/lib/marty/data_conversion.rb +5 -7
- data/lib/marty/version.rb +1 -1
- data/spec/features/jobs_dashboard_spec.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e0cd1fb1ea76e53a48783a66d697d7d7014d2ed
|
4
|
+
data.tar.gz: 4f3bc6b7970ed8f8bcb394b28ad4a91f583078bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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(
|
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 =
|
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
|
-
#
|
104
|
-
#
|
105
|
-
|
106
|
-
|
107
|
-
|
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 =
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
@@ -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.
|
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
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.
|
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-
|
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
|