Commit fe2282a1 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

make loadData() function.

parent afee6b20
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
applicationname: "dream" applicationname: "dream"
}); });
var window_id = 1;
var id_container = {}; // to allow generating next ids, like Machine_1, Machine_2, etc var id_container = {}; // to allow generating next ids, like Machine_1, Machine_2, etc
var property_container = { var property_container = {
entity: { entity: {
...@@ -231,21 +230,16 @@ ...@@ -231,21 +230,16 @@
}, },
_class: _class _class: _class
}); });
window_id += 1;
} }
}); });
// Check if there is already data when we first load the page, if yes, then build graph from it var loadData = function(data) {
jio.get({ var preference = data.preference !== undefined ?
_id: "dream_demo" data.preference : {};
}, function (err, response) {
if (response !== undefined && response.data !== undefined) {
var preference = response.data.preference !== undefined ?
response.data.preference : {};
dream_instance.setPreferences(preference); dream_instance.setPreferences(preference);
// Add all elements // Add all elements
$.each(response.data.nodes, function (key, value) { $.each(data.nodes, function (key, value) {
var coordinates = preference['coordinates'] || {}; var coordinates = preference['coordinates'] || {};
var coordinate = coordinates[key] || {}; var coordinate = coordinates[key] || {};
value['coordinate'] = {}; value['coordinate'] = {};
...@@ -257,12 +251,12 @@ ...@@ -257,12 +251,12 @@
data: value.data || {} data: value.data || {}
}); });
}); });
$.each(response.data.edges, function (key, value) { $.each(data.edges, function (key, value) {
dream_instance.connect(value[0], value[1]); dream_instance.connect(value[0], value[1]);
}); });
// Now update id_container // Now update id_container
$.each(response.data.nodes, function (key, value) { $.each(data.nodes, function (key, value) {
var element_id = value.id, var element_id = value.id,
prefix, suffix, splitted_element_id; prefix, suffix, splitted_element_id;
splitted_element_id = element_id.split("_"); splitted_element_id = element_id.split("_");
...@@ -271,12 +265,20 @@ ...@@ -271,12 +265,20 @@
id_container[prefix] = Math.max((id_container[prefix] || 0), id_container[prefix] = Math.max((id_container[prefix] || 0),
parseInt(suffix, 10)); parseInt(suffix, 10));
}); });
dream_instance.setGeneralProperties(response.data.general); dream_instance.setGeneralProperties(data.general);
dream_instance.initGeneralProperties(); // XXX dream_instance.initGeneralProperties(); // XXX
dream_instance.redraw()
$("#json_output").text(JSON.stringify(dream_instance.getData(), $("#json_output").text(JSON.stringify(dream_instance.getData(),
undefined, " ")); undefined, " "));
} };
// Check if there is already data when we first load the page, if yes, then build graph from it
jio.get({
_id: "dream_demo"
}, function (err, response) {
if (response !== undefined && response.data !== undefined) {
loadData(response.data);
}
// once the data is read, we can subscribe to every changes // once the data is read, we can subscribe to every changes
$.subscribe("Dream.Gui.onDataChange", function (event, data) { $.subscribe("Dream.Gui.onDataChange", function (event, data) {
$("#json_output").text(JSON.stringify(data, undefined, " ")); $("#json_output").text(JSON.stringify(data, undefined, " "));
......
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