Removed old code, fixed root node showing up in tree
This commit is contained in:
parent
41952df764
commit
147dc12e99
@ -94,6 +94,7 @@ export class NodeStore {
|
|||||||
Name: 'Notes2',
|
Name: 'Notes2',
|
||||||
Content: 'Hello, World!',
|
Content: 'Hello, World!',
|
||||||
Updated: new Date().toISOString(),
|
Updated: new Date().toISOString(),
|
||||||
|
ParentUUID: '',
|
||||||
})
|
})
|
||||||
putRequest.onsuccess = (event) => {
|
putRequest.onsuccess = (event) => {
|
||||||
resolve(event.target.result)
|
resolve(event.target.result)
|
||||||
@ -353,7 +354,6 @@ export class NodeStore {
|
|||||||
})
|
})
|
||||||
}//}}}
|
}//}}}
|
||||||
async getNodeAncestry(node, accumulated) {//{{{
|
async getNodeAncestry(node, accumulated) {//{{{
|
||||||
console.log('blaha')
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const nodeParentIndex = this.db
|
const nodeParentIndex = this.db
|
||||||
.transaction('nodes', 'readonly')
|
.transaction('nodes', 'readonly')
|
||||||
|
@ -68,7 +68,6 @@ export class Notes2 extends Component {
|
|||||||
class Tree extends Component {
|
class Tree extends Component {
|
||||||
constructor(props) {//{{{
|
constructor(props) {//{{{
|
||||||
super(props)
|
super(props)
|
||||||
this.treeNodes = {}
|
|
||||||
this.treeNodeComponents = {}
|
this.treeNodeComponents = {}
|
||||||
this.treeTrunk = []
|
this.treeTrunk = []
|
||||||
this.selectedNode = null
|
this.selectedNode = null
|
||||||
@ -94,29 +93,16 @@ class Tree extends Component {
|
|||||||
nodeStore.getTreeNodes('', 0)
|
nodeStore.getTreeNodes('', 0)
|
||||||
.then(async res => {
|
.then(async res => {
|
||||||
res.sort(Node.sort)
|
res.sort(Node.sort)
|
||||||
|
|
||||||
this.treeNodes = {}
|
|
||||||
this.treeNodeComponents = {}
|
this.treeNodeComponents = {}
|
||||||
this.treeTrunk = []
|
this.treeTrunk = []
|
||||||
|
|
||||||
// A tree of nodes is built. This requires the list of nodes
|
|
||||||
// returned from the server to be sorted in such a way that
|
|
||||||
// a parent node always appears before a child node.
|
|
||||||
// The server uses a recursive SQL query delivering this.
|
|
||||||
for (const node of res) {
|
for (const node of res) {
|
||||||
this.treeNodes[node.UUID] = node
|
// The root node isn't supposed to be shown in the tree.
|
||||||
|
if (node.UUID === '00000000-0000-0000-0000-000000000000')
|
||||||
|
continue
|
||||||
if (node.ParentUUID === '')
|
if (node.ParentUUID === '')
|
||||||
this.treeTrunk.push(node)
|
this.treeTrunk.push(node)
|
||||||
else if (this.treeNodes[node.ParentUUD] !== undefined)
|
|
||||||
this.treeNodes[node.ParentUUID].Children.push(node)
|
|
||||||
}
|
}
|
||||||
// When starting with an explicit node value, expanding all nodes
|
|
||||||
// on its path gives the user a sense of location. Not necessarily working
|
|
||||||
// as the start node isn't guaranteed to have returned data yet.
|
|
||||||
// XXX this.crumbsUpdateNodes()
|
|
||||||
this.forceUpdate()
|
this.forceUpdate()
|
||||||
|
|
||||||
if (callback)
|
if (callback)
|
||||||
callback()
|
callback()
|
||||||
|
|
||||||
@ -140,25 +126,6 @@ class Tree extends Component {
|
|||||||
isSelected(node) {//{{{
|
isSelected(node) {//{{{
|
||||||
return this.selectedNode?.UUID === node.UUID
|
return this.selectedNode?.UUID === node.UUID
|
||||||
}//}}}
|
}//}}}
|
||||||
crumbsUpdateNodes(node) {//{{{
|
|
||||||
console.log('crumbs', this.props.app.startNode.Crumbs)
|
|
||||||
for (const crumb in this.props.app.startNode.Crumbs) {
|
|
||||||
// Start node is loaded before the tree.
|
|
||||||
const node = this.treeNodes[crumb.ID]
|
|
||||||
if (node)
|
|
||||||
node._expanded = true
|
|
||||||
|
|
||||||
// Tree is done before the start node.
|
|
||||||
const component = this.treeNodeComponents[crumb.ID]
|
|
||||||
if (component?.component.current)
|
|
||||||
component.current.expanded.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Will be undefined when called from tree initialization
|
|
||||||
// (as tree nodes aren't rendered yet)
|
|
||||||
if (node !== undefined)
|
|
||||||
this.setSelected(node)
|
|
||||||
}//}}}
|
|
||||||
async expandToTrunk(node) {//{{{
|
async expandToTrunk(node) {//{{{
|
||||||
// Get all ancestors from a certain node up to the highest grandparent.
|
// Get all ancestors from a certain node up to the highest grandparent.
|
||||||
const ancestry = await nodeStore.getNodeAncestry(node, [])
|
const ancestry = await nodeStore.getNodeAncestry(node, [])
|
||||||
@ -167,6 +134,10 @@ class Tree extends Component {
|
|||||||
this.setNodeExpanded(ancestry[i].UUID, true)
|
this.setNodeExpanded(ancestry[i].UUID, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Already a top node, no need to expand anything.
|
||||||
|
if (ancestry.length === 0)
|
||||||
|
return
|
||||||
|
|
||||||
// Start the chain of by expanding the top node.
|
// Start the chain of by expanding the top node.
|
||||||
this.setNodeExpanded(ancestry[ancestry.length-1].UUID, true)
|
this.setNodeExpanded(ancestry[ancestry.length-1].UUID, true)
|
||||||
}//}}}
|
}//}}}
|
||||||
|
Loading…
Reference in New Issue
Block a user