Prep work for flat tree

This commit is contained in:
Jokob-sk
2023-01-25 23:50:02 +11:00
parent 2d92e93b7b
commit 8624851cf5
2 changed files with 68 additions and 4 deletions

View File

@@ -504,6 +504,45 @@
var treeLoadedAlready = false;
var hiddenMacs = [];
// ---------------------------------------------------------------------------
function formatFlatDevicesList()
{
devList = getDevicesList()
result = []
for(i=0;i<devList.length;i++)
{
node = devList[i]
if(!hiddenMacs.includes(node.parentMac))
{
result.push(
{
name: node.name,
path: '',
mac: node.mac,
id: node.mac,
parentMac: node.parentMac,
icon: node.icon,
type: node.type,
status: node.status,
hasChildren: true,
hiddenChildren: true,
qty: 5,
// children: children
})
}
}
console.log(result)
return result;
}
// ---------------------------------------------------------------------------
function getChildren(node, list, path)
{
var children = [];
@@ -529,6 +568,7 @@
name: node.name,
path: path,
mac: node.mac,
id: node.mac,
parentMac: node.parentMac,
icon: node.icon,
type: node.type,
@@ -582,6 +622,27 @@
// re-attach any onclick events
attachTreeEvents();
}
// ---------------------------------------------------------------------------
function toggleFlatSubTree(parentMac, treePath)
{
// treePath = treePath.split('|')
if(!hiddenMacs.includes(parentMac))
{
hiddenMacs.push(parentMac)
}
else
{
removeItemFromArray(hiddenMacs, parentMac)
}
list = formatFlatDevicesList();
myTree.refresh(list);
// re-attach any onclick events
attachTreeEvents();
}
// ---------------------------------------------------------------------------
function attachTreeEvents()
@@ -646,20 +707,23 @@
// console.log(this)
},
mainAxisNodeSpacing: 'auto',
// mainAxisNodeSpacing: 3,
secondaryAxisNodeSpacing: 0.3,
nodeHeight: '25',
marginTop: '5',
hasZoom: false,
hasPan: false,
// marginLeft: '15',
idKey: "name",
idKey: "id",
hasFlatData: false,
// hasFlatData: true,
linkWidth: (nodeData) => 3,
relationnalField: "children",
// relationnalField: "parentMac",
});
myTree.refresh(myHierarchy);
// myTree.refresh(formatFlatDevicesList()); //hasFlatData
}
// ---------------------------------------------------------------------------