Commit deda5a37 authored by Georgios Dagkakis's avatar Georgios Dagkakis

Merge branch 'remoteMaster'

parents 84cc414c 87e7ab07
...@@ -2,7 +2,6 @@ import json ...@@ -2,7 +2,6 @@ import json
import traceback import traceback
import multiprocessing import multiprocessing
from pprint import pformat
from flask import Flask, jsonify, redirect, url_for from flask import Flask, jsonify, redirect, url_for
from flask import request from flask import request
...@@ -17,7 +16,8 @@ def front_page(): ...@@ -17,7 +16,8 @@ def front_page():
@app.route("/runSimulation", methods=["POST", "OPTIONS"]) @app.route("/runSimulation", methods=["POST", "OPTIONS"])
def runSimulation(): def runSimulation():
parameter_dict = request.json['json'] parameter_dict = request.json['json']
app.logger.debug("running with:\n%s" % (pformat(parameter_dict,))) app.logger.debug("running with:\n%s" % (json.dumps(parameter_dict,
sort_keys=True, indent=2)))
try: try:
timeout = int(parameter_dict['general']['processTimeout']) timeout = int(parameter_dict['general']['processTimeout'])
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
<form> <form>
<fieldset id="general-fieldset"> <fieldset id="general-fieldset">
</fieldset> </fieldset>
<!-- <button id="run_simulation">Run Simulation</button> -->
<a id="run_simulation">Run Simulation</a> <a id="run_simulation">Run Simulation</a>
</form> </form>
</div> </div>
...@@ -56,7 +55,6 @@ ...@@ -56,7 +55,6 @@
--> -->
</div> </div>
<!-- DEP --> <!-- DEP -->
<script type="text/javascript" src="lib/underscore-min.js"></script>
<script type="text/javascript" src="lib/jquery-1.8.1-min.js"></script> <script type="text/javascript" src="lib/jquery-1.8.1-min.js"></script>
<script type="text/javascript" src="lib/jquery-ui-1.8.23-min.js"></script> <script type="text/javascript" src="lib/jquery-ui-1.8.23-min.js"></script>
<script type="text/javascript" src="lib/jquery.ui.touch-punch.min.js"></script> <script type="text/javascript" src="lib/jquery.ui.touch-punch.min.js"></script>
......
This diff is collapsed.
This diff is collapsed.
...@@ -17,14 +17,13 @@ ...@@ -17,14 +17,13 @@
* along with DREAM. If not, see <http://www.gnu.org/licenses/>. * along with DREAM. If not, see <http://www.gnu.org/licenses/>.
* =========================================================================== */ * =========================================================================== */
(function($, _) { (function($) {
"use strict"; "use strict";
jsPlumb.bind("ready", function() { jsPlumb.bind("ready", function() {
var dream_instance, available_people = {}, people_list, var dream_instance, jio;
i, i_length, updateWorkerCount, json_plumb_configuration = {}, jio;
jio = new jIO.newJio({type: "local", username: "dream", applicationname: "dream"}); jio = new jIO.newJio({type: "local", username: "dream", applicationname: "dream"});
var window_id = 1; var window_id = 1;
var element_id;
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 = {entity: {id: "entity", type:"string", _class: "Dream.Property", default: "Part"}, var property_container = {entity: {id: "entity", type:"string", _class: "Dream.Property", default: "Part"},
// XXX is it possible not to repeat id ? // XXX is it possible not to repeat id ?
...@@ -84,17 +83,18 @@ ...@@ -84,17 +83,18 @@
_class: 'Dream.Repairman', }, _class: 'Dream.Repairman', },
} }
dream_instance = DREAM.newDream(configuration) dream_instance = Dream(configuration)
dream_instance.start(); dream_instance.start();
$( ".tool" ).draggable({ opacity: 0.7, helper: "clone", $( ".tool" ).draggable({ opacity: 0.7, helper: "clone",
stop: function(tool) { stop: function(tool) {
var box_top, box_left, _class; var box_top, box_left, _class;
box_top = tool.clientY; var offset = $("[id=render]").offset();
box_left = tool.clientX; box_top = tool.clientY - offset.top + "px";
box_left = tool.clientX - offset.left + "px";
id_container[tool.target.id] = (id_container[tool.target.id] || 0) + 1; id_container[tool.target.id] = (id_container[tool.target.id] || 0) + 1;
_class = tool.target.id.replace('-', '.'); // XXX - vs . _class = tool.target.id.replace('-', '.'); // XXX - vs .
dream_instance.newElement({id : tool.target.id + "_" + id_container[tool.target.id], dream_instance.newElement({id : tool.target.id + "_" + id_container[tool.target.id],
coordinate: {y: box_top, x: box_left}, coordinate: {top: box_top, left: box_left},
_class: _class, _class: _class,
}); });
window_id += 1; window_id += 1;
...@@ -103,31 +103,28 @@ ...@@ -103,31 +103,28 @@
// Check if there is already data when we first load the page, if yes, then build graph from it // 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) { jio.get({_id: "dream_demo"}, function(err, response) {
console.log("jio get:", response);
if (response !== undefined && response.data !== undefined) { if (response !== undefined && response.data !== undefined) {
// Add all elements // Add all elements
_.each(response.data.element, function(value, key, list) { $.each(response.data.element, function(key, value) {
var element_id = value.id; var preference_data = response.data.preference !== undefined ? response.data.preference[value.id] : {};
var preference_data = response.data.preference !== undefined ? response.data.preference[element_id] : {}; $.each(preference_data, function(preference_key, preference_value){
_.each(_.pairs(preference_data), function(preference_value, preference_key, preference_list) { value[preference_key] = preference_value;
value[preference_value[0]] = preference_value[1];
}); });
dream_instance.newElement(value); dream_instance.newElement(value);
dream_instance.updateElementData(element_id, {data: value.data || {}}); dream_instance.updateElementData(value.id, {data: value.data || {}});
}); });
// Now link elements between them and update id_container // Now link elements between them and update id_container
_.each(response.data.element, function(value, key, list) { $.each(response.data.element, function(key, value) {
var element_id = value.id, prefix, suffix, splitted_element_id, var element_id = value.id, prefix, suffix, splitted_element_id,
successor_list = value.successorList || []; successor_list = value.successorList || [];
splitted_element_id = element_id.split("_"); splitted_element_id = element_id.split("_");
prefix = splitted_element_id[0]; prefix = splitted_element_id[0];
suffix = splitted_element_id[1]; suffix = splitted_element_id[1];
id_container[prefix] = Math.max((id_container[prefix] || 0), parseInt(suffix, 10)); id_container[prefix] = Math.max((id_container[prefix] || 0), parseInt(suffix, 10));
if (successor_list.length > 0) { $.each(successor_list, function(idx, successor_value) {
_.each(successor_list, function(successor_value, successor_key, list) {
dream_instance.connect(value.id, successor_value); dream_instance.connect(value.id, successor_value);
}); });
}
}); });
dream_instance.setGeneralProperties(response.data.general); dream_instance.setGeneralProperties(response.data.general);
dream_instance.initGeneralProperties(); // XXX dream_instance.initGeneralProperties(); // XXX
...@@ -144,13 +141,16 @@ ...@@ -144,13 +141,16 @@
}); });
}); });
// Enable "Run Simulation" button
$("#run_simulation").button().click( $("#run_simulation").button().click(
function(e){ function(e){
dream_instance.runSimulation( dream_instance.runSimulation(
function(data) { function(data) {
if (data['success']) { if (data['success']) {
$("#json_result").text(JSON.stringify(data['success'], undefined, " ")); $("#json_result").text(JSON.stringify(data['success'], undefined, " "));
$.each(data.coreObject, function(idx, obj){ $.each(data['success'].coreObject, function(idx, obj){
var e = $("#" + obj.id); var e = $("#" + obj.id);
/* attach something to each corresponding core object */ /* attach something to each corresponding core object */
// e.tooltip(JSON.stringify(obj['results'], undefined, " ")); // e.tooltip(JSON.stringify(obj['results'], undefined, " "));
...@@ -162,15 +162,14 @@ ...@@ -162,15 +162,14 @@
e.preventDefault(); e.preventDefault();
return false; return false;
}); });
// Enable "Clear All" button
$("#clear_all").button().click( $("#clear_all").button().click(
function(e){ function(e){
dream_instance.clearAll(
function() {
dream_instance.clearAll(); dream_instance.clearAll();
});
e.preventDefault(); e.preventDefault();
return false; return false;
}); });
}) })
})(jQuery, _); })(jQuery);
...@@ -17,15 +17,11 @@ ...@@ -17,15 +17,11 @@
* along with DREAM. If not, see <http://www.gnu.org/licenses/>. * along with DREAM. If not, see <http://www.gnu.org/licenses/>.
* =========================================================================== */ * =========================================================================== */
(function (scope, $, jsPlumb, console, _) { (function (scope, $, jsPlumb, console) {
"use strict"; "use strict";
var jsonPlumb = function (model) { scope.jsonPlumb = function (model) {
var that = {}, priv = {}; var that = {}, priv = {};
priv.onError = function(error) {
console.log("Error", error);
};
priv.initJsPlumb = function () { priv.initJsPlumb = function () {
jsPlumb.setRenderMode(jsPlumb.SVG); jsPlumb.setRenderMode(jsPlumb.SVG);
var color = "#00f"; var color = "#00f";
...@@ -101,11 +97,14 @@ ...@@ -101,11 +97,14 @@
priv.draggable(); priv.draggable();
}; };
priv.updateElementCoordinate = function(element_id, x, y) { priv.updateElementCoordinate = function(element_id, coordinate) {
var preference = priv.preference_container[element_id] || {}; var preference = priv.preference_container[element_id] || {}, element;
var coordinate = preference.coordinate || {}; if (coordinate === undefined) {
coordinate.x = x; coordinate = {};
coordinate.y = y; element = $("#" + element_id);
coordinate.top = element.css("top");
coordinate.left = element.css("left");
}
preference["coordinate"] = coordinate; preference["coordinate"] = coordinate;
priv.preference_container[element_id] = preference; priv.preference_container[element_id] = preference;
priv.onDataChange(); priv.onDataChange();
...@@ -116,7 +115,7 @@ ...@@ -116,7 +115,7 @@
// make all the window divs draggable // make all the window divs draggable
var stop = function(el) { var stop = function(el) {
var element_id = el.target.id; var element_id = el.target.id;
priv.updateElementCoordinate(element_id, el.clientX, el.clientY); priv.updateElementCoordinate(element_id);
} }
jsPlumb.draggable(jsPlumb.getSelector(".window"), { grid: [20, 20] , jsPlumb.draggable(jsPlumb.getSelector(".window"), { grid: [20, 20] ,
stop: stop, stop: stop,
...@@ -150,106 +149,56 @@ ...@@ -150,106 +149,56 @@
priv.onDataChange(); priv.onDataChange();
}; };
Object.defineProperty(that, "updateElementData", { that.updateElementData = function (element_id, data) {
configurable: false, $.extend(priv.element_container[element_id], data);
enumerable: false,
writable: false,
value: function (element_id, data) {
_.extend(priv.element_container[element_id], data);
priv.onDataChange(); priv.onDataChange();
} };
});
Object.defineProperty(that, "start", { that.start = function () {
configurable: false,
enumerable: false,
writable: false,
value: function () {
priv.element_container = {}; priv.element_container = {};
priv.preference_container = {}; priv.preference_container = {};
priv.general_container = {}; priv.general_container = {};
priv.initJsPlumb(); priv.initJsPlumb();
} };
});
Object.defineProperty(that, "removeElement", { that.removeElement = function (element_id) {
configurable: false,
enumerable: false,
writable: false,
value: function (element_id) {
console.log("going to remove element", element_id); console.log("going to remove element", element_id);
priv.removeElement(element_id); priv.removeElement(element_id);
} };
});
Object.defineProperty(that, "getData", { that.getData = function () {
configurable: false,
enumerable: false,
writable: false,
value: function () {
return priv.getData(); return priv.getData();
} };
});
Object.defineProperty(that, "clearAll", { that.clearAll = function () {
configurable: false,
enumerable: false,
writable: false,
value: function () {
$("[id=render]").children().remove() $("[id=render]").children().remove()
_.each(_.pairs(priv.element_container), function(element, index) { $.each(priv.element_container, function(idx, element) {
priv.removeElement(element[0]); priv.removeElement(element);
});
}
}); });
};
Object.defineProperty(that, "connect", { that.connect = function (source_id, target_id) {
configurable: false,
enumerable: false,
writable: false,
value: function (source_id, target_id) {
jsPlumb.connect({source: source_id, target: target_id}); jsPlumb.connect({source: source_id, target: target_id});
} };
});
Object.defineProperty(that, "setGeneralProperties", { that.setGeneralProperties = function (properties) {
configurable: false,
enumerable: false,
writable: false,
value: function (properties) { // XXX or k, v ?
priv.general_container = properties; priv.general_container = properties;
priv.onDataChange(); priv.onDataChange();
}, };
});
Object.defineProperty(that, "newElement", { that.newElement = function (element, option) {
configurable: false, var render_element, style_string="", coordinate=element.coordinate,
enumerable: false, box;
writable: false,
value: function (element, option) {
var render_element, style_string="", coordinate = {};
render_element = $("[id=render]"); render_element = $("[id=render]");
if (element.coordinate !== undefined) { if (coordinate !== undefined) {
priv.updateElementCoordinate(element.id, element.coordinate.x, element.coordinate.y) coordinate = priv.updateElementCoordinate(element.id, coordinate)
var main_div_offset = $("#main").offset();
coordinate.x = element.coordinate.x - main_div_offset.left;
coordinate.y = element.coordinate.y - main_div_offset.top;
_.each(coordinate, function(value, key, list) {
if (key === "x") {
key = "left";
} else {
key = "top";
}
style_string = style_string + key + ':' + value + 'px;';
})
}
if (style_string.length > 0) {
style_string = 'style="' + style_string + '"';
} }
render_element.append('<div class="window" id="' + render_element.append('<div class="window" id="' +
element.id + '" ' + style_string + '">' element.id + '">' + element.id + '</div>');
+ element.id + '</div>'); box = $("#" + element.id);
box.css("top", coordinate.top);
box.css("left", coordinate.left);
// Initial DEMO code : make all the window divs draggable // Initial DEMO code : make all the window divs draggable
priv.draggable(); priv.draggable();
...@@ -266,56 +215,16 @@ ...@@ -266,56 +215,16 @@
paintStyle:{ width:25, height:21, fillStyle:color }, paintStyle:{ width:25, height:21, fillStyle:color },
isSource:true, isSource:true,
scope:"blue rectangle", scope:"blue rectangle",
/*connectorStyle : {
gradient:{stops:[[0, color], [0.5, gradient_color], [1, color]]},
lineWidth:5,
strokeStyle:color,
dashstyle:"2 2"
},*/
//connector: ["Bezier", { curviness:63 } ],
maxConnections:3, maxConnections:3,
isTarget:true, isTarget:true,
//dropOptions : exampleDropOptions
}; };
_.each(_.pairs(option.anchor), function(value, key, list) { for (var key in option.anchor) {
var anchor = value[0], jsPlumb.addEndpoint(element.id, { anchor: key }, endpoint);
endpoint_configuration = value[1]; };
jsPlumb.addEndpoint(element.id, { anchor: anchor }, endpoint);
})
priv.addElementToContainer(element); priv.addElementToContainer(element);
}
});
return that;
}; };
var JsonPlumbNamespace = (function () {
var that = {};
/**
* Creates a new dream instance.
* @method newDream
* @param {object} model The model definition
* @return {object} The new Dream instance.
*/
Object.defineProperty(that, "newJsonPlumb", {
configurable: false,
enumerable: false,
writable: false,
value: function (model) {
var instance = jsonPlumb(model);
return instance;
}
});
return that; return that;
})(); };
Object.defineProperty(scope, "jsonPlumb", {
configurable: false,
enumerable: false,
writable: false,
value: JsonPlumbNamespace
});
}(window, jQuery, jsPlumb, console, _)); }(window, jQuery, jsPlumb, console));
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