web app added node position updates
This commit is contained in:
parent
0ee3fca97c
commit
10486dfe1a
3 changed files with 64 additions and 0 deletions
|
@ -155,6 +155,7 @@ class CoreNetwork {
|
|||
};
|
||||
this.network = new vis.Network(this.container, this.networkData, this.networkOptions);
|
||||
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.nodesEnabled = false;
|
||||
}
|
||||
|
@ -173,6 +174,25 @@ class CoreNetwork {
|
|||
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() {
|
||||
this.nodeId = 0;
|
||||
this.nodes.clear();
|
||||
|
|
|
@ -69,6 +69,14 @@ class CoreRest {
|
|||
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) {
|
||||
return await postJson(`/sessions/${this.currentSession}/links`, link);
|
||||
}
|
||||
|
@ -102,4 +110,9 @@ class CoreRest {
|
|||
|
||||
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