Files
Trilium/src/public/javascripts/services/note_detail.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

import server from './server.js';
2019-08-26 20:21:43 +02:00
import ws from "./ws.js";
2018-03-25 23:25:17 -04:00
import treeCache from "./tree_cache.js";
import NoteFull from "../entities/note_full.js";
2020-01-12 11:15:23 +01:00
import appContext from "./app_context.js";
2019-05-05 10:59:34 +02:00
function getActiveEditor() {
2020-01-12 12:37:44 +01:00
const activeTabContext = appContext.getActiveTabContext();
if (activeTabContext && activeTabContext.note && activeTabContext.note.type === 'text') {
return activeTabContext.getComponent().getEditor();
}
else {
return null;
}
}
async function loadNote(noteId) {
const row = await server.get('notes/' + noteId);
2019-10-26 09:51:08 +02:00
const noteShort = await treeCache.getNote(noteId);
return new NoteFull(treeCache, row, noteShort);
}
function focusOnTitle() {
2020-01-24 17:54:47 +01:00
appContext.trigger('focusOnTitle');
}
function focusAndSelectTitle() {
2020-01-24 17:54:47 +01:00
appContext.trigger('focusAndSelectTitle');
}
2019-08-26 20:21:43 +02:00
ws.subscribeToOutsideSyncMessages(syncData => {
const noteIdsToRefresh = new Set();
syncData
.filter(sync => sync.entityName === 'notes')
.forEach(sync => noteIdsToRefresh.add(sync.entityId));
// we need to reload because of promoted attributes
syncData
.filter(sync => sync.entityName === 'attributes')
.forEach(sync => noteIdsToRefresh.add(sync.noteId));
2020-01-19 21:24:14 +01:00
// FIXME
for (const noteId of noteIdsToRefresh) {
2020-01-12 12:30:30 +01:00
appContext.refreshTabs(null, noteId);
}
});
2019-06-12 19:59:52 +02:00
function noteChanged() {
2020-01-12 12:37:44 +01:00
const activeTabContext = appContext.getActiveTabContext();
2019-06-12 19:59:52 +02:00
if (activeTabContext) {
activeTabContext.noteChanged();
}
}
// this makes sure that when user e.g. reloads the page or navigates away from the page, the note's content is saved
// this sends the request asynchronously and doesn't wait for result
2020-01-19 21:40:23 +01:00
// FIXME
2020-01-19 22:05:45 +01:00
$(window).on('beforeunload', () => {
//saveNotesIfChanged();
});
export default {
loadNote,
focusOnTitle,
focusAndSelectTitle,
getActiveEditor,
2020-01-24 17:54:47 +01:00
noteChanged
};