|
|
@@ -6,7 +6,7 @@ import abp |
|
|
#TODO: only send deltas |
|
|
#TODO: only send deltas |
|
|
|
|
|
|
|
|
#graphstate = abp.GraphState() |
|
|
#graphstate = abp.GraphState() |
|
|
cache=SimpleCache() |
|
|
|
|
|
|
|
|
cache = SimpleCache(default_timeout = 10000) |
|
|
cache.set("state", abp.GraphState()) |
|
|
cache.set("state", abp.GraphState()) |
|
|
app = Flask(__name__) |
|
|
app = Flask(__name__) |
|
|
|
|
|
|
|
|
@@ -17,8 +17,13 @@ def index(): |
|
|
@app.route("/state", methods = ["GET", "POST"]) |
|
|
@app.route("/state", methods = ["GET", "POST"]) |
|
|
def state(): |
|
|
def state(): |
|
|
if request.method == "GET": |
|
|
if request.method == "GET": |
|
|
return jsonify(cache.get("state").to_json()) |
|
|
|
|
|
|
|
|
state = cache.get("state") |
|
|
|
|
|
output = state.to_json() |
|
|
|
|
|
output["update_required"] = cache.get("update") |
|
|
|
|
|
cache.set("update", False) |
|
|
|
|
|
return jsonify(output) |
|
|
elif request.method == "POST": |
|
|
elif request.method == "POST": |
|
|
|
|
|
cache.set("update", True) |
|
|
graphstate = abp.GraphState() |
|
|
graphstate = abp.GraphState() |
|
|
graphstate.from_json(json.loads(request.data)) |
|
|
graphstate.from_json(json.loads(request.data)) |
|
|
cache.set("state", graphstate) |
|
|
cache.set("state", graphstate) |
|
|
@@ -29,32 +34,42 @@ def add_node(node): |
|
|
""" Add a node to the graph """ |
|
|
""" Add a node to the graph """ |
|
|
graphstate = cache.get("state") |
|
|
graphstate = cache.get("state") |
|
|
graphstate.add_node(node) |
|
|
graphstate.add_node(node) |
|
|
|
|
|
graphstate.layout() |
|
|
|
|
|
cache.set("update", True) |
|
|
cache.set("state", graphstate) |
|
|
cache.set("state", graphstate) |
|
|
return jsonify({"add_node": "okay"}) |
|
|
return jsonify({"add_node": "okay"}) |
|
|
|
|
|
|
|
|
@app.route("/act_local_rotation/<int:node>/<int:operation>") |
|
|
@app.route("/act_local_rotation/<int:node>/<int:operation>") |
|
|
def act_local_rotation(node): |
|
|
|
|
|
|
|
|
def act_local_rotation(node, operation): |
|
|
""" Add a node to the graph """ |
|
|
""" Add a node to the graph """ |
|
|
# TODO: try to lookup the operation first |
|
|
# TODO: try to lookup the operation first |
|
|
|
|
|
graphstate = cache.get("state") |
|
|
graphstate.act_local_rotation(node, operation) |
|
|
graphstate.act_local_rotation(node, operation) |
|
|
|
|
|
cache.set("update", True) |
|
|
|
|
|
cache.set("state", graphstate) |
|
|
return jsonify({"act_local_rotation": "okay"}) |
|
|
return jsonify({"act_local_rotation": "okay"}) |
|
|
|
|
|
|
|
|
@app.route("/act_cz/<int:a>/<int:b>") |
|
|
@app.route("/act_cz/<int:a>/<int:b>") |
|
|
def act_cz(a, b): |
|
|
def act_cz(a, b): |
|
|
""" Add a node to the graph """ |
|
|
""" Add a node to the graph """ |
|
|
|
|
|
graphstate = cache.get("state") |
|
|
graphstate.act_cz(a, b) |
|
|
graphstate.act_cz(a, b) |
|
|
|
|
|
graphstate.layout() |
|
|
|
|
|
cache.set("update", True) |
|
|
|
|
|
cache.set("state", graphstate) |
|
|
return jsonify({"act_cz": "okay"}) |
|
|
return jsonify({"act_cz": "okay"}) |
|
|
|
|
|
|
|
|
@app.route("/clear") |
|
|
@app.route("/clear") |
|
|
def clear(): |
|
|
def clear(): |
|
|
""" Clear the current state """ |
|
|
""" Clear the current state """ |
|
|
graphstate = abp.GraphState() |
|
|
graphstate = abp.GraphState() |
|
|
|
|
|
cache.set("update", True) |
|
|
cache.set("state", graphstate) |
|
|
cache.set("state", graphstate) |
|
|
return jsonify({"clear": "okay"}) |
|
|
return jsonify({"clear": "okay"}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
app.debug = False |
|
|
|
|
|
|
|
|
app.debug = True |
|
|
app.run(host="0.0.0.0") |
|
|
app.run(host="0.0.0.0") |
|
|
|
|
|
|
|
|
|
|
|
|