wip
This commit is contained in:
parent
9a164b984a
commit
5c2842c995
212
design.drawio
Normal file
212
design.drawio
Normal file
@ -0,0 +1,212 @@
|
||||
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36" version="24.9.3">
|
||||
<diagram name="Page-1" id="G2-a1oUG1H-bwT7ce2_Y">
|
||||
<mxGraphModel dx="974" dy="653" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1169" pageHeight="827" math="0" shadow="0">
|
||||
<root>
|
||||
<mxCell id="0" />
|
||||
<mxCell id="1" style="locked=1;" parent="0" />
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-26" value="<b>Webserver</b><div>golang</div>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;" vertex="1" parent="1">
|
||||
<mxGeometry x="600" y="40" width="100" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-27" value="<b>Backend</b><div>PostgreSQL</div>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#ffe6cc;strokeColor=#d79b00;" vertex="1" parent="1">
|
||||
<mxGeometry x="720" y="40" width="100" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-28" value="<b>Frontend</b><div>notes2.mjs</div>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;" vertex="1" parent="1">
|
||||
<mxGeometry x="40" y="40" width="100" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-29" value="<b>NodeStore</b>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;" vertex="1" parent="1">
|
||||
<mxGeometry x="200" y="40" width="100" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-30" value="" style="endArrow=none;html=1;rounded=0;strokeColor=#B3B3B3;" edge="1" parent="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="89.5" y="780" as="sourcePoint" />
|
||||
<mxPoint x="89.5" y="80" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-31" value="" style="endArrow=none;html=1;rounded=0;strokeColor=#B3B3B3;" edge="1" parent="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="249.5" y="780" as="sourcePoint" />
|
||||
<mxPoint x="249.5" y="80" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-32" value="" style="endArrow=none;html=1;rounded=0;strokeColor=#B3B3B3;" edge="1" parent="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="649.5" y="780" as="sourcePoint" />
|
||||
<mxPoint x="649.5" y="80" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-33" value="" style="endArrow=none;html=1;rounded=0;strokeColor=#B3B3B3;" edge="1" parent="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="769.5" y="780" as="sourcePoint" />
|
||||
<mxPoint x="769.5" y="80" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-58" value="<b>IndexedDB</b>" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#d5e8d4;strokeColor=#82b366;" vertex="1" parent="1">
|
||||
<mxGeometry x="360" y="40" width="100" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-59" value="" style="endArrow=none;html=1;rounded=0;strokeColor=#B3B3B3;" edge="1" parent="1">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="409.5" y="780" as="sourcePoint" />
|
||||
<mxPoint x="409.5" y="80" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-44" value="Floats" style="locked=1;" parent="0" />
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-54" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="rRo1dadeA1uCrzt-e38k-44">
|
||||
<mxGeometry x="240" y="120" width="20" height="140" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-55" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="rRo1dadeA1uCrzt-e38k-44">
|
||||
<mxGeometry x="80" y="120" width="20" height="320" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-60" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="rRo1dadeA1uCrzt-e38k-44">
|
||||
<mxGeometry x="400" y="120" width="20" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-87" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="rRo1dadeA1uCrzt-e38k-44">
|
||||
<mxGeometry x="640" y="300" width="20" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-92" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="rRo1dadeA1uCrzt-e38k-44">
|
||||
<mxGeometry x="760" y="300" width="20" height="80" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-98" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="rRo1dadeA1uCrzt-e38k-44">
|
||||
<mxGeometry x="240" y="280" width="20" height="160" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-73" value="Connections" parent="0" />
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-74" value="" style="endArrow=classic;html=1;rounded=0;entryX=0;entryY=0.098;entryDx=0;entryDy=0;entryPerimeter=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="100" y="140" as="sourcePoint" />
|
||||
<mxPoint x="240" y="140.18000000000006" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-75" value="Always access<div>nodes from</div><div>the NodeStore</div>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="rRo1dadeA1uCrzt-e38k-74">
|
||||
<mxGeometry x="0.0143" relative="1" as="geometry">
|
||||
<mxPoint as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-76" value="" style="endArrow=classic;html=1;rounded=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="260" y="140" as="sourcePoint" />
|
||||
<mxPoint x="400" y="140" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-77" value="Check if already<div>in IndexedDB</div>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="rRo1dadeA1uCrzt-e38k-76">
|
||||
<mxGeometry x="-0.1143" relative="1" as="geometry">
|
||||
<mxPoint as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-78" value="" style="endArrow=classic;html=1;rounded=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;edgeStyle=orthogonalEdgeStyle;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73" target="rRo1dadeA1uCrzt-e38k-96">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="400" y="180" as="sourcePoint" />
|
||||
<mxPoint x="260" y="181" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-79" value="&nbsp;Reply&nbsp;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="rRo1dadeA1uCrzt-e38k-78">
|
||||
<mxGeometry x="0.0602" y="-1" relative="1" as="geometry">
|
||||
<mxPoint x="18" as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-82" value="t" style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry x="840" y="240" width="40" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-83" value="Data<div>exist?</div>" style="text;html=1;align=center;verticalAlign=middle;resizable=0;points=[];autosize=1;strokeColor=none;fillColor=none;" vertex="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry x="340" y="195" width="50" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-84" value="" style="endArrow=classic;html=1;rounded=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="310" y="239.71" as="sourcePoint" />
|
||||
<mxPoint x="260" y="240" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-85" value="&nbsp;Yes&nbsp;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="rRo1dadeA1uCrzt-e38k-84">
|
||||
<mxGeometry x="-0.1033" y="2" relative="1" as="geometry">
|
||||
<mxPoint x="2" y="-2" as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-91" value="" style="endArrow=classic;html=1;rounded=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="660" y="320" as="sourcePoint" />
|
||||
<mxPoint x="760" y="321" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-103" value="&nbsp;Fetch from<div>Postgres</div>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="rRo1dadeA1uCrzt-e38k-91">
|
||||
<mxGeometry x="-0.3315" relative="1" as="geometry">
|
||||
<mxPoint x="17" as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-93" value="" style="endArrow=classic;html=1;rounded=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="760" y="360" as="sourcePoint" />
|
||||
<mxPoint x="660" y="360" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-96" value="" style="rhombus;whiteSpace=wrap;html=1;fillColor=#fff2cc;strokeColor=#d6b656;" vertex="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry x="310" y="220" width="40" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-97" value="" style="endArrow=classic;html=1;rounded=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="240" y="240" as="sourcePoint" />
|
||||
<mxPoint x="100" y="240" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-108" value="Response from<div>NodeStore and</div><div>IndexedDB</div>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="rRo1dadeA1uCrzt-e38k-97">
|
||||
<mxGeometry x="-0.0653" relative="1" as="geometry">
|
||||
<mxPoint as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-99" value="" style="endArrow=classic;html=1;rounded=0;edgeStyle=orthogonalEdgeStyle;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73" source="rRo1dadeA1uCrzt-e38k-96">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="310" y="320" as="sourcePoint" />
|
||||
<mxPoint x="260" y="300" as="targetPoint" />
|
||||
<Array as="points">
|
||||
<mxPoint x="330" y="300" />
|
||||
</Array>
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-100" value="&nbsp;No&nbsp;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="rRo1dadeA1uCrzt-e38k-99">
|
||||
<mxGeometry x="0.382" relative="1" as="geometry">
|
||||
<mxPoint x="6" as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-101" value="" style="endArrow=classic;html=1;rounded=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="260" y="320" as="sourcePoint" />
|
||||
<mxPoint x="640" y="320" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-102" value="&nbsp;Fetch from backend&nbsp;" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="rRo1dadeA1uCrzt-e38k-101">
|
||||
<mxGeometry x="-0.018" y="2" relative="1" as="geometry">
|
||||
<mxPoint x="-127" y="2" as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-104" value="" style="endArrow=classic;html=1;rounded=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="640" y="360" as="sourcePoint" />
|
||||
<mxPoint x="260" y="360" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-106" value="" style="endArrow=classic;html=1;rounded=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="260" y="400" as="sourcePoint" />
|
||||
<mxPoint x="400" y="400" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-109" value="Store for future<div>use in IndexedDB</div>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="rRo1dadeA1uCrzt-e38k-106">
|
||||
<mxGeometry x="-0.0898" y="-1" relative="1" as="geometry">
|
||||
<mxPoint as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-107" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;" vertex="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry x="400" y="380" width="20" height="40" as="geometry" />
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-110" value="" style="endArrow=classic;html=1;rounded=0;" edge="1" parent="rRo1dadeA1uCrzt-e38k-73">
|
||||
<mxGeometry width="50" height="50" relative="1" as="geometry">
|
||||
<mxPoint x="240" y="420" as="sourcePoint" />
|
||||
<mxPoint x="100" y="420" as="targetPoint" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
<mxCell id="rRo1dadeA1uCrzt-e38k-111" value="Response from<div>NodeStore and</div><div>PostgreSQL</div>" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" vertex="1" connectable="0" parent="rRo1dadeA1uCrzt-e38k-110">
|
||||
<mxGeometry x="0.2449" relative="1" as="geometry">
|
||||
<mxPoint x="17" as="offset" />
|
||||
</mxGeometry>
|
||||
</mxCell>
|
||||
</root>
|
||||
</mxGraphModel>
|
||||
</diagram>
|
||||
</mxfile>
|
1
page.go
1
page.go
@ -29,6 +29,5 @@ func (p Page) GetLayout() string {
|
||||
|
||||
func (p Page) GetData() any {
|
||||
p.Data["_dev"] = FlagDev
|
||||
p.Data["GRIS"] = "foo"
|
||||
return p.Data
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 123 KiB After Width: | Height: | Size: 123 KiB |
@ -8,12 +8,13 @@ const html = htm.bind(h)
|
||||
export class Notes2 {
|
||||
constructor() {//{{{
|
||||
this.startNode = null
|
||||
this.tree = createRef()
|
||||
this.setStartNode()
|
||||
}//}}}
|
||||
render() {//{{{
|
||||
return html`
|
||||
<button onclick=${()=>API.logout()}>Log out</button>
|
||||
<${Tree} app=${this} />
|
||||
<button onclick=${() => API.logout()}>Log out</button>
|
||||
<${Tree} ref=${this.tree} app=${this} />
|
||||
`
|
||||
}//}}}
|
||||
setStartNode() {//{{{
|
||||
@ -26,7 +27,8 @@ export class Notes2 {
|
||||
const req = {}
|
||||
API.query('POST', '/node/tree', req)
|
||||
.then(response => {
|
||||
console.log(response)
|
||||
console.log(response.Nodes)
|
||||
nodeStore.add(response.Nodes)
|
||||
})
|
||||
.catch(e => console.log(e.type, e.error))
|
||||
}
|
||||
@ -51,8 +53,7 @@ class Tree extends Component {
|
||||
}//}}}
|
||||
|
||||
retrieve(callback = null) {//{{{
|
||||
const req = { StartNodeID: 0 }
|
||||
API.query('POST', '/node/tree', req)
|
||||
nodeStore.getTreeNodes()
|
||||
.then(res => {
|
||||
this.treeNodes = {}
|
||||
this.treeNodeComponents = {}
|
||||
@ -63,7 +64,7 @@ class Tree extends Component {
|
||||
// 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.
|
||||
res.Nodes.forEach(nodeData => {
|
||||
res.forEach(nodeData => {
|
||||
let node = new Node(
|
||||
this,
|
||||
nodeData.ID,
|
||||
|
@ -1,4 +1,3 @@
|
||||
import 'preact/devtools'
|
||||
import { h, Component } from 'preact'
|
||||
import htm from 'htm'
|
||||
import Crypto from 'crypto'
|
||||
|
87
static/js/node_store.mjs
Normal file
87
static/js/node_store.mjs
Normal file
@ -0,0 +1,87 @@
|
||||
export class NodeStore {
|
||||
constructor() {
|
||||
if (!('indexedDB' in window)) {
|
||||
throw 'Missing IndexedDB'
|
||||
}
|
||||
|
||||
this.db = null
|
||||
}
|
||||
|
||||
async initializeDB() {
|
||||
return new Promise((resolve, reject) => {
|
||||
let req = indexedDB.open('notes', 2)
|
||||
|
||||
|
||||
// Schema upgrades for IndexedDB.
|
||||
// These can start from different points depending on updates to Notes2 since a device was online.
|
||||
req.onupgradeneeded = (event) => {
|
||||
var store
|
||||
let db = event.target.result
|
||||
let trx = event.target.transaction
|
||||
|
||||
for (let i = event.oldVersion + 1; i <= event.newVersion; i++) {
|
||||
console.log(`Upgrade to schema ${i}`)
|
||||
|
||||
// The schema transformations.
|
||||
switch (i) {
|
||||
case 1:
|
||||
store = db.createObjectStore('nodes', { keyPath: 'ID' })
|
||||
store.createIndex('nameIndex', 'Name', { unique: false })
|
||||
break
|
||||
case 2:
|
||||
trx.objectStore('nodes').createIndex('parentIndex', 'ParentID', { unique: false })
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
req.onsuccess = (event) => {
|
||||
this.db = event.target.result
|
||||
resolve()
|
||||
}
|
||||
|
||||
req.onerror = (event) => {
|
||||
reject(event.target.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async add(records) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
let t = this.db.transaction('nodes', 'readwrite')
|
||||
let nodeStore = t.objectStore('nodes')
|
||||
t.onerror = (event) => {
|
||||
console.log('transaction error', event.target.error)
|
||||
reject(event.target.error)
|
||||
}
|
||||
t.oncomplete = () => {
|
||||
resolve()
|
||||
}
|
||||
|
||||
records.forEach(record => {
|
||||
let addReq = nodeStore.add(record)
|
||||
addReq.onsuccess = (event) => {
|
||||
console.log('OK!', record.ID, record.Name)
|
||||
}
|
||||
addReq.onerror = (event) => {
|
||||
console.log('Error!', event.target.error, record.ID)
|
||||
}
|
||||
})
|
||||
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async getTreeNodes() {
|
||||
return new Promise((resolve, reject)=>{
|
||||
let trx = this.db.transaction('nodes', 'readonly')
|
||||
let nodeStore = trx.objectStore('nodes')
|
||||
let req = nodeStore.getAll()
|
||||
req.onsuccess = (event)=>resolve(event.target.result)
|
||||
req.onerror = (event)=>reject(event.target.error)
|
||||
})
|
||||
}
|
||||
}
|
@ -15,25 +15,23 @@
|
||||
"imports": {
|
||||
"preact": "/js/{{ .VERSION }}/lib/preact/preact.mjs",
|
||||
"preact/hooks": "/js/{{ .VERSION }}/lib/preact/hooks.mjs",
|
||||
{{- if .Data._dev }}
|
||||
"preact/debug": "/js/{{ .VERSION }}/lib/preact/debug.mjs",
|
||||
"preact/devtools": "/js/{{ .VERSION }}/lib/preact/devtools.mjs",
|
||||
{{- end }}
|
||||
"@preact/signals-core": "/js/{{ .VERSION }}/lib/signals/signals-core.mjs",
|
||||
"preact/signals": "/js/{{ .VERSION }}/lib/signals/signals.mjs",
|
||||
"htm": "/js/{{ .VERSION }}/lib/htm/htm.mjs",
|
||||
|
||||
"api": "/js/{{ .VERSION }}/api.mjs",
|
||||
"key": "/js/{{ .VERSION }}/key.mjs",
|
||||
"checklist": "/js/{{ .VERSION }}/checklist.mjs",
|
||||
"crypto": "/js/{{ .VERSION }}/crypto.mjs",
|
||||
"node": "/js/{{ .VERSION }}/node.mjs"
|
||||
"api": "/js/{{ .VERSION }}/api.mjs",
|
||||
"key": "/js/{{ .VERSION }}/key.mjs",
|
||||
"checklist": "/js/{{ .VERSION }}/checklist.mjs",
|
||||
"crypto": "/js/{{ .VERSION }}/crypto.mjs",
|
||||
"node_store": "/js/{{ .VERSION }}/node_store.mjs",
|
||||
"node": "/js/{{ .VERSION }}/node.mjs"
|
||||
{{/*
|
||||
"session": "/js/{{ .VERSION }}/session.mjs",
|
||||
"node": "/js/{{ .VERSION }}/node.mjs",
|
||||
"node_store": "/js/{{ .VERSION }}/node_store.mjs",
|
||||
"key": "/js/{{ .VERSION }}/key.mjs",
|
||||
"crypto": "/js/{{ .VERSION }}/crypto.mjs",
|
||||
"checklist": "/js/{{ .VERSION }}/checklist.mjs",
|
||||
"ws": "/_js/{{ .VERSION }}/websocket.mjs"
|
||||
"session": "/js/{{ .VERSION }}/session.mjs",
|
||||
"ws": "/_js/{{ .VERSION }}/websocket.mjs"
|
||||
*/}}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import htm from 'htm'
|
||||
import 'preact/debug'
|
||||
import 'preact/devtools'
|
||||
{{- end }}
|
||||
import { NodeStore } from 'node_store'
|
||||
import { Notes2 } from "/js/{{ .VERSION }}/app.mjs"
|
||||
import { API } from 'api'
|
||||
|
||||
@ -15,8 +16,15 @@ if (!API.hasAuthenticationToken()) {
|
||||
location.href = '/login'
|
||||
} else {
|
||||
const html = htm.bind(h)
|
||||
window._notes2 = createRef()
|
||||
render(html`<${Notes2} ref=${window._notes2} />`, document.getElementById('app'))
|
||||
try {
|
||||
window.nodeStore = new NodeStore()
|
||||
window.nodeStore.initializeDB().then(() => {
|
||||
window._notes2 = createRef()
|
||||
render(html`<${Notes2} ref=${window._notes2} />`, document.getElementById('app'))
|
||||
})
|
||||
} catch (e) {
|
||||
alert(e)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user