t2-web 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,11 @@
1
1
  = Changes log for the Taverna via the Web Gem
2
2
 
3
+ == Version 0.1.0
4
+ * Results are downloaded directly and stored in tmp files - progress cycle works once
5
+ * Added rackup configuration file: config.ru
6
+ * webapp is run using rackup now to enable configuration of web server timeout
7
+ * Increased tooltip size and anchored them to the 'west'
8
+ * Port is set via: rackup -p 9494
3
9
 
4
10
  == Version 0.0.9
5
11
  * Changed " to ' in generate_header_table (header HTML block used in JS .write("") method)
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
  Authors:: Konstantinos Karasavvas
5
- Gem Version:: 0.0.9
5
+ Gem Version:: 0.1.0
6
6
  Contact:: mailto:kostas.karasavvas@nbic.nl
7
7
  Licence:: MIT (See LICENCE or http://www.opensource.org/licenses/mit-license)
8
8
  Copyright:: (c) 2012 Netherlands Bioinformatics Centre, The Netherlands
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ require 'rdoc/task'
12
12
 
13
13
  spec = Gem::Specification.new do |s|
14
14
  s.name = 't2-web'
15
- s.version = '0.0.9'
15
+ s.version = '0.1.0'
16
16
  s.extra_rdoc_files = ['README', 'LICENSE', 'CHANGES']
17
17
  s.summary = 'Web application that generates a Web UI form for a Taverna2 workflow, given its myExperiment id, for ease of execution. The only requirement for the user is a web browser.'
18
18
  s.description = s.summary
data/bin/config.ru ADDED
@@ -0,0 +1,8 @@
1
+ require 'sinatra'
2
+ require './t2_webapp'
3
+
4
+ set :timeout, 600
5
+ #not picked up! ... set :port, 9494
6
+
7
+ run WebT2App
8
+
data/bin/t2_webapp.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'rubygems' if RUBY_VERSION < '1.9'
4
- require 'sinatra'
4
+ require 'sinatra/base'
5
5
  require 'haml'
6
6
  require 'open-uri'
7
7
  require 'rest-client'
8
8
  require 't2-server'
9
9
  require 'myexperiment-rest'
10
10
  require 'cgi'
11
+ require 'stringio'
11
12
  #require "t2-web" TODO: move whole of WebT2App in lib
12
13
 
13
14
  # TODO: add constants.rb file in lib for all constants (e.g. myExp user URL, other URLs
@@ -17,7 +18,7 @@ class WebT2App < Sinatra::Base
17
18
  WEB_APP_NAME = "t2web"
18
19
  # TODO: const for TMP_UPLOAD_PATH ? - need to read from config file?
19
20
 
20
- set :port, 9494
21
+ #set :port, 9494 set from: rackup -p 9494
21
22
  set :views, File.dirname(__FILE__) + '/../views'
22
23
  set :public_folder, File.dirname(__FILE__) + '/../public'
23
24
 
@@ -71,7 +72,7 @@ END
71
72
  end
72
73
 
73
74
 
74
- # Generates the contents of the header frame
75
+ # Generates the contents of the header frame table
75
76
  def generate_header_table(my_exp_wkf, my_exp_usr)
76
77
  <<END
77
78
  <div id='header'>
@@ -100,15 +101,20 @@ END
100
101
  end
101
102
 
102
103
 
103
- # Generates tooltip html text for descriptions
104
- def generate_label_tooltip(input)
105
- "Description: " << CGI::unescapeHTML(input.descriptions[0])
104
+ # Generates tooltip html text with type prefix
105
+ def generate_tooltip(type, input)
106
+ if type =~ /description/i
107
+ type << CGI::unescapeHTML(input.descriptions[0])
108
+ else
109
+ type << CGI::unescapeHTML(input.examples[0])
110
+ end
106
111
  end
107
112
 
113
+ # TODO: remove 02/04/2012
108
114
  # Generates tooltip html text for textarea example
109
- def generate_textarea_tooltip(input)
110
- "Example: " << CGI::unescapeHTML(input.examples[0])
111
- end
115
+ #def generate_textarea_tooltip(input)
116
+ # "Example: " << CGI::unescapeHTML(input.examples[0])
117
+ #end
112
118
 
113
119
 
114
120
  # Generates the contents of the data-navigation frame
@@ -119,7 +125,8 @@ END
119
125
  my_exp_wkf.outputs.each do |output|
120
126
  data_navigation_frame << "<tr>"
121
127
  if finished_execution
122
- data_navigation_frame << "<td><a href='javascript:void(0);' onclick='parent.getSampleOutput(\\\"#{t2_server}\\\", \\\"#{uuid}\\\", " <<
128
+ # TODO: currently t2_server, wid and wkf_version are not used
129
+ data_navigation_frame << "<td><a href='javascript:void(0);' onclick='parent.readTmpOutput(\\\"#{t2_server}\\\", \\\"#{uuid}\\\", " <<
123
130
  "\\\"#{output.name}\\\", \\\"#{wid}\\\", \\\"#{wkf_version}\\\");'>#{output.name}</a></td><td></td>"
124
131
  else
125
132
  data_navigation_frame << "<td>#{output.name}</td><td><img src='/images/snake_transparent.gif' alt='Loading Content...'></td>"
@@ -132,17 +139,38 @@ END
132
139
 
133
140
 
134
141
  # Check type of data and generate appropriate html for that result!
142
+ # Takes list as input -- TODO: rdoc methods properly!
135
143
  def generate_html_result(data)
136
- html = ""
137
- #p data
138
- if data.instance_of? Array
139
- html = data.flatten.join('<br>')
140
- elsif data.instance_of? String
141
- html = data.gsub(/[\n]/, '<br>')
144
+ data.gsub(/[\n]/, '<br>')
145
+ end
146
+
147
+
148
+ # Check type of data and generate appropriate html for that result!
149
+ # Takes list as input, returns as file stream -- TODO: rdoc methods properly!
150
+ def flatten_list_results(list)
151
+ data = ""
152
+ #p list
153
+ if list.instance_of? Array
154
+ # flatten (sub-)list and remove nils and if present, newlines
155
+ # then join list as a multi-line string
156
+ data = list.flatten.compact.map {|e| e.chomp}.join("\n")
142
157
  else
143
- html = data
158
+ data = list.chomp
144
159
  end
145
- html
160
+
161
+ StringIO.new data
162
+ end
163
+
164
+
165
+
166
+ # copies output stream to a tmp file in the specified subdir
167
+ # TODO: make proper rdoc
168
+ def copy_to_tmp(subdir, filename, out)
169
+ FileUtils.mkdir_p("/tmp/#{WEB_APP_NAME}/#{subdir}") unless File.exist?("/tmp/#{WEB_APP_NAME}/#{subdir}")
170
+ tmp_file = File.open("/tmp/#{WEB_APP_NAME}/#{subdir}/#{filename}", "w")
171
+ FileUtils.copy_stream(out, tmp_file)
172
+ tmp_file.close
173
+ "Successfully copied #{filename}!!"
146
174
  end
147
175
 
148
176
  end
@@ -240,46 +268,58 @@ END
240
268
  end
241
269
 
242
270
 
243
-
244
- # Get results for specified run and output - display it in data-display div
271
+ # Get results from all outputs and store in tmp folder
245
272
  # Cross-domain AJAX to get result from T2
246
- get "/#{WEB_APP_NAME}/run/:uuid/output/:out" do
247
-
248
- # Get http request's parameters
249
- # TODO: consider adding the following to a session
250
- @wid = params[:wid]
251
- @wkf_version = params[:wkf_version]
252
-
253
- # Get myExperiment workflow object
254
- # TODO: with sessions that would be remembered
255
- @my_exp_wkf = MyExperimentREST::Workflow.from_id_and_version(@wid, @wkf_version)
273
+ get "/#{WEB_APP_NAME}/run/:uuid/outputs" do
256
274
 
257
275
  @run_uuid = params[:uuid]
258
276
  @t2_server = params[:server]
259
- t2_output = params[:out]
260
277
 
261
278
  # Get t2 server and then the run using uuid
262
279
  server = T2Server::Server.connect(@t2_server)
263
280
  run = server.run(@run_uuid)
264
281
 
265
- # Get output from t2 server
282
+ # Get output ports from t2 server and store in tmp folder
283
+ # TODO: TMP folder constant from config!
266
284
  # TODO: that gets the whole output.. request client lib to support partial
267
285
  # download! -- refs could then be used to download the full results!
268
- begin
269
- data_lists = run.get_output(t2_output, false)
270
- rescue Exception => e
271
- data_lists = run.get_output("#{t2_output}.error", false)
286
+ run.get_output_ports.each do |t2_output|
287
+ begin
288
+ data_lists = run.get_output(t2_output, false)
289
+ rescue Exception => e
290
+ data_lists = run.get_output("#{t2_output}.error", false)
291
+ end
292
+
293
+ # flatten the results
294
+ data_stream = flatten_list_results(data_lists)
295
+
296
+ # copy results to tmp
297
+ copy_to_tmp("outputs/#{@run_uuid}", t2_output, data_stream)
272
298
  end
273
-
274
- # that should be a sample of the results -- not the complete results!
275
- data = generate_html_result(data_lists)
276
299
 
277
- data
300
+ # return success!
301
+ "Successful download!"
302
+ end
303
+
304
+
305
+ # Get results for specified run and output (stored locally from tmp)
306
+ # display it in data-display div
307
+ # Cross-domain AJAX to get result from T2
308
+ get "/#{WEB_APP_NAME}/run/:uuid/output/:out" do
309
+
310
+ run_uuid = params[:uuid]
311
+ t2_output = params[:out]
312
+
313
+ # add HTML tags to display properly
314
+ data = File.open("/tmp/#{WEB_APP_NAME}/outputs/#{run_uuid}/#{t2_output}", "r").read
315
+
316
+ generate_html_result(data)
278
317
  end
279
318
 
280
319
 
281
320
  # Used from input's upload-form to upload files without refresh (actually
282
321
  # a hidden iframe is refreshed).
322
+ # TODO: use copy_to_tmp method!!
283
323
  post "/#{WEB_APP_NAME}/upload" do
284
324
  filename = params[:file][:filename]
285
325
  tempfile = params[:file][:tempfile]
@@ -288,8 +328,10 @@ END
288
328
  "Successfully copied #{filename}!!"
289
329
  end
290
330
 
331
+ # start the server if ruby file executed directly
332
+ run! if app_file == $0
291
333
  end
292
334
 
293
335
 
294
336
  # Start Web App
295
- WebT2App.run!
337
+ # $ rackup -p 9494
@@ -76,6 +76,21 @@
76
76
 
77
77
  <h1>Changes log for the Taverna via the Web Gem</h1>
78
78
 
79
+ <h2>Version 0.1.0</h2>
80
+ <ul><li>
81
+ <p>Results are downloaded directly and stored in tmp files - progress cycle
82
+ works once</p>
83
+ </li><li>
84
+ <p>Added rackup configuration file: config.ru</p>
85
+ </li><li>
86
+ <p>webapp is run using rackup now to enable configuration of web server
87
+ timeout</p>
88
+ </li><li>
89
+ <p>Increased tooltip size and anchored them to the ‘west’</p>
90
+ </li><li>
91
+ <p>Port is set via: rackup -p 9494</p>
92
+ </li></ul>
93
+
79
94
  <h2>Version 0.0.9</h2>
80
95
  <ul><li>
81
96
  <p>Changed “ to ‘ in generate_header_table (header HTML block used in JS
data/doc/rdoc/README.html CHANGED
@@ -80,7 +80,7 @@
80
80
  <p>Konstantinos Karasavvas</p>
81
81
  </td></tr><tr><td class="rdoc-term"><p>Gem Version</p></td>
82
82
  <td>
83
- <p>0.0.9</p>
83
+ <p>0.1.0</p>
84
84
  </td></tr><tr><td class="rdoc-term"><p>Contact</p></td>
85
85
  <td>
86
86
  <p><a href="mailto:kostas.karasavvas@nbic.nl">kostas.karasavvas@nbic.nl</a></p>
data/doc/rdoc/created.rid CHANGED
@@ -1,4 +1,4 @@
1
- Wed, 21 Mar 2012 16:46:27 +0100
1
+ Wed, 04 Apr 2012 14:30:43 +0200
2
2
  LICENSE Fri, 22 Jul 2011 16:33:48 +0200
3
- README Tue, 20 Mar 2012 17:41:35 +0100
4
- CHANGES Wed, 21 Mar 2012 15:19:25 +0100
3
+ README Fri, 23 Mar 2012 10:39:17 +0100
4
+ CHANGES Mon, 02 Apr 2012 17:10:11 +0200
data/doc/rdoc/index.html CHANGED
@@ -29,7 +29,7 @@
29
29
  <p>Konstantinos Karasavvas</p>
30
30
  </td></tr><tr><td class="rdoc-term"><p>Gem Version</p></td>
31
31
  <td>
32
- <p>0.0.9</p>
32
+ <p>0.1.0</p>
33
33
  </td></tr><tr><td class="rdoc-term"><p>Contact</p></td>
34
34
  <td>
35
35
  <p><a href="mailto:kostas.karasavvas@nbic.nl">kostas.karasavvas@nbic.nl</a></p>
data/public/css/form.css CHANGED
@@ -19,6 +19,7 @@ td.header-title {
19
19
  padding: 12px;
20
20
  border-bottom: 4px solid #909090;
21
21
  border-top: 4px solid #909090;
22
+ text-align: center;
22
23
  }
23
24
 
24
25
  #inputs {
data/public/css/tipsy.css CHANGED
@@ -1,5 +1,5 @@
1
1
  .tipsy { padding: 5px; font-size: 13px; opacity: 0.8; filter: alpha(opacity=80); background-repeat: no-repeat; background-image: url(../images/tipsy.gif); }
2
- .tipsy-inner { padding: 5px 8px 4px 8px; background-color: #161616; color: white; max-width: 240px; text-align: left; }
2
+ .tipsy-inner { padding: 5px 8px 4px 8px; background-color: #161616; color: white; max-width: 300px; text-align: left; }
3
3
  .tipsy-inner { -moz-border-radius:3px; -webkit-border-radius:3px; }
4
4
  .tipsy-north { background-position: top center; }
5
5
  .tipsy-south { background-position: bottom center; }
@@ -41,23 +41,9 @@ function uploadFile(input) { //, files) {
41
41
  // TODO: what if it exists already!? - currently replaces it
42
42
  $('#workflow-form').append("<input name='" + input + "-file' type='hidden' value='" + filename +"' />");
43
43
 
44
-
45
- //var file = files[0];
46
-
47
- // create form to send to server-side upload handler
48
- //var formdata = new FormData();
49
-
50
- // include file to form
51
- //formdata.append("file", file);
52
-
53
-
54
44
  // get the form from the document (jQuery selector wasn't working inside function!)
55
45
  var formdata = new FormData(document.getElementById(input + '-upload-form'));
56
46
 
57
- //$.ajax({
58
- // type: "POST",
59
- // url: "http://" + document.location.host + "/t2web/upload",
60
-
61
47
  var xhr = new XMLHttpRequest();
62
48
  //xhr.file = file; // not necessary if you create scopes like this
63
49
  xhr.upload.addEventListener('progress', function(e) {
@@ -65,7 +51,6 @@ function uploadFile(input) { //, files) {
65
51
  console.log('xhr progress: ' + (Math.floor(done/total*1000)/10) + '%');
66
52
  }, false);
67
53
  if ( xhr.upload ) {
68
- console.log("AAAAAAAAAAAAAAAA");
69
54
  xhr.upload.onprogress = function(e) {
70
55
  var done = e.position || e.loaded, total = e.totalSize || e.total;
71
56
  console.log('xhr.upload progress: ' + done + ' / ' + total + ' = ' + (Math.floor(done/total*1000)/10) + '%');
@@ -79,20 +64,11 @@ function uploadFile(input) { //, files) {
79
64
 
80
65
  xhr.open('post', "http://" + document.location.host + "/t2web/upload", false);
81
66
  xhr.send(formdata);
82
-
83
-
84
-
85
- // submit the form to upload the file
86
- // we would like to do that via XHR to include client-side progress bar!
87
- //$('#' + input + '-upload-form').submit();
88
-
89
67
  }
90
68
 
91
69
  // initilises certain html elements to employ tipsy for their tooltips
92
70
  function initialiseTipsys() {
93
- $('[name$="-input"]').tipsy({gravity: 'e', fade: true, html: true, fallback: "No available example"});
94
- $('[for$="-label"]').tipsy({gravity: 'e', fade: true, html: true, fallback: "No available description"});
95
- //$('[name$="-input"]').tooltip();
96
-
71
+ $('[name$="-input"]').tipsy({gravity: 'w', fade: true, html: true, fallback: "No available example"});
72
+ $('[for$="-label"]').tipsy({gravity: 'w', fade: true, html: true, fallback: "No available description"});
97
73
  }
98
74
 
@@ -1,30 +1,81 @@
1
+ // TODO: remove soon! (not used anymore! files are stored locally in tmp!!
1
2
  function getSampleOutput(t2_server, uuid, output, wid, wkf_version) {
2
3
  // t2 server REST call to sample output
4
+ // the following RESt is used for displaying tmp local files to the screen
3
5
  var httpcall = "http://" + document.location.host + "/t2web/run/" + uuid + "/output/" + output +
4
6
  "?server=" + t2_server + "&wid=" + wid + "&wkf_version=" + wkf_version;
5
7
 
6
- // display progress cycle icon in output during fetching
7
-
8
8
  // ajax request
9
9
  $.get(httpcall, function (result) {
10
10
  window.frames['data-display'].document.documentElement.innerHTML = result;
11
11
  });
12
12
 
13
- // remove progress cycle icon in output
13
+ }
14
+
15
+ function readTmpOutput(t2_server, uuid, output, wid, wkf_version) {
16
+ // TODO: currently t2_server, wid and wkf_version are not used
17
+
18
+ // t2web server call to get wkf results from tmp file
19
+ var httpcall = "http://" + document.location.host + "/t2web/run/" + uuid + "/output/" + output;
20
+
21
+ $.get(httpcall, function (result) {
22
+ window.frames['data-display'].document.documentElement.innerHTML = result;
23
+ });
14
24
 
15
25
  }
16
26
 
17
- function checkRunStatus(t2_server, uuid) {
27
+ function checkRunStatus(t2_server, uuid, wid, wkf_version) {
18
28
  // t2 server REST call to uuid's status
19
29
  var httpcall = "http://" + document.location.host + "/runs/" + uuid + "/status?server=" + t2_server;
20
30
 
21
- // ajax request
22
- $.get(httpcall, function (result) {
23
- if (result == 'Finished') {
24
- window.frames['data-navigation'].document.documentElement.innerHTML = results_navigation;
25
- clearInterval(runStatusIntervalId);
26
- }
27
- });
31
+ // ajax request to confirm finished execution
32
+ //$.get(httpcall, function (result) {
33
+ // if (result == 'Finished') {
34
+
35
+ // TODO: that probably causes the browser status to show that it's still working!!
36
+ // clearInterval(runStatusIntervalId);
37
+
38
+ // getOutputs(t2_server, uuid);
39
+ //getOutputs("http://test.mybiobank.org/taverna-server", "f3dca934-a6d7-44e3-acc3-f8c1f30e0973");
40
+ // }
41
+ //});
28
42
 
43
+ $.ajax({
44
+ type: "GET",
45
+ url: httpcall,
46
+ success: function (result) {
47
+ if (result == 'Finished') {
48
+ clearInterval(runStatusIntervalId);
49
+ getOutputs(t2_server, uuid);
50
+ }
51
+ }
52
+ });
29
53
  }
30
54
 
55
+ function getOutputs(t2_server, uuid) {
56
+ // prepare get outputs call (to local ruby, cross-domain ajax call)
57
+ var httpoutputs = "http://" + document.location.host + "/t2web/run/" + uuid + "/outputs" +
58
+ "?server=" + t2_server;
59
+ console.log("in new function!!!!");
60
+
61
+ // ajax request to get outputs
62
+ //$.get(httpoutputs, function (reply) {
63
+ // if (reply == 'Successful download!') {
64
+ // window.frames['data-navigation'].document.documentElement.innerHTML = results_navigation;
65
+ // }
66
+ //});
67
+
68
+ $.ajax({
69
+ type: "GET",
70
+ url: httpoutputs,
71
+ success: function(reply) {
72
+ if (reply == 'Successful download!') {
73
+ window.frames['data-navigation'].document.documentElement.innerHTML = results_navigation;
74
+ }
75
+ }//,
76
+ //error: function(reply) {
77
+ // window.frames['data-navigation'].document.documentElement.innerHTML = results_navigation;
78
+ //}
79
+ });
80
+
81
+ }
data/views/form.haml CHANGED
@@ -38,12 +38,11 @@
38
38
  %input{:type => "submit", :value => "Execute", :class => "button"}
39
39
  - if @my_exp_wkf.inputs.size >=1
40
40
  - @my_exp_wkf.inputs.each do |input|
41
- -# TODO: make helper create_input_tooltip(input) to return proper tooltip html string!!!
42
41
  - if input.descriptions.size >=1
43
- - input_label_tooltip = generate_label_tooltip(input)
42
+ - input_label_tooltip = generate_tooltip("Description: ", input)
44
43
  - input_textarea_tooltip = ""
45
44
  - if input.examples.size >=1
46
- - input_textarea_tooltip = generate_textarea_tooltip(input)
45
+ - input_textarea_tooltip = generate_tooltip("Example: ", input)
47
46
  %div{:id => "#{input.name}-upload-form-div"}
48
47
  -#%form{:id => "#{input.name}-upload-form", :enctype => "multipart/form-data", :target => "hidden-iframe", :action => "/t2web/upload", :method => "post"}
49
48
  %form{:id => "#{input.name}-upload-form", :enctype => "multipart/form-data"}
@@ -120,7 +119,7 @@
120
119
  %img{:src => "/images/bullet_go.png", :alt => "Important!" }
121
120
  %td.inputs
122
121
  For more information on this workflow please visit the
123
- %a{ :href => "http://www.myExperiment.org/workflows/#{@wid}" } myExperiment website
122
+ %a{ :href => "http://www.myExperiment.org/workflows/#{@wid}", :target => "_blank" } myExperiment website
124
123
  -# if #{@my_exp_wkf.user.email}
125
124
  %tr
126
125
  %td.inputs
data/views/results.haml CHANGED
@@ -14,6 +14,7 @@
14
14
  window.frames['header'].document.write("#{generate_header_frame(@my_exp_wkf, @my_exp_usr).gsub!(/\n/, "")}");
15
15
  window.frames['data-navigation'].document.write("#{generate_data_navigation_frame(@my_exp_wkf, @run_uuid, @wid, @wkf_version, @t2_server, false)}");
16
16
  runStatusIntervalId = window.setInterval( "checkRunStatus('#{@t2_server}', '#{@run_uuid}')", 5000);
17
+ //checkRunStatus("#{@t2_server}", "#{@run_uuid}");
17
18
  });
18
19
  %script{:type => "text/javascript", :src => "/scripts/results.js"}
19
20
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: t2-web
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 9
10
- version: 0.0.9
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kostas Karasavvas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-21 00:00:00 Z
18
+ date: 2012-04-04 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: sinatra
@@ -112,6 +112,7 @@ files:
112
112
  - README
113
113
  - CHANGES
114
114
  - Rakefile
115
+ - bin/config.ru
115
116
  - bin/t2_webapp.rb
116
117
  - doc/rdoc-style.css
117
118
  - doc/fr_file_index.html