diff options
| author | Alon Levy <alon@pobox.com> | 2014-10-06 10:08:55 +0300 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2014-10-07 08:51:35 +0300 |
| commit | ce469af4988546ef36661020abd10da93ce0de32 (patch) | |
| tree | 667a5f1c8223f7923b8a58cd2b24409efe600605 /scripts/rhizicore.js | |
| parent | f7c32bf55b857042a665263b02f0b3213ecbef3a (diff) | |
rhizicore: merge node addition
Diffstat (limited to 'scripts/rhizicore.js')
| -rw-r--r-- | scripts/rhizicore.js | 74 |
1 files changed, 30 insertions, 44 deletions
diff --git a/scripts/rhizicore.js b/scripts/rhizicore.js index 26059cc6..f0b7e8d8 100644 --- a/scripts/rhizicore.js +++ b/scripts/rhizicore.js @@ -28,59 +28,41 @@ function myGraph(el) { update(); } - function makeNewNode(spec) { - return { - 'id': spec.id, - 'name': spec.name, - 'type': spec.type, - 'state': spec.state, - 'start': spec.start, - 'end': spec.end, - 'status': spec.status, - 'url': spec.url - }; - } - ///FUNCTIONS this.addNode = function(id, type, state) { - var start = 0, - end = 0; - var status = "unknown"; - var name = id; - id = id.toLowerCase(); - var node = findNode(id, null); - if (node === undefined) { - var new_node = makeNewNode({ - "id": id, - "name": name, - "type": type, - "state": state, - "start": start, - "end": end, - "status": status - }); - nodes.push(new_node); - if (this.history !== undefined) { - this.history.record_nodes([new_node]); - } + var new_node = this.addNodeNoHistory( + {id:id, + name:id, + type:type, + state:state, + start:0, + end:0, + status:"unknown"}); + if (new_node && this.history !== undefined) { + this.history.record_nodes([new_node]); } } - this.addNodeComplete = function(id, name, type, state, start, end, status) { + this.addNodeNoHistory = function(spec) { // No history recorded - this is a helper for loading from files / constant graphs - id = id.toLowerCase(); + var id = spec.id.toLowerCase(); var node = findNode(id, null); + var new_node = undefined; + if (node === undefined) { - nodes.push(makeNewNode({ + new_node = { "id": id, - "name": name, - "type": type, - "state": state, - "start": start, - "end": end, - "status": status - })); + "name": spec.name, + "type": spec.type, + "state": spec.state, + "start": spec.start, + "end": spec.end, + "status": spec.status, + 'url': undefined + }; + nodes.push(new_node); } + return new_node; } this.removeNode = function(id, state) { @@ -431,7 +413,11 @@ function myGraph(el) { } for(i = 0; i < data["nodes"].length; i++){ node = data.nodes[i]; - graph.addNodeComplete(node.id, node.name, node.type,"perm",new Date(node.start),new Date(node.end),node.status); + graph.addNodeNoHistory({id:node.id, name:node.name, + type:node.type,state:"perm", + start:new Date(node.start), + end:new Date(node.end), + status:node.status}); autoSuggestAddName(node.id); } for(i = 0; i < data["links"].length; i++){ |
