mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
abstracted note detail components
This commit is contained in:
parent
000cf99546
commit
913b6bb6f6
@ -31,6 +31,23 @@ let noteChangeDisabled = false;
|
|||||||
|
|
||||||
let isNoteChanged = false;
|
let isNoteChanged = false;
|
||||||
|
|
||||||
|
const components = {
|
||||||
|
'code': noteDetailCode,
|
||||||
|
'text': noteDetailText,
|
||||||
|
'file': noteDetailAttachment,
|
||||||
|
'search': noteDetailSearch,
|
||||||
|
'render': noteDetailRender
|
||||||
|
};
|
||||||
|
|
||||||
|
function getComponent(type) {
|
||||||
|
if (components[type]) {
|
||||||
|
return components[type];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
infoService.throwError("Unrecognized type: " + type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getCurrentNote() {
|
function getCurrentNote() {
|
||||||
return currentNote;
|
return currentNote;
|
||||||
}
|
}
|
||||||
@ -84,23 +101,8 @@ async function saveNoteIfChanged() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateNoteFromInputs(note) {
|
function updateNoteFromInputs(note) {
|
||||||
if (note.type === 'text') {
|
|
||||||
note.content = noteDetailText.getContent();
|
|
||||||
}
|
|
||||||
else if (note.type === 'code') {
|
|
||||||
note.content = noteDetailCode.getContent();
|
|
||||||
}
|
|
||||||
else if (note.type === 'search') {
|
|
||||||
note.content = noteDetailSearch.getContent();
|
|
||||||
}
|
|
||||||
else if (note.type === 'render') {
|
|
||||||
// nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
infoService.throwError("Unrecognized type: " + note.type);
|
|
||||||
}
|
|
||||||
|
|
||||||
note.title = $noteTitle.val();
|
note.title = $noteTitle.val();
|
||||||
|
note.content = getComponent(note.type).getContent();
|
||||||
|
|
||||||
treeService.setNoteTitle(note.noteId, note.title);
|
treeService.setNoteTitle(note.noteId, note.title);
|
||||||
}
|
}
|
||||||
@ -164,21 +166,7 @@ async function loadNoteToEditor(noteId) {
|
|||||||
|
|
||||||
$noteDetailComponents.hide();
|
$noteDetailComponents.hide();
|
||||||
|
|
||||||
if (currentNote.type === 'render') {
|
await getComponent(currentNote.type).show();
|
||||||
await noteDetailRender.showRenderNote();
|
|
||||||
}
|
|
||||||
else if (currentNote.type === 'file') {
|
|
||||||
await noteDetailAttachment.showFileNote();
|
|
||||||
}
|
|
||||||
else if (currentNote.type === 'text') {
|
|
||||||
await noteDetailText.showTextNote();
|
|
||||||
}
|
|
||||||
else if (currentNote.type === 'code') {
|
|
||||||
await noteDetailCode.showCodeNote();
|
|
||||||
}
|
|
||||||
else if (currentNote.type === 'search') {
|
|
||||||
noteDetailSearch.showSearchNote();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
noteChangeDisabled = false;
|
noteChangeDisabled = false;
|
||||||
@ -221,18 +209,7 @@ async function loadNote(noteId) {
|
|||||||
function focus() {
|
function focus() {
|
||||||
const note = getCurrentNote();
|
const note = getCurrentNote();
|
||||||
|
|
||||||
if (note.type === 'text') {
|
getComponent(note.type).focus();
|
||||||
noteDetailText.focus();
|
|
||||||
}
|
|
||||||
else if (note.type === 'code') {
|
|
||||||
noteDetailCode.focus();
|
|
||||||
}
|
|
||||||
else if (note.type === 'render' || note.type === 'file' || note.type === 'search') {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
infoService.throwError('Unrecognized type: ' + note.type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
messagingService.subscribeToMessages(syncData => {
|
messagingService.subscribeToMessages(syncData => {
|
||||||
|
@ -11,7 +11,7 @@ const $attachmentFileSize = $("#attachment-filesize");
|
|||||||
const $attachmentDownload = $("#attachment-download");
|
const $attachmentDownload = $("#attachment-download");
|
||||||
const $attachmentOpen = $("#attachment-open");
|
const $attachmentOpen = $("#attachment-open");
|
||||||
|
|
||||||
async function showFileNote() {
|
async function show() {
|
||||||
const currentNote = noteDetailService.getCurrentNote();
|
const currentNote = noteDetailService.getCurrentNote();
|
||||||
|
|
||||||
const labels = await server.get('notes/' + currentNote.noteId + '/labels');
|
const labels = await server.get('notes/' + currentNote.noteId + '/labels');
|
||||||
@ -44,7 +44,7 @@ function getAttachmentUrl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
showFileNote,
|
show,
|
||||||
getContent: () => null,
|
getContent: () => null,
|
||||||
focus: () => null
|
focus: () => null
|
||||||
}
|
}
|
@ -9,7 +9,7 @@ let codeEditor = null;
|
|||||||
const $noteDetailCode = $('#note-detail-code');
|
const $noteDetailCode = $('#note-detail-code');
|
||||||
const $executeScriptButton = $("#execute-script-button");
|
const $executeScriptButton = $("#execute-script-button");
|
||||||
|
|
||||||
async function showCodeNote() {
|
async function show() {
|
||||||
if (!codeEditor) {
|
if (!codeEditor) {
|
||||||
await utils.requireLibrary(utils.CODE_MIRROR);
|
await utils.requireLibrary(utils.CODE_MIRROR);
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ $(document).bind('keydown', "ctrl+return", executeCurrentNote);
|
|||||||
$executeScriptButton.click(executeCurrentNote);
|
$executeScriptButton.click(executeCurrentNote);
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
showCodeNote,
|
show,
|
||||||
getContent,
|
getContent,
|
||||||
focus
|
focus
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ import noteDetailService from "./note_detail.js";
|
|||||||
|
|
||||||
const $noteDetailRender = $('#note-detail-render');
|
const $noteDetailRender = $('#note-detail-render');
|
||||||
|
|
||||||
async function showRenderNote() {
|
async function show() {
|
||||||
$noteDetailRender.show();
|
$noteDetailRender.show();
|
||||||
|
|
||||||
const bundle = await server.get('script/bundle/' + noteDetailService.getCurrentNoteId());
|
const bundle = await server.get('script/bundle/' + noteDetailService.getCurrentNoteId());
|
||||||
@ -15,7 +15,7 @@ async function showRenderNote() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
showRenderNote,
|
show,
|
||||||
getContent: () => null,
|
getContent: () => null,
|
||||||
focus: () => null
|
focus: () => null
|
||||||
}
|
}
|
@ -9,7 +9,7 @@ function getContent() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showSearchNote() {
|
function show() {
|
||||||
$noteDetailSearch.show();
|
$noteDetailSearch.show();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -27,6 +27,6 @@ function showSearchNote() {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
getContent,
|
getContent,
|
||||||
showSearchNote,
|
show,
|
||||||
focus: () => null
|
focus: () => null
|
||||||
}
|
}
|
@ -5,7 +5,7 @@ const $noteDetailText = $('#note-detail-text');
|
|||||||
|
|
||||||
let textEditor = null;
|
let textEditor = null;
|
||||||
|
|
||||||
async function showTextNote() {
|
async function show() {
|
||||||
if (!textEditor) {
|
if (!textEditor) {
|
||||||
await utils.requireLibrary(utils.CKEDITOR);
|
await utils.requireLibrary(utils.CKEDITOR);
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ function getEditor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
showTextNote,
|
show,
|
||||||
getEditor,
|
getEditor,
|
||||||
getContent,
|
getContent,
|
||||||
focus
|
focus
|
||||||
|
@ -69,7 +69,12 @@ async function ajax(url, method, data) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
|
try {
|
||||||
options.data = JSON.stringify(data);
|
options.data = JSON.stringify(data);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log("Can't stringify data: ", data, " because of error: ", e)
|
||||||
|
}
|
||||||
options.contentType = "application/json";
|
options.contentType = "application/json";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user