Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,24 +191,6 @@ async function init(options = {}) {
console.log("[INFO] Node-Secure is ready!");
}

function getNodeLevel(node) {
const rootNode = secureDataSet.linker.get(0);
if (node.id === rootNode.id) {
return 0;
}

let level = 1;
let currentNode = node;
while (currentNode.usedBy[rootNode.name] === undefined) {
currentNode = secureDataSet.linker.get(
[...secureDataSet.linker].find(([_, { name }]) => Object.keys(currentNode.usedBy)[0] === name)[0]
);
level++;
}

return level;
}

async function updateShowInfoMenu(params) {
if (params.nodes.length === 0) {
window.networkNav.currentNodeParams = null;
Expand All @@ -226,7 +208,7 @@ async function updateShowInfoMenu(params) {
const selectedNode = secureDataSet.linker.get(
Number(currentNode)
);
const selectedNodeLevel = getNodeLevel(selectedNode);
const selectedNodeLevel = nsn.getNodeLevel(selectedNode);

window.networkNav.setLevel(selectedNodeLevel);
if (window.networkNav.dependenciesMapByLevel.get(selectedNodeLevel) === undefined) {
Expand Down
18 changes: 18 additions & 0 deletions workspaces/vis-network/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,24 @@ export default class NodeSecureNetwork {
this.network.stopSimulation();
}

getNodeLevel(node) {
const rootNode = this.secureDataSet.linker.get(0);
if (node.id === rootNode.id) {
return 0;
}

let level = 1;
let currentNode = node;
while (currentNode.usedBy[rootNode.name] === undefined) {
currentNode = this.secureDataSet.linker.get(
[...this.secureDataSet.linker].find(([_, { name }]) => Object.keys(currentNode.usedBy)[0] === name)[0]
);
level++;
}

return level;
}

/**
* Search for neighbours nodes of a given node
*
Expand Down