From ef40c66344b5994cd6099479c2459b95be65c5c7 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 14 Mar 2019 20:21:27 +0100 Subject: [PATCH] renamed currentNote to activeNote to be consistent with frontend API --- src/public/javascripts/desktop.js | 2 +- src/public/javascripts/dialogs/add_link.js | 6 +- src/public/javascripts/dialogs/attributes.js | 4 +- src/public/javascripts/dialogs/note_info.js | 12 +-- .../javascripts/dialogs/note_revisions.js | 4 +- src/public/javascripts/dialogs/note_source.js | 2 +- src/public/javascripts/services/attributes.js | 6 +- .../services/frontend_script_api.js | 6 +- .../javascripts/services/note_autocomplete.js | 2 +- .../javascripts/services/note_detail.js | 86 +++++++++---------- .../javascripts/services/note_detail_code.js | 18 ++-- .../javascripts/services/note_detail_file.js | 14 +-- .../javascripts/services/note_detail_image.js | 10 +-- .../services/note_detail_relation_map.js | 8 +- .../services/note_detail_render.js | 2 +- .../services/note_detail_search.js | 4 +- .../javascripts/services/note_detail_text.js | 2 +- src/public/javascripts/services/note_type.js | 4 +- .../javascripts/services/protected_session.js | 16 ++-- src/public/javascripts/services/tree.js | 16 ++-- src/routes/api/autocomplete.js | 8 +- src/services/backend_script_api.js | 2 +- 22 files changed, 117 insertions(+), 117 deletions(-) diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.js index 9f64d56ab..0f5f55da8 100644 --- a/src/public/javascripts/desktop.js +++ b/src/public/javascripts/desktop.js @@ -49,7 +49,7 @@ window.glob.noteChanged = noteDetailService.noteChanged; window.glob.refreshTree = treeService.reload; // required for ESLint plugin -window.glob.getCurrentNote = noteDetailService.getCurrentNote; +window.glob.getActiveNote = noteDetailService.getActiveNote; window.glob.requireLibrary = libraryLoader.requireLibrary; window.glob.ESLINT = libraryLoader.ESLINT; diff --git a/src/public/javascripts/dialogs/add_link.js b/src/public/javascripts/dialogs/add_link.js index 87819bc6b..d40bb9535 100644 --- a/src/public/javascripts/dialogs/add_link.js +++ b/src/public/javascripts/dialogs/add_link.js @@ -27,7 +27,7 @@ function setLinkType(linkType) { async function showDialog() { glob.activeDialog = $dialog; - if (noteDetailService.getCurrentNoteType() === 'text') { + if (noteDetailService.getActiveNoteType() === 'text') { $linkTypeHtml.prop('disabled', false); setLinkType('html'); @@ -99,14 +99,14 @@ $form.submit(() => { else if (linkType === 'selected-to-current') { const prefix = $clonePrefix.val(); - cloningService.cloneNoteTo(noteId, noteDetailService.getCurrentNoteId(), prefix); + cloningService.cloneNoteTo(noteId, noteDetailService.getActiveNoteId(), prefix); $dialog.modal('hide'); } else if (linkType === 'current-to-selected') { const prefix = $clonePrefix.val(); - cloningService.cloneNoteTo(noteDetailService.getCurrentNoteId(), noteId, prefix); + cloningService.cloneNoteTo(noteDetailService.getActiveNoteId(), noteId, prefix); $dialog.modal('hide'); } diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js index b27f5e261..550d3b562 100644 --- a/src/public/javascripts/dialogs/attributes.js +++ b/src/public/javascripts/dialogs/attributes.js @@ -90,7 +90,7 @@ function AttributesModel() { } this.loadAttributes = async function() { - const noteId = noteDetailService.getCurrentNoteId(); + const noteId = noteDetailService.getActiveNoteId(); const attributes = await server.get('notes/' + noteId + '/attributes'); @@ -136,7 +136,7 @@ function AttributesModel() { self.updateAttributePositions(); - const noteId = noteDetailService.getCurrentNoteId(); + const noteId = noteDetailService.getActiveNoteId(); const attributesToSave = self.ownedAttributes() .map(attribute => attribute()) diff --git a/src/public/javascripts/dialogs/note_info.js b/src/public/javascripts/dialogs/note_info.js index 98f1a4bc6..c5ad9927b 100644 --- a/src/public/javascripts/dialogs/note_info.js +++ b/src/public/javascripts/dialogs/note_info.js @@ -13,13 +13,13 @@ function showDialog() { $dialog.modal(); - const currentNote = noteDetailService.getCurrentNote(); + const activeNote = noteDetailService.getActiveNote(); - $noteId.text(currentNote.noteId); - $utcDateCreated.text(currentNote.utcDateCreated); - $utcDateModified.text(currentNote.utcDateModified); - $type.text(currentNote.type); - $mime.text(currentNote.mime); + $noteId.text(activeNote.noteId); + $utcDateCreated.text(activeNote.utcDateCreated); + $utcDateModified.text(activeNote.utcDateModified); + $type.text(activeNote.type); + $mime.text(activeNote.mime); } $okButton.click(() => $dialog.modal('hide')); diff --git a/src/public/javascripts/dialogs/note_revisions.js b/src/public/javascripts/dialogs/note_revisions.js index df386ba9b..55696deb0 100644 --- a/src/public/javascripts/dialogs/note_revisions.js +++ b/src/public/javascripts/dialogs/note_revisions.js @@ -11,7 +11,7 @@ let revisionItems = []; let note; async function showCurrentNoteRevisions() { - await showNoteRevisionsDialog(noteDetailService.getCurrentNoteId()); + await showNoteRevisionsDialog(noteDetailService.getActiveNoteId()); } async function showNoteRevisionsDialog(noteId, noteRevisionId) { @@ -22,7 +22,7 @@ async function showNoteRevisionsDialog(noteId, noteRevisionId) { $list.empty(); $content.empty(); - note = noteDetailService.getCurrentNote(); + note = noteDetailService.getActiveNote(); revisionItems = await server.get('notes/' + noteId + '/revisions'); for (const item of revisionItems) { diff --git a/src/public/javascripts/dialogs/note_source.js b/src/public/javascripts/dialogs/note_source.js index b91cb0165..c7db2b586 100644 --- a/src/public/javascripts/dialogs/note_source.js +++ b/src/public/javascripts/dialogs/note_source.js @@ -8,7 +8,7 @@ function showDialog() { $dialog.modal(); - const noteText = noteDetailService.getCurrentNote().noteContent.content; + const noteText = noteDetailService.getActiveNote().noteContent.content; $noteSource.text(formatHtml(noteText)); } diff --git a/src/public/javascripts/services/attributes.js b/src/public/javascripts/services/attributes.js index 2f0337e0a..200025602 100644 --- a/src/public/javascripts/services/attributes.js +++ b/src/public/javascripts/services/attributes.js @@ -18,7 +18,7 @@ function invalidateAttributes() { } function reloadAttributes() { - attributePromise = server.get('notes/' + noteDetailService.getCurrentNoteId() + '/attributes'); + attributePromise = server.get('notes/' + noteDetailService.getActiveNoteId() + '/attributes'); } async function refreshAttributes() { @@ -40,7 +40,7 @@ async function showAttributes() { $attributeList.hide(); $attributeListInner.empty(); - const note = noteDetailService.getCurrentNote(); + const note = noteDetailService.getActiveNote(); const attributes = await attributePromise; @@ -283,7 +283,7 @@ async function promotedAttributeChanged(event) { value = $attr.val(); } - const result = await server.put("notes/" + noteDetailService.getCurrentNoteId() + "/attribute", { + const result = await server.put("notes/" + noteDetailService.getActiveNoteId() + "/attribute", { attributeId: $attr.prop("attribute-id"), type: $attr.prop("attribute-type"), name: $attr.prop("attribute-name"), diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.js index 7c79931d2..0fa7d98fb 100644 --- a/src/public/javascripts/services/frontend_script_api.js +++ b/src/public/javascripts/services/frontend_script_api.js @@ -202,13 +202,13 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) { * @method * @returns {string} content of active note (loaded into right pane) */ - this.getActiveNoteContent = noteDetailService.getCurrentNoteContent; + this.getActiveNoteContent = noteDetailService.getActiveNoteContent; /** * @method * @returns {NoteFull} active note (loaded into right pane) */ - this.getActiveNote = noteDetailService.getCurrentNote; + this.getActiveNote = noteDetailService.getActiveNote; /** * This method checks whether user navigated away from the note from which the scripts has been started. @@ -220,7 +220,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) { * @return {boolean} returns true if the original note is still loaded, false if user switched to another */ this.isNoteStillActive = () => { - return this.originEntity.noteId === noteDetailService.getCurrentNoteId(); + return this.originEntity.noteId === noteDetailService.getActiveNoteId(); }; /** diff --git a/src/public/javascripts/services/note_autocomplete.js b/src/public/javascripts/services/note_autocomplete.js index 2dfcdd537..cb2760d47 100644 --- a/src/public/javascripts/services/note_autocomplete.js +++ b/src/public/javascripts/services/note_autocomplete.js @@ -8,7 +8,7 @@ const SELECTED_PATH_KEY = "data-note-path"; async function autocompleteSource(term, cb) { const result = await server.get('autocomplete' + '?query=' + encodeURIComponent(term) - + '¤tNoteId=' + noteDetailService.getCurrentNoteId()); + + '&activeNoteId=' + noteDetailService.getActiveNoteId()); if (result.length === 0) { result.push({ diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 1cd8b55ba..4b1f60bed 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -32,7 +32,7 @@ const $scriptArea = $("#note-detail-script-area"); const $savedIndicator = $("#saved-indicator"); const $body = $("body"); -let currentNote = null; +let activeNote = null; let noteChangeDisabled = false; @@ -52,7 +52,7 @@ const components = { function getComponent(type) { if (!type) { - type = getCurrentNote().type; + type = getActiveNote().type; } if (components[type]) { @@ -63,18 +63,18 @@ function getComponent(type) { } } -function getCurrentNote() { - return currentNote; +function getActiveNote() { + return activeNote; } -function getCurrentNoteId() { - return currentNote ? currentNote.noteId : null; +function getActiveNoteId() { + return activeNote ? activeNote.noteId : null; } -function getCurrentNoteType() { - const currentNote = getCurrentNote(); +function getActiveNoteType() { + const activeNote = getActiveNote(); - return currentNote ? currentNote.type : null; + return activeNote ? activeNote.type : null; } function noteChanged() { @@ -90,18 +90,18 @@ function noteChanged() { async function reload() { // no saving here - await loadNoteDetail(getCurrentNoteId()); + await loadNoteDetail(getActiveNoteId()); } async function switchToNote(noteId) { - if (getCurrentNoteId() !== noteId) { + if (getActiveNoteId() !== noteId) { await saveNoteIfChanged(); await loadNoteDetail(noteId); } } -function getCurrentNoteContent() { +function getActiveNoteContent() { return getComponent().getContent(); } @@ -110,7 +110,7 @@ function onNoteChange(func) { } async function saveNote() { - const note = getCurrentNote(); + const note = getActiveNote(); if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) { return; @@ -119,7 +119,7 @@ async function saveNote() { note.title = $noteTitle.val(); if (note.noteContent != null) { // might be null for file/image - note.noteContent.content = getCurrentNoteContent(note); + note.noteContent.content = getActiveNoteContent(note); } // it's important to set the flag back to false immediatelly after retrieving title and content @@ -137,7 +137,7 @@ async function saveNote() { $savedIndicator.fadeIn(); // run async - bundleService.executeRelationBundles(getCurrentNote(), 'runOnNoteChange'); + bundleService.executeRelationBundles(getActiveNote(), 'runOnNoteChange'); } async function saveNoteIfChanged() { @@ -150,11 +150,11 @@ async function saveNoteIfChanged() { } function updateNoteView() { - $noteDetailWrapper.toggleClass("protected", currentNote.isProtected); - $protectButton.toggleClass("active", currentNote.isProtected); - $protectButton.prop("disabled", currentNote.isProtected); - $unprotectButton.toggleClass("active", !currentNote.isProtected); - $unprotectButton.prop("disabled", !currentNote.isProtected || !protectedSessionHolder.isProtectedSessionAvailable()); + $noteDetailWrapper.toggleClass("protected", activeNote.isProtected); + $protectButton.toggleClass("active", activeNote.isProtected); + $protectButton.prop("disabled", activeNote.isProtected); + $unprotectButton.toggleClass("active", !activeNote.isProtected); + $unprotectButton.prop("disabled", !activeNote.isProtected || !protectedSessionHolder.isProtectedSessionAvailable()); for (const clazz of Array.from($body[0].classList)) { // create copy to safely iterate over while removing classes if (clazz.startsWith("type-") || clazz.startsWith("mime-")) { @@ -162,14 +162,14 @@ function updateNoteView() { } } - $body.addClass(utils.getNoteTypeClass(currentNote.type)); - $body.addClass(utils.getMimeTypeClass(currentNote.mime)); + $body.addClass(utils.getNoteTypeClass(activeNote.type)); + $body.addClass(utils.getMimeTypeClass(activeNote.mime)); } async function handleProtectedSession() { - const newSessionCreated = await protectedSessionService.ensureProtectedSession(currentNote.isProtected, false); + const newSessionCreated = await protectedSessionService.ensureProtectedSession(activeNote.isProtected, false); - if (currentNote.isProtected) { + if (activeNote.isProtected) { protectedSessionHolder.touchProtectedSession(); } @@ -192,8 +192,8 @@ async function loadNoteDetail(noteId) { return; } - // only now that we're in sync with tree active node we will switch currentNote - currentNote = loadedNote; + // only now that we're in sync with tree active node we will switch activeNote + activeNote = loadedNote; if (utils.isDesktop()) { // needs to happen after loading the note itself because it references current noteId @@ -211,15 +211,15 @@ async function loadNoteDetail(noteId) { noteChangeDisabled = true; try { - $noteTitle.val(currentNote.title); + $noteTitle.val(activeNote.title); if (utils.isDesktop()) { - noteTypeService.setNoteType(currentNote.type); - noteTypeService.setNoteMime(currentNote.mime); + noteTypeService.setNoteType(activeNote.type); + noteTypeService.setNoteMime(activeNote.mime); } for (const componentType in components) { - if (componentType !== currentNote.type) { + if (componentType !== activeNote.type) { components[componentType].cleanup(); } } @@ -234,7 +234,7 @@ async function loadNoteDetail(noteId) { $noteTitle.removeAttr("readonly"); // this can be set by protected session service - await getComponent(currentNote.type).show(); + await getComponent(activeNote.type).show(); } finally { noteChangeDisabled = false; @@ -243,13 +243,13 @@ async function loadNoteDetail(noteId) { treeService.setBranchBackgroundBasedOnProtectedStatus(noteId); // after loading new note make sure editor is scrolled to the top - getComponent(currentNote.type).scrollToTop(); + getComponent(activeNote.type).scrollToTop(); fireDetailLoaded(); $scriptArea.empty(); - await bundleService.executeRelationBundles(getCurrentNote(), 'runOnNoteView'); + await bundleService.executeRelationBundles(getActiveNote(), 'runOnNoteView'); if (utils.isDesktop()) { await attributeService.showAttributes(); @@ -259,7 +259,7 @@ async function loadNoteDetail(noteId) { } async function showChildrenOverview() { - const note = getCurrentNote(); + const note = getActiveNote(); const attributes = await attributeService.getAttributes(); const hideChildrenOverview = attributes.some(attr => attr.type === 'label' && attr.name === 'hideChildrenOverview') || note.type === 'relation-map' @@ -273,7 +273,7 @@ async function showChildrenOverview() { $childrenOverview.empty(); - const notePath = treeService.getCurrentNotePath(); + const notePath = treeService.getActiveNotePath(); for (const childBranch of await note.getChildBranches()) { const link = $('', { @@ -317,7 +317,7 @@ function addDetailLoadedListener(noteId, callback) { function fireDetailLoaded() { for (const {noteId, callback} of detailLoadedListeners) { - if (noteId === currentNote.noteId) { + if (noteId === activeNote.noteId) { callback(); } } @@ -327,7 +327,7 @@ function fireDetailLoaded() { } messagingService.subscribeToSyncMessages(syncData => { - if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === getCurrentNoteId())) { + if (syncData.some(sync => sync.entityName === 'notes' && sync.entityId === getActiveNoteId())) { infoService.showMessage('Reloading note because of background changes'); reload(); @@ -339,7 +339,7 @@ $noteDetailWrapper.on("dragover", e => e.preventDefault()); $noteDetailWrapper.on("dragleave", e => e.preventDefault()); $noteDetailWrapper.on("drop", e => { - importDialog.uploadFiles(getCurrentNoteId(), e.originalEvent.dataTransfer.files, { + importDialog.uploadFiles(getActiveNoteId(), e.originalEvent.dataTransfer.files, { safeImport: true, shrinkImages: true, textImportedAsText: true, @@ -354,7 +354,7 @@ $(document).ready(() => { const title = $noteTitle.val(); - treeService.setNoteTitle(getCurrentNoteId(), title); + treeService.setNoteTitle(getActiveNoteId(), title); }); noteDetailText.focus(); @@ -371,10 +371,10 @@ export default { switchToNote, updateNoteView, loadNote, - getCurrentNote, - getCurrentNoteContent, - getCurrentNoteType, - getCurrentNoteId, + getActiveNote, + getActiveNoteContent, + getActiveNoteType, + getActiveNoteId, focusOnTitle, focusAndSelectTitle, saveNote, diff --git a/src/public/javascripts/services/note_detail_code.js b/src/public/javascripts/services/note_detail_code.js index e06e9e8db..a250f9010 100644 --- a/src/public/javascripts/services/note_detail_code.js +++ b/src/public/javascripts/services/note_detail_code.js @@ -44,14 +44,14 @@ async function show() { $component.show(); - const currentNote = noteDetailService.getCurrentNote(); + const activeNote = noteDetailService.getActiveNote(); // this needs to happen after the element is shown, otherwise the editor won't be refreshed // CodeMirror breaks pretty badly on null so even though it shouldn't happen (guarded by consistency check) // we provide fallback - codeEditor.setValue(currentNote.noteContent.content || ""); + codeEditor.setValue(activeNote.noteContent.content || ""); - const info = CodeMirror.findModeByMIME(currentNote.mime); + const info = CodeMirror.findModeByMIME(activeNote.mime); if (info) { codeEditor.setOption("mode", info.mime); @@ -71,21 +71,21 @@ function focus() { async function executeCurrentNote() { // ctrl+enter is also used elsewhere so make sure we're running only when appropriate - if (noteDetailService.getCurrentNoteType() !== 'code') { + if (noteDetailService.getActiveNoteType() !== 'code') { return; } // make sure note is saved so we load latest changes await noteDetailService.saveNoteIfChanged(); - const currentNote = noteDetailService.getCurrentNote(); + const activeNote = noteDetailService.getActiveNote(); - if (currentNote.mime.endsWith("env=frontend")) { - await bundleService.getAndExecuteBundle(noteDetailService.getCurrentNoteId()); + if (activeNote.mime.endsWith("env=frontend")) { + await bundleService.getAndExecuteBundle(noteDetailService.getActiveNoteId()); } - if (currentNote.mime.endsWith("env=backend")) { - await server.post('script/run/' + noteDetailService.getCurrentNoteId()); + if (activeNote.mime.endsWith("env=backend")) { + await server.post('script/run/' + noteDetailService.getActiveNoteId()); } infoService.showMessage("Note executed"); diff --git a/src/public/javascripts/services/note_detail_file.js b/src/public/javascripts/services/note_detail_file.js index 23f8e9f06..d8f044900 100644 --- a/src/public/javascripts/services/note_detail_file.js +++ b/src/public/javascripts/services/note_detail_file.js @@ -15,21 +15,21 @@ const $downloadButton = $("#file-download"); const $openButton = $("#file-open"); async function show() { - const currentNote = noteDetailService.getCurrentNote(); + const activeNote = noteDetailService.getActiveNote(); - const attributes = await server.get('notes/' + currentNote.noteId + '/attributes'); + const attributes = await server.get('notes/' + activeNote.noteId + '/attributes'); const attributeMap = utils.toObject(attributes, l => [l.name, l.value]); $component.show(); - $fileNoteId.text(currentNote.noteId); + $fileNoteId.text(activeNote.noteId); $fileName.text(attributeMap.originalFileName || "?"); $fileSize.text((attributeMap.fileSize || "?") + " bytes"); - $fileType.text(currentNote.mime); + $fileType.text(activeNote.mime); - if (currentNote.noteContent && currentNote.noteContent.content) { + if (activeNote.noteContent && activeNote.noteContent.content) { $previewRow.show(); - $previewContent.text(currentNote.noteContent.content); + $previewContent.text(activeNote.noteContent.content); } else { $previewRow.hide(); @@ -51,7 +51,7 @@ $openButton.click(() => { function getFileUrl() { // electron needs absolute URL so we extract current host, port, protocol - return utils.getHost() + "/api/notes/" + noteDetailService.getCurrentNoteId(); + return utils.getHost() + "/api/notes/" + noteDetailService.getActiveNoteId(); } export default { diff --git a/src/public/javascripts/services/note_detail_image.js b/src/public/javascripts/services/note_detail_image.js index 8e5769a74..0202080d0 100644 --- a/src/public/javascripts/services/note_detail_image.js +++ b/src/public/javascripts/services/note_detail_image.js @@ -15,18 +15,18 @@ const $fileType = $("#image-filetype"); const $fileSize = $("#image-filesize"); async function show() { - const currentNote = noteDetailService.getCurrentNote(); + const activeNote = noteDetailService.getActiveNote(); - const attributes = await server.get('notes/' + currentNote.noteId + '/attributes'); + const attributes = await server.get('notes/' + activeNote.noteId + '/attributes'); const attributeMap = utils.toObject(attributes, l => [l.name, l.value]); $component.show(); $fileName.text(attributeMap.originalFileName || "?"); $fileSize.text((attributeMap.fileSize || "?") + " bytes"); - $fileType.text(currentNote.mime); + $fileType.text(activeNote.mime); - $imageView.prop("src", `api/images/${currentNote.noteId}/${currentNote.title}`); + $imageView.prop("src", `api/images/${activeNote.noteId}/${activeNote.title}`); } $imageDownloadButton.click(() => utils.download(getFileUrl())); @@ -62,7 +62,7 @@ $copyToClipboardButton.click(() => { function getFileUrl() { // electron needs absolute URL so we extract current host, port, protocol - return utils.getHost() + "/api/notes/" + noteDetailService.getCurrentNoteId() + "/download"; + return utils.getHost() + "/api/notes/" + noteDetailService.getActiveNoteId() + "/download"; } export default { diff --git a/src/public/javascripts/services/note_detail_relation_map.js b/src/public/javascripts/services/note_detail_relation_map.js index 2835a94ce..d2a762fb2 100644 --- a/src/public/javascripts/services/note_detail_relation_map.js +++ b/src/public/javascripts/services/note_detail_relation_map.js @@ -79,7 +79,7 @@ const linkOverlays = [ ]; function loadMapData() { - const currentNote = noteDetailService.getCurrentNote(); + const activeNote = noteDetailService.getActiveNote(); mapData = { notes: [], // it is important to have this exact value here so that initial transform is same as this @@ -93,9 +93,9 @@ function loadMapData() { } }; - if (currentNote.noteContent.content) { + if (activeNote.noteContent.content) { try { - mapData = JSON.parse(currentNote.noteContent.content); + mapData = JSON.parse(activeNote.noteContent.content); } catch (e) { console.log("Could not parse content: ", e); } @@ -507,7 +507,7 @@ $createChildNote.click(async () => { return; } - const {note} = await server.post(`notes/${noteDetailService.getCurrentNoteId()}/children`, { + const {note} = await server.post(`notes/${noteDetailService.getActiveNoteId()}/children`, { title, target: 'into' }); diff --git a/src/public/javascripts/services/note_detail_render.js b/src/public/javascripts/services/note_detail_render.js index ce1735667..e37d4f4ef 100644 --- a/src/public/javascripts/services/note_detail_render.js +++ b/src/public/javascripts/services/note_detail_render.js @@ -26,7 +26,7 @@ async function render() { $noteDetailRenderContent.append(bundle.html); - await bundleService.executeBundle(bundle, noteDetailService.getCurrentNote()); + await bundleService.executeBundle(bundle, noteDetailService.getActiveNote()); } } diff --git a/src/public/javascripts/services/note_detail_search.js b/src/public/javascripts/services/note_detail_search.js index ef7466664..9ee52c9a6 100644 --- a/src/public/javascripts/services/note_detail_search.js +++ b/src/public/javascripts/services/note_detail_search.js @@ -9,10 +9,10 @@ const $refreshButton = $('#note-detail-search-refresh-results-button'); function show() { $component.show(); - console.log(noteDetailService.getCurrentNote()); + console.log(noteDetailService.getActiveNote()); try { - const json = JSON.parse(noteDetailService.getCurrentNote().noteContent.content); + const json = JSON.parse(noteDetailService.getActiveNote().noteContent.content); $searchString.val(json.searchString); } diff --git a/src/public/javascripts/services/note_detail_text.js b/src/public/javascripts/services/note_detail_text.js index 512f68c64..3adb34064 100644 --- a/src/public/javascripts/services/note_detail_text.js +++ b/src/public/javascripts/services/note_detail_text.js @@ -31,7 +31,7 @@ async function show() { $component.show(); - textEditor.setData(noteDetailService.getCurrentNote().noteContent.content); + textEditor.setData(noteDetailService.getActiveNote().noteContent.content); } function getContent() { diff --git a/src/public/javascripts/services/note_type.js b/src/public/javascripts/services/note_type.js index 7d21c851b..b54ba3436 100644 --- a/src/public/javascripts/services/note_type.js +++ b/src/public/javascripts/services/note_type.js @@ -97,7 +97,7 @@ function NoteTypeModel() { }; async function save() { - const note = noteDetailService.getCurrentNote(); + const note = noteDetailService.getActiveNote(); await server.put('notes/' + note.noteId + '/type/' + encodeURIComponent(self.type()) @@ -112,7 +112,7 @@ function NoteTypeModel() { } function confirmChangeIfContent() { - if (!noteDetailService.getCurrentNoteContent()) { + if (!noteDetailService.getActiveNoteContent()) { return true; } diff --git a/src/public/javascripts/services/protected_session.js b/src/public/javascripts/services/protected_session.js index 1388dd0d1..5921d32bc 100644 --- a/src/public/javascripts/services/protected_session.js +++ b/src/public/javascripts/services/protected_session.js @@ -112,13 +112,13 @@ async function enterProtectedSessionOnServer(password) { } async function protectNoteAndSendToServer() { - if (noteDetailService.getCurrentNote().isProtected) { + if (noteDetailService.getActiveNote().isProtected) { return; } await ensureProtectedSession(true, true); - const note = noteDetailService.getCurrentNote(); + const note = noteDetailService.getActiveNote(); note.isProtected = true; await noteDetailService.saveNote(note); @@ -129,10 +129,10 @@ async function protectNoteAndSendToServer() { } async function unprotectNoteAndSendToServer() { - const currentNote = noteDetailService.getCurrentNote(); + const activeNote = noteDetailService.getActiveNote(); - if (!currentNote.isProtected) { - infoService.showAndLogError(`Note ${currentNote.noteId} is not protected`); + if (!activeNote.isProtected) { + infoService.showAndLogError(`Note ${activeNote.noteId} is not protected`); return; } @@ -146,11 +146,11 @@ async function unprotectNoteAndSendToServer() { return; } - currentNote.isProtected = false; + activeNote.isProtected = false; - await noteDetailService.saveNote(currentNote); + await noteDetailService.saveNote(activeNote); - treeService.setProtected(currentNote.noteId, currentNote.isProtected); + treeService.setProtected(activeNote.noteId, activeNote.isProtected); noteDetailService.updateNoteView(); } diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index ebb7f9922..42b128848 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -39,7 +39,7 @@ function getCurrentNode() { return $tree.fancytree("getActiveNode"); } -function getCurrentNotePath() { +function getActiveNotePath() { const node = getCurrentNode(); return treeUtils.getNotePath(node); @@ -330,7 +330,7 @@ async function setExpandedToServer(branchId, isExpanded) { function addRecentNote(branchId, notePath) { setTimeout(async () => { // we include the note into recent list only if the user stayed on the note at least 5 seconds - if (notePath && notePath === getCurrentNotePath()) { + if (notePath && notePath === getActiveNotePath()) { await server.post('recent-notes', { branchId, notePath }); } }, 1500); @@ -339,12 +339,12 @@ function addRecentNote(branchId, notePath) { function setCurrentNotePathToHash(node) { utils.assertArguments(node); - const currentNotePath = treeUtils.getNotePath(node); + const activeNotePath = treeUtils.getNotePath(node); const currentBranchId = node.data.branchId; - document.location.hash = currentNotePath; + document.location.hash = activeNotePath; - addRecentNote(currentBranchId, currentNotePath); + addRecentNote(currentBranchId, activeNotePath); } function getSelectedNodes(stopOnParents = false) { @@ -563,7 +563,7 @@ async function createNote(node, parentNoteId, target, isProtected, saveSelection isProtected = false; } - if (noteDetailService.getCurrentNoteType() !== 'text') { + if (noteDetailService.getActiveNoteType() !== 'text') { saveSelection = false; } else { @@ -714,7 +714,7 @@ $(window).bind('hashchange', function() { if (isNotePathInAddress()) { const notePath = getHashValueFromAddress(); - if (notePath !== '-' && getCurrentNotePath() !== notePath) { + if (notePath !== '-' && getActiveNotePath() !== notePath) { console.debug("Switching to " + notePath + " because of hash change"); activateNote(notePath); @@ -738,7 +738,7 @@ export default { activateNote, getFocusedNode, getCurrentNode, - getCurrentNotePath, + getActiveNotePath, setCurrentNotePathToHash, setNoteTitle, setPrefix, diff --git a/src/routes/api/autocomplete.js b/src/routes/api/autocomplete.js index aec46a188..5b7d326ae 100644 --- a/src/routes/api/autocomplete.js +++ b/src/routes/api/autocomplete.js @@ -8,14 +8,14 @@ const optionService = require('../../services/options'); async function getAutocomplete(req) { const query = req.query.query; - const currentNoteId = req.query.currentNoteId || 'none'; + const activeNoteId = req.query.activeNoteId || 'none'; let results; const timestampStarted = Date.now(); if (query.trim().length === 0) { - results = await getRecentNotes(currentNoteId); + results = await getRecentNotes(activeNoteId); } else { results = await noteCacheService.findNotes(query); @@ -30,7 +30,7 @@ async function getAutocomplete(req) { return results; } -async function getRecentNotes(currentNoteId) { +async function getRecentNotes(activeNoteId) { let extraCondition = ''; const hoistedNoteId = await optionService.getOption('hoistedNoteId'); @@ -51,7 +51,7 @@ async function getRecentNotes(currentNoteId) { ${extraCondition} ORDER BY utcDateCreated DESC - LIMIT 200`, [currentNoteId]); + LIMIT 200`, [activeNoteId]); return recentNotes.map(rn => { const title = noteCacheService.getNoteTitleForPath(rn.notePath.split('/')); diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index c5a997827..a172980b8 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -22,7 +22,7 @@ const appInfo = require('./app_info'); function BackendScriptApi(currentNote, apiParams) { /** @property {Note} note where script started executing */ this.startNote = apiParams.startNote; - /** @property {Note} note where script is currently executing */ + /** @property {Note} note where script is currently executing. Don't mix this up with concept of active note */ this.currentNote = currentNote; /** @property {Entity} entity whose event triggered this executions */ this.originEntity = apiParams.originEntity;