trim content for grid view

This commit is contained in:
zadam 2020-10-25 11:00:27 +01:00
parent 4202af96c8
commit 37e111d8a9
2 changed files with 19 additions and 4 deletions

View File

@ -4,7 +4,11 @@ import renderService from "./render.js";
import protectedSessionService from "./protected_session.js";
import protectedSessionHolder from "./protected_session_holder.js";
async function getRenderedContent(note) {
async function getRenderedContent(note, options = {}) {
options = Object.assign({
trim: false
}, options);
const type = getRenderingType(note);
let $rendered;
@ -12,12 +16,12 @@ async function getRenderedContent(note) {
if (type === 'text') {
const fullNote = await server.get('notes/' + note.noteId);
$rendered = $('<div class="ck-content">').html(fullNote.content);
$rendered = $('<div class="ck-content">').html(trim(fullNote.content, options.trim));
}
else if (type === 'code') {
const fullNote = await server.get('notes/' + note.noteId);
$rendered = $("<pre>").text(fullNote.content);
$rendered = $("<pre>").text(trim(fullNote.content, options.trim));
}
else if (type === 'image') {
$rendered = $("<img>")
@ -89,6 +93,15 @@ async function getRenderedContent(note) {
};
}
function trim(text, doTrim) {
if (!doTrim) {
return text;
}
else {
return text.substr(0, Math.min(text.length, 1000));
}
}
function getRenderingType(note) {
let type = note.type;

View File

@ -300,7 +300,9 @@ class NoteListRenderer {
const $content = $('<div class="note-book-content">');
try {
const {renderedContent, type} = await noteContentRenderer.getRenderedContent(note);
const {renderedContent, type} = await noteContentRenderer.getRenderedContent(note, {
trim: this.viewType === 'grid' // for grid only short content is needed
});
$content.append(renderedContent);
$content.addClass("type-" + type);