tree work

This commit is contained in:
Magnus Åhall 2025-07-07 15:45:32 +02:00
parent 4e834766ac
commit c7b0823900

View file

@ -277,15 +277,41 @@ export class App {
body: JSON.stringify(req),
})
.then(data => data.json())
.then(json => {
.then(async json => {
if (!json.OK) {
showError(json.Error)
return
}
const parentTreenode = this.tree.treeNodes.get(newParentID)
const node = await this.tree.fetchNodes(newParentID)
parentTreenode.node = node
parentTreenode.updateExpandImages()
const newParentElement = this.tree.treeNodes.get(newParentID).children
for (const n of nodes)
newParentElement.append(this.tree.treeNodes.get(n.ID).element)
for (const n of nodes) {
const movedTreeNode = this.tree.treeNodes.get(n.ID)
newParentElement.append(movedTreeNode.element)
// Moved nodes' parents are updated to remove the moved nodes from their children.
const treenode = this.tree.treeNodes.get(n.ParentID)
const node = await this.tree.fetchNodes(n.ParentID)
treenode.node = node
treenode.updateExpandImages()
// Children are resorted to get the moved node into correct order.
/*
this.tree.sortChildren(parentTreenode.node.Children)
for (const c of parentTreenode.node.Children) {
const treenode = this.tree.treeNodes.get(c.ID)
if (treenode)
parentTreenode.children.append(treenode.element)
}
*/
// The moved node is updated with its new parent ID for future moves.
movedTreeNode.node.ParentID = newParentID
}
})
.catch(err => showError(err))