diff --git a/src/public/javascripts/services/branches.js b/src/public/javascripts/services/branches.js
index 55f59cafa..9f9a79c58 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.js
index aa2384b86..201210829 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.js
index 942387978..9181bbfbf 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.js
index 6227e0c9c..c9df86980 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.js
index d8b11d92f..0c691afe9 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.js
index f8fbbd574..9f66d9446 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.js
index b2c7a8b53..4299a84c0 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.js
index 920c1727b..9d243d39a 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.js
index ff053b9d3..ff57fe56e 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.js
index 8caa6a602..a28ec7b45 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: $("
").text(this.tabContext.note && this.tabContext.note.title).prop('outerHTML') ,
+ header: $("").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.js
index c5249f785..ea796842e 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.js
index 17d51c9eb..c3d0ac262 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.js
index 6ef8f900e..348dd0d1c 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 file
diff --git a/src/public/javascripts/widgets/similar_notes.js b/src/public/javascripts/widgets/similar_notes.js
index 5d6946d42..22095b40f 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 notes
this.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.js
index b50fe7b31..e44d4c133 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 = $('
')
.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.js
index c08db8bf8..90c0b4287 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.js
index e8113119f..ac84fc6ed 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.js
index 6e5261078..12be5bdd0 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.js
index cba4eb01e..2780018ef 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.js
index d6fc86ab0..4dc55596d 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.js
index 1cb506879..97fadb559 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.js
index cd3f4c2ef..d5fc2ea17 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($("
").text(`${targetRelations.length - i} more links ...`))
+ $list.append($("").text(`${targetRelations.length - i} more links ...`));
}
this.$body.empty().append($list);