From 6a36e1ca8609ce6f602b441d3bb62f91ced6310a Mon Sep 17 00:00:00 2001 From: azivner Date: Fri, 16 Nov 2018 23:27:57 +0100 Subject: [PATCH] we're now saving links also for notes included in relation maps which helps with translation of noteIds during import from native tar --- .../services/note_detail_relation_map.js | 2 ++ src/services/consistency_checks.js | 3 ++- src/services/import/tar.js | 2 +- src/services/notes.js | 25 ++++++++++++++++--- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.js index d573376e5..868a78660 100644 --- a/src/public/javascripts/services/note_detail_relation_map.js +++ b/src/public/javascripts/services/note_detail_relation_map.js @@ -549,6 +549,8 @@ async function dropNoteOntoRelationMapHandler(ev) { } } + saveData(); + await refresh(); } diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index a6045ef84..6e6a91344 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -263,7 +263,8 @@ async function runAllChecks() { links WHERE type != 'image' - AND type != 'hyper'`, + AND type != 'hyper' + AND type != 'relation-map'`, "Link type is invalid", errorList); await runCheck(` diff --git a/src/services/import/tar.js b/src/services/import/tar.js index 9c8168d55..26045c77b 100644 --- a/src/services/import/tar.js +++ b/src/services/import/tar.js @@ -202,7 +202,7 @@ async function importNotes(ctx, files, parentNoteId) { isExpanded: !!file.meta.isExpanded }).save(); - return; + continue; } if (file.meta.type !== 'file' && file.meta.type !== 'image') { diff --git a/src/services/notes.js b/src/services/notes.js index e74e64971..4fa7503eb 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -199,15 +199,34 @@ function findHyperLinks(content, foundLinks) { return match; } +function findRelationMapLinks(content, foundLinks) { + const obj = JSON.parse(content); + + for (const note of obj.notes) { + foundLinks.push({ + type: 'relation-map', + targetNoteId: note.noteId + }) + } +} + async function saveLinks(note) { - if (note.type !== 'text') { + if (note.type !== 'text' && note.type !== 'relation-map') { return; } const foundLinks = []; - findImageLinks(note.content, foundLinks); - findHyperLinks(note.content, foundLinks); + if (note.type === 'text') { + findImageLinks(note.content, foundLinks); + findHyperLinks(note.content, foundLinks); + } + else if (note.type === 'relation-map') { + findRelationMapLinks(note.content, foundLinks); + } + else { + throw new Error("Unrecognized type " + note.type); + } const existingLinks = await note.getLinks();