Sorting of "folders" before leafs
This commit is contained in:
parent
2f27aeffb3
commit
cc69f7194e
3 changed files with 42 additions and 8 deletions
|
|
@ -176,14 +176,32 @@ export class NodeStore {
|
|||
const nodeStore = trx.objectStore('nodes')
|
||||
const index = nodeStore.index('byParent')
|
||||
const req = index.getAll(storeParent)
|
||||
|
||||
const hasChildrenPromises = []
|
||||
req.onsuccess = (event) => {
|
||||
const nodes = []
|
||||
for (const i in event.target.result) {
|
||||
const nodeData = event.target.result[i]
|
||||
const node = this.node(nodeData.UUID, nodeData, newLevel)
|
||||
|
||||
// Look for the key of any children, a hopefully fast way
|
||||
// to tell if any children exists at all and this node is a
|
||||
// "folder". Needed quite early on for sorting.
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const countReq = index.getKey(nodeData.UUID)
|
||||
countReq.onsuccess = event => {
|
||||
node.setHasChildren(event.target.result !== undefined)
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
hasChildrenPromises.push(promise)
|
||||
nodes.push(node)
|
||||
}
|
||||
resolve(nodes)
|
||||
|
||||
Promise.all(hasChildrenPromises)
|
||||
.then(() => {
|
||||
resolve(nodes)
|
||||
})
|
||||
}
|
||||
req.onerror = (event) => reject(event.target.error)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue