web app added initial basic linking to wlan nodes

This commit is contained in:
Blake J. Harnden 2018-05-15 10:11:55 -07:00
parent 014dea2dd0
commit c4d8dcbdf5
2 changed files with 54 additions and 5 deletions

View file

@ -416,22 +416,67 @@ class CoreNetwork {
console.log('added node: ', coreNode.getNetworkNode()); console.log('added node: ', coreNode.getNetworkNode());
} }
linkAllRouters(nodeId) {
const toNode = this.getCoreNode(nodeId);
const routerNodes = this.nodes.get({filter: node => {
return node.coreNode.model === 'mdr';
}});
console.log('router nodes: ', routerNodes);
for (let fromNode of routerNodes) {
if (this.edgeExists(fromNode.id, toNode.id)) {
console.log('ignoring router link that already exists');
continue;
}
const edge = {
from: fromNode.id,
to: toNode.id
};
this.addEdgeLink(edge, fromNode.coreNode, toNode)
.catch(err => console.log('add edge link error: ', err));
}
}
edgeExists(fromId, toId) {
console.log('checking if edge exists: ', fromId, toId);
console.log('links: ', this.links);
const idOne = `${fromId}-${toId}`;
const idTwo = `${toId}-${fromId}`;
let exists = idOne in this.links;
exists = exists || idTwo in this.links;
return exists;
}
enableEdgeMode() {
setTimeout(() => this.network.addEdgeMode(), 250);
}
addEdge(_, properties) { addEdge(_, properties) {
const edgeId = properties.items[0]; const edgeId = properties.items[0];
const edge = this.edges.get(edgeId); const edge = this.edges.get(edgeId);
// ignore edges being recreated
if (edge.recreated) { if (edge.recreated) {
console.log('ignoring recreated edge'); console.log('ignoring recreated edge');
return; return;
} }
console.log('added edge: ', edgeId, edge); // ignore cycles
if (edge.from === edge.to) { if (edge.from === edge.to) {
console.log('removing cyclic edge'); console.log('removing cyclic edge');
this.edges.remove(edge.id); this.edges.remove(edge.id);
setTimeout(() => this.network.addEdgeMode(), 250); this.enableEdgeMode();
return; return;
} }
// ignore edges that already exist between nodes
if (this.edgeExists(edge.from, edge.to)) {
console.log('edge already exists');
this.enableEdgeMode();
return false;
}
console.log('added edge: ', edgeId, edge);
const fromNode = this.nodes.get(edge.from).coreNode; const fromNode = this.nodes.get(edge.from).coreNode;
const toNode = this.nodes.get(edge.to).coreNode; const toNode = this.nodes.get(edge.to).coreNode;
@ -443,7 +488,7 @@ class CoreNetwork {
console.log('create link error: ', err); console.log('create link error: ', err);
}); });
setTimeout(() => this.network.addEdgeMode(), 250); this.enableEdgeMode();
} }
async addEdgeLink(edge, fromNode, toNode) { async addEdgeLink(edge, fromNode, toNode) {

View file

@ -216,6 +216,10 @@ class NodeContext {
console.log('error showing services modal: ', err); console.log('error showing services modal: ', err);
}); });
break; break;
case 'linkrf':
console.log('linking all routers');
self.coreNetwork.linkAllRouters(nodeId);
break;
case 'delete': case 'delete':
self.coreNetwork.deleteNode(nodeId); self.coreNetwork.deleteNode(nodeId);
break; break;
@ -428,14 +432,14 @@ class InfoPanel {
this.$infoCard.addClass('visible'); this.$infoCard.addClass('visible');
this.$infoCardHeader.text('Edge'); this.$infoCardHeader.text('Edge');
this.$infoCardTable.find('tbody tr').remove(); this.$infoCardTable.find('tbody tr').remove();
this.addInfoTable(nodeOne.name, null);
const interfaceOne = link.interfaceOne; const interfaceOne = link.interfaceOne;
if (interfaceOne) { if (interfaceOne) {
this.addInfoTable(nodeOne.name, null);
this.addInterfaceInfo(interfaceOne); this.addInterfaceInfo(interfaceOne);
} }
this.addInfoTable(nodeTwo.name, null);
const interfaceTwo = link.interfaceTwo; const interfaceTwo = link.interfaceTwo;
if (interfaceTwo) { if (interfaceTwo) {
this.addInfoTable(nodeTwo.name, null);
this.addInterfaceInfo(interfaceTwo); this.addInterfaceInfo(interfaceTwo);
} }
this.addInfoTable('Bandwidth', edge.link.bandwidth); this.addInfoTable('Bandwidth', edge.link.bandwidth);