mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 15:25:51 +01:00
basic text preview implemented
This commit is contained in:
@@ -6,6 +6,7 @@ const RecentNote = require('../entities/recent_note');
|
||||
const ApiToken = require('../entities/api_token');
|
||||
const Option = require('../entities/option');
|
||||
const repository = require('../services/repository');
|
||||
const cls = require('./cls');
|
||||
|
||||
const ENTITY_NAME_TO_ENTITY = {
|
||||
"attributes": Attribute,
|
||||
@@ -32,9 +33,13 @@ function createEntityFromRow(row) {
|
||||
|
||||
if (row.attributeId) {
|
||||
entity = new Attribute(row);
|
||||
|
||||
cls.setEntityToCache('attributes', row.attributeId, entity);
|
||||
}
|
||||
else if (row.noteRevisionId) {
|
||||
entity = new NoteRevision(row);
|
||||
|
||||
cls.setEntityToCache('note_revisions', row.noteRevisionId, entity);
|
||||
}
|
||||
else if (row.branchId && row.notePath) {
|
||||
entity = new RecentNote(row);
|
||||
@@ -44,9 +49,13 @@ function createEntityFromRow(row) {
|
||||
}
|
||||
else if (row.branchId) {
|
||||
entity = new Branch(row);
|
||||
|
||||
cls.setEntityToCache('branches', row.branchId, entity);
|
||||
}
|
||||
else if (row.noteId) {
|
||||
entity = new Note(row);
|
||||
|
||||
cls.setEntityToCache('notes', row.noteId, entity);
|
||||
}
|
||||
else if (row.name) {
|
||||
entity = new Option(row);
|
||||
|
||||
@@ -57,6 +57,7 @@ class TabContext extends Component {
|
||||
this.noteId = noteId;
|
||||
|
||||
this.autoBookDisabled = false;
|
||||
this.textPreviewDisabled = false;
|
||||
|
||||
setTimeout(async () => {
|
||||
// we include the note into recent list only if the user stayed on the note at least 5 seconds
|
||||
|
||||
@@ -18,6 +18,7 @@ import appContext from "../services/app_context.js";
|
||||
import keyboardActionsService from "../services/keyboard_actions.js";
|
||||
import noteCreateService from "../services/note_create.js";
|
||||
import DeletedTypeWidget from "./type_widgets/deleted.js";
|
||||
import TextPreviewTypeWidget from "./type_widgets/text_preview.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="note-detail">
|
||||
@@ -36,6 +37,7 @@ const typeWidgetClasses = {
|
||||
'empty': EmptyTypeWidget,
|
||||
'deleted': DeletedTypeWidget,
|
||||
'text': TextTypeWidget,
|
||||
'text-preview': TextPreviewTypeWidget,
|
||||
'code': CodeTypeWidget,
|
||||
'file': FileTypeWidget,
|
||||
'image': ImageTypeWidget,
|
||||
@@ -176,6 +178,14 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
}
|
||||
}
|
||||
|
||||
if (type === 'text' && !this.tabContext.textPreviewDisabled) {
|
||||
const noteComplement = await this.tabContext.getNoteComplement();
|
||||
|
||||
if (noteComplement.content && noteComplement.content.length > 10000) {
|
||||
type = 'text-preview';
|
||||
}
|
||||
}
|
||||
|
||||
if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) {
|
||||
type = 'protected-session';
|
||||
}
|
||||
@@ -252,6 +262,12 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
||||
}
|
||||
}
|
||||
|
||||
textPreviewDisabledEvent({tabContext}) {
|
||||
if (this.isTab(tabContext.tabId)) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
async cutIntoNoteCommand() {
|
||||
const note = appContext.tabManager.getActiveTabNote();
|
||||
|
||||
|
||||
80
src/public/javascripts/widgets/type_widgets/text_preview.js
Normal file
80
src/public/javascripts/widgets/type_widgets/text_preview.js
Normal file
@@ -0,0 +1,80 @@
|
||||
import TypeWidget from "./type_widget.js";
|
||||
import appContext from "../../services/app_context.js";
|
||||
import treeCache from "../../services/tree_cache.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="note-detail-text-preview note-detail-printable">
|
||||
<style>
|
||||
.note-detail-text-preview h1 { font-size: 2.0em; }
|
||||
.note-detail-text-preview h2 { font-size: 1.8em; }
|
||||
.note-detail-text-preview h3 { font-size: 1.6em; }
|
||||
.note-detail-text-preview h4 { font-size: 1.4em; }
|
||||
.note-detail-text-preview h5 { font-size: 1.2em; }
|
||||
.note-detail-text-preview h6 { font-size: 1.1em; }
|
||||
|
||||
.note-detail-text-preview {
|
||||
overflow: auto;
|
||||
height: 100%;
|
||||
padding: 10px;
|
||||
font-family: var(--detail-text-font-family);
|
||||
}
|
||||
|
||||
.note-detail-text-preview p:first-child, .note-detail-text::before {
|
||||
margin-top: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="alert alert-warning" title="This note is long so for performance reasons only text preview is shown by default.">
|
||||
Text preview is shown. <a href="#" class="edit-note">Click here</a> to edit the note.
|
||||
</div>
|
||||
|
||||
<div class="note-detail-text-preview-content"></div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class TextPreviewTypeWidget extends TypeWidget {
|
||||
static getType() { return "text-preview"; }
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.$content = this.$widget.find('.note-detail-text-preview-content');
|
||||
|
||||
this.$widget.on("dblclick", "img", e => {
|
||||
const $img = $(e.target);
|
||||
const src = $img.prop("src");
|
||||
|
||||
const match = src.match(/\/api\/images\/([A-Za-z0-9]+)\//);
|
||||
|
||||
if (match) {
|
||||
const noteId = match[1];
|
||||
|
||||
appContext.tabManager.getActiveTabContext().setNote(noteId);
|
||||
}
|
||||
else {
|
||||
window.open(src, '_blank');
|
||||
}
|
||||
});
|
||||
|
||||
this.$widget.find('a.edit-note').on('click', () => {
|
||||
this.tabContext.textPreviewDisabled = true;
|
||||
|
||||
this.triggerEvent('textPreviewDisabled', {tabContext: this.tabContext});
|
||||
});
|
||||
|
||||
return this.$widget;
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
this.$content.html('');
|
||||
}
|
||||
|
||||
scrollToTop() {
|
||||
this.$content.scrollTop(0);
|
||||
}
|
||||
|
||||
async doRefresh(note) {
|
||||
const noteComplement = await treeCache.getNoteComplement(note.noteId);
|
||||
|
||||
this.$content.html(noteComplement.content);
|
||||
}
|
||||
}
|
||||
@@ -42,4 +42,10 @@ export default class TypeWidget extends TabAwareWidget {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
textPreviewDisabledEvent({tabContext}) {
|
||||
if (this.isTab(tabContext.tabId)) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -544,22 +544,18 @@ async function deleteBranch(branch, deleteId, taskContext) {
|
||||
note.deleteId = deleteId;
|
||||
await note.save();
|
||||
|
||||
console.log("Deleting note", note.noteId);
|
||||
log.info("Deleting note " + note.noteId);
|
||||
|
||||
for (const attribute of await note.getOwnedAttributes()) {
|
||||
attribute.isDeleted = true;
|
||||
attribute.deleteId = deleteId;
|
||||
await attribute.save();
|
||||
|
||||
console.log("Deleting note's", note.noteId, "attribute", attribute.attributeId);
|
||||
}
|
||||
|
||||
for (const relation of await note.getTargetRelations()) {
|
||||
relation.isDeleted = true;
|
||||
relation.deleteId = deleteId;
|
||||
await relation.save();
|
||||
|
||||
console.log("Deleting note's", note.noteId, "target relation", relation.attributeId);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user