|
@@ -1,4 +1,5 @@ |
|
|
from flask import Flask, request, render_template, jsonify |
|
|
from flask import Flask, request, render_template, jsonify |
|
|
|
|
|
import json |
|
|
import abp |
|
|
import abp |
|
|
|
|
|
|
|
|
graphstate = abp.GraphState() |
|
|
graphstate = abp.GraphState() |
|
@@ -8,18 +9,39 @@ app = Flask(__name__) |
|
|
def index(): |
|
|
def index(): |
|
|
return render_template("index.html") |
|
|
return render_template("index.html") |
|
|
|
|
|
|
|
|
@app.route("/state") |
|
|
|
|
|
|
|
|
@app.route("/state", methods = ["GET", "POST"]) |
|
|
def state(): |
|
|
def state(): |
|
|
if request.method == "GET": |
|
|
if request.method == "GET": |
|
|
return jsonify(graphstate.to_json()) |
|
|
return jsonify(graphstate.to_json()) |
|
|
elif request.method == "POST": |
|
|
elif request.method == "POST": |
|
|
graphstate.from_json(request.data) |
|
|
|
|
|
|
|
|
graphstate.from_json(json.loads(request.data)) |
|
|
return jsonify(graphstate.to_json()) |
|
|
return jsonify(graphstate.to_json()) |
|
|
|
|
|
|
|
|
@app.route("/state") |
|
|
|
|
|
def state(): |
|
|
|
|
|
|
|
|
@app.route("/add/<int:node>") |
|
|
|
|
|
def add(node): |
|
|
|
|
|
""" Add a node to the graph """ |
|
|
|
|
|
graphstate.add_node(node) |
|
|
|
|
|
return jsonify(graphstate.to_json()) |
|
|
|
|
|
|
|
|
|
|
|
@app.route("/rotate/<int:node>/<int:operation>") |
|
|
|
|
|
def rotate(node): |
|
|
|
|
|
""" Add a node to the graph """ |
|
|
|
|
|
graphstate.act_local_rotation(node, operation) |
|
|
return jsonify(graphstate.to_json()) |
|
|
return jsonify(graphstate.to_json()) |
|
|
|
|
|
|
|
|
|
|
|
@app.route("/cz/<int:a>/<int:b>") |
|
|
|
|
|
def cz(a, b): |
|
|
|
|
|
""" Add a node to the graph """ |
|
|
|
|
|
graphstate.act_cz(a, b) |
|
|
|
|
|
return jsonify(graphstate.to_json()) |
|
|
|
|
|
|
|
|
|
|
|
@app.route("/clear") |
|
|
|
|
|
def clear(): |
|
|
|
|
|
""" Clear the current state """ |
|
|
|
|
|
graphstate = abp.GraphState() |
|
|
|
|
|
return jsonify({"clear": "ok"}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
if __name__ == "__main__": |
|
|
app.debug = True |
|
|
app.debug = True |
|
|
app.run(host="0.0.0.0") |
|
|
app.run(host="0.0.0.0") |
|
|