summaryrefslogtreecommitdiff
path: root/src/client/model
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-01-05 16:10:24 +0200
committerAlon Levy <alon@pobox.com>2015-01-05 16:10:24 +0200
commit51ea23cd2b521577e1398f7bc143643aab3f92cd (patch)
tree3a1c22f43ae6b3a5bf68269b90625e1e1d78732b /src/client/model
parent1b19e764c55c368390100402dbf4ff0014b2c74f (diff)
client: partial fix of drag-n-drop & load - fails in server with Neo4JException
Diffstat (limited to 'src/client/model')
-rw-r--r--src/client/model/graph.js64
1 files changed, 44 insertions, 20 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js
index 86e25de1..f867cd08 100644
--- a/src/client/model/graph.js
+++ b/src/client/model/graph.js
@@ -782,35 +782,59 @@ function Graph(spec) {
}
this.load_from_backend = load_from_backend;
+ var new_topo_diff__from_nodes_links = function (nodes, links) {
+ var diff,
+ node_by_id = {};
+
+ diff = model_diff.new_topo_diff();
+ diff.node_set_add = nodes.map(function(node) {
+ return model_core.create_node_from_spec({
+ id: node.id,
+ name: node.name ? node.name : node.id,
+ type: node.type,
+ state: "perm",
+ start: new Date(node.start),
+ end: new Date(node.end),
+ status: node.status,
+ url: node.url,
+ x: node.x,
+ y: node.y,
+ });
+ });
+ diff.node_set_add.forEach(function (node) {
+ node_by_id[node.id] = node;
+ });
+ diff.link_set_add = links.map(function (link_spec) {
+ var src = node_by_id[link_spec.__src],
+ dst = node_by_id[link_spec.__dst],
+ link = model_core.create_link__set_random_id(src, dst, {
+ name: link_spec.name,
+ state: 'perm', // FIXME: this is meaningless now with graph separation
+ });
+ link.__src_id = src.id;
+ link.__dst_id = dst.id;
+ return link;
+ });
+ return diff;
+ }
+ this.new_topo_diff__from_nodes_links = new_topo_diff__from_nodes_links;
+
this.load_from_json = function(json) {
- var data = JSON.parse(json),
- added_nodes,
- that = this;
+ var data = JSON.parse(json);
- clear();
if (data == null) {
console.log('load callback: no data to load');
return;
}
- added_names = data.nodes.map(function(node) {
- return that.__addNode({id:node.id, name:node.name ? node.name : node.id,
- type:node.type,state:"perm",
- start:new Date(node.start),
- end:new Date(node.end),
- status:node.status,
- url:node.url,
- x: node.x,
- y: node.y,
- }).name;
- });
- data.links.forEach(function(link) {
- __addLink(link.__src, link.__dst, link.name, "perm");
- });
- this.clear_history();
+ // FIXME: prompt for replace/merge; now defaulting to merge
+ commit_and_tx_diff__topo(new_topo_diff__from_nodes_links(data.nodes, data.links));
}
this.save_to_json = function() {
- var d = {"nodes":[], "links":[]};
+ var d = {"nodes":[], "links":[]},
+ nodes = get_nodes(),
+ links = get_links();
+
for(var i = 0 ; i < nodes.length ; i++){
var node = nodes[i];
d['nodes'].push({