web app updates for deleting a node and disabling node context options

This commit is contained in:
Blake J. Harnden 2018-05-14 14:33:17 -07:00
parent 8c31b75c39
commit f004d20b79
5 changed files with 104 additions and 35 deletions

View file

@ -177,10 +177,9 @@ class CoreNetwork {
}
};
this.network = new vis.Network(this.container, this.networkData, this.networkOptions);
this.network.on('doubleClick', this.addNode.bind(this));
this.network.on('doubleClick', this.doubleClick.bind(this));
this.network.on('dragEnd', this.dragEnd.bind(this));
this.edges.on('add', this.addEdge.bind(this));
this.nodesEnabled = false;
}
async initialSession() {
@ -197,6 +196,29 @@ class CoreNetwork {
return session;
}
deleteNode(nodeId) {
// remove node from graph
this.nodes.remove(nodeId);
// remove node links
const edges = this.edges.get();
for (let edge of edges) {
const link = edge.link;
if (edge.from === nodeId) {
this.edges.remove(edge);
const otherNode = this.getCoreNode(edge.to);
delete otherNode.interfaces[link.interfaceTwo.id];
delete this.links[edge.linkId]
} else if (edge.to === nodeId) {
this.edges.remove(edge);
const otherNode = this.getCoreNode(edge.from);
delete otherNode.interfaces[link.interfaceOne.id];
delete this.links[edge.linkId]
}
}
}
getCoreNode(nodeId) {
return this.nodes.get(nodeId).coreNode;
}
@ -223,11 +245,6 @@ class CoreNetwork {
this.links = {};
}
enableNodeCreation(enabled) {
console.log('node created enabled: ', enabled);
this.nodesEnabled = enabled;
}
getCoreNodes() {
const coreNodes = [];
for (let node of this.nodes.get()) {
@ -359,9 +376,19 @@ class CoreNetwork {
return await coreRest.setSessionState(SessionStates.instantiation);
}
addNode(properties) {
if (!this.nodesEnabled) {
console.log('node creation disabled');
async doubleClick(properties) {
const isRunning = await this.coreRest.isRunning();
// check for terminal interaction
if (isRunning && properties.nodes.length === 1) {
const nodeId = properties.nodes[0];
await this.coreRest.nodeTerminal(nodeId);
console.log('launched node terminal: ', nodeId);
return;
}
if (isRunning) {
console.log('node creation disabled, while running');
return;
}