From dea519522373edf0a59e81ccf2ff6a051d9905f7 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 10 Nov 2019 19:29:51 +0100 Subject: [PATCH 1/3] fix setNoteToParent and deprecate it --- src/services/backend_script_api.js | 3 ++- src/services/consistency_checks.js | 2 +- src/services/tree.js | 23 +++++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 620f6480f..c430c9f88 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -282,9 +282,10 @@ function BackendScriptApi(currentNote, apiParams) { * This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix. * * @method + * @deprecated - this method is pretty confusing and serves specialized purpose only * @param {string} noteId * @param {string} prefix - * @param {string} [parentNoteId] + * @param {string|null} parentNoteId */ this.setNoteToParent = treeService.setNoteToParent; diff --git a/src/services/consistency_checks.js b/src/services/consistency_checks.js index 9393b6224..5d0a286dd 100644 --- a/src/services/consistency_checks.js +++ b/src/services/consistency_checks.js @@ -195,7 +195,7 @@ async function findExistencyIssues() { HAVING COUNT(*) > 1`, async ({noteId, parentNoteId}) => { - const branches = await repository.getEntities(`SELECT * FROM branches WHERE noteId = ? and parentNoteId = ? and isDeleted = 1`, [noteId, parentNoteId]); + const branches = await repository.getEntities(`SELECT * FROM branches WHERE noteId = ? and parentNoteId = ? and isDeleted = 0`, [noteId, parentNoteId]); // it's not necessarily "original" branch, it's just the only one which will survive const origBranch = branches[0]; diff --git a/src/services/tree.js b/src/services/tree.js index ca2459ac7..5a38c97a9 100644 --- a/src/services/tree.js +++ b/src/services/tree.js @@ -36,7 +36,7 @@ async function validateParentChild(parentNoteId, childNoteId, branchId = null) { } async function getExistingBranch(parentNoteId, childNoteId) { - return await sql.getRow('SELECT * FROM branches WHERE noteId = ? AND parentNoteId = ? AND isDeleted = 0', [childNoteId, parentNoteId]); + return await repository.getEntity('SELECT * FROM branches WHERE noteId = ? AND parentNoteId = ? AND isDeleted = 0', [childNoteId, parentNoteId]); } /** @@ -123,6 +123,9 @@ async function sortNotesAlphabetically(parentNoteId, directoriesFirst = false) { }); } +/** + * @deprecated - this will be removed in the future + */ async function setNoteToParent(noteId, prefix, parentNoteId) { const parentNote = await repository.getNote(parentNoteId); @@ -151,11 +154,19 @@ async function setNoteToParent(noteId, prefix, parentNoteId) { throw new Error(`Cannot create a branch for ${noteId} which is deleted.`); } - await new Branch({ - noteId: noteId, - parentNoteId: parentNoteId, - prefix: prefix - }).save(); + const branch = await repository.getEntity('SELECT * FROM branches WHERE isDeleted = 0 AND noteId = ? AND parentNoteId = ?', [noteId, parentNoteId]); + + if (branch) { + branch.prefix = prefix; + await branch.save(); + } + else { + await new Branch({ + noteId: noteId, + parentNoteId: parentNoteId, + prefix: prefix + }).save(); + } } } From b8db8427882f01a373cba4530257418270466773 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 10 Nov 2019 19:34:15 +0100 Subject: [PATCH 2/3] added frontend API methods to refresh tabs --- docs/backend_api/BackendScriptApi.html | 43 +--- .../services_backend_script_api.js.html | 3 +- docs/frontend_api/FrontendScriptApi.html | 238 +++++++++++++++++- .../services_frontend_script_api.js.html | 16 ++ .../services/frontend_script_api.js | 16 ++ 5 files changed, 269 insertions(+), 47 deletions(-) diff --git a/docs/backend_api/BackendScriptApi.html b/docs/backend_api/BackendScriptApi.html index e4dc8c372..eec8511d8 100644 --- a/docs/backend_api/BackendScriptApi.html +++ b/docs/backend_api/BackendScriptApi.html @@ -396,7 +396,7 @@ the backend.
Source:
@@ -1533,7 +1533,7 @@ the backend.
Source:
@@ -4249,7 +4249,7 @@ if some action needs to happen on only one specific instance. -

setNoteToParent(noteId, prefix, parentNoteIdopt)

+

setNoteToParent(noteId, prefix, parentNoteId)

@@ -4284,8 +4284,6 @@ This method looks similar to toggleNoteInParent() but differs because we're look Type - Attributes - @@ -4311,14 +4309,6 @@ This method looks similar to toggleNoteInParent() but differs because we're look - - - - - - - - @@ -4342,14 +4332,6 @@ This method looks similar to toggleNoteInParent() but differs because we're look - - - - - - - - @@ -4367,22 +4349,15 @@ This method looks similar to toggleNoteInParent() but differs because we're look string +| + +null - - - <optional>
- - - - - - - @@ -4415,6 +4390,8 @@ This method looks similar to toggleNoteInParent() but differs because we're look +
Deprecated:
  • - this method is pretty confusing and serves specialized purpose only
+ @@ -4427,7 +4404,7 @@ This method looks similar to toggleNoteInParent() but differs because we're look
Source:
@@ -4935,7 +4912,7 @@ transactional by default.
Source:
diff --git a/docs/backend_api/services_backend_script_api.js.html b/docs/backend_api/services_backend_script_api.js.html index 52e7f3546..eb68860b6 100644 --- a/docs/backend_api/services_backend_script_api.js.html +++ b/docs/backend_api/services_backend_script_api.js.html @@ -310,9 +310,10 @@ function BackendScriptApi(currentNote, apiParams) { * This method looks similar to toggleNoteInParent() but differs because we're looking up branch by prefix. * * @method + * @deprecated - this method is pretty confusing and serves specialized purpose only * @param {string} noteId * @param {string} prefix - * @param {string} [parentNoteId] + * @param {string|null} parentNoteId */ this.setNoteToParent = treeService.setNoteToParent; diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.html index 3fd3adc2b..dc8fc5a64 100644 --- a/docs/frontend_api/FrontendScriptApi.html +++ b/docs/frontend_api/FrontendScriptApi.html @@ -1366,7 +1366,7 @@
Source:
@@ -1546,7 +1546,7 @@
Source:
@@ -1785,7 +1785,7 @@
Source:
@@ -1891,7 +1891,7 @@
Source:
@@ -2050,7 +2050,7 @@
Source:
@@ -2312,7 +2312,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -2775,7 +2775,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -2930,7 +2930,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -3039,7 +3039,7 @@ note.
Source:
@@ -3194,7 +3194,7 @@ note.
Source:
@@ -3433,7 +3433,7 @@ note.
Source:
@@ -3463,6 +3463,218 @@ note. + + + + + + +

refreshActiveTab() → {Promise.<void>}

+ + + + + + +
+ Refresh active tab +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<void> + + +
+
+ + + + + + + + + + + + + +

refreshAllTabs() → {Promise.<void>}

+ + + + + + +
+ Refresh current tab +
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + + + + + + + +
Returns:
+ + + + +
+
+ Type +
+
+ +Promise.<void> + + +
+
+ + + + + + + @@ -4308,7 +4520,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -4459,7 +4671,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.html index 60cc942ba..5d9104316 100644 --- a/docs/frontend_api/services_frontend_script_api.js.html +++ b/docs/frontend_api/services_frontend_script_api.js.html @@ -293,6 +293,22 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte */ this.refreshTree = treeService.reload; + /** + * Refresh active tab + * + * @method + * @returns {Promise<void>} + */ + this.refreshActiveTab = noteDetailService.reload; + + /** + * Refresh current tab + * + * @method + * @returns {Promise<void>} + */ + this.refreshAllTabs = noteDetailService.reloadAllTabs; + /** * Create note link (jQuery object) for given note. * diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.js index e90921677..7ff5e85f5 100644 --- a/src/public/javascripts/services/frontend_script_api.js +++ b/src/public/javascripts/services/frontend_script_api.js @@ -265,6 +265,22 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte */ this.refreshTree = treeService.reload; + /** + * Refresh active tab + * + * @method + * @returns {Promise} + */ + this.refreshActiveTab = noteDetailService.reload; + + /** + * Refresh current tab + * + * @method + * @returns {Promise} + */ + this.refreshAllTabs = noteDetailService.reloadAllTabs; + /** * Create note link (jQuery object) for given note. * From b5a0cadcf45e51377573c12b939a1654b09f4931 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 10 Nov 2019 21:34:15 +0100 Subject: [PATCH 3/3] fix showing up of render note help view if no renderNote relations have been found --- src/public/javascripts/services/note_detail_render.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/public/javascripts/services/note_detail_render.js b/src/public/javascripts/services/note_detail_render.js index 49585942f..f738001ce 100644 --- a/src/public/javascripts/services/note_detail_render.js +++ b/src/public/javascripts/services/note_detail_render.js @@ -18,7 +18,11 @@ class NoteDetailRender { this.$component.show(); this.$noteDetailRenderHelp.hide(); - await renderService.render(this.ctx.note, this.$noteDetailRenderContent, this.ctx); + const renderNotesFound = await renderService.render(this.ctx.note, this.$noteDetailRenderContent, this.ctx); + + if (!renderNotesFound) { + this.$noteDetailRenderHelp.show(); + } } getContent() {}