web app added node position updates
This commit is contained in:
parent
0ee3fca97c
commit
10486dfe1a
3 changed files with 64 additions and 0 deletions
|
@ -182,6 +182,37 @@ def create_node(session_id):
|
||||||
), 201
|
), 201
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/sessions/<int:session_id>/nodes/<node_id>", methods=["PUT"])
|
||||||
|
@synchronized
|
||||||
|
def edit_node(session_id, node_id):
|
||||||
|
session = coreemu.sessions.get(session_id)
|
||||||
|
if not session:
|
||||||
|
return jsonify(error="session does not exist"), 404
|
||||||
|
|
||||||
|
if node_id.isdigit():
|
||||||
|
node_id = int(node_id)
|
||||||
|
node = session.objects.get(node_id)
|
||||||
|
if not node:
|
||||||
|
return jsonify(error="node does not exist"), 404
|
||||||
|
|
||||||
|
data = request.get_json() or {}
|
||||||
|
|
||||||
|
node_options = NodeOptions()
|
||||||
|
x = data.get("x")
|
||||||
|
y = data.get("y")
|
||||||
|
node_options.set_position(x, y)
|
||||||
|
lat = data.get("lat")
|
||||||
|
lon = data.get("lon")
|
||||||
|
alt = data.get("alt")
|
||||||
|
node_options.set_location(lat, lon, alt)
|
||||||
|
|
||||||
|
result = session.update_node(node_id, node_options)
|
||||||
|
if result:
|
||||||
|
return jsonify()
|
||||||
|
else:
|
||||||
|
return jsonify(error="error during node edit"), 404
|
||||||
|
|
||||||
|
|
||||||
@app.route("/sessions/<int:session_id>/nodes/<node_id>")
|
@app.route("/sessions/<int:session_id>/nodes/<node_id>")
|
||||||
def get_node(session_id, node_id):
|
def get_node(session_id, node_id):
|
||||||
session = coreemu.sessions.get(session_id)
|
session = coreemu.sessions.get(session_id)
|
||||||
|
|
|
@ -155,6 +155,7 @@ class CoreNetwork {
|
||||||
};
|
};
|
||||||
this.network = new vis.Network(this.container, this.networkData, this.networkOptions);
|
this.network = new vis.Network(this.container, this.networkData, this.networkOptions);
|
||||||
this.network.on('doubleClick', this.addNode.bind(this));
|
this.network.on('doubleClick', this.addNode.bind(this));
|
||||||
|
this.network.on('dragEnd', this.dragEnd.bind(this));
|
||||||
this.edges.on('add', this.addEdge.bind(this));
|
this.edges.on('add', this.addEdge.bind(this));
|
||||||
this.nodesEnabled = false;
|
this.nodesEnabled = false;
|
||||||
}
|
}
|
||||||
|
@ -173,6 +174,25 @@ class CoreNetwork {
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCoreNode(nodeId) {
|
||||||
|
return this.nodes.get(nodeId).coreNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
async dragEnd(properties) {
|
||||||
|
console.log('drag end properties: ', properties);
|
||||||
|
if (properties.nodes.length == 1) {
|
||||||
|
const nodeId = properties.nodes[0];
|
||||||
|
const networkNode = this.nodes.get(nodeId);
|
||||||
|
const coreNode = networkNode.coreNode;
|
||||||
|
coreNode.x = properties.pointer.canvas.x;
|
||||||
|
coreNode.y = properties.pointer.canvas.y;
|
||||||
|
if (await this.coreRest.isRunning()) {
|
||||||
|
console.log('updated core node location: ', coreNode.x, coreNode.y);
|
||||||
|
await this.coreRest.editNode(coreNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.nodeId = 0;
|
this.nodeId = 0;
|
||||||
this.nodes.clear();
|
this.nodes.clear();
|
||||||
|
|
|
@ -69,6 +69,14 @@ class CoreRest {
|
||||||
return await postJson(`/sessions/${this.currentSession}/nodes`, node);
|
return await postJson(`/sessions/${this.currentSession}/nodes`, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async editNode(node) {
|
||||||
|
return await putJson(`/sessions/${this.currentSession}/nodes/${node.id}`, {
|
||||||
|
id: node.id,
|
||||||
|
x: node.x,
|
||||||
|
y: node.y
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async createLink(link) {
|
async createLink(link) {
|
||||||
return await postJson(`/sessions/${this.currentSession}/links`, link);
|
return await postJson(`/sessions/${this.currentSession}/links`, link);
|
||||||
}
|
}
|
||||||
|
@ -102,4 +110,9 @@ class CoreRest {
|
||||||
|
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async isRunning() {
|
||||||
|
const session = await this.getSession();
|
||||||
|
return session.state === SessionStates.runtime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue