rbbt-rest 1.7.19 → 1.7.20

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: a370ffece6117d1fb32747e5701e9f46858be458
4
- data.tar.gz: 4ea778ce9a36602c8346ba96bf3dc62f07a47066
3
+ metadata.gz: a40ff490d992383fabd6576ad3b06df0c1a9e7c4
4
+ data.tar.gz: d6ea9091bd3dca0e92f0628ef84b477a6e43f344
5
5
  SHA512:
6
- metadata.gz: a72b386310566ea2aac5a86dda0a8d89f00b08d11f8066edbdaa99178972a23bd7f0749edf1d10825e53297a1397d499d78d1fefb6d91ac32ce572edb7b4402f
7
- data.tar.gz: 43d2059b419238e5bb05737494806f175ace47735f271f039607acfe43ba73a18c49324fc2b78f453fdb072a563fb13cade7d45047e21ef0c922aa708952414e
6
+ metadata.gz: 5b813d5e2dfe4bbd36b1676a569393f7903eb8f1eb14c9392ed583991fa22cbdfea40b63f910642c5cce50610040154925aa23987855ed7c0112d15b2881754c
7
+ data.tar.gz: b70426b8a0d31ce739e551c23ca91ab6823aa2bc9b6036f31cf988b6327fd33bb15577ae6aef3c1c740288d46ba7139b53506df9cdb9eaad8ce8557c651aa03c
@@ -58,9 +58,21 @@ module RbbtRESTHelpers
58
58
  clean_url = remove_GET_param(clean_url, :_update)
59
59
  clean_url = remove_GET_param(clean_url, :_)
60
60
 
61
- class << step; def url; @url; end; end
61
+ class << step
62
+ def url
63
+ @url
64
+ end
65
+
66
+ def knowledge_base(organism = Organism.default_code("Hsa"))
67
+ @_kb ||= begin
68
+ kb_dir = self.file('knowledge_base')
69
+ KnowledgeBase.new kb_dir, organism
70
+ end
71
+ end
72
+ end
62
73
  step.instance_variable_set(:@url, clean_url)
63
74
 
75
+ Thread.current["step_path"] = step.path
64
76
  # Issue
65
77
  if not step.started?
66
78
  if cache_type == :synchronous or cache_type == :sync
@@ -264,12 +264,14 @@ module Haml::Filters::DeferJS
264
264
  include Haml::Filters::Base
265
265
 
266
266
  def render(text)
267
+ step_path = Thread.current["step_path"]
267
268
  defer_text =<<-EOF
268
269
  %script
269
270
  :plain
270
- defer(function(){
271
+ defer(function(step_path){
272
+
271
273
  #{text.gsub(/^/," ")}
272
- })
274
+ }, '#{step_path}')
273
275
  EOF
274
276
  Haml::Engine.new(defer_text).to_html
275
277
  end
@@ -69,6 +69,11 @@ module Sinatra
69
69
  redirect '/login'
70
70
  end
71
71
  end
72
+
73
+ app.get '/logout' do
74
+ session[:user] = nil
75
+ redirect '/'
76
+ end
72
77
  end
73
78
  end
74
79
 
@@ -542,7 +542,8 @@ module Sinatra
542
542
  begin
543
543
  res = list.send(property,*args)
544
544
  rescue
545
- if list.respond_to?(:format) and list.base_type.respond_to?(:default_format) and list.format != list.base_type.default_format
545
+ Log.exception $!
546
+ if list.respond_to?(:format) and list.base_type.respond_to?(:default_format) and list.format != list.base_type.default_format
546
547
  list = list.to(:default)
547
548
  Log.warn "Error computing property #{property} for list. Automatically changing list format to default"
548
549
  retry
@@ -309,8 +309,9 @@ module Sinatra
309
309
  source_type = kb.source_type(database)
310
310
  target_type = kb.target_type(database)
311
311
  fields = kb.fields(database)
312
- source_entity_options = kb.entity_options_for source_type
313
- target_entity_options = kb.entity_options_for target_type
312
+ source_entity_options = kb.entity_options_for source_type, database
313
+ target_entity_options = kb.entity_options_for target_type, database
314
+ undirected = kb.undirected(database) == 'undirected'
314
315
 
315
316
  info = {
316
317
  :source => source,
@@ -320,6 +321,7 @@ module Sinatra
320
321
  :source_entity_options => source_entity_options,
321
322
  :target_entity_options => target_entity_options,
322
323
  :fields => fields,
324
+ :undirected => undirected,
323
325
  }
324
326
 
325
327
  halt 200, info.to_json
@@ -539,6 +541,7 @@ module Sinatra
539
541
  content_type "application/json"
540
542
  halt 200, serialize_entities(list).to_json
541
543
  end
544
+
542
545
  end
543
546
  end
544
547
  end
@@ -53,6 +53,10 @@ module KnowledgeBaseRESTHelpers
53
53
 
54
54
  def get_knowledge_base(name=:user, namespace = nil)
55
55
  kb = case name.to_s
56
+ when 'step'
57
+ dir = cookies[:step_path] + '.files/knowledge_base'
58
+ iii dir
59
+ KnowledgeBase.load(dir)
56
60
  when "user"
57
61
  user_kb(user)
58
62
  else
@@ -90,4 +94,9 @@ module KnowledgeBaseRESTHelpers
90
94
  {:id => e, :name => name, :type => e.base_type, :info => e.info}
91
95
  end
92
96
  end
97
+
98
+ def get_matrix(code)
99
+ name, study = code.split("@")
100
+ Study.setup(study).matrix(name)
101
+ end
93
102
  end
@@ -7,6 +7,7 @@ require 'ruby-prof'
7
7
  require 'sinatra/base'
8
8
  require 'sinatra/cross_origin'
9
9
  require "sinatra/multi_route"
10
+ require "sinatra/cookies"
10
11
  require 'json'
11
12
 
12
13
  module Sinatra
@@ -41,6 +42,7 @@ module Sinatra
41
42
 
42
43
  helpers RbbtRESTHelpers
43
44
  register Sinatra::RbbtAuth
45
+ helpers Sinatra::Cookies
44
46
 
45
47
  add_sass_load_path Rbbt.share.views.compass.find(:lib)
46
48
 
@@ -41,3 +41,9 @@ a.entity
41
41
  float: right
42
42
  height: 22px
43
43
 
44
+ .content > .info
45
+ &:hover
46
+ z-index: 10
47
+
48
+ table > caption
49
+ max-width: 60em
@@ -30,9 +30,12 @@
30
30
  requirejs.config({baseUrl: '/js-find'})
31
31
 
32
32
 
33
+ -# Cookies
34
+ - record_js '/plugins/js-cookie/js/js.cookie.js'
33
35
 
34
36
  -# JQUERY JS
35
- - %w(jquery-2.1.1 jquery.cookie jquery.form).each do |jquery_file|
37
+ -# %w(jquery-2.1.1 jquery.cookie jquery.form).each do |jquery_file|
38
+ - %w(jquery-2.1.1 jquery.form).each do |jquery_file|
36
39
  - record_js File.join('/plugins/jquery/js/', jquery_file)
37
40
 
38
41
  - record_js '/plugins/jquery-ui/js/jquery-ui-1.8.14.custom.min.js'
@@ -53,8 +56,6 @@
53
56
  - record_js '/plugins/cola/js/cola.js'
54
57
  - record_js '/plugins/mithril-node-render/js/index.js'
55
58
 
56
-
57
-
58
59
  - %w(helpers _md5 _ajax_replace _ellipsis).each do |file|
59
60
  - record_js "/js-find/helpers/#{ file }"
60
61
 
@@ -65,7 +66,10 @@
65
66
  - %w(rbbt rbbt.basic rbbt.exception rbbt.job rbbt.page rbbt.entity.basic rbbt.entity rbbt.entity_list rbbt.entity_map rbbt.views rbbt.favourites rbbt.modal).each do |file|
66
67
  - record_js "/js-find/#{ file }"
67
68
 
68
- - %w(rbbt.knowledge_base rbbt.aesthetics rbbt.plots rbbt.aes_plots).each do |file|
69
+ - %w(rbbt.knowledge_base).each do |file|
69
70
  - record_js "/js-find/#{ file }"
70
71
 
72
+ - %w(rbbt.plots.basic rbbt.plots.aes rbbt.plots.graph rbbt.plots.graph.kb rbbt.plots.graph.adapters rbbt.plots.aesthetics rbbt.plots.list).each do |file|
73
+ - record_js "/js-find/rbbt.plots/#{ file }"
74
+
71
75
  - record_js "/js-find/app"
@@ -1,25 +1,27 @@
1
1
  var deferred_execution = [];
2
2
 
3
- function defer(deps, func){
3
+ function defer(deps, func, step_path){
4
+ if (typeof func == 'string'){
5
+ step_path = func
6
+ func = deps
7
+ deps = undefined;
8
+ }
4
9
  if (undefined === func){
5
10
  func = deps;
6
11
  deps = undefined;
7
12
  }
8
- if (undefined !== deps){
9
- deferred_execution.push([deps, func]);
10
- }else{
11
- deferred_execution.push(func)
12
- }
13
+ document.step_path = step_path
14
+ deferred_execution.push([func, deps, step_path]);
13
15
  }
14
16
 
15
17
  function start_deferred(){
16
18
  var tmp = $.unique(deferred_execution);
17
19
  deferred_execution = [];
18
20
  $(tmp).each(function(pos,func){
19
- if (typeof(func) == 'object'){
20
- require_js(func[0], func[1]);
21
+ if (undefined === func[1]){
22
+ rbbt.try(func[0])(func[2])
21
23
  }else{
22
- rbbt.try(func).call()
24
+ require_js(func[1], func[0], func[2]);
23
25
  }
24
26
  })
25
27
  return(false)
@@ -57,7 +57,7 @@ function parse_parameters(params){
57
57
  }
58
58
 
59
59
  var required_js = [];
60
- function require_js(url, success){
60
+ function require_js(url, success, script){
61
61
  if (typeof url == 'object'){
62
62
  if (url.length > 1){
63
63
  var u = url.shift()
@@ -82,9 +82,9 @@ function require_js(url, success){
82
82
  url = url.replace('/js/', '/js-find/')
83
83
 
84
84
  if ($.inArray(url, required_js) >= 0){
85
- if (typeof success == 'function'){ success.call() }
85
+ if (typeof success == 'function'){ success.call(script) }
86
86
  }else{
87
- var _success = function(){ required_js.push(url); if (typeof success == 'function'){ success.call() }; }
87
+ var _success = function(){ required_js.push(url); if (typeof success == 'function'){ success.call(script) }; }
88
88
  $.ajax({url: url, cache:cache, dataType:'script', async: async, success: _success} ).fail(function(jqxhr, settings, exception){ console.log('Failed to load ' + url) })
89
89
  }
90
90
  }
@@ -105,6 +105,16 @@ function merge_hash(destination, source){
105
105
  return destination;
106
106
  }
107
107
 
108
+ function clean_hash(h){
109
+ var clean = {}
110
+
111
+ forHash(h, function(k,v){
112
+ if (undefined !== v) clean[k] = v
113
+ })
114
+
115
+ return clean
116
+ }
117
+
108
118
  function array_values(hash){
109
119
  var tmp_arr = [], key = '';
110
120
  for (key in hash) {
@@ -195,12 +205,16 @@ function get_gradient(values, color1, color2){
195
205
  var color2 = Color(color2)
196
206
  var steps = values.length
197
207
  var clean_values = []
198
- forArray(values,function(v){ if (typeof v == 'number' && ! isNaN(v)) clean_values.push(v) })
208
+ forArray(values,function(v){
209
+ if (typeof v == 'string') v = parseFloat(v)
210
+ if (typeof v == 'number' && ! isNaN(v)) clean_values.push(v)
211
+ })
199
212
  var max = Math.max.apply(null,clean_values)
200
213
  var min = Math.min.apply(null,clean_values)
201
214
  var diff = max - min
202
215
  var colors = []
203
216
  forArray(values, function(value){
217
+ if (typeof value == 'string') value = parseFloat(value)
204
218
  if (typeof value == 'number'){
205
219
  var a = (value - min)/diff
206
220
  colors.push(color1.blend(color2, a).toString())
@@ -218,11 +232,15 @@ function get_sign_gradient(values, color1, color0, color2){
218
232
  var color2 = Color(color2)
219
233
  var steps = values.length
220
234
  var clean_values = []
221
- forArray(values,function(v){ if (typeof v == 'number' && ! isNaN(v)) clean_values.push(v) })
235
+ forArray(values,function(v){
236
+ if (typeof v == 'string') v = parseFloat(v)
237
+ if (typeof v == 'number' && ! isNaN(v)) clean_values.push(v)
238
+ })
222
239
  var max = Math.max.apply(null,clean_values)
223
240
  var min = Math.min.apply(null,clean_values)
224
241
  var colors = []
225
242
  forArray(values, function(value){
243
+ if (typeof value == 'string') value = parseFloat(value)
226
244
  if (typeof value == 'number'){
227
245
  if (value > 0){
228
246
  var a = value/max
@@ -11,7 +11,21 @@ rbbt.ajax = function(params){
11
11
  }else{
12
12
  params.config = function(xhr, options){ xhr.setRequestHeader( "X-Requested-With", "XMLHttpRequest"); return xhr; }
13
13
  }
14
- return m.request(params)
14
+
15
+ if (params.cookies){
16
+ forHash(params.cookies, function(k,v){rbbt.set_cookie(k,v)})
17
+ params.cookies_set = true
18
+ params.onreadystatechange = function(){
19
+ if (params.cookies_set){
20
+ forHash(params.cookies, function(k,v){rbbt.remove_cookie(k)})
21
+ params.cookies_set = false
22
+ }
23
+ }
24
+ }
25
+
26
+ req = m.request(params)
27
+
28
+ return req
15
29
  }
16
30
 
17
31
  rbbt.insist_request = function(params, deferred, timeout, missing){
@@ -54,6 +68,7 @@ rbbt.post = function(url, data, params){
54
68
  if (undefined === params.url) params.url = url
55
69
 
56
70
  request_params = {url: url, method: "POST", data: data, serialize: function(formData){return formData} }
71
+ forHash(params, function(k,v){request_params[k] = v})
57
72
  }
58
73
 
59
74
  if (undefined === request_params.method) request_params.method = 'POST'
@@ -74,6 +89,22 @@ rbbt.post = function(url, data, params){
74
89
  return rbbt.insist_request(request_params)
75
90
  }
76
91
 
92
+ // Cookies
93
+
94
+ rbbt.set_cookie = function(name,value){
95
+ Cookies.set(name, value)
96
+ }
97
+
98
+ rbbt.get_cookie = function(name){
99
+ if (undefined === name)
100
+ return Cookies.get()
101
+ else
102
+ return Cookies.get(name)
103
+ }
104
+
105
+ rbbt.remove_cookie = function(name){
106
+ Cookies.remove(name)
107
+ }
77
108
 
78
109
  // LocalStorage
79
110
 
@@ -38,21 +38,37 @@ rbbt.entity_array.property = function(codes, type, info, name, args){
38
38
  return rbbt.post(url, data)
39
39
  }
40
40
 
41
- rbbt.entity_array.parents = function(codes, type, database){
42
- var url = '/knowledge_base/user/' + database + '/collection_parents'
43
-
44
- var collection = {}
45
- collection[type] = codes
46
-
47
- var data = {}
48
- data.collection = collection
49
- data._format = 'tsv_json'
50
-
51
- return rbbt.post(url, data)
41
+ rbbt.entity_array.parents = function(codes, type, database_code){
42
+ var parts = rbbt.knowledge_base.parse_db(database_code)
43
+ var kb,database,params
44
+ kb = parts[0]; database = parts[1], cookies = parts[2]
45
+
46
+ var params = {}
47
+
48
+ params.cookies = cookies
49
+
50
+ var url = '/knowledge_base/'+kb+'/' + database + '/collection_parents'
51
+
52
+ var collection = {}
53
+ collection[type] = codes
54
+
55
+ var data = {}
56
+ data.collection = collection
57
+ data._format = 'tsv_json'
58
+
59
+ return rbbt.post(url, data,params)
52
60
  }
53
61
 
54
- rbbt.entity_array.children = function(codes, type, database){
55
- var url = '/knowledge_base/user/' + database + '/collection_parents'
62
+ rbbt.entity_array.children = function(codes, type, database_code){
63
+ var parts = rbbt.knowledge_base.parse_db(database_code)
64
+ var kb,database,params
65
+ kb = parts[0]; database = parts[1], cookies = parts[2]
66
+
67
+ var params = {}
68
+
69
+ params.cookies = cookies
70
+
71
+ var url = '/knowledge_base/'+kb+'/' + database + '/collection_children'
56
72
 
57
73
  var collection = {}
58
74
  collection[type] = codes
@@ -61,11 +77,19 @@ rbbt.entity_array.children = function(codes, type, database){
61
77
  data.collection = collection
62
78
  data._format = 'tsv_json'
63
79
 
64
- return rbbt.post(url, data)
80
+ return rbbt.post(url, data,params)
65
81
  }
66
82
 
67
- rbbt.entity_array.subset = function(database, source, target){
68
- var url = '/knowledge_base/user/' + database + '/subset'
83
+ rbbt.entity_array.subset = function(database_code, source, target){
84
+ var parts = rbbt.knowledge_base.parse_db(database_code)
85
+ var kb,database,params
86
+ kb = parts[0]; database = parts[1], cookies = parts[2]
87
+
88
+ var params = {}
89
+
90
+ params.cookies = cookies
91
+
92
+ var url = '/knowledge_base/' + kb + '/' + database + '/subset'
69
93
 
70
94
  var data = {}
71
95
  var source = source.join(",")
@@ -73,5 +97,5 @@ rbbt.entity_array.subset = function(database, source, target){
73
97
  data.source = source
74
98
  if (target) data.target = target.join(",")
75
99
 
76
- return rbbt.post(url, data)
100
+ return rbbt.post(url, data, params)
77
101
  }
@@ -14,21 +14,72 @@ var KB = rbbt.knowledge_base = {}
14
14
  // return m.request({url: url, method: "GET", type: Entity})
15
15
  //}
16
16
 
17
- KB.database_info = function(database){
18
- var url = '/knowledge_base/user/' + database + '/info'
19
- url = add_parameter(url, '_format', 'json')
20
- return m.request({url: url, method: "GET"})
17
+ rbbt.step_path = function(path, func){
18
+ if (undefined === path){
19
+ if (typeof step_path == 'string')
20
+ return step_path
21
+ if (rbbt._step_path)
22
+ return rbbt._step_path
23
+ else{
24
+ if (document.step_path)
25
+ return document.step_path
26
+ else
27
+ return undefined
28
+ }
29
+ }else{
30
+ old = rbbt._step_path
31
+ rbbt._step_path = path
32
+ }
33
+
34
+ if (undefined === func)
35
+ return
36
+ else{
37
+ func()
38
+ rbbt._step_path = old
39
+ }
40
+ }
41
+
42
+ KB.parse_db = function(database_code){
43
+ var kb = 'user'
44
+ var database
45
+
46
+ if (database_code.indexOf(':') > 0){
47
+ var parts = database_code.split(":")
48
+ kb = parts[0]
49
+ database = parts[1]
50
+ }else{
51
+ database = database_code
52
+ }
53
+
54
+ if (kb == 'step'){
55
+ var path
56
+ if (typeof step_path != 'undefined') path = step_path
57
+ if (undefined === path) path = rbbt.step_path()
58
+ cookies = {step_path: path}
59
+ }else
60
+ cookies = undefined
61
+
62
+ return [kb, database, cookies]
63
+ }
64
+
65
+ KB.database_info = function(database_code){
66
+ var parts = rbbt.knowledge_base.parse_db(database_code)
67
+ var kb,database,params
68
+ kb = parts[0]; database = parts[1], cookies = parts[2]
69
+
70
+ var url = '/knowledge_base/' + kb + '/' + database + '/info'
71
+
72
+ url = add_parameter(url, '_format', 'json')
73
+
74
+ params = {url: url, method: "GET", cookies: cookies}
75
+
76
+ return rbbt.insist_request(params)
21
77
  }
22
78
 
23
79
  KB.list_parents = function(database, list){
24
80
  return list.get().then(function(list_info){
25
81
  var url = '/knowledge_base/user/' + database + '/collection_parents'
26
82
 
27
- //url = add_parameter(url, 'collection', JSON.stringify(collection))
28
- //return m.request({url: url, method: "POST", data:{collection:collection}})
29
- //url = add_parameter(url, '_format', 'tsv_json')
30
- //return rbbt.post(url, {collection: collection})
31
-
32
83
  var collection = {}
33
84
  collection[list.type] = list_info.entities
34
85