sync changes for note_tree_id and fixed recent notes

This commit is contained in:
azivner 2017-11-18 17:17:46 -05:00
parent 5fb94fcbbd
commit 9a819cafed
6 changed files with 23 additions and 19 deletions

View File

@ -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',

View File

@ -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() {

View File

@ -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])
});
});

View File

@ -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);

View File

@ -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) {

View File

@ -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 <note>, " + utils.formatTwoTimestamps(orig.date_modified, entity.date_modified));
await eventLog.addNoteEvent(entity.note_tree_id, "Sync conflict in note tree <note>, " + 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 () => {