Commit 5f82ccfc authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

make internal data format and runSimulation data format consistent.

parent 7f14d3bb
......@@ -195,14 +195,16 @@
"property_list"
] || [];
var updateDefaultData = function (data, property_list) {
$.each(property_list, function (key, element) {
if (element) {
if (element._class === "Dream.Property") {
data[element.id] = element._default;
} else if (element._class === "Dream.PropertyList") {
data[element.id] = {};
var next_data = data[element.id];
var next_property_list = element.property_list || [];
$.each(property_list, function (idx, value) {
if (value) {
if (element[value.id]) {
data[value.id] = element[value.id];
} else if (value._class === "Dream.Property") {
data[value.id] = value._default;
} else if (value._class === "Dream.PropertyList") {
data[value.id] = {};
var next_data = data[value.id];
var next_property_list = value.property_list || [];
updateDefaultData(next_data, next_property_list);
}
}
......@@ -229,31 +231,6 @@
that.initGeneralProperties();
};
priv.formatForManpy = function (data) {
var manpy_dict = {}, nodes = {}, edges = {}, edge_id = 0;
$.each(data['nodes'], function (node_id, node) {
var clone_node = {};
/* clone the node and put content of 'data' at the top level. */
$.each(node, function (k, v) {
if (k == 'data') {
$.each(v, function (kk, vv) {
clone_node[kk] = vv;
});
} else if (k == 'element_id') {
true; // no need to output
} else {
clone_node[k] = v;
}
});
nodes[node_id] = clone_node;
});
manpy_dict['nodes'] = nodes;
manpy_dict['edges'] = data['edges'];
manpy_dict['general'] = data['general'];
manpy_dict['spreadsheet'] = data['spreadsheet'];
return manpy_dict;
};
/** Runs the simulation, and call the callback with results once the
* simulation is finished.
*/
......@@ -271,11 +248,10 @@
});
that.setGeneralProperties(properties);
var model = priv.formatForManpy(that.getData());
$.ajax(
'/runSimulation', {
data: JSON.stringify({
json: model
json: that.getData()
}),
contentType: 'application/json',
type: 'POST',
......
......@@ -277,9 +277,11 @@
}
value['id'] = key;
dream_instance.newElement(value);
dream_instance.updateElementData(key, {
data: value.data || {}
});
if (value.data) { // backward compatibility
dream_instance.updateElementData(key, {
data: value.data
});
}
});
$.each(data.edges, function (key, value) {
dream_instance.connect(value[0], value[1]);
......
......@@ -324,7 +324,7 @@
}
var new_id = data['id'];
delete(data['id']);
$.extend(priv.node_container[node_id], data);
$.extend(priv.node_container[node_id], data.data);
if (new_id && new_id !== node_id) {
priv.node_container[new_id] = priv.node_container[node_id];
delete(priv.node_container[node_id]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment