From 788712d12ca2264b84cd95b311a8892de08d4df9 Mon Sep 17 00:00:00 2001 From: "Blake J. Harnden" Date: Tue, 15 May 2018 10:22:26 -0700 Subject: [PATCH] web app, added logic to hide info panel on remove events for edges/nodes --- webapp/static/corenetwork.js | 2 ++ webapp/static/coreui.js | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/webapp/static/corenetwork.js b/webapp/static/corenetwork.js index c11030ac..c153da74 100644 --- a/webapp/static/corenetwork.js +++ b/webapp/static/corenetwork.js @@ -316,6 +316,8 @@ class CoreNetwork { this.nodeId = 0; } + this.network.fit(); + return { id: sessionId, state: session.state diff --git a/webapp/static/coreui.js b/webapp/static/coreui.js index e8381cb1..128bc4fb 100644 --- a/webapp/static/coreui.js +++ b/webapp/static/coreui.js @@ -379,6 +379,30 @@ class InfoPanel { this.$infoCard = $('#info-card'); this.$infoCardTable = $('#info-card-table'); this.$infoCardHeader = $('#info-card-header'); + this.coreNetwork.nodes.on('remove', this.onNodeDelete.bind(this)); + this.coreNetwork.edges.on('remove', this.onEdgeDelete.bind(this)); + } + + onNodeDelete(_, properties) { + if (properties.items.length !== 1) { + return; + } + + const nodeId = properties.items[0]; + if (nodeId === this.$infoCard.data('node')) { + this.hide(); + } + } + + onEdgeDelete(_, properties) { + if (properties.items.length !== 1) { + return; + } + + const edgeId = properties.items[0]; + if (edgeId === this.$infoCard.data('edge')) { + this.hide(); + } } addInfoTable(name, value) { @@ -410,6 +434,7 @@ class InfoPanel { showNode(nodeId) { const node = coreNetwork.getCoreNode(nodeId); + this.$infoCard.data('node', nodeId); this.$infoCardHeader.text(node.name); this.$infoCardTable.find('tbody tr').remove(); this.addInfoTable('Model', node.model); @@ -429,6 +454,7 @@ class InfoPanel { const nodeOne = coreNetwork.getCoreNode(link.nodeOne); const nodeTwo = coreNetwork.getCoreNode(link.nodeTwo); console.log('clicked edge: ', link); + this.$infoCard.data('edge', edgeId); this.$infoCard.addClass('visible'); this.$infoCardHeader.text('Edge'); this.$infoCardTable.find('tbody tr').remove();