added some checks to enable/disable node creation based on start/stop state
This commit is contained in:
parent
915d65cc8e
commit
f588757159
2 changed files with 53 additions and 36 deletions
|
@ -148,6 +148,12 @@ 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.edges.on('add', this.addEdge.bind(this));
|
this.edges.on('add', this.addEdge.bind(this));
|
||||||
|
this.nodesEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
enableNodeCreation(enabled) {
|
||||||
|
console.log('node created enabled: ', enabled);
|
||||||
|
this.nodesEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
getCoreNodes() {
|
getCoreNodes() {
|
||||||
|
@ -172,11 +178,14 @@ class CoreNetwork {
|
||||||
|
|
||||||
joinedSessions(nodes) {
|
joinedSessions(nodes) {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
const nodeIds = [0];
|
||||||
|
|
||||||
for (let node of nodes) {
|
for (let node of nodes) {
|
||||||
if (node.type === CoreNodeHelper.ptpNode) {
|
if (node.type === CoreNodeHelper.ptpNode) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodeIds.push(node.id);
|
||||||
this.addCoreNode(node);
|
this.addCoreNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,9 +207,7 @@ class CoreNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nodes.length) {
|
if (nodes.length) {
|
||||||
this.nodeId = Math.max.apply(Math, nodes.map(function (node) {
|
this.nodeId = Math.max.apply(Math, nodeIds) || 0;
|
||||||
return node.id
|
|
||||||
}));
|
|
||||||
} else {
|
} else {
|
||||||
this.nodeId = 0;
|
this.nodeId = 0;
|
||||||
}
|
}
|
||||||
|
@ -243,14 +250,12 @@ class CoreNetwork {
|
||||||
};
|
};
|
||||||
|
|
||||||
const edge = {
|
const edge = {
|
||||||
|
id: linkId,
|
||||||
from: fromNode.id,
|
from: fromNode.id,
|
||||||
to: toNode.id,
|
to: toNode.id,
|
||||||
recreated: true,
|
recreated: true,
|
||||||
label: 'from: name\nto: name',
|
label: 'from: name\nto: name',
|
||||||
title: 'this is a title',
|
title: 'from: name\nto: name'
|
||||||
font: {
|
|
||||||
//background: '#fff'
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
this.edges.add(edge);
|
this.edges.add(edge);
|
||||||
}
|
}
|
||||||
|
@ -272,17 +277,24 @@ class CoreNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
addNode(properties) {
|
addNode(properties) {
|
||||||
console.log('add node event: ', properties);
|
if (!this.nodesEnabled) {
|
||||||
if (properties.nodes.length === 0) {
|
console.log('node creation disabled');
|
||||||
const {x, y} = properties.pointer.canvas;
|
return;
|
||||||
const nodeId = this.nextNodeId();
|
|
||||||
const nodeDisplay = CoreNodeHelper.getDisplay(this.nodeType);
|
|
||||||
const name = `${nodeDisplay.name}${nodeId}`;
|
|
||||||
const coreNode = new CoreNode(nodeId, this.nodeType, name, x, y);
|
|
||||||
coreNode.model = this.nodeModel;
|
|
||||||
this.nodes.add(coreNode.getNetworkNode());
|
|
||||||
console.log('added node: ', coreNode.getNetworkNode());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('add node event: ', properties);
|
||||||
|
if (properties.nodes.length !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const {x, y} = properties.pointer.canvas;
|
||||||
|
const nodeId = this.nextNodeId();
|
||||||
|
const nodeDisplay = CoreNodeHelper.getDisplay(this.nodeType);
|
||||||
|
const name = `${nodeDisplay.name}${nodeId}`;
|
||||||
|
const coreNode = new CoreNode(nodeId, this.nodeType, name, x, y);
|
||||||
|
coreNode.model = this.nodeModel;
|
||||||
|
this.nodes.add(coreNode.getNetworkNode());
|
||||||
|
console.log('added node: ', coreNode.getNetworkNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
addEdge(_, properties) {
|
addEdge(_, properties) {
|
||||||
|
@ -354,8 +366,9 @@ class CoreNetwork {
|
||||||
interface_two: interfaceTwo
|
interface_two: interfaceTwo
|
||||||
};
|
};
|
||||||
|
|
||||||
edge.label = 'this is a label';
|
edge.id = linkId;
|
||||||
edge.title = 'this is a title';
|
edge.label = 'from: name\nto: name';
|
||||||
|
edge.title = 'from: name\nto: name';
|
||||||
this.edges.update(edge);
|
this.edges.update(edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,28 +115,15 @@
|
||||||
const $sessionsTable = $('#sessions-table');
|
const $sessionsTable = $('#sessions-table');
|
||||||
const $runButton = $('#run-button');
|
const $runButton = $('#run-button');
|
||||||
|
|
||||||
function setRunButton(start) {
|
|
||||||
const $runButton = $('#run-button');
|
|
||||||
$runButton.removeClass('btn-danger btn-success');
|
|
||||||
if (start) {
|
|
||||||
$runButton.text('Start');
|
|
||||||
$runButton.addClass('btn-success');
|
|
||||||
} else {
|
|
||||||
$runButton.text('Stop');
|
|
||||||
$runButton.addClass('btn-danger');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// initial core setup
|
// initial core setup
|
||||||
const coreRest = new CoreRest();
|
const coreRest = new CoreRest();
|
||||||
|
const coreNetwork = new CoreNetwork('core-network', coreRest);
|
||||||
coreRest.retrieveSession()
|
coreRest.retrieveSession()
|
||||||
.then(function (session) {
|
.then(function (session) {
|
||||||
console.log('get session: ', session);
|
console.log('get session: ', session);
|
||||||
$sessionId.text(`Session: ${session.id}`);
|
$sessionId.text(`Session: ${session.id}`);
|
||||||
if (session.state === SessionStates.runtime) {
|
const isStartEnabled = session.state !== SessionStates.runtime;
|
||||||
setRunButton(false);
|
setRunButton(isStartEnabled);
|
||||||
}
|
|
||||||
|
|
||||||
return coreRest.getSession();
|
return coreRest.getSession();
|
||||||
})
|
})
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
|
@ -148,7 +135,24 @@
|
||||||
console.log('get session error: ', err);
|
console.log('get session error: ', err);
|
||||||
});
|
});
|
||||||
|
|
||||||
const coreNetwork = new CoreNetwork('core-network', coreRest);
|
function setRunButton(start) {
|
||||||
|
console.log('set run button: ', start);
|
||||||
|
const $runButton = $('#run-button');
|
||||||
|
$runButton.removeClass('btn-danger btn-success');
|
||||||
|
if (start) {
|
||||||
|
$runButton.text('Start');
|
||||||
|
$runButton.addClass('btn-success');
|
||||||
|
$linkButton.removeAttr('disabled');
|
||||||
|
coreNetwork.enableNodeCreation(true);
|
||||||
|
} else {
|
||||||
|
$runButton.text('Stop');
|
||||||
|
$runButton.addClass('btn-danger');
|
||||||
|
$linkButton.removeClass('active');
|
||||||
|
$linkButton.attr('disabled', 'disabled');
|
||||||
|
coreNetwork.enableNodeCreation(false);
|
||||||
|
coreNetwork.linkMode(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// page interactions
|
// page interactions
|
||||||
$linkButton.click(function () {
|
$linkButton.click(function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue