Commit 5fe492cb authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by Sebastien Robin

added ui and dream folders

parent b6b837a3
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
from flask import Flask, jsonify
from flask import request
from crossdomain import crossdomain
from util import deunicodeData
app = Flask(__name__)
global data
data = {'model': None,
'simulation_parameters': {}}
@app.route("/")
def welcome():
app.logger.debug('welcome')
return "Welcome to DREAM Simulation"
@app.route("/addModel")
def addModel():
pass
def main(*args):
app.run(debug=True)
@app.route("/someTest", methods=["POST", "OPTIONS"])
@crossdomain(origin='*')
def someTest():
app.logger.debug('someTest')
app.logger.debug(request)
app.logger.debug(request.__dict__)
app.logger.debug("request headers content type: %r" % (request.headers['Content-Type'],))
app.logger.debug("request.json: %r" % (request.json,))
response =request.json
return jsonify(request.json)
@app.route("/setModel", methods=["POST", "OPTIONS"])
@crossdomain(origin='*')
def setModel():
app.logger.debug('setModel')
data['model'] = request.json
data['simulation_parameters'] = {}
app.logger.debug("model: %r" % (data['model'],))
return "ok"
@app.route("/updateModel", methods=["POST", "OPTIONS"])
@crossdomain(origin='*')
def updateModel():
app.logger.debug('updateModel')
data['model'] = request.json
return "ok"
@app.route("/setSimulationParameters", methods=["POST", "OPTIONS"])
@crossdomain(origin='*')
def setSimulationParameters():
app.logger.debug('setSimulationParameters')
parameter_dict = request.json
app.logger.debug("parameter_dict: %r" % (parameter_dict,))
data['simulation_parameters']['available_people'] = parameter_dict
return "ok"
def _simulate():
# Well, it's only dummy code now, but we will have to think about
# running simulation later
box_to_enable_list = [1, 2, 3, 7, 8, 9]
people_dict = data['simulation_parameters'].get('available_people', {})
available_people_list = [x for x in people_dict if people_dict[x]]
to_enable = len(available_people_list) >= 6
throughput = None
for box in data['model']["box_list"]:
box["worker"] = None
box["enabled"] = False
if int(box["id"][len("window"):]) in box_to_enable_list:
box["enabled"] = to_enable
if to_enable:
box["worker"] = available_people_list.pop()
if throughput is None:
throughput = box["throughput"]
throughput = min(throughput, box["throughput"])
app.logger.debug('box and throughput : %r, %r' % (box, throughput))
if throughput is None:
throughput = 0
data['model']["throughput"] = throughput
@app.route("/getModel", methods=["GET", "OPTIONS"])
@crossdomain(origin='*')
def getModel():
app.logger.debug('getModel')
_simulate()
return jsonify(data['model'])
if __name__ == "__main__":
main()
# This code comes from http://flask.pocoo.org/snippets/56/
from datetime import timedelta
from flask import make_response, request, current_app
from functools import update_wrapper
def crossdomain(origin=None, methods=None, headers=None,
max_age=21600, attach_to_all=True,
automatic_options=True):
if methods is not None:
methods = ', '.join(sorted(x.upper() for x in methods))
if headers is not None and not isinstance(headers, basestring):
headers = ', '.join(x.upper() for x in headers)
if not isinstance(origin, basestring):
origin = ', '.join(origin)
if isinstance(max_age, timedelta):
max_age = max_age.total_seconds()
def get_methods():
if methods is not None:
return methods
options_resp = current_app.make_default_options_response()
return options_resp.headers['allow']
def decorator(f):
def wrapped_function(*args, **kwargs):
if automatic_options and request.method == 'OPTIONS':
resp = current_app.make_default_options_response()
else:
resp = make_response(f(*args, **kwargs))
if not attach_to_all and request.method != 'OPTIONS':
return resp
h = resp.headers
h['Access-Control-Allow-Origin'] = origin
h['Access-Control-Allow-Methods'] = get_methods()
h['Access-Control-Max-Age'] = str(max_age)
# XXX It should not be necessary to hardcode allow-headers
h['Access-Control-Allow-Headers'] = 'Content-Type'
if headers is not None:
h['Access-Control-Allow-Headers'] = headers
return resp
f.provide_automatic_options = False
return update_wrapper(wrapped_function, f)
return decorator
def deunicodeData(data):
if isinstance(data, list):
new_data = []
for sub_data in data:
new_data.append(deunicodeData(sub_data))
elif isinstance(data, unicode):
new_data = data.encode('utf8')
elif isinstance(data, dict):
new_data = {}
for key, value in data.iteritems():
key = deunicodeData(key)
value = deunicodeData(value)
new_data[key] = value
elif isinstance(data, (int, float)):
new_data = data
else:
raise ValueError("unknow type : %r" % (data,))
return new_data
@font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
src:local('Open Sans'),
local('OpenSans'),
url("../font/OpenSans-Regular.ttf") format('truetype'),
url("../font/OpenSans.woff") format('woff');
}
body {
padding:0;
margin:0;
background-color:white;
font-family:'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
text-align:center;
}
#headerWrapper {
width:100%;
background-color:black;
position:fixed;
top:0;left:0;
z-index:10000;
height:44px;
padding:0;
border-bottom:1px solid #999;
box-shadow: 0px 2px 19px #aaa;
-o-box-shadow: 0px 2px 19px #aaa;
-webkit-box-shadow: 0px 2px 19px #aaa;
-moz-box-shadow: 0px 2px 19px #aaa;
opacity:0.8;
}
#header {
margin-top:0;
height:44px;
font-size:80%;
margin-left:auto;
margin-right:auto;
width:950px;
background-image:url(../../img/logo_bw_44h.jpg);
background-repeat:no-repeat;
}
#intro {
margin-top:59px;
}
#main {
/* these two margins settings are here just to ensure that jsPlumb handles
margins properly.*/
margin-top:44px;
margin-left: auto;
position: relative;
font-size: 80%;
margin-right: auto;
width: 850px;
border-left: 2px solid #456;
border-right: 2px solid #456;
border-bottom: 2px solid #456;
height: 600px;
overflow: hidden;
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
background-color:#eaedef;
}
#available {
position: absolute;
width: 200px;
height: 200px;
border: 2px solid;
margin-top: 350px;
margin-left: 150px;
border-radius: 10px;
}
#not_available {
position: absolute;
width: 200px;
height: 200px;
border: 2px solid;
margin-top: 350px;
margin-left: 500px;
border-radius: 10px;
}
#total_workers {
position: absolute;
width: 100px;
height: 80px;
border: 2px solid;
margin-top: 80px;
margin-left: 720px;
border-radius: 10px;
}
#total_throughput {
position: absolute;
width: 100px;
height: 80px;
border: 2px solid;
margin-top: 200px;
margin-left: 720px;
border-radius: 10px;
}
/* Setting for dialog */
label, input { display:block; }
input.text { margin-bottom:12px; width:95%; padding: .4em; }
fieldset { padding:0; border:0; margin-top:25px; }
h1 { font-size: 1.2em; margin: .6em 0; }
div#users-contain { width: 350px; margin: 20px 0; }
div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
.ui-dialog .ui-state-error { padding: .3em; }
.validateTips { border: 1px solid transparent; padding: 0.3em; }
/* End of dialog setting */
li { margin: 3px;
/*padding: 1px;*/
/*text-align: -webkit-match-parent;*/
background: #e6e6e6;
border: 1px solid #d3d3d3;
list-style-type: none;
width: 120px; }
#sidebar {
margin-left:auto;
margin-right:auto;
width:800px;
font-size:13px;
}
/* demo elements */
.menu,#render, #explanation {
background-color:#fff;
}
.menu {
height: 15px;
float:right;
padding-top:1em;
padding-bottom:0.4em;
background-color: transparent;
margin-right:30px;
}
#render {
padding-top:2px;
margin-left:auto;
margin-right:auto;
z-index:5000;
margin-top:0px;
text-align: center;
background-color:white;
}
#render ul {
padding-left:1em;
}
#render ul li {
list-style-type:none;
}
#render h5 {
display:inline;
}
.otherLibraries {
display:inline;
}
a, a:visited {
text-decoration:none;
color:#01a3c6;
font-family:helvetica;
padding:0.3em;
border-radius:0.2em;
}
a:hover {
color:#1b911b;
}
.selected {
color:rgb(189,11,11) !important;
}
.window, .label {
background-color:white;
text-align:center;
z-index:23;
cursor:pointer;
box-shadow: 2px 2px 19px #aaa;
-o-box-shadow: 2px 2px 19px #aaa;
-webkit-box-shadow: 2px 2px 19px #aaa;
-moz-box-shadow: 2px 2px 19px #aaa;
}
path, ._jsPlumb_endpoint { cursor:pointer; }
/* z index stuff */
._jsPlumb_connector { z-index:18; }
._jsPlumb_endpoint { z-index:19; }
._jsPlumb_overlay { z-index:23; }
._jsPlumb_connector._jsPlumb_hover {
z-index:21 !important;
}
._jsPlumb_endpoint._jsPlumb_hover {
z-index:22 !important;
}
._jsPlumb_overlay {
border:1px solid #346789;
opacity:0.8;
filter:alpha(opacity=80);
background-color:white;
color:black;
font-family:helvetica;
padding:0.5em;
}
.window { border:1px solid #346789;
box-shadow: 2px 2px 19px #aaa;
-o-box-shadow: 2px 2px 19px #aaa;
-webkit-box-shadow: 2px 2px 19px #aaa;
-moz-box-shadow: 2px 2px 19px #aaa;
-moz-border-radius:0.5em;
border-radius:0.5em;
opacity:0.8;
filter:alpha(opacity=80);
width:5em; height:5em;
/*line-height:5em;*/
text-align:center;
z-index:20; position:absolute;
background-color:#eeeeef;
color:black;
font-family:helvetica;padding:0.5em;
font-size:0.9em;}
.window:hover {
box-shadow: 2px 2px 19px #444;
-o-box-shadow: 2px 2px 19px #444;
-webkit-box-shadow: 2px 2px 19px #444;
-moz-box-shadow: 2px 2px 19px #444;
opacity:0.6;
filter:alpha(opacity=60);
}
.active {
border:1px dotted green;
}
.hover {
border:1px dotted red;
}
._jsPlumb_connector { z-index:3; }
._jsPlumb_endpoint, .endpointTargetLabel, .endpointSourceLabel{ z-index:21;cursor:pointer; }
.hl { border:3px solid red; }
#debug { position:absolute; background-color:black; color:red; z-index:5000 }
.aLabel {
background-color:white;
padding:0.4em;
font:12px sans-serif;
color:#444;
z-index:10;
border:1px dotted gray;
opacity:0.8;
filter:alpha(opacity=80);
}
\ No newline at end of file
This diff is collapsed.
<!doctype html>
<html>
<head>
<title>jsPlumb 1.4.0 - flowchart connectors demonstration - jQuery</title>
<link rel="stylesheet" href="css/demo-new.css">
<link rel="stylesheet" href="css/flowchartDemo.css">
<link rel="stylesheet" href="css/jquery-ui.css">
</head>
<body data-demo-id="flowchartConnectorsDemo" data-library="jquery">
<div id="headerWrapper"><div id="header"></div></div>
<div id="main">
<div id="render"></div>
<div id="available">
Available
<ul>
</ul>
</div>
<div id="not_available">
Not Available
<ul>
</ul>
</div>
<div id="total_workers">
Workers
<h2>0</h2>
</div>
<div id="total_throughput">
Throughput
<h2></h2>
</div>
</div>
<div id="sidebar">
<div id="explanation">
<p>This is a demonstration of Flowchart combined with simulation.</p>
<p>Drag not available people to the box "Available". If there is enough workers, a green path will be displayed on the Flowchart.</p>
<p>Every time there is change to the list of available/not available people, a simulation server get informations and process new calculation.</p>
<p>For now, there is no real simulation, only some little code to make this demo working</p>
<p>This demonstration uses jsPlumb 1.4.0, jQuery 1.8.1 and jQuery UI 1.8.23.</p>
</div>
</div>
<div id="dialog-form" title="Change Througput">
<p class="validateTips">All form fields are required.</p>
<form>
<fieldset>
<label for="Throughput">Throughput</label>
<input type="text" name="throughput" id="throughput" class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>
</div>
<!-- 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-ui-1.8.23-min.js"></script>
<script type="text/javascript" src="lib/jquery.ui.touch-punch.min.js"></script>
<!-- /DEP -->
<!-- JS -->
<!-- support lib for bezier stuff -->
<script src="lib/jsBezier-0.5.js"></script>
<!-- jsplumb util -->
<script src="lib/jsPlumb/jsPlumb-util.js"></script>
<!-- base DOM adapter -->
<script src="lib/jsPlumb/jsPlumb-dom-adapter.js"></script>
<!-- main jsplumb engine -->
<script src="lib/jsPlumb/jsPlumb.js"></script>
<!-- anchors -->
<script src="lib/jsPlumb/jsPlumb-anchors.js"></script>
<!-- endpoint -->
<script src="lib/jsPlumb/jsPlumb-endpoint.js"></script>
<!-- connection -->
<script src="lib/jsPlumb/jsPlumb-connection.js"></script>
<!-- connector editors -->
<script src="lib/jsPlumb/jsPlumb-connector-editors.js"></script>
<!-- connectors, endpoint and overlays -->
<script src="lib/jsPlumb/jsPlumb-defaults.js"></script>
<!-- state machine connectors -->
<script src="lib/jsPlumb/jsPlumb-connectors-statemachine.js"></script>
<!-- flowchart connectors -->
<script src="lib/jsPlumb/jsPlumb-connectors-flowchart.js"></script>
<!-- SVG renderer -->
<script src="lib/jsPlumb/jsPlumb-renderers-svg.js"></script>
<!-- canvas renderer -->
<script src="lib/jsPlumb/jsPlumb-renderers-canvas.js"></script>
<!-- vml renderer -->
<script src="lib/jsPlumb/jsPlumb-renderers-vml.js"></script>
<!-- jquery jsPlumb adapter -->
<script src="lib/jsPlumb/jquery.jsPlumb.js"></script>
<!-- /JS -->
<!-- demo code -->
<script src="src/dream.js"></script>
<script src="src/dream_launcher.js"></script>
<!-- demo helper code -->
<!--script src="src/demo-list.js"></script-->
<!--script src="src/demo-helper-jquery.js"></script-->
</body>
</html>
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* jQuery UI Touch Punch 0.2.2
*
* Copyright 2011, Dave Furfero
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Depends:
* jquery.ui.widget.js
* jquery.ui.mouse.js
*/
(function(b){b.support.touch="ontouchend" in document;if(!b.support.touch){return;}var c=b.ui.mouse.prototype,e=c._mouseInit,a;function d(g,h){if(g.originalEvent.touches.length>1){return;}g.preventDefault();var i=g.originalEvent.changedTouches[0],f=document.createEvent("MouseEvents");f.initMouseEvent(h,true,true,window,1,i.screenX,i.screenY,i.clientX,i.clientY,false,false,false,false,0,null);g.target.dispatchEvent(f);}c._touchStart=function(g){var f=this;if(a||!f._mouseCapture(g.originalEvent.changedTouches[0])){return;}a=true;f._touchMoved=false;d(g,"mouseover");d(g,"mousemove");d(g,"mousedown");};c._touchMove=function(f){if(!a){return;}this._touchMoved=true;d(f,"mousemove");};c._touchEnd=function(f){if(!a){return;}d(f,"mouseup");d(f,"mouseout");if(!this._touchMoved){d(f,"click");}a=false;};c._mouseInit=function(){var f=this;f.element.bind("touchstart",b.proxy(f,"_touchStart")).bind("touchmove",b.proxy(f,"_touchMove")).bind("touchend",b.proxy(f,"_touchEnd"));e.call(f);};})(jQuery);
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* jsPlumb
*
* Title:jsPlumb 1.4.0
*
* Provides a way to visually connect elements on an HTML page, using either SVG, Canvas
* elements, or VML.
*
* This file contains the base functionality for DOM type adapters.
*
* Copyright (c) 2010 - 2013 Simon Porritt (http://jsplumb.org)
*
* http://jsplumb.org
* http://github.com/sporritt/jsplumb
* http://code.google.com/p/jsplumb
*
* Dual licensed under the MIT and GPL2 licenses.
*/
;(function() {
var canvasAvailable = !!document.createElement('canvas').getContext,
svgAvailable = !!window.SVGAngle || document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1"),
// http://stackoverflow.com/questions/654112/how-do-you-detect-support-for-vml-or-svg-in-a-browser
vmlAvailable = function() {
if (vmlAvailable.vml == undefined) {
var a = document.body.appendChild(document.createElement('div'));
a.innerHTML = '<v:shape id="vml_flag1" adj="1" />';
var b = a.firstChild;
b.style.behavior = "url(#default#VML)";
vmlAvailable.vml = b ? typeof b.adj == "object": true;
a.parentNode.removeChild(a);
}
return vmlAvailable.vml;
};
/**
Manages dragging for some instance of jsPlumb.
*/
var DragManager = function(_currentInstance) {
var _draggables = {}, _dlist = [], _delements = {}, _elementsWithEndpoints = {},
// elementids mapped to the draggable to which they belong.
_draggablesForElements = {};
/**
register some element as draggable. right now the drag init stuff is done elsewhere, and it is
possible that will continue to be the case.
*/
this.register = function(el) {
var jpcl = jsPlumb.CurrentLibrary;
el = jpcl.getElementObject(el);
var id = _currentInstance.getId(el),
domEl = jpcl.getDOMElement(el),
parentOffset = jpcl.getOffset(el);
if (!_draggables[id]) {
_draggables[id] = el;
_dlist.push(el);
_delements[id] = {};
}
// look for child elements that have endpoints and register them against this draggable.
var _oneLevel = function(p, startOffset) {
if (p) {
for (var i = 0; i < p.childNodes.length; i++) {
if (p.childNodes[i].nodeType != 3 && p.childNodes[i].nodeType != 8) {
var cEl = jpcl.getElementObject(p.childNodes[i]),
cid = _currentInstance.getId(cEl, null, true);
if (cid && _elementsWithEndpoints[cid] && _elementsWithEndpoints[cid] > 0) {
var cOff = jpcl.getOffset(cEl);
_delements[id][cid] = {
id:cid,
offset:{
left:cOff.left - parentOffset.left,
top:cOff.top - parentOffset.top
}
};
_draggablesForElements[cid] = id;
}
_oneLevel(p.childNodes[i]);
}
}
}
};
_oneLevel(domEl);
};
// refresh the offsets for child elements of this element.
this.updateOffsets = function(elId) {
var jpcl = jsPlumb.CurrentLibrary,
el = jpcl.getElementObject(elId),
id = _currentInstance.getId(el),
children = _delements[id],
parentOffset = jpcl.getOffset(el);
if (children) {
for (var i in children) {
var cel = jpcl.getElementObject(i),
cOff = jpcl.getOffset(cel);
_delements[id][i] = {
id:i,
offset:{
left:cOff.left - parentOffset.left,
top:cOff.top - parentOffset.top
}
};
_draggablesForElements[i] = id;
}
}
};
/**
notification that an endpoint was added to the given el. we go up from that el's parent
node, looking for a parent that has been registered as a draggable. if we find one, we add this
el to that parent's list of elements to update on drag (if it is not there already)
*/
this.endpointAdded = function(el) {
var jpcl = jsPlumb.CurrentLibrary, b = document.body, id = _currentInstance.getId(el), c = jpcl.getDOMElement(el),
p = c.parentNode, done = p == b;
_elementsWithEndpoints[id] = _elementsWithEndpoints[id] ? _elementsWithEndpoints[id] + 1 : 1;
while (p != null && p != b) {
var pid = _currentInstance.getId(p, null, true);
if (pid && _draggables[pid]) {
var idx = -1, pEl = jpcl.getElementObject(p), pLoc = jpcl.getOffset(pEl);
if (_delements[pid][id] == null) {
var cLoc = jsPlumb.CurrentLibrary.getOffset(el);
_delements[pid][id] = {
id:id,
offset:{
left:cLoc.left - pLoc.left,
top:cLoc.top - pLoc.top
}
};
_draggablesForElements[id] = pid;
}
break;
}
p = p.parentNode;
}
};
this.endpointDeleted = function(endpoint) {
if (_elementsWithEndpoints[endpoint.elementId]) {
_elementsWithEndpoints[endpoint.elementId]--;
if (_elementsWithEndpoints[endpoint.elementId] <= 0) {
for (var i in _delements) {
if (_delements[i]) {
delete _delements[i][endpoint.elementId];
delete _draggablesForElements[endpoint.elementId];
}
}
}
}
};
this.changeId = function(oldId, newId) {
_delements[newId] = _delements[oldId];
_delements[oldId] = {};
_draggablesForElements[newId] = _draggablesForElements[oldId];
_draggablesForElements[oldId] = null;
};
this.getElementsForDraggable = function(id) {
return _delements[id];
};
this.elementRemoved = function(elementId) {
var elId = _draggablesForElements[elementId];
if (elId) {
delete _delements[elId][elementId];
delete _draggablesForElements[elementId];
}
};
this.reset = function() {
_draggables = {};
_dlist = [];
_delements = {};
_elementsWithEndpoints = {};
};
};
// for those browsers that dont have it. they still don't have it! but at least they won't crash.
if (!window.console)
window.console = { time:function(){}, timeEnd:function(){}, group:function(){}, groupEnd:function(){}, log:function(){} };
window.jsPlumbAdapter = {
headless:false,
appendToRoot : function(node) {
document.body.appendChild(node);
},
getRenderModes : function() {
return [ "canvas", "svg", "vml" ]
},
isRenderModeAvailable : function(m) {
return {
"canvas":canvasAvailable,
"svg":svgAvailable,
"vml":vmlAvailable()
}[m];
},
getDragManager : function(_jsPlumb) {
return new DragManager(_jsPlumb);
},
setRenderMode : function(mode) {
var renderMode;
if (mode) {
mode = mode.toLowerCase();
var canvasAvailable = this.isRenderModeAvailable("canvas"),
svgAvailable = this.isRenderModeAvailable("svg"),
vmlAvailable = this.isRenderModeAvailable("vml");
// now test we actually have the capability to do this.
if (mode === "svg") {
if (svgAvailable) renderMode = "svg"
else if (canvasAvailable) renderMode = "canvas"
else if (vmlAvailable) renderMode = "vml"
}
else if (mode === "canvas" && canvasAvailable) renderMode = "canvas";
else if (vmlAvailable) renderMode = "vml";
}
return renderMode;
}
};
})();
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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