Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
various fixes and small refactorings
zadamb757dfcf79c3
diff --git a/src/public/javascripts/services/branches.js b/src/public/javascripts/services/branches.jsindex 55f59cafa6..9f9a79c58d 100644--- a/src/public/javascripts/services/branches.js+++ b/src/public/javascripts/services/branches.js@@ -67,23 +67,6 @@ async function moveToParentNote(branchIdsToMove, newParentNoteId) {}}-// FIXME used for finding a next note to activate after a delete-async function getNextNode(nodes) {- // following code assumes that nodes contain only top-most selected nodes - getSelectedNodes has been- // called with stopOnParent=true- let next = nodes[nodes.length - 1].getNextSibling();-- if (!next) {- next = nodes[0].getPrevSibling();- }-- if (!next && !await hoistedNoteService.isRootNode(nodes[0])) {- next = nodes[0].getParent();- }-- return treeService.getNotePath(next);-}-async function deleteNodes(branchIdsToDelete) {branchIdsToDelete = await filterRootNote(branchIdsToDelete);@@ -132,24 +115,14 @@ async function deleteNodes(branchIdsToDelete) {if (deleteClones) {await server.remove(`notes/${branch.noteId}` + query);-- // FIXME- noteDetailService.noteDeleted(branch.noteId);}else {- const {noteDeleted} = await server.remove(`branches/${branchIdToDelete}` + query);-- if (noteDeleted) {- // FIXME- noteDetailService.noteDeleted(branch.noteId);- }+ await server.remove(`branches/${branchIdToDelete}` + query);}}const noteIds = Array.from(new Set(nodes.map(node => node.getParent().data.noteId)));- appContext.trigger('reloadNotes', {noteIds});-return true;}diff --git a/src/public/javascripts/services/cloning.js b/src/public/javascripts/services/cloning.jsindex aa2384b867..2012108290 100644--- a/src/public/javascripts/services/cloning.js+++ b/src/public/javascripts/services/cloning.js@@ -9,10 +9,7 @@ async function cloneNoteTo(childNoteId, parentNoteId, prefix) {if (!resp.success) {alert(resp.message);- return;}-- appContext.trigger('reloadNotes', {noteIds: [childNoteId, parentNoteId]});}// beware that first arg is noteId and second is branchId!@@ -25,8 +22,6 @@ async function cloneNoteAfter(noteId, afterBranchId) {}const afterBranch = treeCache.getBranch(afterBranchId);-- appContext.trigger('reloadNotes', {noteIds: [noteId, afterBranch.parentNoteId]});}export default {diff --git a/src/public/javascripts/services/import.js b/src/public/javascripts/services/import.jsindex 942387978f..9181bbfbf8 100644--- a/src/public/javascripts/services/import.js+++ b/src/public/javascripts/services/import.js@@ -64,8 +64,6 @@ ws.subscribeToMessages(async message => {toastService.showPersistent(toast);- appContext.trigger('reloadNotes', {noteIds: [message.result.parentNoteId]});-if (message.result.importedNoteId) {await appContext.getActiveTabContext.setNote(message.result.importedNoteId);}diff --git a/src/public/javascripts/services/render.js b/src/public/javascripts/services/render.jsindex 6227e0c9c6..c9df86980a 100644--- a/src/public/javascripts/services/render.js+++ b/src/public/javascripts/services/render.js@@ -1,7 +1,7 @@import server from "./server.js";import bundleService from "./bundle.js";-async function render(note, $el, ctx) {+async function render(note, $el, tabContext) {const relations = await note.getRelations('renderNote');const renderNoteIds = relations.map(rel => rel.value)@@ -18,7 +18,7 @@ async function render(note, $el, ctx) {$scriptContainer.append(bundle.html);// async so that scripts cannot block trilium execution- bundleService.executeBundle(bundle, note, ctx, $scriptContainer);+ bundleService.executeBundle(bundle, note, tabContext, $scriptContainer);}return renderNoteIds.length > 0;diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.jsindex d8b11d92f6..0c691afe9d 100644--- a/src/public/javascripts/services/tab_context.js+++ b/src/public/javascripts/services/tab_context.js@@ -49,6 +49,8 @@ class TabContext extends Component {await this.trigger('beforeNoteSwitch', {tabId: this.tabId}, true);+ utils.closeActiveDialog();+this.notePath = notePath;this.noteId = treeService.getNoteIdFromNotePath(notePath);diff --git a/src/public/javascripts/widgets/attributes.js b/src/public/javascripts/widgets/attributes.jsindex f8fbbd5746..9f66d9446a 100644--- a/src/public/javascripts/widgets/attributes.js+++ b/src/public/javascripts/widgets/attributes.js@@ -35,7 +35,7 @@ export default class AttributesWidget extends CollapsibleWidget {.text("+show inherited").on('click', async () => {const attributes = await note.getAttributes();- const inheritedAttributes = attributes.filter(attr => attr.noteId !== this.tabContext.note.noteId);+ const inheritedAttributes = attributes.filter(attr => attr.noteId !== this.noteId);if (inheritedAttributes.length === 0) {$inheritedAttrs.text("No inherited attributes yet...");diff --git a/src/public/javascripts/widgets/calendar.js b/src/public/javascripts/widgets/calendar.jsindex b2c7a8b530..4299a84c0b 100644--- a/src/public/javascripts/widgets/calendar.js+++ b/src/public/javascripts/widgets/calendar.js@@ -2,7 +2,6 @@ import CollapsibleWidget from "./collapsible_widget.js";import libraryLoader from "../services/library_loader.js";import utils from "../services/utils.js";import dateNoteService from "../services/date_notes.js";-import treeService from "../services/tree.js";import server from "../services/server.js";import appContext from "../services/app_context.js";@@ -30,7 +29,7 @@ export default class CalendarWidget extends CollapsibleWidget {async isEnabled() {return await super.isEnabled()- && this.tabContext.note.hasOwnedLabel("dateNote");+ && this.note.hasOwnedLabel("dateNote");}async doRenderBody() {diff --git a/src/public/javascripts/widgets/edited_notes.js b/src/public/javascripts/widgets/edited_notes.jsindex 920c1727bb..9d243d39ad 100644--- a/src/public/javascripts/widgets/edited_notes.js+++ b/src/public/javascripts/widgets/edited_notes.js@@ -16,7 +16,7 @@ export default class EditedNotesWidget extends CollapsibleWidget {async isEnabled() {return await super.isEnabled()- && await this.tabContext.note.hasLabel("dateNote");+ && await this.note.hasOwnedLabel("dateNote");}async refreshWithNote(note) {diff --git a/src/public/javascripts/widgets/note_actions.js b/src/public/javascripts/widgets/note_actions.jsindex ff053b9d33..ff57fe56e5 100644--- a/src/public/javascripts/widgets/note_actions.js+++ b/src/public/javascripts/widgets/note_actions.js@@ -34,7 +34,7 @@ export default class NoteActionsWidget extends TabAwareWidget {});this.$importNoteButton = this.$widget.find('.import-files-button');- this.$importNoteButton.on("click", () => import('../dialogs/import.js').then(d => d.showDialog(this.tabContext.note.noteId)));+ this.$importNoteButton.on("click", () => import('../dialogs/import.js').then(d => d.showDialog(this.noteId)));return this.$widget;}diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.jsindex 8caa6a602f..a28ec7b453 100644--- a/src/public/javascripts/widgets/note_detail.js+++ b/src/public/javascripts/widgets/note_detail.js@@ -112,7 +112,7 @@ export default class NoteDetailWidget extends TabAwareWidget {}}- const note = this.tabContext.note;+ const note = this.note;if (note) {this.$widget.addClass(note.cssClass);@@ -144,7 +144,7 @@ export default class NoteDetailWidget extends TabAwareWidget {}async getWidgetType() {- const note = this.tabContext.note;+ const note = this.note;if (!note) {return "empty";@@ -199,7 +199,7 @@ export default class NoteDetailWidget extends TabAwareWidget {await libraryLoader.requireLibrary(libraryLoader.PRINT_THIS);this.$widget.find('.note-detail-printable:visible').printThis({- header: $("<h2>").text(this.tabContext.note && this.tabContext.note.title).prop('outerHTML') ,+ header: $("<h2>").text(this.note && this.note.title).prop('outerHTML') ,importCSS: false,loadCSS: ["libraries/codemirror/codemirror.css",diff --git a/src/public/javascripts/widgets/note_title.js b/src/public/javascripts/widgets/note_title.jsindex c5249f7854..ea796842e3 100644--- a/src/public/javascripts/widgets/note_title.js+++ b/src/public/javascripts/widgets/note_title.js@@ -30,10 +30,9 @@ export default class NoteTitleWidget extends TabAwareWidget {super(appContext);this.spacedUpdate = new SpacedUpdate(async () => {- const noteId = this.tabContext.note.noteId;const title = this.$noteTitle.val();- await server.put(`notes/${noteId}/change-title`, {title});+ await server.put(`notes/${this.noteId}/change-title`, {title});});}diff --git a/src/public/javascripts/widgets/note_type.js b/src/public/javascripts/widgets/note_type.jsindex 17d51c9eb8..c3d0ac2628 100644--- a/src/public/javascripts/widgets/note_type.js+++ b/src/public/javascripts/widgets/note_type.js@@ -67,7 +67,7 @@ export default class NoteTypeWidget extends TabAwareWidget {this.save(noteType.type, noteType.mime);});- if (this.tabContext.note.type === noteType.type) {+ if (this.note.type === noteType.type) {$typeLink.addClass("selected");}@@ -93,7 +93,7 @@ export default class NoteTypeWidget extends TabAwareWidget {this.save('code', $link.attr('data-mime-type'))});- if (this.tabContext.note.type === 'code' && this.tabContext.note.mime === mimeType.mime) {+ if (this.note.type === 'code' && this.note.mime === mimeType.mime) {$mimeLink.addClass("selected");this.$noteTypeDesc.text(mimeType.title);@@ -118,11 +118,11 @@ export default class NoteTypeWidget extends TabAwareWidget {}async save(type, mime) {- if (type !== this.tabContext.note.type && !await this.confirmChangeIfContent()) {+ if (type !== this.note.type && !await this.confirmChangeIfContent()) {return;}- await server.put('notes/' + this.tabContext.note.noteId+ await server.put('notes/' + this.noteId+ '/type/' + encodeURIComponent(type)+ '/mime/' + encodeURIComponent(mime));diff --git a/src/public/javascripts/widgets/promoted_attributes.js b/src/public/javascripts/widgets/promoted_attributes.jsindex 6ef8f900e2..348dd0d1cf 100644--- a/src/public/javascripts/widgets/promoted_attributes.js+++ b/src/public/javascripts/widgets/promoted_attributes.js@@ -224,7 +224,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget {.prop("title", "Remove this attribute").on('click', async () => {if (valueAttr.attributeId) {- await server.remove("notes/" + this.tabContext.note.noteId + "/attributes/" + valueAttr.attributeId);+ await server.remove("notes/" + this.noteId + "/attributes/" + valueAttr.attributeId);}$tr.remove();@@ -253,7 +253,7 @@ export default class PromotedAttributesWidget extends TabAwareWidget {value = $attr.val();}- const result = await server.put(`notes/${this.tabContext.note.noteId}/attribute`, {+ const result = await server.put(`notes/${this.noteId}/attribute`, {attributeId: $attr.prop("attribute-id"),type: $attr.prop("attribute-type"),name: $attr.prop("attribute-name"),@@ -261,13 +261,5 @@ export default class PromotedAttributesWidget extends TabAwareWidget {});$attr.prop("attribute-id", result.attributeId);-- // FIXME- // animate only if it's not being animated already, this is important especially for e.g. number inputs- // which can be changed many times in a second by clicking on higher/lower buttons.- // if (this.$savedIndicator.queue().length === 0) {- // this.$savedIndicator.fadeOut();- // this.$savedIndicator.fadeIn();- // }}}\ No newline at end of filediff --git a/src/public/javascripts/widgets/similar_notes.js b/src/public/javascripts/widgets/similar_notes.jsindex 5d6946d421..22095b40f1 100644--- a/src/public/javascripts/widgets/similar_notes.js+++ b/src/public/javascripts/widgets/similar_notes.js@@ -32,7 +32,7 @@ export default class SimilarNotesWidget extends CollapsibleWidget {// remember which title was when we found the similar notesthis.title = note.title;- const similarNotes = await server.get('similar-notes/' + this.tabContext.note.noteId);+ const similarNotes = await server.get('similar-notes/' + this.noteId);if (similarNotes.length === 0) {this.$body.text("No similar notes found ...");diff --git a/src/public/javascripts/widgets/type_widgets/book.js b/src/public/javascripts/widgets/type_widgets/book.jsindex b50fe7b31a..e44d4c1338 100644--- a/src/public/javascripts/widgets/type_widgets/book.js+++ b/src/public/javascripts/widgets/type_widgets/book.js@@ -230,7 +230,7 @@ export default class BookTypeWidget extends TypeWidget {return;}- const childNotePath = this.tabContext.notePath + '/' + childNote.noteId;+ const childNotePath = this.notePath + '/' + childNote.noteId;const $content = $('<div class="note-book-content">').css("max-height", ZOOMS[this.zoomLevel].height);@@ -271,7 +271,7 @@ export default class BookTypeWidget extends TypeWidget {/** @return {boolean} true if this is "auto book" activated (empty text note) and not explicit book note */isAutoBook() {- return this.tabContext.note.type !== 'book';+ return this.note.type !== 'book';}getDefaultZoomLevel() {diff --git a/src/public/javascripts/widgets/type_widgets/code.js b/src/public/javascripts/widgets/type_widgets/code.jsindex c08db8bf8c..90c0b4287d 100644--- a/src/public/javascripts/widgets/type_widgets/code.js+++ b/src/public/javascripts/widgets/type_widgets/code.js@@ -107,20 +107,19 @@ export default class CodeTypeWidget extends TypeWidget {async executeCurrentNote() {// ctrl+enter is also used elsewhere so make sure we're running only when appropriate- if (this.tabContext.note.type !== 'code') {+ if (this.note.type !== 'code') {return;}// make sure note is saved so we load latest changes- // FIXME- await noteDetailService.saveNotesIfChanged();+ await this.spacedUpdate.updateNowIfNecessary();- if (this.tabContext.note.mime.endsWith("env=frontend")) {- await bundleService.getAndExecuteBundle(this.tabContext.note.noteId);+ if (this.note.mime.endsWith("env=frontend")) {+ await bundleService.getAndExecuteBundle(this.noteId);}- if (this.tabContext.note.mime.endsWith("env=backend")) {- await server.post('script/run/' + this.tabContext.note.noteId);+ if (this.note.mime.endsWith("env=backend")) {+ await server.post('script/run/' + this.noteId);}toastService.showMessage("Note executed");diff --git a/src/public/javascripts/widgets/type_widgets/file.js b/src/public/javascripts/widgets/type_widgets/file.jsindex e8113119fe..ac84fc6edb 100644--- a/src/public/javascripts/widgets/type_widgets/file.js+++ b/src/public/javascripts/widgets/type_widgets/file.js@@ -94,7 +94,7 @@ export default class FileTypeWidget extends TypeWidget {formData.append('upload', fileToUpload);const result = await $.ajax({- url: baseApiUrl + 'notes/' + this.tabContext.note.noteId + '/file',+ url: baseApiUrl + 'notes/' + this.noteId + '/file',headers: server.getHeaders(),data: formData,type: 'PUT',@@ -106,7 +106,7 @@ export default class FileTypeWidget extends TypeWidget {if (result.uploaded) {toastService.showMessage("New file revision has been uploaded.");- // FIXME reload+ this.refresh();}else {toastService.showError("Upload of a new file revision failed.");@@ -142,7 +142,7 @@ export default class FileTypeWidget extends TypeWidget {}getFileUrl() {- return utils.getUrlForDownload("api/notes/" + this.tabContext.note.noteId + "/download");+ return utils.getUrlForDownload("api/notes/" + this.noteId + "/download");}getContent() {}diff --git a/src/public/javascripts/widgets/type_widgets/image.js b/src/public/javascripts/widgets/type_widgets/image.jsindex 6e52610786..12be5bdd03 100644--- a/src/public/javascripts/widgets/type_widgets/image.js+++ b/src/public/javascripts/widgets/type_widgets/image.js@@ -97,7 +97,7 @@ class ImageTypeWidget extends TypeWidget {formData.append('upload', fileToUpload);const result = await $.ajax({- url: baseApiUrl + 'images/' + this.tabContext.note.noteId,+ url: baseApiUrl + 'images/' + this.noteId,headers: server.getHeaders(),data: formData,type: 'PUT',@@ -111,8 +111,7 @@ class ImageTypeWidget extends TypeWidget {await utils.clearBrowserCache();- // FIXME- await noteDetailService.reload();+ this.refresh();}else {toastService.showError("Upload of a new image revision failed: " + result.message);@@ -146,7 +145,7 @@ class ImageTypeWidget extends TypeWidget {}getFileUrl() {- return utils.getUrlForDownload(`api/notes/${this.tabContext.note.noteId}/download`);+ return utils.getUrlForDownload(`api/notes/${this.noteId}/download`);}getContent() {}diff --git a/src/public/javascripts/widgets/type_widgets/relation_map.js b/src/public/javascripts/widgets/type_widgets/relation_map.jsindex cba4eb01ed..2780018efa 100644--- a/src/public/javascripts/widgets/type_widgets/relation_map.js+++ b/src/public/javascripts/widgets/type_widgets/relation_map.js@@ -157,7 +157,7 @@ export default class RelationMapTypeWidget extends TypeWidget {return;}- const {note} = await server.post(`notes/${this.tabContext.note.noteId}/children?target=into`, {+ const {note} = await server.post(`notes/${this.noteId}/children?target=into`, {title,content: '',type: 'text'@@ -519,7 +519,7 @@ export default class RelationMapTypeWidget extends TypeWidget {}saveData() {- this.tabContext.noteChanged();+ this.spacedUpdate.scheduleUpdate();}async createNoteBox(noteId, title, x, y) {diff --git a/src/public/javascripts/widgets/type_widgets/render.js b/src/public/javascripts/widgets/type_widgets/render.jsindex d6fc86ab05..4dc55596d5 100644--- a/src/public/javascripts/widgets/type_widgets/render.js+++ b/src/public/javascripts/widgets/type_widgets/render.js@@ -30,8 +30,7 @@ export default class RenderTypeWidget extends TypeWidget {this.$widget.show();this.$noteDetailRenderHelp.hide();- // FIXME this.ctx- const renderNotesFound = await renderService.render(note, this.$noteDetailRenderContent, this.ctx);+ const renderNotesFound = await renderService.render(note, this.$noteDetailRenderContent, this.tabContext);if (!renderNotesFound) {this.$noteDetailRenderHelp.show();diff --git a/src/public/javascripts/widgets/type_widgets/search.js b/src/public/javascripts/widgets/type_widgets/search.jsindex 1cb506879f..97fadb5599 100644--- a/src/public/javascripts/widgets/type_widgets/search.js+++ b/src/public/javascripts/widgets/type_widgets/search.js@@ -29,8 +29,7 @@ export default class SearchTypeWidget extends TypeWidget {this.$refreshButton = this.$widget.find('.note-detail-search-refresh-results-button');this.$refreshButton.on('click', async () => {- // FIXME- await noteDetailService.saveNotesIfChanged();+ await this.spacedUpdate.updateNowIfNecessary();await searchNotesService.refreshSearch();});diff --git a/src/public/javascripts/widgets/what_links_here.js b/src/public/javascripts/widgets/what_links_here.jsindex cd3f4c2ef5..d5fc2ea179 100644--- a/src/public/javascripts/widgets/what_links_here.js+++ b/src/public/javascripts/widgets/what_links_here.js@@ -22,8 +22,8 @@ export default class WhatLinksHereWidget extends CollapsibleWidget {return [$showFullButton];}- async refreshWithNote() {- const targetRelations = this.tabContext.note.getTargetRelations();+ async refreshWithNote(note) {+ const targetRelations = note.getTargetRelations();if (targetRelations.length === 0) {this.$body.text("Nothing links here yet ...");@@ -44,7 +44,7 @@ export default class WhatLinksHereWidget extends CollapsibleWidget {}if (i < targetRelations.length) {- $list.append($("<li>").text(`${targetRelations.length - i} more links ...`))+ $list.append($("<li>").text(`${targetRelations.length - i} more links ...`));}this.$body.empty().append($list);