diff options
| author | Alon Levy <alon@pobox.com> | 2015-03-13 01:43:50 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-03-13 01:43:50 +0200 |
| commit | c842d3bad0d9b3f8b0ab04306bd90c14d7403e49 (patch) | |
| tree | 895ab5b4b2461733f2dc04846354e5ec66bcb82b /src/client/model/graph.js | |
| parent | dc4187c42fa1a85d2958a558940156ffcdf4f9a3 (diff) | |
client: fix json export and import to use model/types to account for allowed attributes
Diffstat (limited to 'src/client/model/graph.js')
| -rw-r--r-- | src/client/model/graph.js | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/src/client/model/graph.js b/src/client/model/graph.js index f38686eb..c560ca30 100644 --- a/src/client/model/graph.js +++ b/src/client/model/graph.js @@ -1,7 +1,10 @@ "use strict" -define(['underscore', 'Bacon_wrapper', 'consts', 'util', 'model/core', 'model/util', 'model/diff', 'rz_api_backend', 'rz_api_mesh', 'history'], -function (_, Bacon, consts, util, model_core, model_util, model_diff, rz_api_backend, rz_api_mesh, history) { +define(['underscore', 'Bacon_wrapper', 'consts', 'util', 'model/core', 'model/util', 'model/diff', 'rz_api_backend', 'rz_api_mesh', 'history', 'model/types'], +function (_, Bacon, consts, util, model_core, model_util, model_diff, rz_api_backend, rz_api_mesh, history, model_types) { + +// aliases +var all_attributes = model_types.all_attributes; var debug = false; @@ -952,14 +955,14 @@ function Graph(spec) { var node_spec = { name: ext_spec.name ? ext_spec.name : ext_spec.id, type: ext_spec.type, - state: "perm", - status: ext_spec.status, - url: ext_spec.url, x: ext_spec.x, y: ext_spec.y, }, node; + all_attributes.forEach(function (attr) { + node_spec[attr] = ext_spec[attr]; + }); if (ext_spec.start) { node_spec.start = new Date(ext_spec.start); } @@ -1002,28 +1005,22 @@ function Graph(spec) { nodes = get_nodes(), links = get_links(); - for(var i = 0 ; i < nodes.length ; i++){ - var node = nodes[i]; - d['nodes'].push({ - "id": node.id, - "name": node.name, - "type":node.type, - "state":"perm", - "start":node.start, - "end":node.end, - "status": node.status, - "url": node.url, - "x": node.x, - "y": node.y, - }); + for (var i = 0 ; i < nodes.length ; i++) { + var node = nodes[i], + node_dict = {id: node.id, x: node.x, y: node.y}; + + all_attributes.forEach(function (attr) { + node_dict[attr] = node[attr]; + }); + d['nodes'].push(node_dict); } - for(var j=0 ; j < links.length ; j++){ - var link = links[j]; - d['links'].push({ - "__src":link.__src.id, - "__dst":link.__dst.id, - "name":link.name - }); + for (var j = 0 ; j < links.length ; j++) { + var link = links[j]; + d['links'].push({ + "__src":link.__src.id, + "__dst":link.__dst.id, + "name":link.name + }); } return JSON.stringify(d); } |
