marty 1.0.22 → 1.0.23

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: 86d8dcf6f031cb37849a2835413f01577fe15309
4
- data.tar.gz: 3230c2099f30abb9f60c6d17d1b7da528e1b928c
3
+ metadata.gz: d0f81a144144beb77d9fafc82b8d638be6fbb501
4
+ data.tar.gz: 49a509cc8458a156deaf186c4401acbc10411436
5
5
  SHA512:
6
- metadata.gz: c6ffb9f4a6e963960f7d22254444c937431f4c185a1be67b6161db0b1d50fabfc857cf39cef9c6100db74d622ea406aed702b2d37863ef5c9af6c005d60e1057
7
- data.tar.gz: 4a0f2d03b75bb07f97f0fb38625a2f3b821a71df0286d27eeae4333965a8d21d6fd3bbfb819f8d47e3d2b6d771f7e33362c42e588b46d0e86f85748c3cc4e3aa
6
+ metadata.gz: eb8843be6891a672779cca79c29ca08b8879d58ef1f7c99a6353ecbd1cc5c28ced1f42913e891f7cb4311a0c5f59d50d906899488ea0978c87a2a75c7543a602
7
+ data.tar.gz: fd0588d9011f7734e478eca8a51e7f3092bd2fbb4a4734f399c2ee91dacad499b27d6ed70d062c877356c90d9be7235b191151618f7f0e8514b724a963bc3989
@@ -185,7 +185,8 @@ class Marty::ReportForm < Marty::Form
185
185
 
186
186
  raise "bad form items" unless items.is_a?(Array)
187
187
  raise "bad format" unless
188
- ["csv", "xlsx", "zip", "json"].member?(format)
188
+ Marty::ContentHandler::GEN_FORMATS.member?(format)
189
+
189
190
  rescue => exc
190
191
  c.title = "ERROR"
191
192
  c.items =
@@ -27,12 +27,6 @@ class Marty::ScriptForm < Marty::Form
27
27
  }
28
28
  JS
29
29
 
30
- c.get_script_body = l(<<-JS)
31
- function() {
32
- return this.getForm().findField('body').getValue();
33
- }
34
- JS
35
-
36
30
  # Sets an editor line class (unset any previous line class). For
37
31
  # now, only one line is classed at a time.
38
32
  c.set_line_error = l(<<-JS)
@@ -59,14 +53,16 @@ class Marty::ScriptForm < Marty::Form
59
53
 
60
54
  ######################################################################
61
55
 
62
- # FIXME: no longer works -- see related FIXME below.
63
- c.on_print = l(<<-JS)
64
- function() {
65
- window.open(
66
- "/marty/components/#{self.name}.html?script_id=" + this.getScriptId(),
67
- "printing",
68
- 'width=800,height=700,toolbar=no,location=no,directories=no,'+
69
- 'status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
56
+ c.netzke_on_do_print = l(<<-JS)
57
+ function(params) {
58
+ this.server.doPrint(this.getScriptId());
59
+ }
60
+ JS
61
+
62
+ c.download_report = l(<<-JS)
63
+ function(jid) {
64
+ // FIXME: seems pretty hacky
65
+ window.location = "#{Marty::Util.marty_path}/job/download?job_id=" + jid;
70
66
  }
71
67
  JS
72
68
  end
@@ -170,13 +166,36 @@ class Marty::ScriptForm < Marty::Form
170
166
  client.netzke_apply_form_errors(build_form_errors(record))
171
167
  end
172
168
 
169
+ endpoint :do_print do |script_id|
170
+ return client.netzke_notify("Permission Denied") unless
171
+ self.class.has_any_perm?
172
+
173
+ script = Marty::Script.find_by_id(script_id)
174
+
175
+ return client.netzke_notify("bad script") unless script
176
+
177
+ begin
178
+ job_id = Marty::Util.
179
+ background_report("ScriptReport",
180
+ "PrettyScript",
181
+ {
182
+ "script_id" => script.id,
183
+ "title" => script.name,
184
+ },
185
+ true,
186
+ )
187
+ client.download_report job_id
188
+ rescue => exc
189
+ return client.netzke_notify "ERROR: #{exc}"
190
+ end
191
+ end
192
+
173
193
  ######################################################################
174
194
 
175
- action :print do |a|
195
+ action :do_print do |a|
176
196
  a.text = I18n.t("script_form.print")
177
197
  a.tooltip = I18n.t("script_form.print")
178
198
  a.icon = :printer
179
- a.handler = :on_print
180
199
  end
181
200
 
182
201
  ######################################################################
@@ -184,26 +203,12 @@ class Marty::ScriptForm < Marty::Form
184
203
  def default_bbar
185
204
  [
186
205
  :apply,
187
- :print,
206
+ :do_print,
188
207
  ]
189
208
  end
190
209
 
191
210
  ######################################################################
192
211
 
193
- # Used for printing: REALLY FIXME -- this no longer works since the
194
- # removal of the component export_content hack. -- To fix, we should
195
- # create a ScriptPrint report. Then, we should have the button run
196
- # this report in the foreground. The problem is that we currently
197
- # don't have any delorean files in Marty to create a report.
198
- def export_content(format, title, params={})
199
- raise "unknown format: #{format}" unless format == "html"
200
-
201
- r = Marty::Script.find_by_id(params[:script_id])
202
- res = CodeRay.scan(r.body, :ruby).div(line_numbers: :table)
203
-
204
- [res, "text/html", "inline", "#{title}.html"]
205
- end
206
-
207
212
  def configure(c)
208
213
  super
209
214
 
@@ -107,12 +107,15 @@ class Marty::Script < Marty::Base
107
107
  elsif Rails.configuration.marty.delorean_scripts_path
108
108
  paths = Rails.configuration.marty.delorean_scripts_path
109
109
  else
110
- paths = ["#{Rails.root}/delorean",
111
- File.expand_path('../../../../delorean', __FILE__)]
110
+ paths = [
111
+ "#{Rails.root}/delorean",
112
+ # FIXME: HACKY, wouldn't it be better to use
113
+ # Gem::Specification.find_by_name("marty").gem_dir??
114
+ File.expand_path('../../../../delorean', __FILE__),
115
+ ]
112
116
  end
113
117
  end
114
118
 
115
-
116
119
  def self.delete_scripts
117
120
  ActiveRecord::Base.connection.
118
121
  execute("ALTER TABLE marty_scripts DISABLE TRIGGER USER;")
@@ -139,4 +142,13 @@ class Marty::Script < Marty::Base
139
142
  # current tag can caused problems.
140
143
  res
141
144
  end
145
+
146
+ delorean_fn :pretty_print, sig: 1 do
147
+ |id|
148
+ script = find_by_id id
149
+
150
+ next "unknown script #{id}" unless script
151
+
152
+ CodeRay.scan(script.body, :ruby).div(line_numbers: :table)
153
+ end
142
154
  end
@@ -49,5 +49,5 @@ end
49
49
 
50
50
  # one time set up for delayed_job/promises, override only needed
51
51
  # if DELAYED_JOB_PATH is not bin/delayed_job
52
- Marty::Config["DELAYED_JOB_PARAMS"] = "-n 4"
52
+ Marty::Config["DELAYED_JOB_PARAMS"] ||= "-n 4 --sleep-delay 5"
53
53
  # Marty::Config["DELAYED_JOB_PATH"] = "script/delayed_job"
@@ -0,0 +1,12 @@
1
+ IdField:
2
+ xtype = ":numberfield"
3
+ field_label = "Id"
4
+ name = "script_id"
5
+
6
+ PrettyScript:
7
+ script_id =? nil
8
+ title =? "Script Printing"
9
+
10
+ form = [IdField]
11
+ result = Marty::Script.pretty_print(script_id)
12
+ format = "html"
@@ -3,7 +3,7 @@ module Marty::ContentHandler
3
3
  "csv" => ['text/csv', 'download'],
4
4
  "zip" => ['application/zip', 'download'],
5
5
  "xlsx" => ['application/vnd.ms-excel', 'download'],
6
- "html" => ['text/html', 'inline'],
6
+ "html" => ['text/html', 'download'],
7
7
  "txt" => ['text/plain', 'inline'],
8
8
  "json" => ['application/json', 'download'],
9
9
 
@@ -29,6 +29,8 @@ module Marty::ContentHandler
29
29
  res = to_zip(data)
30
30
  when nil, "json"
31
31
  res, format = data.to_json, "json"
32
+ when "html"
33
+ res = data.to_s
32
34
  else
33
35
  res, format = {error: "Unknown format: #{format}"}.to_json, "json"
34
36
  end
@@ -107,4 +107,18 @@ module Marty::Util
107
107
  obj.is_a?(Float)? obj.round(digits) : obj
108
108
  end
109
109
  end
110
+
111
+ # Run a report as a promise and return its promise ID.
112
+ def self.background_report(script_name, node_name, params, force)
113
+ engine = Marty::ScriptSet.new.get_engine(script_name)
114
+ res = engine.background_eval(node_name,
115
+ params,
116
+ ["result", "title", "format"],
117
+ )
118
+
119
+ promise_id = res.__promise__.id
120
+ res.force if force
121
+
122
+ promise_id
123
+ end
110
124
  end
@@ -1,3 +1,3 @@
1
1
  module Marty
2
- VERSION = "1.0.22"
2
+ VERSION = "1.0.23"
3
3
  end
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: 1.0.22
4
+ version: 1.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arman Bostani
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2017-02-13 00:00:00.000000000 Z
17
+ date: 2017-03-01 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: pg
@@ -440,6 +440,7 @@ files:
440
440
  - db/migrate/201_create_marty_events.rb
441
441
  - db/migrate/202_add_completion_status_to_event.rb
442
442
  - db/seeds.rb
443
+ - delorean/script_report.dl
443
444
  - gemini_deprecations.md
444
445
  - lib/marty.rb
445
446
  - lib/marty/content_handler.rb