mirror of
https://github.com/zadam/trilium.git
synced 2025-06-05 17:38:47 +02:00
refactoring/cleanup
This commit is contained in:
parent
ff5ea8b311
commit
3fe9218ea8
@ -257,12 +257,6 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
|
||||
*/
|
||||
this.createNoteLink = linkService.createNoteLink;
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @returns {string} content of active note (loaded into right pane)
|
||||
*/
|
||||
this.getActiveNoteContent = noteDetailService.getActiveNoteContent;
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @returns {NoteFull} active note (loaded into right pane)
|
||||
|
@ -17,24 +17,6 @@ const $savedIndicator = $(".saved-indicator");
|
||||
|
||||
let detailLoadedListeners = [];
|
||||
|
||||
/** @return {NoteFull} */
|
||||
function getActiveNote() {
|
||||
const activeContext = getActiveTabContext();
|
||||
return activeContext ? activeContext.note : null;
|
||||
}
|
||||
|
||||
function getActiveNoteId() {
|
||||
const activeNote = getActiveNote();
|
||||
|
||||
return activeNote ? activeNote.noteId : null;
|
||||
}
|
||||
|
||||
function getActiveNoteType() {
|
||||
const activeNote = getActiveNote();
|
||||
|
||||
return activeNote ? activeNote.type : null;
|
||||
}
|
||||
|
||||
async function reload() {
|
||||
// no saving here
|
||||
|
||||
@ -67,10 +49,6 @@ async function switchToNote(notePath) {
|
||||
openTabsChanged();
|
||||
}
|
||||
|
||||
function getActiveNoteContent() {
|
||||
return getActiveTabContext().getComponent().getContent();
|
||||
}
|
||||
|
||||
function onNoteChange(func) {
|
||||
return getActiveTabContext().getComponent().onNoteChange(func);
|
||||
}
|
||||
@ -115,17 +93,40 @@ function getActiveTabContext() {
|
||||
return tabContexts.find(tc => tc.tabId === tabId);
|
||||
}
|
||||
|
||||
function isActive(tabContext) {
|
||||
return tabContext.$tab[0] === tabRow.activateTab;
|
||||
/** @return {NoteFull} */
|
||||
function getActiveNote() {
|
||||
const activeContext = getActiveTabContext();
|
||||
return activeContext ? activeContext.note : null;
|
||||
}
|
||||
|
||||
async function activateTabContext(tabContext) {
|
||||
await tabRow.activateTab(tabContext.$tab[0]);
|
||||
function getActiveNoteId() {
|
||||
const activeNote = getActiveNote();
|
||||
|
||||
return activeNote ? activeNote.noteId : null;
|
||||
}
|
||||
|
||||
/** @returns {TabContext} */
|
||||
function getTabContext(tabId) {
|
||||
return tabContexts.find(tc => tc.tabId === tabId);
|
||||
function getActiveNoteType() {
|
||||
const activeNote = getActiveNote();
|
||||
|
||||
return activeNote ? activeNote.type : null;
|
||||
}
|
||||
|
||||
async function switchToTab(tabId, notePath) {
|
||||
const tabContext = tabContexts.find(tc => tc.tabId === tabId);
|
||||
|
||||
if (!tabContext) {
|
||||
await loadNoteDetail(notePath, {
|
||||
newTab: true,
|
||||
tabId: tabId,
|
||||
activate: true
|
||||
});
|
||||
} else {
|
||||
await tabContext.activate();
|
||||
|
||||
if (notePath && tabContext.notePath !== notePath) {
|
||||
await loadNoteDetail(notePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function showTab(tabId) {
|
||||
@ -348,7 +349,13 @@ $tabContentsContainer.on("dragover", e => e.preventDefault());
|
||||
$tabContentsContainer.on("dragleave", e => e.preventDefault());
|
||||
|
||||
$tabContentsContainer.on("drop", e => {
|
||||
importDialog.uploadFiles(getActiveNoteId(), e.originalEvent.dataTransfer.files, {
|
||||
const activeNote = getActiveNote();
|
||||
|
||||
if (!activeNote) {
|
||||
return;
|
||||
}
|
||||
|
||||
importDialog.uploadFiles(activeNote.noteId, e.originalEvent.dataTransfer.files, {
|
||||
safeImport: true,
|
||||
shrinkImages: true,
|
||||
textImportedAsText: true,
|
||||
@ -502,7 +509,6 @@ export default {
|
||||
loadNote,
|
||||
loadNoteDetail,
|
||||
getActiveNote,
|
||||
getActiveNoteContent,
|
||||
getActiveNoteType,
|
||||
getActiveNoteId,
|
||||
focusOnTitle,
|
||||
@ -510,12 +516,10 @@ export default {
|
||||
saveNotesIfChanged,
|
||||
onNoteChange,
|
||||
addDetailLoadedListener,
|
||||
getTabContext,
|
||||
switchToTab,
|
||||
getTabContexts,
|
||||
getActiveTabContext,
|
||||
getActiveEditor,
|
||||
isActive,
|
||||
activateTabContext,
|
||||
clearOpenTabsTask,
|
||||
filterTabs,
|
||||
openEmptyTab,
|
||||
|
@ -65,7 +65,7 @@ class NoteDetailImage {
|
||||
|
||||
getFileUrl() {
|
||||
// electron needs absolute URL so we extract current host, port, protocol
|
||||
return utils.getHost() + "/api/notes/" + noteDetailService.getActiveNoteId() + "/download";
|
||||
return utils.getHost() + `/api/notes/${this.ctx.note.noteId}/download`;
|
||||
}
|
||||
|
||||
getContent() {}
|
||||
|
@ -114,7 +114,7 @@ function NoteTypeContext(ctx) {
|
||||
}
|
||||
|
||||
function confirmChangeIfContent() {
|
||||
if (!noteDetailService.getActiveNoteContent()) {
|
||||
if (!self.ctx.getComponent().getContent()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ async function enterProtectedSessionOnServer(password) {
|
||||
}
|
||||
|
||||
async function protectNoteAndSendToServer() {
|
||||
if (noteDetailService.getActiveNote().isProtected) {
|
||||
if (!noteDetailService.getActiveNote() || noteDetailService.getActiveNote().isProtected) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -192,13 +192,17 @@ class TabContext {
|
||||
return this.components[type];
|
||||
}
|
||||
|
||||
async activate() {
|
||||
await this.tabRow.activateTab(this.$tab[0]);
|
||||
}
|
||||
|
||||
async saveNote() {
|
||||
if (this.note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.note.title = this.$noteTitle.val();
|
||||
this.note.content = noteDetailService.getActiveNoteContent();
|
||||
this.note.content = this.getComponent().getContent();
|
||||
|
||||
// it's important to set the flag back to false immediatelly after retrieving title and content
|
||||
// otherwise we might overwrite another change (especially async code)
|
||||
|
File diff suppressed because one or more lines are too long
@ -791,24 +791,7 @@ $(window).bind('hashchange', async function() {
|
||||
|
||||
console.debug(`Switching to ${notePath} on tab ${tabId} because of hash change`);
|
||||
|
||||
let tabContext = noteDetailService.getTabContext(tabId);
|
||||
|
||||
if (!tabContext) {
|
||||
noteDetailService.loadNoteDetail(notePath, {
|
||||
newTab: true,
|
||||
tabId: tabId,
|
||||
activate: true
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (!noteDetailService.isActive(tabContext)) {
|
||||
noteDetailService.activateTabContext(tabContext);
|
||||
}
|
||||
|
||||
if (notePath && tabContext.notePath !== notePath) {
|
||||
noteDetailService.loadNoteDetail(notePath);
|
||||
}
|
||||
}
|
||||
noteDetailService.switchToTab(tabId, notePath);
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user