Work on node history
This commit is contained in:
parent
71af26ca1d
commit
5f068ac036
5 changed files with 246 additions and 20 deletions
|
|
@ -74,7 +74,7 @@ export class NodeStore {
|
|||
req.onsuccess = (event) => {
|
||||
this.db = event.target.result
|
||||
this.sendQueue = new SimpleNodeStore(this.db, 'send_queue')
|
||||
this.nodesHistory = new SimpleNodeStore(this.db, 'nodes_history')
|
||||
this.nodesHistory = new NodeHistoryStore(this.db, 'nodes_history')
|
||||
this.files = new SimpleNodeStore(this.db, 'files')
|
||||
this.initializeRootNode()
|
||||
.then(() => resolve())
|
||||
|
|
@ -437,24 +437,66 @@ class SimpleNodeStore {
|
|||
}//}}}
|
||||
}
|
||||
|
||||
export class StoreFile {
|
||||
static createFromFileObject(f) {
|
||||
const obj = new StoreFile()
|
||||
obj.name = f.name
|
||||
obj.size = f.size
|
||||
obj.mime = f.type
|
||||
return obj
|
||||
}
|
||||
constructor() {
|
||||
this.name = ''
|
||||
this.size = 0
|
||||
this.mime = ''
|
||||
class NodeHistoryStore extends SimpleNodeStore {
|
||||
constructor(db, storeName) {//{{{
|
||||
super(db, storeName)
|
||||
}//}}}
|
||||
count(uuid) {//{{{
|
||||
if (uuid === undefined)
|
||||
return super.count()
|
||||
|
||||
this.objectURL = null // URL.createObjectURL(blob)
|
||||
}
|
||||
data() {
|
||||
return {
|
||||
}
|
||||
const index = this.db
|
||||
.transaction(['nodes', this.storeName], 'readonly')
|
||||
.objectStore(this.storeName)
|
||||
.index('byUUID')
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = index.count(uuid)
|
||||
request.onsuccess = (event) => resolve(event.target.result)
|
||||
request.onerror = (event) => reject(event.target.error)
|
||||
})
|
||||
}//}}}
|
||||
retrievePage(uuid, perPage, page) {
|
||||
return new Promise((resolve, _reject) => {
|
||||
const cursor = this.db
|
||||
.transaction(['nodes', this.storeName], 'readonly')
|
||||
.objectStore(this.storeName)
|
||||
.index('byUUID')
|
||||
.openCursor(uuid)
|
||||
|
||||
let retrieved = 0
|
||||
let first = true
|
||||
const nodes = []
|
||||
|
||||
cursor.onsuccess = (event) => {
|
||||
const cursor = event.target.result
|
||||
if (!cursor) {
|
||||
resolve(nodes)
|
||||
return
|
||||
}
|
||||
|
||||
// openCursor returns the first value which is only useful
|
||||
// if the first page is requested.
|
||||
if (page == 1 || !first) {
|
||||
retrieved++
|
||||
nodes.push(new Node(cursor.value))
|
||||
if (retrieved === perPage) {
|
||||
resolve(nodes)
|
||||
return
|
||||
}
|
||||
cursor.continue()
|
||||
return
|
||||
}
|
||||
|
||||
// Jump to the start of the requested page.
|
||||
// Minus one since the first record was already returned.
|
||||
if (page > 1 && first) {
|
||||
first = false
|
||||
cursor.advance((perPage * (page - 1)))
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue