rbbt-rest 1.7.17 → 1.7.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,9 +12,21 @@ aes_module.map_aesthetic = function(aes, mapper, map_obj){
12
12
  case 'gradient':
13
13
  return get_gradient(aes, 'green', 'red')
14
14
  case 'sign-gradient':
15
- return get_sign_gradient(aes, 'green', 'white', 'red')
15
+ return get_sign_gradient(aes, 'green', 'grey', 'red')
16
16
  case 'map':
17
- return aes.map(function(value){ map_obj[value] })
17
+ if (typeof aes == 'object')
18
+ return aes.map(function(value){ return map_obj[value] })
19
+ else
20
+ return map_obj[aes]
21
+ case 'function':
22
+ var res = []
23
+ if (typeof aes == 'object')
24
+ for (i in aes) res.push(map_obj(aes[i]))
25
+ else
26
+ res = map_obj(aes)
27
+ return res
28
+ case 'list_function':
29
+ return map_obj(aes)
18
30
  }
19
31
  }
20
32
 
@@ -5,39 +5,13 @@ rbbt.mlog = function(data){
5
5
  // AJAX
6
6
 
7
7
  rbbt.ajax = function(params){
8
- params.config = function(xhr, options){ xhr.setRequestHeader( "X-Requested-With", "XMLHttpRequest"); return xhr; }
9
8
  if (undefined === params.method) params.method = "GET"
10
- return m.request(params)
11
- }
12
-
13
- rbbt.post = function(url, data, params){
14
- var request_params
15
- if (typeof url === 'object'){
16
- request_params = url
17
- if (data) request_params.data = data
9
+ if (rbbt.proxy && params.url.indexOf('//') < 0 && params.url.indexOf('/') == 0){
10
+ params.url = rbbt.proxy + params.url
18
11
  }else{
19
-
20
- if (undefined === params) params = {}
21
- if (undefined === params.url) params.url = url
22
-
23
- request_params = {url: url, method: "POST", data: data, serialize: function(formData){return formData} }
12
+ params.config = function(xhr, options){ xhr.setRequestHeader( "X-Requested-With", "XMLHttpRequest"); return xhr; }
24
13
  }
25
-
26
- if (undefined === request_params.method) request_params.method = 'POST'
27
- if (undefined === request_params.serialize) request_params.serialize = function(formData) {return formData}
28
-
29
- if (request_params.data){
30
- var formData = new FormData()
31
- forHash(request_params.data, function(key,value){
32
- if (typeof value == 'object')
33
- formData.append(key, JSON.stringify(value))
34
- else
35
- formData.append(key, value)
36
- })
37
- request_params.data = formData
38
- }
39
-
40
- return rbbt.ajax(request_params)
14
+ return m.request(params)
41
15
  }
42
16
 
43
17
  rbbt.insist_request = function(params, deferred, timeout, missing){
@@ -70,6 +44,38 @@ rbbt.insist_request = function(params, deferred, timeout, missing){
70
44
  return deferred.promise
71
45
  }
72
46
 
47
+ rbbt.post = function(url, data, params){
48
+ var request_params
49
+ if (typeof url === 'object'){
50
+ request_params = url
51
+ if (data) request_params.data = data
52
+ }else{
53
+
54
+ if (undefined === params) params = {}
55
+ if (undefined === params.url) params.url = url
56
+
57
+ request_params = {url: url, method: "POST", data: data, serialize: function(formData){return formData} }
58
+ }
59
+
60
+ if (undefined === request_params.method) request_params.method = 'POST'
61
+ if (undefined === request_params.serialize) request_params.serialize = function(formData) {return formData}
62
+
63
+ if (request_params.data){
64
+ var formData = new FormData()
65
+ forHash(request_params.data, function(key,value){
66
+ if (typeof value == 'object')
67
+ formData.append(key, JSON.stringify(value))
68
+ else
69
+ if (undefined !== value) formData.append(key, value)
70
+ })
71
+ request_params.data = formData
72
+ }
73
+
74
+ //return rbbt.ajax(request_params)
75
+ return rbbt.insist_request(request_params)
76
+ }
77
+
78
+
73
79
  // LocalStorage
74
80
 
75
81
  rbbt.LS = {}
@@ -0,0 +1,77 @@
1
+ rbbt.entity = {}
2
+ rbbt.entity_array = {}
3
+ rbbt.entity_list = {}
4
+
5
+ rbbt.entity.property = function(code, type, info, name, args){
6
+ if (info.format && ! type.indexOf(":") < 0){
7
+ type = type + ':' + info.format
8
+ }
9
+ var url = "/entity_property/" + name + "/" + type + "/" + code
10
+ url = add_parameters(url, info)
11
+ if (undefined !== args){
12
+ var arg_str
13
+ if (typeof args == 'string'){
14
+ arg_str = args
15
+ }else{
16
+ arg_str = JSON.stringify(args)
17
+ }
18
+ url = add_parameter(url, "args", arg_str)
19
+ }
20
+ return rbbt.insist_request({url: url})
21
+ }
22
+
23
+ rbbt.entity_array.property = function(codes, type, info, name, args){
24
+ var promises = []
25
+ forArray(codes, function(code){
26
+ promises.push(rbbt.entity.property(code,type,info,name,args))
27
+ })
28
+ return m.sync(promises)
29
+ }
30
+
31
+ rbbt.entity_array.property = function(codes, type, info, name, args){
32
+ if (info.format && ! type.indexOf(":") < 0){
33
+ type = type + ':' + info.format
34
+ }
35
+ var url = "/entity_list_property/" + name + "/" + type
36
+
37
+ var data = {list: codes.join(","), args: args, info: info}
38
+ return rbbt.post(url, data)
39
+ }
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)
52
+ }
53
+
54
+ rbbt.entity_array.children = function(codes, type, database){
55
+ var url = '/knowledge_base/user/' + database + '/collection_parents'
56
+
57
+ var collection = {}
58
+ collection[type] = codes
59
+
60
+ var data = {}
61
+ data.collection = collection
62
+ data._format = 'tsv_json'
63
+
64
+ return rbbt.post(url, data)
65
+ }
66
+
67
+ rbbt.entity_array.subset = function(database, source, target){
68
+ var url = '/knowledge_base/user/' + database + '/subset'
69
+
70
+ var data = {}
71
+ var source = source.join(",")
72
+ data._format = 'tsv_json'
73
+ data.source = source
74
+ if (target) data.target = target.join(",")
75
+
76
+ return rbbt.post(url, data)
77
+ }
@@ -1,63 +1,123 @@
1
1
 
2
+ var EntityArray = function(array){
3
+ this.entities = array
4
+
5
+ this.get = function(){
6
+ var result = m.deferred();
7
+
8
+ var codes = []
9
+ for (i in this.entities){
10
+ codes.push(this.entities[i].code)
11
+ }
12
+ type = this.entities[0].type
13
+ format = this.entities[0].format
14
+ info = this.entities[0].info
15
+ result.resolve({entities: codes, entity_type: type, info: info})
16
+
17
+ return(result.promise)
18
+ }
19
+
20
+ this.get_entities = function(func){
21
+ var result = m.deferred();
22
+
23
+ result.resolve(this.entities)
24
+
25
+ return(result.promise)
26
+ }
27
+
28
+
29
+ this.property = function(name, args){
30
+ var result = m.deferred();
31
+ var promises = []
32
+
33
+ for (i in this.entities){
34
+ var entity = this.entities[i];
35
+ promises.push(entity.property(name, args))
36
+ }
37
+
38
+ m.sync(promises).then(result.resolve)
39
+
40
+ return(result.promise)
41
+ }
42
+
43
+ this.codes = function(){
44
+ }
45
+
46
+ this.children = function(knowledgebase, database){
47
+ var db_key = [database, knowledgebase].join("@")
48
+ return rbbt.knowledge_base.list_children(db_key, this)
49
+ }
50
+
51
+ this.parents = function(knowledgebase, database){
52
+ var db_key = [database, knowledgebase].join("@")
53
+ return rbbt.knowledge_base.list_parents(db_key, this)
54
+ }
55
+
56
+ this.subset = function(knowledgebase, database){
57
+ var db_key = [database, knowledgebase].join("@")
58
+ return rbbt.knowledge_base.list_subset(db_key, this)
59
+ }
60
+ }
61
+
2
62
  var EntityList = function(data){
3
- this.id = data.id
4
- this.name = data.id
5
- this.type = data.type
63
+ this.id = data.id
64
+ this.name = data.id
65
+ this.type = data.type
6
66
 
7
- this.full_type = function(){
8
- return this.type
9
- }
67
+ this.full_type = function(){
68
+ return this.type
69
+ }
10
70
 
11
- this.url = function(){
12
- var url = "/entity_list/" + this.full_type() + "/" + clean_element(this.id)
13
- return url
14
- }
71
+ this.url = function(){
72
+ var url = "/entity_list/" + this.full_type() + "/" + clean_element(this.id)
73
+ return url
74
+ }
15
75
 
16
- this.get = function(){
17
- if (undefined === this.entities && ! this.loading){
18
- var url = this.url()
19
- url = add_parameter(url, '_format', 'json')
20
- list = this
21
- this.loading = m.request({url: url, method: 'GET'}).then(this.entities).then(function(x){ list.loading = undefined; return x})
22
- return this.loading
23
- }else{
24
- var deferred = m.deferred()
25
- if (this.loading)
26
- this.loading.then(function(x){ deferred.resolve(x)})
27
- else
28
- deferred.resolve(this.entities)
29
- return deferred.promise
76
+ this.get = function(){
77
+ if (undefined === this.entities && ! this.loading){
78
+ var url = this.url()
79
+ url = add_parameter(url, '_format', 'json')
80
+ list = this
81
+ this.loading = m.request({url: url, method: 'GET'}).then(this.entities).then(function(x){ list.loading = undefined; return x})
82
+ return this.loading
83
+ }else{
84
+ var deferred = m.deferred()
85
+ if (this.loading)
86
+ this.loading.then(function(x){ deferred.resolve(x)})
87
+ else
88
+ deferred.resolve(this.entities)
89
+ return deferred.promise
90
+ }
30
91
  }
31
- }
32
92
 
33
- this.get_entities = function(func){
34
- var result = m.deferred();
93
+ this.get_entities = function(func){
94
+ var result = m.deferred();
35
95
 
36
- this.get().then(function(list_data){
37
- var item_values = []
38
- forArray(list_data.entities, function(entity_code){
39
- item_values.push(new Entity({code: entity_code, info: list_data.info}))
40
- })
41
- result.resolve(item_values)
42
- })
96
+ this.get().then(function(list_data){
97
+ var item_values = []
98
+ forArray(list_data.entities, function(entity_code){
99
+ item_values.push(new Entity({code: entity_code, info: list_data.info}))
100
+ })
101
+ result.resolve(item_values)
102
+ })
43
103
 
44
- return(result.promise)
45
- }
104
+ return(result.promise)
105
+ }
46
106
 
47
- this.property = function(name, args){
48
- var url = "/entity_list_property/" + name + "/" + this.full_type() + "/" + clean_element(this.id)
49
- if (undefined !== args)
50
- if ('string' === typeof args)
51
- url = add_parameter(url, "args", args)
107
+ this.property = function(name, args){
108
+ var url = "/entity_list_property/" + name + "/" + this.full_type() + "/" + clean_element(this.id)
109
+ if (undefined !== args)
110
+ if ('string' === typeof args)
111
+ url = add_parameter(url, "args", args)
52
112
  else
53
113
  url = add_parameter(url, "args", JSON.stringify(args))
54
- return rbbt.insist_request({url: url})
55
- }
114
+ return rbbt.insist_request({url: url})
115
+ }
56
116
 
57
- this.children = function(knowledgebase, database){
58
- var db_key = [database, knowledgebase].join("@")
59
- return rbbt.knowledge_base.list_children(db_key, this)
60
- }
117
+ this.children = function(knowledgebase, database){
118
+ var db_key = [database, knowledgebase].join("@")
119
+ return rbbt.knowledge_base.list_children(db_key, this)
120
+ }
61
121
 
62
122
  this.parents = function(knowledgebase, database){
63
123
  var db_key = [database, knowledgebase].join("@")
@@ -10,7 +10,7 @@ rbbt.exception.report = function(err){
10
10
  var stack = err.stack
11
11
  if(undefined === stack) stack = "No stack trace"
12
12
  if (rbbt.modal){
13
- stack = "<ul><li>" + stack.replace(/\n/g, '</li><li>') + '<li/></ul>'
13
+ stack = "<ul class='stacktrace'><li>" + stack.replace(/\n/g, '</li><li>') + '<li/></ul>'
14
14
  stack = stack.replace(/<li><li\/>/g,'').replace(/<li>(.*?)@(.*?):(\d+:\d+)<\/li>/g, '<li>$2<span style="font-weight:bold">$3</span><br/><em>$1</em></li>')
15
15
  rbbt.modal.controller.error(m('.ui.error.message', [m('.header', err), m('.description', m.trust(stack))]), "Application Error")
16
16
  }else{
@@ -45,7 +45,7 @@ KB.list_children = function(database, list){
45
45
  var url = '/knowledge_base/user/' + database + '/collection_children'
46
46
 
47
47
  var collection = {}
48
- collection[list.type] = list_info.entities
48
+ collection[list_info.entity_type] = list_info.entities
49
49
 
50
50
  var data = {}
51
51
  data.collection = JSON.stringify(collection)
@@ -227,14 +227,14 @@ rbbt.plots.svg_obj = function(aes){
227
227
  return m('foreignObject', location, m('body[xmlns="http://www.w3.org/1999/xhtml"]',tile))
228
228
  }
229
229
 
230
- rbbt.plots.d3js_graph = function(graph, object){
231
- var xsize = 300, ysize = 200
232
- var width = 1200
233
- height = 800
230
+ rbbt.plots.d3js_graph = function(graph, object, node_obj){
231
+ var xsize = 40, ysize = 40
232
+ var width = 1000
233
+ height = 500
234
234
 
235
235
  var color = d3.scale.category20();
236
236
 
237
- forArray(graph.nodes, function(node){node.width=300; node.height=200})
237
+ forArray(graph.nodes, function(node){node.width=40; node.height=40})
238
238
 
239
239
  var svg = d3.select(object)
240
240
  .attr("width", "100%")
@@ -249,28 +249,35 @@ rbbt.plots.d3js_graph = function(graph, object){
249
249
  .start()
250
250
 
251
251
  force.on("tick", function() {
252
- link.attr("x1", function(d) { return d.source.x + xsize/2; })
253
- .attr("y1", function(d) { return d.source.y + ysize/2; })
254
- .attr("x2", function(d) { return d.target.x + xsize/2; })
255
- .attr("y2", function(d) { return d.target.y + ysize/2; });
252
+ link.attr("x1", function(d) { return d.source.x + 0*xsize/2; })
253
+ .attr("y1", function(d) { return d.source.y + 0*ysize/2; })
254
+ .attr("x2", function(d) { return d.target.x + 0*xsize/2; })
255
+ .attr("y2", function(d) { return d.target.y + 0*ysize/2; });
256
256
 
257
- node.attr("x", function(d) { return d.x; })
258
- .attr("y", function(d) { return d.y; });
257
+ node.attr("transform", function(d) { return 'translate('+d.x+','+d.y+')'; })
259
258
  })
260
259
 
261
260
  var link = svg.selectAll(".link").data(graph.links).enter()
262
261
  .append("line").attr("class", "link")
263
- .style("stroke-width", 5)
262
+ .style("stroke-width", 5).style('stroke', 'grey')
264
263
 
265
- var node = svg.selectAll(".node").data(graph.nodes).enter()
266
- .append("foreignObject").attr("class", "node")
267
- .attr('width',xsize)
268
- .attr('height',ysize).html(function(d){ return mrender(rbbt.plots.card_obj(d)) })
269
- .call(force.drag)
264
+ var node = svg.selectAll(".node").
265
+ data(graph.nodes).
266
+ enter()
267
+
268
+ if (undefined === node_obj){
269
+ node = node.append("foreignObject").html(function(d){
270
+ return mrender(rbbt.plots.card_obj(d))
271
+ }).attr('width',xsize).attr('height',ysize)
272
+ }else{
273
+ node = node_obj(node)
274
+ }
275
+
276
+ node.call(force.drag)
270
277
 
271
278
 
272
279
  rbbt.log("force:warmup")
273
- for(i=0; i<1000; i++) force.tick()
280
+ for(i=0; i<100; i++) force.tick()
274
281
 
275
282
  rbbt.log("force:panZoom")
276
283
  svgPanZoom(object)
@@ -354,7 +361,7 @@ rbbt.plots.make_groups = function(graph, nodes, rbbt_groups){
354
361
  }
355
362
 
356
363
 
357
- rbbt.plots.d3js_group_graph = function(graph, object){
364
+ rbbt.plots.d3js_group_graph = function(graph, object, node_obj){
358
365
  var xsize = 300, ysize = 200, pad = 20
359
366
  var width = 1200
360
367
  height = 800
@@ -438,7 +445,12 @@ rbbt.plots.d3js_group_graph = function(graph, object){
438
445
 
439
446
  var node = svg.selectAll(".node").data(graph.nodes).enter()
440
447
  .append("foreignObject").attr("class", "node").attr('width',xsize).attr('height',ysize)
441
- .html(function(d){ return mrender(rbbt.plots.card_obj(d)) })
448
+ .html(function(d){
449
+ if (undefined == node_obj)
450
+ return mrender(rbbt.plots.card_obj(d))
451
+ else
452
+ return node_obj(d)
453
+ })
442
454
  .call(force.drag)
443
455
 
444
456
  //var node = svg.selectAll(".node").data(graph.nodes).enter()