web app update to use a link object, that should help with editing and retaining values

This commit is contained in:
Blake J. Harnden 2018-05-10 08:30:52 -07:00
parent 10486dfe1a
commit 5f6f718e92
2 changed files with 36 additions and 32 deletions

View file

@ -113,12 +113,22 @@ class CoreNode {
} }
} }
function setEdgeData(edge, linkId, fromNode, toNode, interfaceOne, interfaceTwo) { class CoreLink {
edge.core = linkId; constructor(nodeOne, nodeTwo, interfaceOne, interfaceTwo) {
edge.nodeOne = fromNode.name; this.nodeOne = nodeOne;
edge.interfaceOne = interfaceOne; this.nodeTwo = nodeTwo;
edge.nodeTwo = toNode.name; this.interfaceOne = interfaceOne;
edge.interfaceTwo = interfaceTwo; this.interfaceTwo = interfaceTwo;
}
json() {
return {
node_one: this.nodeOne,
node_two: this.nodeTwo,
interface_one: this.interfaceOne,
interface_two: this.interfaceTwo
}
}
} }
class CoreNetwork { class CoreNetwork {
@ -302,19 +312,16 @@ class CoreNetwork {
toNode.interfaces[linkData.interface2_id] = interfaceTwo; toNode.interfaces[linkData.interface2_id] = interfaceTwo;
} }
this.links[linkId] = { const link = new CoreLink(fromNode.id, toNode.id, interfaceOne, interfaceTwo);
node_one: fromNode.id, this.links[linkId] = link;
node_two: toNode.id,
interface_one: interfaceOne,
interface_two: interfaceTwo
};
const edge = { const edge = {
recreated: true, recreated: true,
from: fromNode.id, from: fromNode.id,
to: toNode.id to: toNode.id,
linkId: linkId,
link
}; };
setEdgeData(edge, linkId, fromNode, toNode, interfaceOne, interfaceTwo);
this.edges.add(edge); this.edges.add(edge);
} }
@ -327,7 +334,7 @@ class CoreNetwork {
for (let linkId in this.links) { for (let linkId in this.links) {
const link = this.links[linkId]; const link = this.links[linkId];
const response = await coreRest.createLink(link); const response = await coreRest.createLink(link.json());
console.log('created link: ', response); console.log('created link: ', response);
} }
@ -417,14 +424,10 @@ class CoreNetwork {
toNode.interfaces[interfaceTwoId] = interfaceTwo; toNode.interfaces[interfaceTwoId] = interfaceTwo;
} }
this.links[linkId] = { const link = new CoreLink(fromNode.id, toNode.id, interfaceOne, interfaceTwo);
node_one: fromNode.id, this.links[linkId] = link;
node_two: toNode.id, edge.linkId = linkId;
interface_one: interfaceOne, edge.link = link;
interface_two: interfaceTwo
};
setEdgeData(edge, linkId, fromNode, toNode, interfaceOne, interfaceTwo);
this.edges.update(edge); this.edges.update(edge);
} }

View file

@ -225,12 +225,13 @@
} else if (properties.edges.length === 1) { } else if (properties.edges.length === 1) {
const edgeId = properties.edges[0]; const edgeId = properties.edges[0];
const edge = coreNetwork.edges.get(edgeId); const edge = coreNetwork.edges.get(edgeId);
console.log('clicked edge: ', edge); const link = edge.link;
console.log('clicked edge: ', link);
$infoCard.addClass('visible'); $infoCard.addClass('visible');
$infoCardHeader.text('Edge'); $infoCardHeader.text('Edge');
$infoCardTable.find('tbody tr').remove(); $infoCardTable.find('tbody tr').remove();
addInfoTable(edge.nodeOne, null); addInfoTable(link.nodeOne, null);
const interfaceOne = edge.interfaceOne; const interfaceOne = link.interfaceOne;
if (interfaceOne) { if (interfaceOne) {
if (interfaceOne.ip4) { if (interfaceOne.ip4) {
addInfoTable('IP4', `${interfaceOne.ip4}/${interfaceOne.ip4mask}`); addInfoTable('IP4', `${interfaceOne.ip4}/${interfaceOne.ip4mask}`);
@ -239,8 +240,8 @@
addInfoTable('IP6', `${interfaceOne.ip6}/${interfaceOne.ip6mask}`); addInfoTable('IP6', `${interfaceOne.ip6}/${interfaceOne.ip6mask}`);
} }
} }
addInfoTable(edge.nodeTwo, null); addInfoTable(link.nodeTwo, null);
const interfaceTwo = edge.interfaceTwo; const interfaceTwo = link.interfaceTwo;
if (interfaceTwo) { if (interfaceTwo) {
if (interfaceTwo.ip4) { if (interfaceTwo.ip4) {
addInfoTable('IP4', `${interfaceTwo.ip4}/${interfaceTwo.ip4mask}`); addInfoTable('IP4', `${interfaceTwo.ip4}/${interfaceTwo.ip4mask}`);