Work on sync element, now a custom HTML element
This commit is contained in:
parent
99063d34be
commit
9fc4a14ce3
10 changed files with 190 additions and 1001 deletions
|
|
@ -13,7 +13,7 @@ export class NodeStore {
|
|||
this.sendQueue = null
|
||||
this.nodesHistory = null
|
||||
}//}}}
|
||||
async initializeDB() {//{{{
|
||||
initializeDB() {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = indexedDB.open('notes', 7)
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ export class NodeStore {
|
|||
}
|
||||
})
|
||||
}//}}}
|
||||
async initializeRootNode() {//{{{
|
||||
initializeRootNode() {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
// The root node is a magical node which displays as the first node if none is specified.
|
||||
// If not already existing, it will be created.
|
||||
|
|
@ -120,7 +120,7 @@ export class NodeStore {
|
|||
return n
|
||||
}//}}}
|
||||
|
||||
async getAppState(key) {//{{{
|
||||
getAppState(key) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
const trx = this.db.transaction('app_state', 'readonly')
|
||||
const appState = trx.objectStore('app_state')
|
||||
|
|
@ -135,7 +135,7 @@ export class NodeStore {
|
|||
getRequest.onerror = (event) => reject(event.target.error)
|
||||
})
|
||||
}//}}}
|
||||
async setAppState(key, value) {//{{{
|
||||
setAppState(key, value) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
const t = this.db.transaction('app_state', 'readwrite')
|
||||
|
|
@ -159,32 +159,7 @@ export class NodeStore {
|
|||
})
|
||||
}//}}}
|
||||
|
||||
/* TODO - Remove?
|
||||
async storeNode(node) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
const t = this.db.transaction('nodes', 'readwrite')
|
||||
const nodeStore = t.objectStore('nodes')
|
||||
t.onerror = (event) => {
|
||||
console.log('transaction error', event.target.error)
|
||||
reject(event.target.error)
|
||||
}
|
||||
t.oncomplete = () => {
|
||||
resolve()
|
||||
}
|
||||
|
||||
const nodeReq = nodeStore.put(node.data)
|
||||
nodeReq.onsuccess = () => {
|
||||
console.debug(`Storing ${node.UUID} (${node.get('Name')})`)
|
||||
}
|
||||
queueReq.onerror = (event) => {
|
||||
console.log(`Error storing ${node.UUID}`, event.target.error)
|
||||
reject(event.target.error)
|
||||
}
|
||||
})
|
||||
}//}}}
|
||||
*/
|
||||
|
||||
async upsertNodeRecords(records) {//{{{
|
||||
upsertNodeRecords(records) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
const t = this.db.transaction('nodes', 'readwrite')
|
||||
const nodeStore = t.objectStore('nodes')
|
||||
|
|
@ -222,7 +197,7 @@ export class NodeStore {
|
|||
}
|
||||
})
|
||||
}//}}}
|
||||
async getTreeNodes(parent, newLevel) {//{{{
|
||||
getTreeNodes(parent, newLevel) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
// Parent of toplevel nodes is ROOT_NODE in indexedDB.
|
||||
// Only the root node has '' as parent.
|
||||
|
|
@ -274,13 +249,13 @@ export class NodeStore {
|
|||
})
|
||||
}//}}}
|
||||
|
||||
async add(records) {//{{{
|
||||
add(records) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
const t = this.db.transaction('nodes', 'readwrite')
|
||||
const nodeStore = t.objectStore('nodes')
|
||||
t.onerror = (event) => {
|
||||
console.log('transaction error', event.target.error)
|
||||
console.error('transaction error', event.target.error)
|
||||
reject(event.target.error)
|
||||
}
|
||||
|
||||
|
|
@ -291,12 +266,9 @@ export class NodeStore {
|
|||
const addReq = nodeStore.put(record.data)
|
||||
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
addReq.onsuccess = () => {
|
||||
console.debug('OK!', record.ID, record.Name)
|
||||
resolve()
|
||||
}
|
||||
addReq.onsuccess = () => resolve()
|
||||
addReq.onerror = (event) => {
|
||||
console.log('Error!', event.target.error, record.ID)
|
||||
console.error('Error!', event.target.error, record.ID)
|
||||
reject(event.target.error)
|
||||
}
|
||||
})
|
||||
|
|
@ -309,7 +281,7 @@ export class NodeStore {
|
|||
}
|
||||
})
|
||||
}//}}}
|
||||
async get(uuid) {//{{{
|
||||
get(uuid) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
const trx = this.db.transaction('nodes', 'readonly')
|
||||
const nodeStore = trx.objectStore('nodes')
|
||||
|
|
@ -325,7 +297,7 @@ export class NodeStore {
|
|||
}
|
||||
})
|
||||
}//}}}
|
||||
async getNodeAncestry(node, accumulated) {//{{{
|
||||
getNodeAncestry(node, accumulated) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
if (accumulated === undefined)
|
||||
accumulated = []
|
||||
|
|
@ -357,7 +329,7 @@ export class NodeStore {
|
|||
|
||||
}//}}}
|
||||
|
||||
async nodeCount() {//{{{
|
||||
nodeCount() {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
const t = this.db.transaction('nodes', 'readwrite')
|
||||
const nodeStore = t.objectStore('nodes')
|
||||
|
|
@ -374,7 +346,7 @@ class SimpleNodeStore {
|
|||
this.db = db
|
||||
this.storeName = storeName
|
||||
}//}}}
|
||||
async add(node) {//{{{
|
||||
add(node) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
const t = this.db.transaction(['nodes', this.storeName], 'readwrite')
|
||||
const store = t.objectStore(this.storeName)
|
||||
|
|
@ -394,7 +366,7 @@ class SimpleNodeStore {
|
|||
}
|
||||
})
|
||||
}//}}}
|
||||
async retrieve(limit) {//{{{
|
||||
retrieve(limit) {//{{{
|
||||
return new Promise((resolve, reject) => {
|
||||
const cursorReq = this.db
|
||||
.transaction(['nodes', this.storeName], 'readonly')
|
||||
|
|
@ -422,7 +394,7 @@ class SimpleNodeStore {
|
|||
}
|
||||
})
|
||||
}//}}}
|
||||
async delete(keys) {//{{{
|
||||
delete(keys) {//{{{
|
||||
const store = this.db
|
||||
.transaction(['nodes', this.storeName], 'readwrite')
|
||||
.objectStore(this.storeName)
|
||||
|
|
@ -439,7 +411,7 @@ class SimpleNodeStore {
|
|||
}
|
||||
return Promise.all(promises)
|
||||
}//}}}
|
||||
async count() {//{{{
|
||||
count() {//{{{
|
||||
const store = this.db
|
||||
.transaction(['nodes', this.storeName], 'readonly')
|
||||
.objectStore(this.storeName)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue