Added lorem ipsum generation and Javascript search

This commit is contained in:
Magnus Åhall 2025-04-21 17:56:25 +02:00
parent 05be8548fe
commit 8d6ec8b4ff
8 changed files with 87 additions and 1 deletions

View file

@ -44,6 +44,7 @@ html {
display: flex;
justify-content: center;
margin-bottom: 32px;
gap: 8px;
}
#tree .node {
display: grid;

View file

@ -242,6 +242,35 @@ export class NodeStore {
req.onerror = (event) => reject(event.target.error)
})
}//}}}
async search(searchfor, parent) {//{{{
return new Promise((resolve, reject) => {
const trx = this.db.transaction('nodes', 'readonly')
const nodeStore = trx.objectStore('nodes')
const index = nodeStore.index('byParent')
const req = index.getAll(parent)
req.onsuccess = async (event) => {
let nodes = []
for (const i in event.target.result) {
const nodeData = event.target.result[i]
const children = await this.search(searchfor, nodeData.UUID)
// Data is searched for the provided text.
// TODO: implement an array of words to search?
if (nodeData.Content.toLowerCase().includes(searchfor))
nodes.push({
uuid: nodeData.UUID,
name: nodeData.Name,
ancestry: await this.getNodeAncestry(nodeData, []),
})
nodes = nodes.concat(children)
}
resolve(nodes)
return
}
req.onerror = (event) => reject(event.target.error)
})
}//}}}
async add(records) {//{{{
return new Promise((resolve, reject) => {

View file

@ -99,6 +99,7 @@ class Tree extends Component {
<div id="tree" ref=${this.treeDiv} tabindex="0">
<div id="logo" onclick=${() => _notes2.current.goToNode(ROOT_NODE)}><img src="/images/${_VERSION}/logo.svg" /></div>
<div class="icons">
<img src="/images/${_VERSION}/icon_search.svg" style="height: 22px" onclick=${()=>_sync.run()} />
<img src="/images/${_VERSION}/icon_refresh.svg" onclick=${()=>_sync.run()} />
</div>
${renderedTreeTrunk}

View file

@ -76,6 +76,7 @@ html {
display: flex;
justify-content: center;
margin-bottom: 32px;
gap: 8px;
}
.node {