Better node saving/history
This commit is contained in:
parent
3e8d5b6d9a
commit
95a26e67d5
3 changed files with 32 additions and 31 deletions
|
|
@ -162,10 +162,6 @@ export class App {
|
|||
|
||||
const nn = Node.create(name, this.currentNode.UUID)
|
||||
nn.save()
|
||||
|
||||
nodeStore.sendQueue.add(nn)
|
||||
nodeStore.add([nn])
|
||||
|
||||
}//}}}
|
||||
async goToNode(nodeUUID, dontPush, dontExpand) {//{{{
|
||||
if (nodeUUID === null || nodeUUID === undefined)
|
||||
|
|
|
|||
|
|
@ -115,31 +115,9 @@ export class N2PageNodeUI extends CustomHTMLElement {
|
|||
if (!this.node.isModified())
|
||||
return
|
||||
|
||||
/* The node history is a local store for node history.
|
||||
* This could be provisioned from the server or cleared if
|
||||
* deemed unnecessary.
|
||||
*
|
||||
* The send queue is what will be sent back to the server
|
||||
* to have a recorded history of the notes.
|
||||
*
|
||||
* A setting to be implemented in the future could be to
|
||||
* not save the history locally at all. */
|
||||
|
||||
// The node is still in its old state and will present
|
||||
// the unmodified content to the node store.
|
||||
const history = nodeStore.nodesHistory.add(this.node)
|
||||
|
||||
// Prepares the node object for saving.
|
||||
// Sets Updated value to current date and time.
|
||||
// node.save takes care of both "nodes" and "nodes_history" stores, also adds it to send queue.
|
||||
// Sets "Updated" value to current date and time and generates a new history UUID.
|
||||
await this.node.save()
|
||||
|
||||
// Updated node is added to the send queue to be stored on server.
|
||||
const sendQueue = nodeStore.sendQueue.add(this.node)
|
||||
|
||||
// Updated node is saved to the primary node store.
|
||||
const nodeStoreAdding = nodeStore.add([this.node])
|
||||
|
||||
await Promise.all([history, sendQueue, nodeStoreAdding])
|
||||
}// }}}
|
||||
|
||||
contentChanged(event) {//{{{
|
||||
|
|
@ -306,7 +284,7 @@ export class Node {
|
|||
return 0
|
||||
}//}}}
|
||||
static create(name, parentUUID) {// {{{
|
||||
return new Node({
|
||||
const node = new Node({
|
||||
UUID: uuidv7(),
|
||||
Created: (new Date()).toISOString(),
|
||||
Content: '',
|
||||
|
|
@ -315,6 +293,12 @@ export class Node {
|
|||
Markdown: false,
|
||||
History: false,
|
||||
})
|
||||
|
||||
// Newly created node (not constructed from existing data) is considered modified
|
||||
// since node.save returns early if it isn't modified.
|
||||
node._modified = true
|
||||
|
||||
return node
|
||||
}// }}}
|
||||
|
||||
constructor(nodeData, level) {//{{{
|
||||
|
|
@ -431,6 +415,28 @@ export class Node {
|
|||
// the ancestry path could be interesting.
|
||||
const ancestors = await nodeStore.getNodeAncestry(this)
|
||||
this.data.Ancestors = ancestors.map(a => a.get('Name')).reverse()
|
||||
|
||||
/* The node history is a local store for node history.
|
||||
* This could be provisioned from the server or cleared if
|
||||
* deemed unnecessary.
|
||||
*
|
||||
* The send queue is what will be sent back to the server
|
||||
* to have a recorded history of the notes.
|
||||
*
|
||||
* A setting to be implemented in the future could be to
|
||||
* not save the history locally at all. */
|
||||
|
||||
// Current node is added to history. It will be duplicated with the "nodes" store
|
||||
// for simplicity, to hopefully avoid bugs.
|
||||
const history = nodeStore.nodesHistory.add(this)
|
||||
|
||||
// Updated node is added to the send queue to be stored on server.
|
||||
const sendQueue = nodeStore.sendQueue.add(this)
|
||||
|
||||
// Updated node is saved to the primary node store.
|
||||
const nodeStoreAdding = nodeStore.add([this])
|
||||
|
||||
return Promise.all([history, sendQueue, nodeStoreAdding])
|
||||
}//}}}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ export class Sync {
|
|||
|
||||
nodeStore.setAppState('latest_sync_node', currMax)
|
||||
} catch (e) {
|
||||
console.log('sync node tree', e)
|
||||
console.error('sync node tree', e)
|
||||
} finally {
|
||||
syncEnd = Date.now()
|
||||
const duration = (syncEnd - syncStart) / 1000
|
||||
|
|
@ -235,7 +235,6 @@ export class N2SyncProgress extends CustomHTMLElement {
|
|||
this.elDownloadTransferred.innerText = this.state.nodesDowloaded
|
||||
this.elDownloadTotal.innerText = this.state.nodesToDownload
|
||||
|
||||
console.log('setting elUploadTransferred', this.state.nodesUploaded)
|
||||
this.elUploadTransferred.innerText = this.state.nodesUploaded
|
||||
this.elUploadTotal.innerText = this.state.nodesToUpload
|
||||
}//}}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue