From 9a819cafed52b3a45d3e5bf074e76a79df73f0ab Mon Sep 17 00:00:00 2001 From: azivner Date: Sat, 18 Nov 2017 17:17:46 -0500 Subject: [PATCH] sync changes for note_tree_id and fixed recent notes --- public/javascripts/dialogs/recent_notes.js | 5 ++++- public/javascripts/note_tree.js | 2 +- routes/api/sync.js | 8 ++++---- services/sync.js | 6 +++--- services/sync_table.js | 8 ++++---- services/sync_update.js | 13 +++++++------ 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/public/javascripts/dialogs/recent_notes.js b/public/javascripts/dialogs/recent_notes.js index d5bd7d113..4278aece2 100644 --- a/public/javascripts/dialogs/recent_notes.js +++ b/public/javascripts/dialogs/recent_notes.js @@ -18,8 +18,11 @@ const recentNotes = (function() { function addRecentNote(noteTreeId) { setTimeout(() => { + console.log("note tree: " + noteTreeId); + console.log("current note tree: " + noteTree.getCurrentNoteTreeId()); + // we include the note into recent list only if the user stayed on the note at least 5 seconds - if (noteTreeId === noteEditor.getCurrentNoteId()) { + if (noteTreeId === noteTree.getCurrentNoteTreeId()) { $.ajax({ url: baseApiUrl + 'recent-notes/' + noteTreeId, type: 'PUT', diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.js index 2e8fd2ec5..835215e74 100644 --- a/public/javascripts/note_tree.js +++ b/public/javascripts/note_tree.js @@ -317,7 +317,7 @@ const noteTree = (function() { function getCurrentNoteTreeId() { const node = getCurrentNode(); - return node.note_tree_id; + return node.data.note_tree_id; } function setCurrentNoteTreeBasedOnProtectedStatus() { diff --git a/routes/api/sync.js b/routes/api/sync.js index 1354fdfd8..9bddbca20 100644 --- a/routes/api/sync.js +++ b/routes/api/sync.js @@ -50,12 +50,12 @@ router.get('/options/:optName', auth.checkApiAuth, async (req, res, next) => { } }); -router.get('/notes_reordering/:noteParentId', auth.checkApiAuth, async (req, res, next) => { - const noteParentId = req.params.noteParentId; +router.get('/notes_reordering/:noteTreeParentId', auth.checkApiAuth, async (req, res, next) => { + const noteTreeParentId = req.params.noteTreeParentId; res.send({ - note_pid: noteParentId, - ordering: await sql.getMap("SELECT note_id, note_pos FROM notes_tree WHERE note_pid = ?", [noteParentId]) + note_pid: noteTreeParentId, + ordering: await sql.getMap("SELECT note_tree_id, note_pos FROM notes_tree WHERE note_pid = ?", [noteTreeParentId]) }); }); diff --git a/services/sync.js b/services/sync.js index f73d4032f..4a13080a8 100644 --- a/services/sync.js +++ b/services/sync.js @@ -179,7 +179,7 @@ async function readAndPushEntity(sync, syncContext) { entity = await sql.getSingleResult('SELECT * FROM notes WHERE note_id = ?', [sync.entity_id]); } else if (sync.entity_name === 'notes_tree') { - entity = await sql.getSingleResult('SELECT * FROM notes_tree WHERE note_id = ?', [sync.entity_id]); + entity = await sql.getSingleResult('SELECT * FROM notes_tree WHERE note_tree_id = ?', [sync.entity_id]); } else if (sync.entity_name === 'notes_history') { entity = await sql.getSingleResult('SELECT * FROM notes_history WHERE note_history_id = ?', [sync.entity_id]); @@ -187,14 +187,14 @@ async function readAndPushEntity(sync, syncContext) { else if (sync.entity_name === 'notes_reordering') { entity = { note_pid: sync.entity_id, - ordering: await sql.getMap('SELECT note_id, note_pos FROM notes_tree WHERE note_pid = ?', [sync.entity_id]) + ordering: await sql.getMap('SELECT note_tree_id, note_pos FROM notes_tree WHERE note_pid = ?', [sync.entity_id]) }; } else if (sync.entity_name === 'options') { entity = await sql.getSingleResult('SELECT * FROM options WHERE opt_name = ?', [sync.entity_id]); } else if (sync.entity_name === 'recent_notes') { - entity = await sql.getSingleResult('SELECT * FROM recent_notes WHERE note_id = ?', [sync.entity_id]); + entity = await sql.getSingleResult('SELECT * FROM recent_notes WHERE note_tree_id = ?', [sync.entity_id]); } else { throw new Error("Unrecognized entity type " + sync.entity_name); diff --git a/services/sync_table.js b/services/sync_table.js index b0f8fc71b..6cebc62af 100644 --- a/services/sync_table.js +++ b/services/sync_table.js @@ -6,12 +6,12 @@ async function addNoteSync(noteId, sourceId) { await addEntitySync("notes", noteId, sourceId) } -async function addNoteTreeSync(noteId, sourceId) { - await addEntitySync("notes_tree", noteId, sourceId) +async function addNoteTreeSync(noteTreeId, sourceId) { + await addEntitySync("notes_tree", noteTreeId, sourceId) } -async function addNoteReorderingSync(parentNoteId, sourceId) { - await addEntitySync("notes_reordering", parentNoteId, sourceId) +async function addNoteReorderingSync(parentNoteTreeId, sourceId) { + await addEntitySync("notes_reordering", parentNoteTreeId, sourceId) } async function addNoteHistorySync(noteHistoryId, sourceId) { diff --git a/services/sync_update.js b/services/sync_update.js index fb849b899..b590f606f 100644 --- a/services/sync_update.js +++ b/services/sync_update.js @@ -35,7 +35,7 @@ async function updateNote(entity, links, sourceId) { } async function updateNoteTree(entity, sourceId) { - const orig = await sql.getSingleResultOrNull("select * from notes_tree where note_id = ?", [entity.note_id]); + const orig = await sql.getSingleResultOrNull("select * from notes_tree where note_tree_id = ?", [entity.note_tree_id]); if (orig === null || orig.date_modified < entity.date_modified) { await sql.doInTransaction(async () => { @@ -43,15 +43,16 @@ async function updateNoteTree(entity, sourceId) { await sql.replace('notes_tree', entity); - await sync_table.addNoteTreeSync(entity.note_id, sourceId); + await sync_table.addNoteTreeSync(entity.note_tree_id, sourceId); + // not sure why this is here ... await sql.addAudit(audit_category.UPDATE_TITLE, sourceId, entity.note_id); }); - log.info("Update/sync note tree " + entity.note_id); + log.info("Update/sync note tree " + entity.note_tree_id); } else { - await eventLog.addNoteEvent(entity.note_id, "Sync conflict in note tree , " + utils.formatTwoTimestamps(orig.date_modified, entity.date_modified)); + await eventLog.addNoteEvent(entity.note_tree_id, "Sync conflict in note tree , " + utils.formatTwoTimestamps(orig.date_modified, entity.date_modified)); } } @@ -75,7 +76,7 @@ async function updateNoteHistory(entity, sourceId) { async function updateNoteReordering(entity, sourceId) { await sql.doInTransaction(async () => { Object.keys(entity.ordering).forEach(async key => { - await sql.execute("UPDATE notes_tree SET note_pos = ? WHERE note_id = ?", [entity.ordering[key], key]); + await sql.execute("UPDATE notes_tree SET note_pos = ? WHERE note_tree_id = ?", [entity.ordering[key], key]); }); await sync_table.addNoteReorderingSync(entity.note_pid, sourceId); @@ -105,7 +106,7 @@ async function updateOptions(entity, sourceId) { } async function updateRecentNotes(entity, sourceId) { - const orig = await sql.getSingleResultOrNull("select * from recent_notes where note_id = ?", [entity.note_id]); + const orig = await sql.getSingleResultOrNull("select * from recent_notes where note_tree_id = ?", [entity.note_tree_id]); if (orig === null || orig.date_accessed < entity.date_accessed) { await sql.doInTransaction(async () => {