Sync from and to server
This commit is contained in:
parent
e07258e014
commit
25179ffd15
6 changed files with 125 additions and 76 deletions
|
|
@ -37,7 +37,7 @@ export class NodeUI extends Component {
|
|||
const crumbDivs = [
|
||||
html`<div class="crumb" onclick=${() => _notes2.current.goToNode(ROOT_NODE)}>Start</div>`
|
||||
]
|
||||
for (let i = this.crumbs.length-1; i >= 0; i--) {
|
||||
for (let i = this.crumbs.length - 1; i >= 0; i--) {
|
||||
const crumbNode = this.crumbs[i]
|
||||
crumbDivs.push(html`<div class="crumb" onclick=${() => _notes2.current.goToNode(crumbNode.UUID)}>${crumbNode.get('Name')}</div>`)
|
||||
}
|
||||
|
|
@ -167,13 +167,32 @@ export class NodeUI extends Component {
|
|||
if (!this.nodeModified.value)
|
||||
return
|
||||
|
||||
await nodeStore.copyToNodesHistory(this.node.value)
|
||||
/* 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. */
|
||||
const node = this.node.value
|
||||
|
||||
// The node is still in its old state and will present
|
||||
// the unmodified content to the node store.
|
||||
const history = nodeStore.nodesHistory.add(node)
|
||||
|
||||
// Prepares the node object for saving.
|
||||
// Sets Updated value to current date and time.
|
||||
const node = this.node.value
|
||||
node.save()
|
||||
await nodeStore.add([node])
|
||||
await node.save()
|
||||
|
||||
// Updated node is added to the send queue to be stored on server.
|
||||
const sendQueue = nodeStore.sendQueue.add(this.node.value)
|
||||
|
||||
// Updated node is saved to the primary node store.
|
||||
const nodeStoreAdding = nodeStore.add([node])
|
||||
|
||||
await Promise.all([history, sendQueue, nodeStoreAdding])
|
||||
this.nodeModified.value = false
|
||||
}//}}}
|
||||
|
||||
|
|
@ -315,6 +334,7 @@ export class Node {
|
|||
|
||||
this._children_fetched = false
|
||||
this.Children = []
|
||||
this.Ancestors = []
|
||||
|
||||
this._content = this.data.Content
|
||||
this._modified = false
|
||||
|
|
@ -372,10 +392,15 @@ export class Node {
|
|||
this._decrypted = true
|
||||
*/
|
||||
}//}}}
|
||||
save() {//{{{
|
||||
async save() {//{{{
|
||||
this.data.Content = this._content
|
||||
this.data.Updated = new Date().toISOString()
|
||||
this._modified = false
|
||||
|
||||
// When stored into database and ancestry was changed,
|
||||
// the ancestry path could be interesting.
|
||||
const ancestors = await nodeStore.getNodeAncestry(this)
|
||||
this.data.Ancestors = ancestors.map(a => a.get('Name')).reverse()
|
||||
}//}}}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue